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