Author: lluis
Date: 2006-12-17 12:31:52 -0500 (Sun, 17 Dec 2006)
New Revision: 69608

Added:
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileEventArgs.cs
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
Removed:
   
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileUtilityService.cs
Modified:
   trunk/monodevelop/Core/src/MonoDevelop.Core/ChangeLog
   trunk/monodevelop/Core/src/MonoDevelop.Core/Makefile.am
   
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns.Setup/SetupService.cs
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns/AddIn.cs
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.addin.xml
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.mdp
   trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs
   
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs
Log:
* MonoDevelop.Core.AddIns/AddIn.cs,
  MonoDevelop.Core.AddIns.Setup/SetupService.cs: Track changes in
  FileService API.
* Makefile.am, MonoDevelop.Core/FileEventArgs.cs: Moved from
  MonoDevelop.Core.Gui.
* MonoDevelop.Core.addin.xml: Registered new extension point for file
  system extensions.
* MonoDevelop.Core.mdp: Updated.
* MonoDevelop.Core/Runtime.cs: Added FileService.
* MonoDevelop.Core/FileUtilityService.cs: Merged with FileService.
* MonoDevelop.Core/ServiceManager.cs: Added null check.
* MonoDevelop.Core/FileService.cs: Moved from MonoDevelop.Core.Gui and
  added some new features. It is now possible to register extensions
  which can hook into the file operations such as Copy or Move.

Modified: trunk/monodevelop/Core/src/MonoDevelop.Core/ChangeLog
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/ChangeLog       2006-12-17 
17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/ChangeLog       2006-12-17 
17:31:52 UTC (rev 69608)
@@ -1,3 +1,20 @@
+2006-12-17  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.Core.AddIns/AddIn.cs,
+         MonoDevelop.Core.AddIns.Setup/SetupService.cs: Track changes in
+         FileService API.
+       * Makefile.am, MonoDevelop.Core/FileEventArgs.cs: Moved from
+         MonoDevelop.Core.Gui.
+       * MonoDevelop.Core.addin.xml: Registered new extension point for file
+         system extensions.
+       * MonoDevelop.Core.mdp: Updated.
+       * MonoDevelop.Core/Runtime.cs: Added FileService.
+       * MonoDevelop.Core/FileUtilityService.cs: Merged with FileService.
+       * MonoDevelop.Core/ServiceManager.cs: Added null check.
+       * MonoDevelop.Core/FileService.cs: Moved from MonoDevelop.Core.Gui and
+         added some new features. It is now possible to register extensions
+         which can hook into the file operations such as Copy or Move.
+
 2006-12-11  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
 
        * MonoDevelop.Core.AddIns/AddInService.cs: In

Modified: trunk/monodevelop/Core/src/MonoDevelop.Core/Makefile.am
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/Makefile.am     2006-12-17 
17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/Makefile.am     2006-12-17 
17:31:52 UTC (rev 69608)
@@ -4,7 +4,8 @@
 FILES= \
 MonoDevelop.Core/AbstractService.cs \
 MonoDevelop.Core/ClrVersion.cs \
-MonoDevelop.Core/FileUtilityService.cs \
+MonoDevelop.Core/FileService.cs \
+MonoDevelop.Core/FileEventArgs.cs \
 MonoDevelop.Core/IService.cs \
 MonoDevelop.Core/IStringTagProvider.cs \
 MonoDevelop.Core/PropertyService.cs \
@@ -127,6 +128,8 @@
 MonoDevelop.Core.Execution/MintPlatformExecutionHandler.cs \
 MonoDevelop.Core.Execution/MonoPlatformExecutionHandler.cs \
 MonoDevelop.Core.Execution/NativePlatformExecutionHandler.cs \
+MonoDevelop.Core.FileSystem/DefaultFileSystemExtension.cs \
+MonoDevelop.Core.FileSystem/FileSystemExtension.cs \
 MonoDevelop.Core.AddIns/ExecutionHandlerCodon.cs \
 MonoDevelop.Core.ProgressMonitoring/AggregatedOperationMonitor.cs \
 MonoDevelop.Core.ProgressMonitoring/SynchronizedProgressMonitor.cs

Added: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileEventArgs.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileEventArgs.cs   
    2006-12-17 17:19:57 UTC (rev 69607)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileEventArgs.cs   
    2006-12-17 17:31:52 UTC (rev 69608)
