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