[Mono-docs-list] Re: [Mono-dev] [PATCH] Monodoc. Workaround for a bug and index improvements

2005-09-19 Thread James Willcox
Mario,

I'd like to try the patch, but it seems you forgot to attach it :)

On Fri, 2005-09-16 at 16:36 +0200, Mario Sopena wrote:
 Hello,
 
 We have a problem in Monodoc when showing big html code with
 gecko. Monodoc hangs and do nothing (try to load the Gtk Namespace).
 This is due to a bug in gtkmozembed
 (https://bugzilla.mozilla.org/show_bug.cgi?id=245960). The workaround
 I've implemented writes the html on disk and loads the file from it,
 when the html code is big enough. The file is being writen to a temp
 directory.
 The only thing I'm not sure is whether I should myself delete what I
 write there or if I can just leave that for the system (for the
 moment, nothing is removed).
 
 The other thing that comes with this patch is a user-feature requested
 by miguel. The index and the search_index require those index to be
 create prior to use them. Right now, if they don't exist, a label is
 showed telling you that you have to run a command in root to create
 them.
 With this patch, monodoc looks for the index also in the user dir, and
 when it doesn't find them, it shows a panel with a progress bar that
 lets you make them at that time. The index are created in another
 Thread, so you can use monodoc while making them (specially the search
 index is slow, well, around a minute in my machine).
 To try the patch, remove your monodoc.index file and search_index dir
 from the monodoc directory and run the patched monodoc.
 
 Hope you all enjoy it. Comments please?!?
 
 Mario
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list
 

___
Mono-docs-list maillist  -  Mono-docs-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-docs-list


[Mono-docs-list] Re: [Mono-dev] [PATCH] Monodoc. Workaround for a bug and index improvements

2005-09-19 Thread Mario Sopena
Hey

2005/9/18, James Willcox [EMAIL PROTECTED]:
 Mario,
 
 I'd like to try the patch, but it seems you forgot to attach it :)
 

wps, I'm sorry. :-P

 On Fri, 2005-09-16 at 16:36 +0200, Mario Sopena wrote:
  Hello,
 
  We have a problem in Monodoc when showing big html code with
  gecko. Monodoc hangs and do nothing (try to load the Gtk Namespace).
  This is due to a bug in gtkmozembed
  (https://bugzilla.mozilla.org/show_bug.cgi?id=245960). The workaround
  I've implemented writes the html on disk and loads the file from it,
  when the html code is big enough. The file is being writen to a temp
  directory.
  The only thing I'm not sure is whether I should myself delete what I
  write there or if I can just leave that for the system (for the
  moment, nothing is removed).
 
  The other thing that comes with this patch is a user-feature requested
  by miguel. The index and the search_index require those index to be
  create prior to use them. Right now, if they don't exist, a label is
  showed telling you that you have to run a command in root to create
  them.
  With this patch, monodoc looks for the index also in the user dir, and
  when it doesn't find them, it shows a panel with a progress bar that
  lets you make them at that time. The index are created in another
  Thread, so you can use monodoc while making them (specially the search
  index is slow, well, around a minute in my machine).
  To try the patch, remove your monodoc.index file and search_index dir
  from the monodoc directory and run the patched monodoc.
 
  Hope you all enjoy it. Comments please?!?
 
  Mario
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 

Index: engine/provider.cs
===
--- engine/provider.cs	(revision 49928)
+++ engine/provider.cs	(working copy)
@@ -1261,7 +1261,14 @@
 	
 	public IndexReader GetIndex ()
 	{
-		return IndexReader.Load (Path.Combine (basedir, monodoc.index));
+		//try to load from basedir
+		string index_file = Path.Combine (basedir, monodoc.index);
+		if (File.Exists (index_file))
+			return IndexReader.Load (index_file);
+		//then, try to load from config dir
+		index_file = Path.Combine (SettingsHandler.Path, monodoc.index);
+		return IndexReader.Load (index_file);
+		
 	}
 
 	public static void MakeIndex ()
@@ -1276,17 +1283,35 @@
 			hs.PopulateIndex (index_maker);
 		}
 
-		index_maker.Save (Path.Combine (root.basedir, monodoc.index));
+		// if the user has no write permissions use config dir
+		string path = Path.Combine (root.basedir, monodoc.index);
+		try {
+			index_maker.Save (path);
+		} catch (System.UnauthorizedAccessException) {
+			path = Path.Combine (SettingsHandler.Path, monodoc.index);
+			try {
+index_maker.Save (path);
+			} catch (System.UnauthorizedAccessException) {
+Console.WriteLine (Unable to write index file in {0}, Path.Combine (SettingsHandler.Path, monodoc.index)); 
+return;
+			}
+		}
 
 		// No octal in C#, how lame is that
-		chmod (Path.Combine (root.basedir, monodoc.index), 0x1a4);
+		chmod (path, 0x1a4);
 		Console.WriteLine (Documentation index updated);
 	}
 	
 	// Search Index
 	public SearchableIndex GetSearchIndex ()
 	{
-		return SearchableIndex.Load (Path.Combine (basedir, search_index));
+		//try to load from basedir
+		string index_file = Path.Combine (basedir, search_index);
+		if (Directory.Exists (index_file))
+			return SearchableIndex.Load (index_file);
+		//then, try to load from config dir
+		index_file = Path.Combine (SettingsHandler.Path, search_index);
+		return SearchableIndex.Load (index_file);
 	}
 
 	public static void MakeSearchIndex ()
@@ -1306,8 +1331,17 @@
 
 			writer = new IndexWriter(Lucene.Net.Store.FSDirectory.GetDirectory(dir, true), new StandardAnalyzer(), true);
 		} catch (UnauthorizedAccessException) {
-			Console.WriteLine (You don't have permissions to wirte on  + dir);
-			return;
+			//try in the .config directory
+			try {
+dir = Path.Combine (SettingsHandler.Path, search_index);
+if (!Directory.Exists (dir)) 
+	Directory.CreateDirectory (dir);
+
+writer = new IndexWriter(Lucene.Net.Store.FSDirectory.GetDirectory(dir, true), new StandardAnalyzer(), true);
+			} catch (UnauthorizedAccessException) {
+Console.WriteLine (You don't have permissions to write on  + dir);
+return;
+			}
 		}
 
 		//Collect all the documents
Index: engine/index.cs
===
--- engine/index.cs	(revision 49928)
+++ engine/index.cs	(working copy)
@@ -251,9 +251,6 @@
 	{
 		Encoding utf8 = new UTF8Encoding (false, true);
 
-		// If the user doesn't have write access to the path then an
-		// exception will be thrown
-		try {	
 			using (FileStream fs = File.OpenWrite (filename)){
 BinaryWriter writer = 
 		new BinaryWriter (fs, utf8);
@@ -274,10 +271,6