@@ -0,0 +1,60 @@
+// <file>
+//     <copyright see="prj:///doc/copyright.txt"/>
+//     <license see="prj:///doc/license.txt"/>
+//     <owner name="Mike Krüger" email="[EMAIL PROTECTED]"/>
+//     <version value="$version"/>
+// </file>
+
+using System;
+
+namespace MonoDevelop.Core
+{
+       public delegate void FileEventHandler(object sender, FileEventArgs e);
+       
+       public class FileEventArgs : EventArgs
+       {
+               string fileName   = null;
+               string sourceFile = null;
+               string targetFile = null;
+               
+               bool   isDirectory;
+               
+               public string FileName {
+                       get {
+                               return fileName;
+                       }
+               }
+               
+               public string SourceFile {
+                       get {
+                               return sourceFile;
+                       }
+               }
+               
+               public string TargetFile {
+                       get {
+                               return targetFile;
+                       }
+               }
+               
+               
+               public bool IsDirectory {
+                       get {
+                               return isDirectory;
+                       }
+               }
+               
+               public FileEventArgs(string fileName, bool isDirectory)
+               {
+                       this.fileName = fileName;
+                       this.isDirectory = isDirectory;
+               }
+               
+               public FileEventArgs(string sourceFile, string targetFile, bool 
isDirectory)
+               {
+                       this.sourceFile = sourceFile;
+                       this.targetFile = targetFile;
+                       this.isDirectory = isDirectory;
+               }
+       }
+}

