diff dwt/dwthelper/System.d @ 126:38807a925e24

Fixed compile errors, support for SWT language files
author Jacob Carlborg <doob@me.com>
date Fri, 16 Jan 2009 23:35:40 +0100
parents c74ba20de292
children 07399639c0c8
line wrap: on
line diff
--- a/dwt/dwthelper/System.d	Fri Jan 16 12:49:08 2009 +0100
+++ b/dwt/dwthelper/System.d	Fri Jan 16 23:35:40 2009 +0100
@@ -5,6 +5,7 @@
 
 import tango.core.Exception;
 import tango.io.Stdout;
+import tango.io.model.IFile;
 
 version (LDC)
 {
@@ -15,9 +16,13 @@
 else
     import tango.io.Print;
 
+import tango.stdc.locale;
 import tango.stdc.stdlib : exit;
+import tango.sys.Environment;
 import tango.time.Clock;
 
+import dwt.dwthelper.utils;
+
 template SimpleType(T) {
     debug{
         static void validCheck(uint SrcLen, uint DestLen, uint copyLen){
@@ -170,13 +175,51 @@
         return (*cast(Object *)&x).toHash();
     }
 
-    public static char[] getProperty( char[] key ){
-        switch( key ){
-        case "os.name": return "windows";
-        default: return null;
+    public static String getProperty( String key, String defval ){
+        String res = getProperty(key);
+        if( res ){
+            return res;
         }
+        return defval;
+    }
+    
+    public static String getProperty( String key ){
+        /* get values for global system keys (environment) */
+        switch( key ) {
+                // Ubuntu Gutsy:Environment.get for OSTYPE is not working
+                // Force default to "linux" for now -JJR
+            case "os.name":
+                version (linux) return Environment.get("OSTYPE","linux");
+                version (darwin) return Environment.get("OSTYPE","darwin");
+            
+            case "user.name": return Environment.get("USER");
+            case "user.home": return Environment.get("HOME");
+            case "user.dir" : return Environment.get("PWD");
+            case "file.separator" : return FileConst.PathSeparatorString ;
+            case "file.encoding" :
+                char* encoding;
+                encoding = setlocale(LC_CTYPE, null);
+                if (encoding is null)
+                    version (linux) return "CP1252"; //default
+                    version (darwin) return "UTF-8"; //default
+                else 
+                    return encoding[0..strlen(encoding)].dup;
+            default: return null;
+        }
+        
+        /* Get values for local dwt specific keys */
+        String* p;
+        return ((p = key in localProperties) != null) ? *p : null;
+    }
+    
+    public static void setProperty ( String key, String value ) {
+        /* set property for LOCAL dwt keys */
+        if (key !is null && value !is null)
+            localProperties[ key ] = value;
     }
     
     static Out out_;
     static Err err;
+    
+    private static String[String] localProperties;
 }