Added missing Exceptions in System.IO and System.Security.Policy
[mono.git] / mcs / class / corlib / System.IO / Directory.cs
index 3d6e849fbc83a016af4a65232339eb81374084d5..f547fcf7e292038288cfb801cd77cf0d0c8d3a6a 100644 (file)
@@ -6,14 +6,17 @@
 // \r
 // Author:         Jim Richardson, develop@wtfo-guru.com\r
 // Created:        Monday, August 13, 2001 \r
-//
+//\r
 // TODO: Research exceptions for all methods\r
 //------------------------------------------------------------------------------\r
 \r
 using System;\r
+using System.Security.Permissions;\r
 \r
 namespace System.IO\r
 {\r
+\r
+\r
        /// <summary>\r
        /// \r
        /// </summary>\r
@@ -24,136 +27,146 @@ namespace System.IO
                /// Creates all directories not existing in path\r
                /// </summary>\r
                public static DirectoryInfo CreateDirectory(string path)\r
-               {       
-                       DirectoryInfo dInfo = getInfo(path);
-                       if(!dInfo.Exists)
-                       {
-                               dInfo.Create();
-                       }
-                       return dInfo;
-               }
+               {       \r
+                       DirectoryInfo dInfo = getInfo(path);\r
+                       if(!dInfo.Exists)\r
+                       {\r
+                               dInfo.Create();\r
+                       }\r
+                       return dInfo;\r
+               }\r
                \r
                /// <summary>\r
                /// Delete an empty directory\r
                /// </summary>\r
                public static void Delete(string path)\r
-               {       
-                       DirectoryInfo dInfo = getInfo(path);
-                       if(dInfo.Exists)
-                       {
-                               dInfo.Delete();
+               {       \r
+                       DirectoryInfo dInfo = getInfo(path);\r
+                       if(dInfo.Exists)\r
+                       {\r
+                               dInfo.Delete();\r
                        }\r
-               }
+               }\r
                \r
                /// <summary>\r
                /// Delete a directory, and contents if bRecurse is true\r
                /// </summary>\r
                public static void Delete(string path, bool bRecurse)\r
-               {       
-                       DirectoryInfo dInfo = getInfo(path);
-                       if(dInfo.Exists)
-                       {
-                               dInfo.Delete(bRecurse);
+               {       \r
+                       DirectoryInfo dInfo = getInfo(path);\r
+                       if(dInfo.Exists)\r
+                       {\r
+                               dInfo.Delete(bRecurse);\r
                        }\r
-               }
+               }\r
                \r
                /// <summary>\r
                /// Returns true if directory exists on disk\r
                /// </summary>\r
-               public static bool Exists(string path)
+               public static bool Exists(string path)\r
                {\r
                        return getInfo(path).Exists;\r
                }\r
+               \r
                /// <summary>\r
                /// Returns the date and time the directory specified by path was created\r
                /// </summary>\r
                public static DateTime GetCreationTime(string path)\r
-               {
-                       return getInfo().GetCreationTime(path);\r
+               {\r
+                       return getInfo(path).CreationTime;\r
                }\r
+               \r
                /// <summary>\r
                /// Returns the date and time the directory specified by path was created\r
                /// </summary>\r
                public static string GetCurrentDirectory()\r
-               {       // TODO: Implement\r
-                       return null;\r
+               {       // Implementation complete 08/25/2001 14:24 except for\r
+                       // LAMESPEC: documentation specifies invalid exceptions (i think)\r
+                       //           also shouldn't need Write to getcurrrent should we?\r
+                       string str = Environment.CurrentDirectory;\r
+                       CheckPermission.Demand(FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, str);\r
+                       return str;     \r
                }\r
+               \r
                /// <summary>\r
                /// Returns an array of directories in the directory specified by path\r
                /// </summary>\r
                public static string[] GetDirectories(string path)\r
                {\r
                        return getNames(getInfo(path).GetDirectories());\r
-               }
+               }\r
                \r
                /// <summary>\r
                /// Returns an array of directories in the directory specified by path\r
                /// matching the filter specified by mask\r
                /// </summary>\r
                public static string[] GetDirectories(string path, string mask)\r
-               {
-                       return getNames(getInfo(path).GetDirectories(mask));\r
-               }
+               {\r
+                       return getNames(DirectoryInfo.GetDirectories(mask));\r
+               }\r
                \r
                /// <summary>\r
                /// Returns the root of the specified path\r
                /// </summary>\r
                public static string GetDirectoryRoot(string path)\r
                {\r
-                       return getInfo(path).Root.FullName();\r
-               }
+                       return getInfo(path).Root.FullName;\r
+               }\r
                \r
                /// <summary>\r
                /// Returns an array of files in the directory specified by path\r
                /// </summary>\r
                public static string[] GetFiles(string path)\r
-               {
+               {\r
                        return getNames(getInfo(path).GetFiles());\r
-               }
+               }\r
                \r
                /// <summary>\r
                /// Returns an array of files in the directory specified by path\r
                /// matching the filter specified by mask\r
                /// </summary>\r
                public static string[] GetFiles(string path, string mask)\r
-               {
+               {\r
                        return getNames(getInfo(path).GetFiles());\r
                }\r
                /// <summary>\r
-               /// Returns an array of filesystementries in the directory specified by path
+               /// Returns an array of filesystementries in the directory specified by path\r
                /// I think this is just files and directories\r
                /// </summary>\r
+               [MonoTODO]\r
                public static string[] GetFileSystemEntries(string path)\r
-               {       // TODO: Research to verify this is files + directories
+               {       // TODO: Research to verify this is files + directories\r
                        return getNames(getInfo(path).GetFileSystemInfos());\r
                }\r
                /// <summary>\r
                /// Returns an array of filesystementries in the directory specified by path\r
                /// matching the filter specified by mask\r
                /// </summary>\r
-               public static string[] GetFileSystemEntries(string path, string mask)
-               {       // TODO: Research to verify this is files + directories
-                       return getNames(getInfo(path).GetFileSystemInfos());            }
+               [MonoTODO]\r
+               public static string[] GetFileSystemEntries(string path, string mask)\r
+               {       // TODO: Research to verify this is files + directories\r
+                       return getNames(getInfo(path).GetFileSystemInfos());            }\r
                \r
                /// <summary>\r
                /// Returns the date and time the directory specified by path was last accessed\r
                /// </summary>\r
                public static DateTime GetLastAccessTime(string path)\r
-               {
-                       return getInfo().GetLastWriteTime(path);\r
-               }
+               {\r
+                       return getInfo(path).LastAccessTime;\r
+               }\r
                \r
                /// <summary>\r
                /// Returns the date and time the directory specified by path was last modified\r
                /// </summary>\r
                public static DateTime GetLastWriteTime(string path)\r
-               {
-                       return getInfo().GetLastWriteTime(path);\r
-               }
+               {\r
+                       return getInfo(path).LastWriteTime;\r
+               }\r
                \r
                /// <summary>\r
                /// Returns an array of logical drives on this system\r
                /// </summary>\r
+               [MonoTODO]\r
                public static string[] GetLogicalDrives()\r
                {       // TODO: Implement\r
                        return null;\r
@@ -161,6 +174,7 @@ namespace System.IO
                /// <summary>\r
                /// Returns the parent directory of the directory specified by path\r
                /// </summary>\r
+               [MonoTODO]\r
                public static DirectoryInfo GetParent(string path)\r
                {       // TODO: Implement\r
                        return null;\r
@@ -169,56 +183,64 @@ namespace System.IO
                /// Moves a directory and its contents\r
                /// </summary>\r
                public static void Move(string src, string dst)\r
-               {
+               {\r
                         getInfo(src).MoveTo(dst);\r
-               }
+               }\r
                \r
                /// <summary>\r
                /// Sets the creation time of the directory specified by path\r
                /// </summary>\r
                public static void SetCreationTime(string path, DateTime creationTime)\r
-               {
-                       getInfo().SetCreationTime(path, creationTime);\r
-               }
+               {\r
+                       getInfo(path).CreationTime = creationTime;\r
+               }\r
                \r
                /// <summary>\r
                /// Sets the current directory to the directory specified by path\r
                /// </summary>\r
                public static void SetCurrentDirectory(string path)\r
-               {       // TODO: Implement\r
-               }
+               {       // Implementation complete 08/25/2001 14:24 except for\r
+                       // LAMESPEC: documentation specifies invalid exceptions IOException (i think)\r
+                       CheckArgument.Path(path, true);\r
+                       CheckPermission.Demand(FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, path);       \r
+                       if(!Exists(path))\r
+                       {\r
+                               throw new DirectoryNotFoundException("Directory \"" + path + "\" not found.");\r
+                       }\r
+                       Environment.CurrentDirectory = path;\r
+               }\r
                \r
                /// <summary>\r
                /// Sets the last access time of the directory specified by path\r
                /// </summary>\r
                public static void SetLastAccessTime(string path, DateTime accessTime)\r
-               {
-                       getInfo().SetLastAccessTime(path, accessTime);\r
-               }
+               {\r
+                       getInfo(path).LastAccessTime = accessTime;\r
+               }\r
                \r
                /// <summary>\r
                /// Sets the last write time of the directory specified by path\r
                /// </summary>\r
                public static void SetLastWriteTime(string path, DateTime modifiedTime)\r
-               {
-                       getInfo().SetLastWriteTime(path, modifiedTime);\r
-               }
-               
-               private static DirectoryInfo getInfo(string path)
-               {
-                       return new DirectoryInfo(path);
-               }
-               
-               private static string[] getNames(FileSystemInfo[] arInfo)
-               {
-                       int index = 0;
-                       string[] ar = new string[arInfo.Length];
-                                               
-                       foreach(FileInfo fi in arInfo)
-                       {
-                               ar[index++] = fi.FullName;
-                       }
-                       return ar;
+               {\r
+                       getInfo(path).LastWriteTime = modifiedTime;\r
+               }\r
+               \r
+               private static DirectoryInfo getInfo(string path)\r
+               {\r
+                       return new DirectoryInfo(path);\r
+               }\r
+               \r
+               private static string[] getNames(FileSystemInfo[] arInfo)\r
+               {\r
+                       int index = 0;\r
+                       string[] ar = new string[arInfo.Length];\r
+                                               \r
+                       foreach(FileInfo fi in arInfo)\r
+                       {\r
+                               ar[index++] = fi.FullName;\r
+                       }\r
+                       return ar;\r
                }\r
        }\r
 }\r