Added: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileService.cs 
2006-12-17 17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileService.cs 
2006-12-17 17:31:52 UTC (rev 69608)
@@ -0,0 +1,383 @@
+// <file>
+//     <copyright see="prj:///doc/copyright.txt"/>
+//     <license see="prj:///doc/license.txt"/>
+//     <owner name="Mike Krüger" email="[EMAIL PROTECTED]"/>
+//     <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Diagnostics;
+using System.IO;
+using System.Xml;
+
+using MonoDevelop.Core.AddIns;
+using MonoDevelop.Core.FileSystem;
+
+namespace MonoDevelop.Core
+{
+       public class FileService
+       {
+               FileServiceErrorHandler errorHandler;
+               const string FileSystemExtensionPath = 
"/Workspace/FileSystemExtensions";
+               
+               FileSystemExtension fileSystemChain;
+               FileSystemExtension defaultExtension = new 
DefaultFileSystemExtension ();
+               
+               readonly static char[] separators = { 
Path.DirectorySeparatorChar, Path.VolumeSeparatorChar, 
Path.AltDirectorySeparatorChar };
+               string sharpDevelopRootPath;
+               
+               public FileService()
+               {
+                       sharpDevelopRootPath = 
PropertyService.EntryAssemblyDirectory + Path.DirectorySeparatorChar + "..";
+                       Runtime.AddInService.ExtensionChanged += delegate 
(string path) {
+                               if (path == FileSystemExtensionPath)
+                                       UpdateExtensions ();
+                       };
+               }
+               
+               void UpdateExtensions ()
+               {
+                       if (!Runtime.Initialized) {
+                               fileSystemChain = defaultExtension;
+                               return;
+                       }
+                       
+                       FileSystemExtension[] extensions = 
(FileSystemExtension[]) Runtime.AddInService.GetTreeItems 
(FileSystemExtensionPath, typeof(FileSystemExtension));
+                       for (int n=0; n<extensions.Length - 1; n++)
+                               extensions [n].Next = extensions [n + 1];
+
+                       if (extensions.Length > 0) {
+                               extensions [extensions.Length - 1].Next = 
defaultExtension;
+                               fileSystemChain = extensions [0];
+                       } else
+                               fileSystemChain = defaultExtension;
+               }
+               
+               public string SharpDevelopRootPath {
+                       get {
+                               return sharpDevelopRootPath;
+                       }
+               }
+               
+               public void DeleteFile (string fileName)
+               {
+                       try {
+                               GetFileSystemForPath (fileName, 
false).DeleteFile (fileName);
+                       } catch (Exception e) {
+                               if (!HandleError (GettextCatalog.GetString 
("Can't remove file {0}"), e))
+                                       throw;
+                               return;
+                       }
+                       OnFileRemoved (new FileEventArgs (fileName, false));
+               }
+               
+               public void DeleteDirectory (string path)
+               {
+                       try {
+                               GetFileSystemForPath (path, 
true).DeleteDirectory (path);
+                       } catch (Exception e) {
+                               if (!HandleError (String.Format 
(GettextCatalog.GetString ("Can't remove directory {0}"), path), e))
+                                       throw;
+                               return;
+                       }
+                       OnFileRemoved (new FileEventArgs (path, true));
+               }
+               
+               public void RenameFile (string filePath, string newName)
+               {
+                       if (Path.GetFileName (filePath) != newName) {
+                               string newPath = Path.Combine 
(Path.GetDirectoryName (filePath), newName);
+                               MoveFile (filePath, newPath);
+                               OnFileRenamed (new FileEventArgs (filePath, 
newPath, false));
+                       }
+               }
+               
+               public void RenameDirectory (string path, string newName)
+               {
+                       if (Path.GetFileName (path) != newName) {
+                               string newPath = Path.Combine 
(Path.GetDirectoryName (path), newName);
+                               MoveDirectory (path, newPath);
+                               OnFileRenamed (new FileEventArgs (path, 
newPath, true));
+                       }
+               }
+               
+               public void CopyFile (string sourcePath, string destPath)
+               {
+                       GetFileSystemForPath (destPath, false).CopyFile 
(sourcePath, destPath, true);
+                       OnFileCreated (new FileEventArgs (destPath, false));
+               }
+
+               public void MoveFile (string sourcePath, string destPath)
+               {
+                       FileSystemExtension srcExt = GetFileSystemForPath 
(sourcePath, false);
+                       FileSystemExtension dstExt = GetFileSystemForPath 
(destPath, false);
+                       
+                       Console.WriteLine ("SRC:" + srcExt + " " + 
srcExt.GetHashCode ());
+                       Console.WriteLine ("DST:" + dstExt + " " + 
dstExt.GetHashCode ());
+                       
+                       if (srcExt == dstExt) {
+                               // Everything can be handled by the same file 
system
+                               srcExt.MoveFile (sourcePath, destPath);
+                               OnFileCreated (new FileEventArgs (destPath, 
false));
+                               OnFileRemoved (new FileEventArgs (destPath, 
false));
+                       } else {
+                               // If the file system of the source and dest 
files are
+                               // different, decompose the Move operation into 
a Copy
+                               // and Delete, so every file system can handle 
its part
+                               dstExt.CopyFile (sourcePath, destPath, true);
+                               OnFileCreated (new FileEventArgs (destPath, 
false));
+                               srcExt.DeleteFile (sourcePath);
+                               OnFileRemoved (new FileEventArgs (destPath, 
false));
+                       }
+               }
+               
+               public void CreateDirectory (string path)
+               {
+                       GetFileSystemForPath (path, true).CreateDirectory 
(path);
+                       OnFileCreated (new FileEventArgs (path, true));
+               }
+               
+               public void CopyDirectory (string sourcePath, string destPath)
+               {
+                       GetFileSystemForPath (destPath, true).CopyDirectory 
(sourcePath, destPath);
+               }
+               
+               public void MoveDirectory (string sourcePath, string destPath)
+               {
+                       FileSystemExtension srcExt = GetFileSystemForPath 
(sourcePath, true);
+                       FileSystemExtension dstExt = GetFileSystemForPath 
(destPath, true);
+                       
+                       if (srcExt == dstExt) {
+                               // Everything can be handled by the same file 
system
+                               srcExt.MoveDirectory (sourcePath, destPath);
+                               OnFileCreated (new FileEventArgs (destPath, 
true));
+                               OnFileRemoved (new FileEventArgs (sourcePath, 
true));
+                       } else {
+                               // If the file system of the source and dest 
files are
+                               // different, decompose the Move operation into 
a Copy
+                               // and Delete, so every file system can handle 
its part
+                               dstExt.CopyDirectory (sourcePath, destPath);
+                               srcExt.DeleteDirectory (sourcePath);
+                               OnFileRemoved (new FileEventArgs (destPath, 
true));
+                       }
+               }
+               
+               public bool RequestFileEdit (string file)
+               {
+                       return GetFileSystemForPath (file, 
false).RequestFileEdit (file);
+               }
+               
+               public void NotifyFileChanged (string path)
+               {
+                       GetFileSystemForPath (path, false).NotifyFileChanged 
(path);
+                       OnFileChanged (new FileEventArgs (path, false));
+               }
+               
+               internal FileSystemExtension GetFileSystemForPath (string path, 
bool isDirectory)
+               {
+                       if (fileSystemChain == null)
+                               UpdateExtensions ();
+                       FileSystemExtension nx = fileSystemChain;
+                       while (nx != null && !nx.CanHandlePath (path, 
isDirectory))
+                               nx = nx.Next;
+                       return nx;
+               }
+               
+               
+               public StringCollection SearchDirectory(string directory, 
string filemask, bool searchSubdirectories)
+               {
+                       StringCollection collection = new StringCollection();
+                       SearchDirectory(directory, filemask, collection, 
searchSubdirectories);
+                       return collection;
+               }
+               
+               public StringCollection SearchDirectory(string directory, 
string filemask)
+               {
+                       return SearchDirectory (directory, filemask, true);
+               }
+               
+               /// <summary>
+               /// Finds all files which are valid to the mask 
<code>filemask</code> in the path
+               /// <code>directory</code> and all subdirectories (if 
searchSubdirectories
+               /// is true. The found files are added to the StringCollection 
+               /// <code>collection</code>.
+               /// </summary>
+               void SearchDirectory (string directory, string filemask, 
StringCollection collection, bool searchSubdirectories)
+               {
+                       string[] file = Directory.GetFiles(directory, filemask);
+                       foreach (string f in file) {
+                               collection.Add(f);
+                       }
+                       
+                       if (searchSubdirectories) {
+                               string[] dir = 
Directory.GetDirectories(directory);
+                               foreach (string d in dir) {
+                                       SearchDirectory(d, filemask, 
collection, searchSubdirectories);
+                               }
+                       }
+               }
+               
+               /// <summary>
+               /// Converts a given absolute path and a given base path to a 
path that leads
+               /// from the base path to the absoulte path. (as a relative 
path)
+               /// </summary>
+               public string AbsoluteToRelativePath (string baseDirectoryPath, 
string absPath)
+               {
+                       if (! Path.IsPathRooted (absPath))
+                               return absPath;
+                       
+                       absPath = Path.GetFullPath (absPath);
+                       baseDirectoryPath = Path.GetFullPath 
(baseDirectoryPath);
+                       
+                       string[] bPath = baseDirectoryPath.Split (separators);
+                       string[] aPath = absPath.Split (separators);
+                       int indx = 0;
+                       for(; indx < Math.Min(bPath.Length, aPath.Length); 
++indx){
+                               if(!bPath[indx].Equals(aPath[indx]))
+                                       break;
+                       }
+                       
+                       if (indx == 0) {
+                               return absPath;
+                       }
+                       
+                       string erg = "";
+                       
+                       if(indx == bPath.Length) {
+                               erg += "." + Path.DirectorySeparatorChar;
+                       } else {
+                               for (int i = indx; i < bPath.Length; ++i) {
+                                       erg += ".." + 
Path.DirectorySeparatorChar;
+                               }
+                       }
+                       erg += 
String.Join(Path.DirectorySeparatorChar.ToString(), aPath, indx, 
aPath.Length-indx);
+                       
+                       return erg;
+               }
+               
+               /// <summary>
+               /// Converts a given relative path and a given base path to a 
path that leads
+               /// to the relative path absoulte.
+               /// </summary>
+               public string RelativeToAbsolutePath (string baseDirectoryPath, 
string relPath)
+               {                       
+                       return Path.GetFullPath (baseDirectoryPath + 
Path.DirectorySeparatorChar + relPath);
+               }
+               
+               /// <summary>
+               /// This method checks the file fileName if it is valid.
+               /// </summary>
+               public bool IsValidFileName (string fileName)
+               {
+                       // Fixme: 260 is the hardcoded maximal length for a 
path on my Windows XP system
+                       //        I can't find a .NET property or method for 
determining this variable.
+                       if (String.IsNullOrEmpty (fileName) || fileName.Length 
>= 260) {
+                               return false;
+                       }
+                       
+                       // platform independent : check for invalid path chars
+                       foreach (char invalidChar in 
Path.GetInvalidPathChars()) {
+                               if (fileName.IndexOf(invalidChar) >= 0) {
+                                       return false;
+                               }
+                       }
+                       
+                       // platform dependend : Check for invalid file names 
(DOS)
+                       // this routine checks for follwing bad file names :
+                       // CON, PRN, AUX, NUL, COM1-9 and LPT1-9
+                       
+                       string nameWithoutExtension = 
Path.GetFileNameWithoutExtension(fileName);
+                       if (nameWithoutExtension != null) {
+                               nameWithoutExtension = 
nameWithoutExtension.ToUpper();
+                       }
+                       
+                       if (nameWithoutExtension == "CON" ||
+                           nameWithoutExtension == "PRN" ||
+                           nameWithoutExtension == "AUX" ||
+                           nameWithoutExtension == "NUL") {
+                       
+                       return false;
+                   }
+                           
+                   char ch = nameWithoutExtension.Length == 4 ? 
nameWithoutExtension[3] : '\0';
+                       
+                       return !((nameWithoutExtension.StartsWith("COM") ||
+                                 nameWithoutExtension.StartsWith("LPT")) &&
+                                 Char.IsDigit(ch));
+               }
+               
+               public bool IsDirectory (string filename)
+               {
+                       if (!Directory.Exists(filename)) {
+                               return false;
+                       }
+                       FileAttributes attr = File.GetAttributes(filename);
+                       return (attr & FileAttributes.Directory) != 0;
+               }
+               
+               /// <summary>
+               /// Returns directoryName + "\\" (Win32) when directoryname 
doesn't end with
+               /// "\\"
+               /// </summary>
+               public string GetDirectoryNameWithSeparator (string 
directoryName)
+               {
+                       if (directoryName == null) return "";
+                       
+                       if 
(directoryName.EndsWith(Path.DirectorySeparatorChar.ToString())) {
+                               return directoryName;
+                       }
+                       return directoryName + Path.DirectorySeparatorChar;
+               }
+               
+               
+               bool HandleError (string message, Exception ex)
+               {
+                       if (errorHandler != null)
+                               return errorHandler (message, ex);
+                       else
+                               return false;
+               }
+               
+               protected virtual void OnFileCreated (FileEventArgs e)
+               {
+                       if (FileCreated != null) {
+                               FileCreated (this, e);
+                       }
+               }
+               
+               protected virtual void OnFileRemoved (FileEventArgs e)
+               {
+                       if (FileRemoved != null) {
+                               FileRemoved(this, e);
+                       }
+               }
+
+               protected virtual void OnFileRenamed (FileEventArgs e)
+               {
+                       if (FileRenamed != null) {
+                               FileRenamed(this, e);
+                       }
+               }
+
+               protected virtual void OnFileChanged (FileEventArgs e)
+               {
+                       if (FileChanged != null) {
+                               FileChanged(this, e);
+                       }
+               }
+               
+               public FileServiceErrorHandler ErrorHandler {
+                       get { return errorHandler; }
+                       set { errorHandler = value; }
+               }
+
+               public event FileEventHandler FileCreated;
+               public event FileEventHandler FileRenamed;
+               public event FileEventHandler FileRemoved;
+               public event FileEventHandler FileChanged;
+       }
+       
+       public delegate bool FileServiceErrorHandler (string message, Exception 
ex);
+}

