00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 module mango.io.FileSystem;
00042
00043 private import mango.sys.OS;
00044
00045 private import mango.io.Utf,
00046 mango.io.FilePath,
00047 mango.io.FileConst,
00048 mango.io.Exception;
00049
00050 private import mango.utils.Text;
00051
00052 version (Win32)
00053 extern (Windows) DWORD GetLogicalDriveStringsA (DWORD, LPTSTR);
00054 else
00055 extern (C) int strlen (char *);
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 class FileSystem
00066 {
00067 version (Win32)
00068 {
00069
00070
00071
00072
00073
00074
00075 static char[][] listRoots ()
00076 {
00077 int len;
00078 char[] str;
00079 char[][] roots;
00080
00081
00082 len = GetLogicalDriveStringsA (0, null);
00083 if (len)
00084 {
00085 str = new char [len];
00086 GetLogicalDriveStringsA (len, str);
00087
00088
00089 roots = Text.split (str [0..str.length-1], "\0");
00090 }
00091 return roots;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 static void setDirectory (FilePath fp)
00101 {
00102 version (Win32SansUnicode)
00103 {
00104 if (! SetCurrentDirectoryA (fp.toUtf8))
00105 throw new IOException ("Failed to set current directory");
00106 }
00107 else
00108 {
00109 if (! SetCurrentDirectoryW (fp.toUtf16))
00110 throw new IOException ("Failed to set current directory");
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120 static FilePath getDirectory ()
00121 {
00122 version (Win32SansUnicode)
00123 {
00124 int length = GetCurrentDirectoryA (0, null);
00125 if (length)
00126 {
00127 char[] dir = new char [length];
00128 GetCurrentDirectoryA (length, dir);
00129 return new FilePath (dir);
00130 }
00131 }
00132 else
00133 {
00134 int length = GetCurrentDirectoryW (0, null);
00135 if (length)
00136 {
00137 wchar[] dir = new wchar [length];
00138 GetCurrentDirectoryW (length, dir);
00139 return new FilePath (Utf.toUtf8 (dir));
00140 }
00141 }
00142 throw new IOException ("Failed to get current directory");
00143 }
00144 }
00145
00146
00147 version (Posix)
00148 {
00149
00150
00151
00152
00153
00154
00155
00156
00157 static char[][] listRoots ()
00158 {
00159 assert(0);
00160 return null;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 static void setDirectory (FilePath fp)
00170 {
00171 if (std.c.linux.linux.chdir (fp.toUtf8))
00172 throw new IOException ("Failed to set current directory");
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 static FilePath getDirectory ()
00182 {
00183 char *s = std.c.linux.linux.getcwd (null, 0);
00184 if (s)
00185
00186 return new FilePath (s[0..strlen(s)].dup);
00187
00188 throw new IOException ("Failed to get current directory");
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198 alias FileConst.PathSeparatorChar PathSeparatorChar;
00199 alias FileConst.FileSeparatorChar FileSeparatorChar;
00200 alias FileConst.RootSeparatorChar RootSeparatorChar;
00201 alias FileConst.PathSeparatorString PathSeparatorString;
00202 alias FileConst.FileSeparatorString FileSeparatorString;
00203 alias FileConst.RootSeparatorString RootSeparatorString;
00204 alias FileConst.NewlineString NewlineString;
00205
00206
00207
00208
00209
00210
00211
00212 alias PathSeparatorChar PathSeperatorChar;
00213 alias FileSeparatorChar FileSeperatorChar;
00214 alias RootSeparatorChar RootSeperatorChar;
00215 alias PathSeparatorString PathSeperatorString;
00216 alias FileSeparatorString FileSeperatorString;
00217 alias RootSeparatorString RootSeperatorString;
00218 }