diff mde/setup/paths.d @ 107:20f7d813bb0f

Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated. New unittest for Translation; I realised the old one wasn't run anymore. Changed unittest data and conf dirs.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 30 Nov 2008 17:17:56 +0000
parents 7f7b40fed72b
children 1b1e2297e2fc
line wrap: on
line diff
--- a/mde/setup/paths.d	Sat Nov 29 16:43:44 2008 +0000
+++ b/mde/setup/paths.d	Sun Nov 30 17:17:56 2008 +0000
@@ -139,17 +139,6 @@
     {
         FilePath[] ret;
         
-        debug (mdeUnitTest) {
-        /* Alternate approach - just try from current directory.
-        * Really just for unittests, but with the if condition it shouldn't break anything else. */
-            if (pathsLen == 0) {
-                FilePath file = findFile (filename);
-                if (file !is null)
-                    ret ~= file;
-                return ret;
-            }
-        }
-        
         if (readOrder == PRIORITY.LOW_HIGH) {
             for (size_t i = 0; i < pathsLen; ++i) {
                 FilePath file = findFile (paths[i]~filename);
@@ -172,12 +161,14 @@
     
     // Unconditionally add a path
     void addPath (char[] path) {
+	assert (pathsLen < MAX_PATHS);
         paths[pathsLen++] = path~'/';
     }
     
     // Test a path and add if is a folder.
     bool tryPath (char[] path, bool create = false) {
-        FilePath fp = FilePath (path);
+	assert (pathsLen < MAX_PATHS);
+	FilePath fp = FilePath (path);
         if (fp.exists && fp.isFolder) {
             paths[pathsLen++] = path~'/';
             return true;
@@ -213,13 +204,17 @@
 char[] logDir;		/// Directory for log files
 
 //BEGIN Path resolution
-// 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. */
+/** Find at least one path for each required directory. */
+debug (mdeUnitTest) {
+    /** In unittest mode, add paths unittest/data and unittest/conf before init runs. */
+    static this () {
+	dataDir.tryPath ("unittest/data");
+	confDir.tryPath ("unittest/conf");
+	if (!(dataDir.pathsLen && confDir.pathsLen))
+	    throw new mdeException ("Fatal: unittest/data and unittest/conf don't both exist");
+	// Don't bother with real paths or logDir or font dir(s) for unittest.
+    }
+}
 version (linux) {
     SortedMap!(char[],char[]) fontFiles;	// key is file name, value is CString path
     /** Get the actual path of a font file, or throw NoFileException if not found.
@@ -246,14 +241,14 @@
         
         // Static data paths:
         dataDir.addPath (staticPath.toString);      // we know this is valid anyway
-        dataDir.tryPath (userPath.toString ~ DATA);
+        dataDir.tryPath (userPath.toString ~ "/data");
         if (extraDataPath) dataDir.tryPath (extraDataPath);
         if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!");
         
         // Configuration paths:
-        confDir.tryPath (staticPath.toString ~ CONF);
+        confDir.tryPath (staticPath.toString ~ "/conf");
         confDir.tryPath ("/etc/mde");
-        confDir.tryPath (userPath.toString ~ CONF, true);
+        confDir.tryPath (userPath.toString ~ "/conf", true);
         if (extraConfPath) confDir.tryPath (extraConfPath);
         if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!");
         
@@ -293,14 +288,14 @@
         
         // Static data paths:
         dataDir.addPath (staticPath.toString);   // we know this is valid anyway
-        dataDir.tryPath (userPath.toString ~ DATA);
+	dataDir.tryPath (userPath.toString ~ "/data");
         if (extraDataPath) dataDir.tryPath (extraDataPath);
         if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!");
         
         // Configuration paths:
-        confDir.tryPath (staticPath.toString ~ CONF);
+        confDir.tryPath (staticPath.toString ~ "/conf");
         confDir.tryPath (installPath.append("user").toString);
-        confDir.tryPath (userPath.toString ~ CONF, true);
+        confDir.tryPath (userPath.toString ~ "/conf", true);
         if (extraConfPath) confDir.tryPath (extraConfPath);
         if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!");
         
@@ -324,8 +319,7 @@
         }
     }
     
-// The maximum number of paths for any one "directory".
-// There are NO CHECKS that this is not exceeded.
+    // The maximum number of paths for any one "directory".
     const MAX_PATHS = 4;
 
     /* Try each path in succession, returning the first to exist and be a folder.