Deleted: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileUtilityService.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileUtilityService.cs
  2006-12-17 17:19:57 UTC (rev 69607)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/FileUtilityService.cs
  2006-12-17 17:31:52 UTC (rev 69608)
@@ -1,189 +0,0 @@
-// <file>
-//     <copyright see="prj:///doc/copyright.txt"/>
-//     <license see="prj:///doc/license.txt"/>
-//     <owner name="Mike Krüger" email="[EMAIL PROTECTED]"/>
-//     <version value="$version"/>
-// </file>
-
-using System;
-using System.IO;
-using System.Collections.Specialized;
-using System.Diagnostics;
-using System.Reflection;
-
-using MonoDevelop.Core;
-using MonoDevelop.Core.AddIns;
-
-namespace MonoDevelop.Core
-{
-       /// <summary>
-       /// A utility class related to file utilities.
-       /// </summary>
-       public class FileUtilityService : AbstractService
-       {
-               readonly static char[] separators = { 
Path.DirectorySeparatorChar, Path.VolumeSeparatorChar, 
Path.AltDirectorySeparatorChar };
-               //readonly static char[] dir_sep = { 
Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
-               string sharpDevelopRootPath;
-               
-               public string SharpDevelopRootPath {
-                       get {
-                               return sharpDevelopRootPath;
-                       }
-               }
-               
-               public FileUtilityService()
-               {
-                       sharpDevelopRootPath = 
PropertyService.EntryAssemblyDirectory + Path.DirectorySeparatorChar + "..";
-               }
-               
-               public override void UnloadService()
-               {
-                       base.UnloadService();
-               }
-
-               public StringCollection SearchDirectory(string directory, 
string filemask, bool searchSubdirectories)
-               {
-                       StringCollection collection = new StringCollection();
-                       SearchDirectory(directory, filemask, collection, 
searchSubdirectories);
-                       return collection;
-               }
-               
-               public StringCollection SearchDirectory(string directory, 
string filemask)
-               {
-                       return SearchDirectory(directory, filemask, true);
-               }
-               
-               /// <summary>
-               /// Finds all files which are valid to the mask 
<code>filemask</code> in the path
-               /// <code>directory</code> and all subdirectories (if 
searchSubdirectories
-               /// is true. The found files are added to the StringCollection 
-               /// <code>collection</code>.
-               /// </summary>
-               void SearchDirectory (string directory, string filemask, 
StringCollection collection, bool searchSubdirectories)
-               {
-                       string[] file = Directory.GetFiles(directory, filemask);
-                       foreach (string f in file) {
-                               collection.Add(f);
-                       }
-                       
-                       if (searchSubdirectories) {
-                               string[] dir = 
Directory.GetDirectories(directory);
-                               foreach (string d in dir) {
-                                       SearchDirectory(d, filemask, 
collection, searchSubdirectories);
-                               }
-                       }
-               }
-               
-               /// <summary>
-               /// Converts a given absolute path and a given base path to a 
path that leads
-               /// from the base path to the absoulte path. (as a relative 
path)
-               /// </summary>
-               public string AbsoluteToRelativePath(string baseDirectoryPath, 
string absPath)
-               {
-                       if (! Path.IsPathRooted (absPath))
-                               return absPath;
-                       
-                       absPath = Path.GetFullPath (absPath);
-                       baseDirectoryPath = Path.GetFullPath 
(baseDirectoryPath);
-                       
-                       string[] bPath = baseDirectoryPath.Split (separators);
-                       string[] aPath = absPath.Split (separators);
-                       int indx = 0;
-                       for(; indx < Math.Min(bPath.Length, aPath.Length); 
++indx){
-                               if(!bPath[indx].Equals(aPath[indx]))
-                                       break;
-                       }
-                       
-                       if (indx == 0) {
-                               return absPath;
-                       }
-                       
-                       string erg = "";
-                       
-                       if(indx == bPath.Length) {
-                               erg += "." + Path.DirectorySeparatorChar;
-                       } else {
-                               for (int i = indx; i < bPath.Length; ++i) {
-                                       erg += ".." + 
Path.DirectorySeparatorChar;
-                               }
-                       }
-                       erg += 
String.Join(Path.DirectorySeparatorChar.ToString(), aPath, indx, 
aPath.Length-indx);
-                       
-                       return erg;
-               }
-               
-               /// <summary>
-               /// Converts a given relative path and a given base path to a 
path that leads
-               /// to the relative path absoulte.
-               /// </summary>
-               public string RelativeToAbsolutePath(string baseDirectoryPath, 
string relPath)
-               {                       
-                       return Path.GetFullPath (baseDirectoryPath + 
Path.DirectorySeparatorChar + relPath);
-               }
-               
-               /// <summary>
-               /// This method checks the file fileName if it is valid.
-               /// </summary>
-               public bool IsValidFileName(string fileName)
-               {
-                       // Fixme: 260 is the hardcoded maximal length for a 
path on my Windows XP system
-                       //        I can't find a .NET property or method for 
determining this variable.
-                       if (String.IsNullOrEmpty (fileName) || fileName.Length 
>= 260) {
-                               return false;
-                       }
-                       
-                       // platform independent : check for invalid path chars
-                       foreach (char invalidChar in 
Path.GetInvalidPathChars()) {
-                               if (fileName.IndexOf(invalidChar) >= 0) {
-                                       return false;
-                               }
-                       }
-                       
-                       // platform dependend : Check for invalid file names 
(DOS)
-                       // this routine checks for follwing bad file names :
-                       // CON, PRN, AUX, NUL, COM1-9 and LPT1-9
-                       
-                       string nameWithoutExtension = 
Path.GetFileNameWithoutExtension(fileName);
-                       if (nameWithoutExtension != null) {
-                               nameWithoutExtension = 
nameWithoutExtension.ToUpper();
-                       }
-                       
-                       if (nameWithoutExtension == "CON" ||
-                           nameWithoutExtension == "PRN" ||
-                           nameWithoutExtension == "AUX" ||
-                           nameWithoutExtension == "NUL") {
-                       
-                       return false;
-                   }
-                           
-                   char ch = nameWithoutExtension.Length == 4 ? 
nameWithoutExtension[3] : '\0';
-                       
-                       return !((nameWithoutExtension.StartsWith("COM") ||
-                                 nameWithoutExtension.StartsWith("LPT")) &&
-                                 Char.IsDigit(ch));
-               }
-               
-               public bool IsDirectory(string filename)
-               {
-                       if (!Directory.Exists(filename)) {
-                               return false;
-                       }
-                       FileAttributes attr = File.GetAttributes(filename);
-                       return (attr & FileAttributes.Directory) != 0;
-               }
-               
-               /// <summary>
-               /// Returns directoryName + "\\" (Win32) when directoryname 
doesn't end with
-               /// "\\"
-               /// </summary>
-               public string GetDirectoryNameWithSeparator(string 
directoryName)
-               {
-                       if (directoryName == null) return "";
-                       
-                       if 
(directoryName.EndsWith(Path.DirectorySeparatorChar.ToString())) {
-                               return directoryName;
-                       }
-                       return directoryName + Path.DirectorySeparatorChar;
-               }
-       }
-}

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs     
2006-12-17 17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs     
2006-12-17 17:31:52 UTC (rev 69608)
@@ -42,7 +42,7 @@
                static PropertyService propertyService;
                static StringParserService stringParserService;
                static SystemAssemblyService systemAssemblyService;
