Mercurial > projects > mde
diff mde/setup/paths.d @ 101:71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
paths: support for getting the full path for a font when just the file name is entered, in order to unify usage on windows and linux.
paths: Used getSpecialPath for some windows paths; needs testing.
Content: Moved line-editing code to abstract ValueContent class and added some conversion functions, so that any type of ValueContent can be edited as text.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 17:03:47 +0000 |
parents | 4d5d53e4f881 |
children | ba035eba07b4 |
line wrap: on
line diff
--- a/mde/setup/paths.d Sat Nov 15 17:39:14 2008 +0000 +++ b/mde/setup/paths.d Sun Nov 16 17:03:47 2008 +0000 @@ -39,8 +39,20 @@ import tango.io.Console; import tango.io.FilePath; -import tango.sys.Environment; -//import tango.scrapple.sys.win32.Registry; // Trouble getting this to work +version (linux) { + import tango.io.FileScan; + import tango.util.container.SortedMap; + import tango.sys.Environment; +} else version (Windows) + import tango.sys.win32.SpecialPath; + +debug { + import tango.util.log.Log : Log, Logger; + private Logger logger; + static this() { + logger = Log.getLogger ("mde.setup.paths"); + } +} /** Order to read files in. * @@ -111,7 +123,15 @@ dataDir.coutPaths; Cout ("\nConf paths found:"); confDir.coutPaths; - Cout ("\nLog file directory:\n\t")(logDir).newline; + Cout ("\nLog file directory:\n\t")(logDir); + version (Windows) { + Cout ("\nFont directory:\n\t")(fontDir).newline; + } else version (linux) { + Cout ("\nFont filse found:"); + foreach (f,p; fontFiles) + Cout ("\n\t")(f)("\t")(p[0..$-1]); + Cout.newline; + } } private: @@ -190,7 +210,7 @@ /** These are the actual instances, one for each of the data and conf "directories". */ mdeDirectory dataDir, confDir; -char[] logDir; +char[] logDir; /// Directory for log files //BEGIN Path resolution // These are used several times: @@ -202,15 +222,26 @@ * Note: the logger cannot be used yet, so only output is exception messages. */ // FIXME: use tango/sys/Environment.d 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. + * + * Returns a C string (null terminated). */ + char[] getFontPath (char[] file) { + char[] ret; + if (fontFiles.get (file, ret)) + return ret; + throw new NoFileException ("Unable to find font file: "~file); + } + // base-path not used on posix - void resolvePaths (char[] = null) { + void resolvePaths (char[] base = "data") { // Home directory: char[] HOME = Environment.get("HOME", "."); // Base paths: // Static data (must exist): FilePath staticPath = - findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data"); + findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", base); // Config (can just use defaults if necessary, so long as we can save afterwards): FilePath userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); @@ -229,17 +260,37 @@ // Logging path: logDir = userPath.toString; + + // Font paths: + auto fs = new FileScan; + // Scan for directories containing truetype and type1 fonts: + fs.sweep ("/usr/share/fonts", (FilePath fp, bool isDir) + { return isDir || fp.suffix == ".ttf" || fp.suffix == ".pfb"; }, + true); + fontFiles = new SortedMap!(char[],char[]); + foreach (fp; fs.files) + fontFiles.add (fp.file, fp.cString); // both strings should be slices of same memory + logger.trace ("found {} font files, {} dirs", fs.files.length, fs.folders.length); } } else version (Windows) { + char[] fontDir; + /** Get the actual path of a font file, or throw NoFileException if not found. + * + * Returns a C string (null terminated). */ + char[] getFontPath (char[] file) { + FilePath path = new FilePath (fontDir~file); + if (path.exists && !path.isFolder) + return path.CString; + throw new NoFileException ("Unable to find font file: "~file); + } + void resolvePaths (char[] base = "./") { - //FIXME: Get path from registry - //FIXME: Get user path (Docs&Settings/USER/Local Settings/Application data/mde) - //http://www.dsource.org/projects/tango/forums/topic/187 + //FIXME: Get base path from registry // Base paths: FilePath installPath = findPath (false, base); - FilePath staticPath = findPath (false, installPath.append("data").toString); - FilePath userPath = findPath (true, installPath.append("user").toString); // FIXME: see above + FilePath staticPath = findPath (false, installPath.toString); + FilePath userPath = findPath (true, getSpecialPath(CSIDL_LOCAL_APPDATA) ~ "/mde"); // Static data paths: dataDir.addPath (staticPath.toString); // we know this is valid anyway @@ -256,6 +307,9 @@ // Logging path: logDir = userPath.toString; + + // Font path: + fontDir = getSpecialPath (CSIDL_FONTS) ~ "/"; // append separator } } else { static assert (false, "Platform is not linux or Windows: no support for paths on this platform yet!");