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