-               static FileUtilityService fileUtilityService;
+               static FileService fileService;
                static ILoggingService loggingService;
                static AddInService addInService;
                static SetupService setupService;
@@ -60,6 +60,10 @@
                        AddInService.Initialize ();
                }
                
+               internal static bool Initialized {
+                       get { return initialized; }
+               }
+               
                public static void Shutdown ()
                {
                        ServiceManager.UnloadAllServices ();
@@ -81,11 +85,11 @@
                        }
                }       
        
-               public static FileUtilityService FileUtilityService {
+               public static FileService FileService {
                        get {
-                               if (fileUtilityService == null)
-                                       fileUtilityService = 
(FileUtilityService) ServiceManager.GetService (typeof(FileUtilityService));
-                               return fileUtilityService; 
+                               if (fileService == null)
+                                       fileService = new FileService ();
+                               return fileService; 
                        }
                }
                

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs  
    2006-12-17 17:19:57 UTC (rev 69607)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs  
    2006-12-17 17:31:52 UTC (rev 69608)
@@ -89,7 +89,6 @@
                        // add 'core' services
                        AddService(new PropertyService());
                        AddService(new StringParserService());
-                       AddService(new FileUtilityService());
                }
                
                /// <remarks>
@@ -129,7 +128,8 @@
                                        IAddInTreeNode node = (IAddInTreeNode) 
