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