view base/src/java/io/File.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents e944a4cf537b
children
line wrap: on
line source

/**
 * Authors: Frank Benoit <keinfarbton@googlemail.com>
 */
module java.io.File;

import java.lang.all;

version(Tango){
    static import tango.io.model.IFile;
    static import tango.io.FilePath;
    static import tango.io.Path;
    static import tango.io.FileSystem;
    static import tango.sys.Environment;
    static import tango.sys.Common;
    static import tango.stdc.stringz; //for toStringz
    version(Posix) static import tango.stdc.posix.unistd; //for access
} else { // Phobos
    static import std.file;
    static import std.path;
    static import std.string; //for toStringz
    version(Posix) static import core.sys.posix.unistd; //for access
}
// Implement this more efficient by using FilePath in Tango 
public class File {

    public static char separatorChar;
    public static String separator;
    public static char pathSeparatorChar;
    public static String pathSeparator;

    private String mFilePath;

    static this(){
        version(Tango){
            separator = tango.io.model.IFile.FileConst.PathSeparatorString;
            separatorChar = tango.io.model.IFile.FileConst.PathSeparatorChar;
            pathSeparator = tango.io.model.IFile.FileConst.SystemPathString;
            pathSeparatorChar = tango.io.model.IFile.FileConst.SystemPathChar;
        } else { // Phobos
            separator = std.path.sep;
            separatorChar = std.path.sep[0];
            pathSeparator = std.path.pathsep;
            pathSeparatorChar = std.path.pathsep[0];
        }
    }

    private static String toStd( String path ){
        version(Tango){
            return tango.io.Path.standard( path.dup );
        } else { // Phobos
            return path;
        }
    }
    private static String join( String path, String file ){
        version(Tango){
            return tango.io.Path.join( toStd(path), toStd(file) );
        } else { // Phobos
            return std.path.join( toStd(path), toStd(file) );
        }
    }

    public this ( String pathname ){
        mFilePath = toStd( pathname );
    }

    public this ( String parent, String child ){
        mFilePath = join( parent, child );
    }

    public this ( java.io.File.File parent, String child ){
        version(Tango){
            mFilePath = tango.io.Path.join( parent.mFilePath, toStd(child) );
        } else { // Phobos
            mFilePath = std.path.join( parent.mFilePath, toStd(child) );
        }
    }

    public int getPrefixLength(){
        implMissing( __FILE__, __LINE__ );
        return 0;
    }

    public String getName(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public String getParent(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public java.io.File.File getParentFile(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public String getPath(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public bool isAbsolute(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public String getAbsolutePath(){
        version(Tango){
            return (new tango.io.FilePath.FilePath(mFilePath)).absolute(tango.sys.Environment.Environment.cwd).toString;
        } else { // Phobos
            return std.path.rel2abs(mFilePath);
        }
    }

    public java.io.File.File getAbsoluteFile(){
        return new File( getAbsolutePath() );
    }

    public String getCanonicalPath(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public java.io.File.File getCanonicalFile(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public bool canRead(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool canWrite(){
        version(Windows) { //Windows's ACL isn't supported
            version(Tango) {
                return tango.io.Path.isWritable(mFilePath);
            } else { // Phobos
                return !(std.file.getAttributes(mFilePath) & 1); //FILE_ATTRIBUTE_READONLY = 1
            }
        } else version(Posix) { //workaround Tango's bug (isWritable is always true)
            version(Tango) {
                return tango.stdc.posix.unistd.access (tango.stdc.stringz.toStringz(mFilePath), 2) is 0; //W_OK = 2
            } else { // Phobos
                return core.sys.posix.unistd.access (std.string.toStringz(mFilePath), 2) is 0; //W_OK = 2
            }
        } else
            static assert(0);
    }

    public bool exists(){
        version(Tango){
            return tango.io.Path.exists(mFilePath);
        } else { // Phobos
            return std.file.exists(mFilePath);
        }
    }

    public bool isDirectory(){
        version(Tango){
            return tango.io.Path.isFolder(mFilePath);
        } else { // Phobos
            return std.file.isDir(mFilePath);
        }
    }

    public bool isFile(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool isHidden(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public long lastModified(){
        implMissing( __FILE__, __LINE__ );
        return 0L;
    }

    public long length(){
        implMissing( __FILE__, __LINE__ );
        return 0L;
    }

    public bool createNewFile(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool delete_KEYWORDESCAPE(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public void deleteOnExit(){
        implMissing( __FILE__, __LINE__ );
    }

    public String[] list(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public java.io.File.File[] listFiles(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public bool mkdir(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool mkdirs(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool renameTo( java.io.File.File dest ){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool setLastModified( long time ){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public bool setReadOnly(){
        implMissing( __FILE__, __LINE__ );
        return false;
    }

    public static java.io.File.File[] listRoots(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public static java.io.File.File createTempFile( String prefix, String suffix, java.io.File.File directory ){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public static java.io.File.File createTempFile( String prefix, String suffix ){
        implMissing( __FILE__, __LINE__ );
        return null;
    }

    public int compareTo( java.io.File.File pathname ){
        implMissing( __FILE__, __LINE__ );
        return 0;
    }

    public String toString(){
        implMissing( __FILE__, __LINE__ );
        return null;
    }


}