de.Value;
                                        if (node.Codon.AddIn == qaddin) {
                                                IService service = (IService) 
rootNode.BuildChildItem ((string)de.Key, defaultServiceManager);
-//                                             service.InitializeService();
+                                               if (service == null)
+                                                       throw new 
InvalidOperationException ("Could not create service: " + de.Key);
 //                                             Console.WriteLine ("     Added 
service " + service.GetType ());
                                                AddService (service);
                                        }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns/AddIn.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns/AddIn.cs    
    2006-12-17 17:19:57 UTC (rev 69607)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns/AddIn.cs    
    2006-12-17 17:31:52 UTC (rev 69608)
@@ -42,8 +42,6 @@
                
                ArrayList        extensions = new ArrayList();
                
-               FileUtilityService fileUtilityService = 
(FileUtilityService)ServiceManager.GetService(typeof(FileUtilityService));
-               
                /// <summary>
                /// returns the filename of the xml definition in which
                /// this AddIn is defined.
@@ -247,7 +245,7 @@
                                        continue;
 
                                string assemblyName = 
curEl.Attributes["assembly"].InnerText;
-                               string pathName     = 
Path.IsPathRooted(assemblyName) ? assemblyName : 
fileUtilityService.GetDirectoryNameWithSeparator(path) + assemblyName;
+                               string pathName     = 
Path.IsPathRooted(assemblyName) ? assemblyName : 
Runtime.FileService.GetDirectoryNameWithSeparator(path) + assemblyName;
                                Assembly asm = 
