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 module mango.io.FileSystem;
00037
00038 private import mango.io.Utf8,
00039 mango.io.FilePath,
00040 mango.io.Exception;
00041
00042
00043 version (linux)
00044 {
00045 extern (C) int strlen (char *);
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 class FileSystem
00057 {
00058
00059
00060
00061
00062
00063
00064
00065 version (Win32)
00066 {
00067 static const char PathSeperatorChar = '\\';
00068 static const char FileSeperatorChar = '.';
00069 static const char RootSeperatorChar = ':';
00070
00071 static const char[] PathSeperatorString = "\\";
00072 static const char[] FileSeperatorString = ".";
00073 static const char[] RootSeperatorString = ":";
00074
00075 static const char[] NewlineString = "\r\n";
00076 }
00077
00078
00079 version (linux)
00080 {
00081 static const char PathSeperatorChar = '/';
00082 static const char FileSeperatorChar = '.';
00083 static const char RootSeperatorChar = ':';
00084
00085 static const char[] PathSeperatorString = "/";
00086 static const char[] FileSeperatorString = ".";
00087 static const char[] RootSeperatorString = ":";
00088
00089 static const char[] NewlineString = "\n";
00090 }
00091
00092 version (Win32)
00093 {
00094 private import std.c.windows.windows;
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 static char[][] listRoots ()
00105 {
00106 assert(0);
00107 return null;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 static void setDirectory (FilePath fp)
00117 {
00118 if (! SetCurrentDirectoryW (fp.toUtf16))
00119 throw new IOException ("Failed to set current directory");
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 static FilePath getDirectory ()
00129 {
00130 wchar[] dir;
00131 int length;
00132
00133 length = GetCurrentDirectoryW (0, null);
00134 if (length)
00135 {
00136 dir = new wchar [length];
00137 GetCurrentDirectoryW (length, dir);
00138 return new FilePath (Utf8.encode (dir));
00139 }
00140 throw new IOException ("Failed to get current directory");
00141 }
00142 }
00143
00144
00145 version (linux)
00146 {
00147 private import std.c.linux.linux;
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 }