1 /**
2  * Authors: Frank Benoit <keinfarbton@googlemail.com>
3  */
4 module java.io.File;
5 
6 import java.lang.all;
7 
8 version(Tango){
9     static import tango.io.model.IFile;
10     static import tango.io.FilePath;
11     static import tango.io.Path;
12     static import tango.io.FileSystem;
13     static import tango.sys.Environment;
14     static import tango.sys.Common;
15     static import tango.stdc.stringz; //for toStringz
16     version(Posix) static import tango.stdc.posix.unistd; //for access
17 } else { // Phobos
18     static import std.file;
19     static import std.path;
20     static import std..string; //for toStringz
21     version(Posix) static import core.sys.posix.unistd; //for access
22 }
23 // Implement this more efficient by using FilePath in Tango 
24 public class File {
25 
26     public static char separatorChar;
27     public static String separator;
28     public static char pathSeparatorChar;
29     public static String pathSeparator;
30 
31     private String mFilePath;
32 
33     static this(){
34         version(Tango){
35             separator = tango.io.model.IFile.FileConst.PathSeparatorString;
36             separatorChar = tango.io.model.IFile.FileConst.PathSeparatorChar;
37             pathSeparator = tango.io.model.IFile.FileConst.SystemPathString;
38             pathSeparatorChar = tango.io.model.IFile.FileConst.SystemPathChar;
39         } else { // Phobos
40             separator = std.path.dirSeparator;
41             separatorChar = std.path.dirSeparator[0];
42             pathSeparator = std.path.pathSeparator;
43             pathSeparatorChar = std.path.pathSeparator[0];
44         }
45     }
46 
47     private static String toStd( String path ){
48         version(Tango){
49             return tango.io.Path.standard( path.dup );
50         } else { // Phobos
51             return path;
52         }
53     }
54     private static String join( String path, String file ){
55         version(Tango){
56             return tango.io.Path.join( toStd(path), toStd(file) );
57         } else { // Phobos
58             return std.path.buildPath( toStd(path), toStd(file) );
59         }
60     }
61 
62     public this ( String pathname ){
63         mFilePath = toStd( pathname );
64     }
65 
66     public this ( String parent, String child ){
67         mFilePath = join( parent, child );
68     }
69 
70     public this ( java.io.File.File parent, String child ){
71         version(Tango){
72             mFilePath = tango.io.Path.join( parent.mFilePath, toStd(child) );
73         } else { // Phobos
74             mFilePath = std.path.buildPath( parent.mFilePath, toStd(child) );
75         }
76     }
77 
78     public int getPrefixLength(){
79         implMissing( __FILE__, __LINE__ );
80         return 0;
81     }
82 
83     public String getName(){
84         implMissing( __FILE__, __LINE__ );
85         return null;
86     }
87 
88     public String getParent(){
89         implMissing( __FILE__, __LINE__ );
90         return null;
91     }
92 
93     public java.io.File.File getParentFile(){
94         implMissing( __FILE__, __LINE__ );
95         return null;
96     }
97 
98     public String getPath(){
99         implMissing( __FILE__, __LINE__ );
100         return null;
101     }
102 
103     public bool isAbsolute(){
104         implMissing( __FILE__, __LINE__ );
105         return false;
106     }
107 
108     public String getAbsolutePath(){
109         version(Tango){
110             return (new tango.io.FilePath.FilePath(mFilePath)).absolute(tango.sys.Environment.Environment.cwd).toString;
111         } else { // Phobos
112             return std.path.absolutePath(mFilePath);
113         }
114     }
115 
116     public java.io.File.File getAbsoluteFile(){
117         return new File( getAbsolutePath() );
118     }
119 
120     public String getCanonicalPath(){
121         implMissing( __FILE__, __LINE__ );
122         return null;
123     }
124 
125     public java.io.File.File getCanonicalFile(){
126         implMissing( __FILE__, __LINE__ );
127         return null;
128     }
129 
130     public bool canRead(){
131         implMissing( __FILE__, __LINE__ );
132         return false;
133     }
134 
135     public bool canWrite(){
136         version(Windows) { //Windows's ACL isn't supported
137             version(Tango) {
138                 return tango.io.Path.isWritable(mFilePath);
139             } else { // Phobos
140                 return !(std.file.getAttributes(mFilePath) & 1); //FILE_ATTRIBUTE_READONLY = 1
141             }
142         } else version(Posix) { //workaround Tango's bug (isWritable is always true)
143             version(Tango) {
144                 return tango.stdc.posix.unistd.access (tango.stdc.stringz.toStringz(mFilePath), 2) is 0; //W_OK = 2
145             } else { // Phobos
146                 return core.sys.posix.unistd.access (std..string.toStringz(mFilePath), 2) is 0; //W_OK = 2
147             }
148         } else
149             static assert(0);
150     }
151 
152     public bool exists(){
153         version(Tango){
154             return tango.io.Path.exists(mFilePath);
155         } else { // Phobos
156             return std.file.exists(mFilePath);
157         }
158     }
159 
160     public bool isDirectory(){
161         version(Tango){
162             return tango.io.Path.isFolder(mFilePath);
163         } else { // Phobos
164             return std.file.isDir(mFilePath);
165         }
166     }
167 
168     public bool isFile(){
169         implMissing( __FILE__, __LINE__ );
170         return false;
171     }
172 
173     public bool isHidden(){
174         implMissing( __FILE__, __LINE__ );
175         return false;
176     }
177 
178     public long lastModified(){
179         implMissing( __FILE__, __LINE__ );
180         return 0L;
181     }
182 
183     public long length(){
184         implMissing( __FILE__, __LINE__ );
185         return 0L;
186     }
187 
188     public bool createNewFile(){
189         implMissing( __FILE__, __LINE__ );
190         return false;
191     }
192 
193     public bool delete_KEYWORDESCAPE(){
194         implMissing( __FILE__, __LINE__ );
195         return false;
196     }
197 
198     public void deleteOnExit(){
199         implMissing( __FILE__, __LINE__ );
200     }
201 
202     public String[] list(){
203         implMissing( __FILE__, __LINE__ );
204         return null;
205     }
206 
207     public java.io.File.File[] listFiles(){
208         implMissing( __FILE__, __LINE__ );
209         return null;
210     }
211 
212     public bool mkdir(){
213         implMissing( __FILE__, __LINE__ );
214         return false;
215     }
216 
217     public bool mkdirs(){
218         implMissing( __FILE__, __LINE__ );
219         return false;
220     }
221 
222     public bool renameTo( java.io.File.File dest ){
223         implMissing( __FILE__, __LINE__ );
224         return false;
225     }
226 
227     public bool setLastModified( long time ){
228         implMissing( __FILE__, __LINE__ );
229         return false;
230     }
231 
232     public bool setReadOnly(){
233         implMissing( __FILE__, __LINE__ );
234         return false;
235     }
236 
237     public static java.io.File.File[] listRoots(){
238         implMissing( __FILE__, __LINE__ );
239         return null;
240     }
241 
242     public static java.io.File.File createTempFile( String prefix, String suffix, java.io.File.File directory ){
243         implMissing( __FILE__, __LINE__ );
244         return null;
245     }
246 
247     public static java.io.File.File createTempFile( String prefix, String suffix ){
248         implMissing( __FILE__, __LINE__ );
249         return null;
250     }
251 
252     public int compareTo( java.io.File.File pathname ){
253         implMissing( __FILE__, __LINE__ );
254         return 0;
255     }
256 
257     override
258     public String toString(){
259         implMissing( __FILE__, __LINE__ );
260         return null;
261     }
262 
263 
264 }
265 
266