AddInTreeSingleton.AddInTree.LoadAssembly(pathName);
                                RuntimeLibraries[assemblyName] = asm;
                        }
@@ -347,7 +345,7 @@
                                                        } else {
                                                                PathAttribute 
pathAttribute = (PathAttribute)Attribute.GetCustomAttribute(fieldInfo, 
typeof(PathAttribute));
                                                                if 
(pathAttribute != null) {
-                                                                       
fieldInfo.SetValue(customizer, 
fileUtilityService.GetDirectoryNameWithSeparator(Path.GetDirectoryName(fileName))
 + Convert.ChangeType(node.Value, fieldInfo.FieldType).ToString());
+                                                                       
fieldInfo.SetValue(customizer, 
Runtime.FileService.GetDirectoryNameWithSeparator(Path.GetDirectoryName(fileName))
 + Convert.ChangeType(node.Value, fieldInfo.FieldType).ToString());
                                                                } else {
                                                                        
fieldInfo.SetValue(customizer, Convert.ChangeType(node.Value, 
fieldInfo.FieldType));
                                                                }

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns.Setup/SetupService.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns.Setup/SetupService.cs
   2006-12-17 17:19:57 UTC (rev 69607)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.AddIns.Setup/SetupService.cs
   2006-12-17 17:31:52 UTC (rev 69608)
@@ -53,7 +53,6 @@
                SystemConfiguration systemConfig;
                
                ArrayList addInDirs = new ArrayList ();
-               FileUtilityService fileUtilityService = 
(FileUtilityService)ServiceManager.GetService(typeof(FileUtilityService));
                
                internal void Initialize (string[] addInDirs, bool 
ignoreDefaultPath)
                {
@@ -656,7 +655,7 @@
                        foreach (string dir in AddinDirectories) {
                                if (!Directory.Exists (dir))
                                        continue;
-                               StringCollection files = 
fileUtilityService.SearchDirectory (dir, "*.addin.xml");
+                               StringCollection files = 
Runtime.FileService.SearchDirectory (dir, "*.addin.xml");
                                foreach (string file in files)
                                        addinSetupInfos.Add (new AddinSetupInfo 
(file));
                        }

Modified: trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.addin.xml
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.addin.xml      
2006-12-17 17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.addin.xml      
2006-12-17 17:31:52 UTC (rev 69608)
@@ -39,7 +39,8 @@
                                        platform = "Native"
                            class = 
"MonoDevelop.Core.Execution.NativePlatformExecutionHandler"/>
        </Extension>
-         
+       
+       <Extension path = "/Workspace/FileSystemExtensions" 
extension-nodes="Class" description="File system extensions|File system 
extensions which can provide specific behavior when handling files. Specified 
classes must implement MonoDevelop.Core.FileSystem.FileSystemExtension.">
+       </Extension>
 
-
 </AddIn>

Modified: trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.mdp
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.mdp    
2006-12-17 17:19:57 UTC (rev 69607)
+++ trunk/monodevelop/Core/src/MonoDevelop.Core/MonoDevelop.Core.mdp    
2006-12-17 17:31:52 UTC (rev 69608)
@@ -18,7 +18,6 @@
     <File name="./MonoDevelop.Core/GettextCatalog.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
     <File name="./MonoDevelop.Core/AbstractService.cs" subtype="Code" 
buildaction="Compile" />
-    <File name="./MonoDevelop.Core/FileUtilityService.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MonoDevelop.Core/IService.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MonoDevelop.Core/IStringTagProvider.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./MonoDevelop.Core/PropertyService.cs" subtype="Code" 
buildaction="Compile" />
@@ -148,6 +147,11 @@
     <File name="./ChangeLog" subtype="Code" buildaction="Nothing" />
     <File name="./Makefile.am" subtype="Code" buildaction="Nothing" />
     <File name="./MonoDevelop.Core.addin.xml" subtype="Code" 
buildaction="FileCopy" />
+    <File name="./MonoDevelop.Core/FileService.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./MonoDevelop.Core/FileEventArgs.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./MonoDevelop.Core.FileSystem" subtype="Directory" 
buildaction="Compile" />
+    <File name="./MonoDevelop.Core.FileSystem/FileSystemExtension.cs" 
subtype="Code" buildaction="Compile" />
+    <File name="./MonoDevelop.Core.FileSystem/DefaultFileSystemExtension.cs" 
subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Assembly" localcopy="True" 
refto="../../../contrib/Mono.Cecil.dll" />

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to