diff mde/resource/paths.d @ 28:b5fadd8d930b

Small addition to GUI, paths work-around for Windows. New GUI widget containing a widget. Paths on windows now uses "." and "./user" as a temporary measure. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 08 Apr 2008 15:52:21 +0100
parents 0aa621b3e070
children 07bd1a09e161
line wrap: on
line diff
--- a/mde/resource/paths.d	Fri Apr 04 17:07:38 2008 +0100
+++ b/mde/resource/paths.d	Tue Apr 08 15:52:21 2008 +0100
@@ -37,10 +37,11 @@
 import mde.mergetag.DataSet;
 import mde.mergetag.exception;
 
+import tango.io.Console;
 import tango.io.FilePath;
-import tango.util.log.Log : Log, Logger;
 import tango.stdc.stdlib;
 import tango.stdc.stringz;
+//import tango.scrapple.sys.win32.Registry;     // Trouble getting this to work
 
 /** Order to read files in.
 *
@@ -124,8 +125,8 @@
                 paths[pathsLen++] = fp.toString~'/';
                 return true;
             } catch (Exception e) {
-                logger.error ("Creating path "~path~" failed:");
-                logger.error (e.msg);
+                // No logging avaiable yet: Use Stdout/Cout
+                Cout ("Creating path "~path~" failed:" ~ e.msg).newline;
             }
         }
         return false;
@@ -142,14 +143,14 @@
 char[] logDir;
 
 //BEGIN Path resolution
-static this() {
-    logger = Log.getLogger ("mde.resource.paths");
-}
-
 // These are used several times:
 const DATA = "/data";
 const CONF = "/conf";
 
+/** Find at least one path for each required directory.
+*
+* Note: the logger cannot be used yet, so only output is exception messages. */
+
 version (linux) {
     void resolvePaths () {
         // Home directory:
@@ -177,26 +178,27 @@
     }
 } else version (Windows) {
     void resolvePaths () {
-        static assert (false, "No registry code");
+        //FIXME: Get path from registry
+        //FIXME: Get user path (Docs&Settings/USER/Local Settings/Application data/mde)
         
         // Base paths:
-        char[] userPath = `...`;
-        char[] installPath = `registryInstallPath or "."`;
-        char[] staticPath = findPath (installPath ~ DATA);
+        PathView installPath = findPath (false, "");;
+        PathView userPath = findPath (true, "user");   // FIXME: see above
+        PathView staticPath = findPath (false, "data");
         
         // Static data paths:
         dataDir.addPath (staticPath.toString);   // we know this is valid anyway
         dataDir.tryPath (userPath.toString ~ DATA);
         if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!");
-                
+        
         // Configuration paths:
         confDir.tryPath (staticPath.toString ~ CONF);
-        bool sysConf = confDir.tryPath (installPath ~ CONF);
-        confDir.tryPath (userPath.toString ~ CONF, !sysConf);   // create if no system conf dir
+        confDir.tryPath ("conf");
+        confDir.tryPath (userPath.toString ~ CONF, true);
         if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!");
         
         // Logging path:
-        logDir = userPath;
+        logDir = userPath.toString;
     }
 } else {
     static assert (false, "Platform is not linux or Windows: no support for paths on this platform yet!");
@@ -207,8 +209,6 @@
 // There are NO CHECKS that this is not exceeded.
 const MAX_PATHS = 3;
 
-Logger logger;
-
 /* Try each path in succession, returning the first to exist and be a folder.
 * If none are valid and create is true, will try creating each in turn.
 * If still none are valid, throws. */
@@ -219,17 +219,17 @@
     }
     if (create) {   // try to create a folder, using each path in turn until succesful
         foreach (path; paths) {
-            PathView pv = new FilePath (path);
+            FilePath fp = new FilePath (path);
             try {
-                return pv;
+                return fp.create;
             }
             catch (Exception e) {}
         }
     }
     // no valid path...
-    logger.fatal ("Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:");
-    foreach (path; paths) logger.fatal ('\t' ~ path);
-    throw new mdeException ("Unable to resolve a required path (see log for details).");
+    char[] msg = "Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:";
+    foreach (path; paths) msg ~= "  \"" ~ path ~ '\"';
+    throw new mdeException (msg);
 }
 //END Path resolution