Mercurial > projects > mde
annotate mde/file/paths.d @ 151:e785e98d3b78
Updated for compatibility with tango 0.99.8.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 04 Apr 2009 17:32:18 +0200 |
parents | 9f035cd139c6 |
children |
rev | line source |
---|---|
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
1 /* LICENSE BLOCK |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
4 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
8 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
11 See the GNU General Public License for more details. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
12 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
15 |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** Resource paths module. |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
17 * |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
18 * Internally, most mde code using files doesn't use absolute paths but paths |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
19 * relative to mde directory. Further, mergetag files are usually not read |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
20 * just from one file, but are the result of merging multiple files from the |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
21 * same relative paths in different directories, including the root data |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
22 * directory, possibly a directory in /etc, a directory for files specific to |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
23 * the user accont, and possibly other directories. |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
24 * |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
25 * This module transforms relative paths to absolute paths, allowing for |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
26 * multiple files to be read and merged. |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
27 * |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
28 * The base paths from which relative files are read are slit into two groups: |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
29 * data paths, and conf paths (usually the conf paths refer to a "conf" |
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
30 * directory within the data paths). */ |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 /* Implementation note: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
32 * All paths are stored internally as strings, rather than as an instance of FilePath/FilePath once |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 * the FilePath has served its immediate purpose, since it's more convenient and creating new |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 * FilePaths for adjusted paths should be no slower than mutating existing ones. */ |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
35 module mde.file.paths; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 import mde.exception; |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
78
diff
changeset
|
38 import mde.file.mergetag.Reader; |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
39 import mde.file.mergetag.MTTagReader; |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
78
diff
changeset
|
40 import mde.file.mergetag.Writer; |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
41 import mde.file.mergetag.MTTagWriter; |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
78
diff
changeset
|
42 import mde.file.mergetag.DataSet; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
78
diff
changeset
|
43 import mde.file.mergetag.exception; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
45 import tango.io.Console; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 import tango.io.FilePath; |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
47 version (linux) { |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
48 import tango.io.FileScan; |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
49 import tango.util.container.SortedMap; |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
50 import tango.sys.Environment; |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
51 } else version (Windows) |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
52 import tango.sys.win32.SpecialPath; |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
53 |
151
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
54 import tango.util.log.Log : Log, Logger; |
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
55 private Logger logger; |
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
56 static this() { |
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
57 logger = Log.getLogger ("mde.file.paths"); |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
58 } |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 /** Order to read files in. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 * Values: HIGH_LOW, LOW_HIGH, HIGH_ONLY. */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 enum PRIORITY : byte { HIGH_LOW, LOW_HIGH, HIGH_ONLY } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 /** This struct has one instance for each "directory". |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 * |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
67 * It is the only item within this module that you should need to interact with. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
68 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
69 * In the case of confDir, the user path is guaranteed to exist (as highest priority path). */ |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
70 struct mdeDirectory |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 { |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
72 /** Creates an MT IReader for each file (using MTMultiReader). |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 * Params: |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
75 * file = The file path and name relative to the mdeDirectory, |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
76 * without a suffix (e.g. "options"). |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
77 * readOrder = Read the highest priority or lowest priority files first? |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
78 * For correct merging, this should be LOW_HIGH when newly- |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
79 * read items override old ones (as is the case with |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
80 * DefaultData) and HIGH_LOW when the first-read items |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
81 * survive. Thus override order needs to be the same for each |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
82 * section, except the header which is always read with |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
83 * LOW_HIGH order. Alternately, for files which shouldn't be |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
84 * merged where only the highest priority file should be read, |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
85 * pass HIGH_ONLY. |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
86 * ds = The dataset, as for mergetag. Note: all actual readers share one dataset. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 * rdHeader = Read the headers for each file and merge if rdHeader == true. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
88 */ |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
89 IReader makeMTReader (char[] file, PRIORITY readOrder, DataSet ds = null, bool rdHeader = false) { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
90 return new MTMultiReader (getFiles (file, readOrder), ds, rdHeader); |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
91 } |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
92 |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
93 /** Creates an MTTagReader for each file (using MTMultiTagReader). |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
94 * |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
95 * Params as for makeMTReader. |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
96 */ |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
97 MTTagReader makeMTTagReader (char[] file, PRIORITY readOrder) { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
98 return new MTMultiTagReader (getFiles (file, readOrder)); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
99 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
100 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 /** Creates an MT writer for file deciding on the best path to use. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
102 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
103 * Params: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
104 * file = The file path and name relative to the mdeDirectory, without a suffix |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
105 * (e.g. "options") |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
106 * ds = The dataset, as for mergetag. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
107 */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
108 IWriter makeMTWriter (char[] file, DataSet ds = null) |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
109 { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
110 // FIXME: use highest priority writable path |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
136
diff
changeset
|
111 return getMTWriter (paths[pathsLen-1] ~ file, ds, WriterMethod.Text); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
113 |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
114 /** Creates an MTTagWriter for file. */ |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
136
diff
changeset
|
115 MTTagWriter makeMTTagWriter (char[] file) |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
116 { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
117 // FIXME: use highest priority writable path |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
136
diff
changeset
|
118 return getMTTagWriter (paths[pathsLen-1] ~ file); |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
119 } |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
120 |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
121 /** Returns a string listing the file name or names (if readOrder is not |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
122 * HIGH_ONLY and multiple matches are found), or an error message. Intended |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
123 * for user output only. */ |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
124 char[] getFileName (char[] file, PRIORITY readOrder) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
125 { |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
126 FilePath[] files; |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
127 try { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
128 files = getFiles (file, readOrder); |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
129 } catch (NoFileException e) { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
130 return e.msg; |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
131 } |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
132 |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
133 char[] ret = files[0].toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
134 foreach (f; files[1..$]) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
135 ret ~= ", " ~ f.toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
136 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
137 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
138 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
139 /// Print all paths found. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
140 static void printPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
141 Cout ("Data paths found:"); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
142 dataDir.coutPaths; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
143 Cout ("\nConf paths found:"); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
144 confDir.coutPaths; |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
145 Cout ("\nLog file directory:\n\t")(logDir); |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
146 Cout ("\nFont directories:"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
147 foreach (path; fontPaths) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
148 Cout ("\n\t")(path.toString); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
149 Cout.newline; |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
150 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
151 |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
152 private: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
153 FilePath[] getFiles (char[] filename, PRIORITY readOrder) |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
154 { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
155 FilePath[] ret; |
68
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
67
diff
changeset
|
156 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
157 if (readOrder == PRIORITY.LOW_HIGH) { |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
158 for (size_t i = 0; i < pathsLen; ++i) { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
159 FilePath file = findFile (paths[i]~filename); |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
160 if (file !is null) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
161 ret ~= file; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
162 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
163 } else { |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
136
diff
changeset
|
164 debug assert (readOrder == PRIORITY.HIGH_LOW || |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
165 readOrder == PRIORITY.HIGH_ONLY ); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
166 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
167 for (int i = pathsLen - 1; i >= 0; --i) { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
168 FilePath file = findFile (paths[i]~filename); |
78
79a1809421aa
Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
169 if (file !is null) |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
170 ret ~= file; |
78
79a1809421aa
Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
171 if (readOrder == PRIORITY.HIGH_ONLY) break; |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
172 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
173 } |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
174 if (ret is null) |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
175 throw new NoFileException ("Unable to find the file: "~filename~"[.mtt|mtb]"); |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
176 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
177 } |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
178 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
179 // Unconditionally add a path |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
180 void addPath (char[] path) { |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
181 assert (pathsLen < MAX_PATHS); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
182 paths[pathsLen++] = path~'/'; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
183 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
184 |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
185 // Test a path and add if is a folder. |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
186 bool tryPath (char[] path, bool create = false) { |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
187 assert (pathsLen < MAX_PATHS); |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
188 FilePath fp = FilePath (path); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
189 if (fp.exists && fp.isFolder) { |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
190 paths[pathsLen++] = path~'/'; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
191 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
192 } else if (create) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
193 try { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
194 fp.create; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
195 paths[pathsLen++] = fp.toString~'/'; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
196 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
197 } catch (Exception e) { |
151
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
198 logger.error ("Creating path {} failed:" ~ e.msg, path); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
199 } |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
200 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
201 return false; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
202 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
203 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
204 void coutPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
205 if (pathsLen) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
206 for (size_t i = 0; i < pathsLen; ++i) |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
207 Cout ("\n\t" ~ paths[i]); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
208 } else |
151
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
209 Cout (" [none]"); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
210 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
211 |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
212 // Use a static array to store all possible paths with separate length counters. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
213 // Lowest priority paths are first. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
214 char[][MAX_PATHS] paths; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 ubyte pathsLen = 0; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
216 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
217 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
218 /** Get the actual path of a font file, or throw NoFileException if not found. |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
219 * |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
220 * Returns a C string (null terminated). */ |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
221 char[] getFontPath (char[] file) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
222 foreach (path; fontPaths) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
223 FilePath font = path.dup.append (file); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
224 if (font.exists && font.isFile) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
225 return font.cString; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
226 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
227 throw new NoFileException ("Unable to find font file: "~file); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
228 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
229 |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
230 /** These are the actual instances, one for each of the data and conf "directories". */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
231 mdeDirectory dataDir, confDir; |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
232 char[] logDir; /// Directory for log files |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
233 FilePath[] fontPaths; /// All directories for fonts |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
234 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
235 //BEGIN Path resolution |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
236 /// For command line args: these paths are added if non-null, with highest priority. |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
237 char[] extraDataPath, extraConfPath; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
238 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
239 /** Add an extra font directory. May be called multiple times. */ |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
240 void addFontPath (char[] path) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
241 FilePath fp = FilePath (path); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
242 if (fp.exists && fp.isFolder) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
243 fontPaths ~= fp; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
244 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
245 |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
246 /** Find at least one path for each required directory. */ |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
247 debug (mdeUnitTest) { |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
248 /** In unittest mode, add paths unittest/data and unittest/conf before init runs. */ |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
249 static this () { |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
250 dataDir.tryPath ("unittest/data"); |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
251 confDir.tryPath ("unittest/conf"); |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
252 if (!(dataDir.pathsLen && confDir.pathsLen)) |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
253 throw new mdeException ("Fatal: unittest/data and unittest/conf don't both exist"); |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
254 // Don't bother with real paths or logDir or font dir(s) for unittest. |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
255 } |
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
256 } |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
257 void resolvePaths (char[] base = ".") { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
258 size_t iFP = fontPaths.length; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
259 fontPaths.length = fontPaths.length + 4; |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
260 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
261 version (linux) { |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
262 // Home directory: |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
263 char[] HOME = Environment.get("HOME", "."); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
264 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
265 // Installation base (should contain "data" and "conf"): |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
266 FilePath staticPath = findPath (false, |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
267 "/usr/share/games/mde", |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
268 "/usr/local/share/games/mde", |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
269 base~"/data"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
270 // Path for user-adjusted files: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
271 FilePath userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
272 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
273 dataDir.addPath (staticPath.toString); |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
274 confDir.tryPath (staticPath.toString ~ "/conf"); |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
275 confDir.tryPath ("/etc/mde"); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
276 |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
277 // Font paths: |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
278 auto fontP1 = FilePath("/usr/share/fonts").toList; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
279 foreach (fp1; fontP1) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
280 if (fp1.isFolder) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
281 foreach (fp2; fp1.toList) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
282 if (fp2.isFolder) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
283 if (iFP >= fontPaths.length) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
284 fontPaths.length = fontPaths.length * 2; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
285 fontPaths[iFP++] = fp2; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
286 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
287 } else version (Windows) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
288 //FIXME: Get base path from registry |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
289 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
290 FilePath staticPath = findPath (false, base~"/data"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
291 FilePath userPath = findPath (true, getSpecialPath(CSIDL_LOCAL_APPDATA) ~ "/mde"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
292 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
293 dataDir.addPath (staticPath.toString); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
294 confDir.tryPath (staticPath.toString ~ "/conf"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
295 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
296 // Font path: |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
297 fontPaths ~= FilePath(getSpecialPath (CSIDL_FONTS)); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
298 } else { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
299 static assert (false, "Platform is not linux or Windows: no support for paths on this platform yet!"); |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
300 } |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
301 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
302 // Static data paths: |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
303 dataDir.tryPath (userPath.toString ~ "/data"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
304 if (extraDataPath) dataDir.tryPath (extraDataPath); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
305 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
306 // Configuration paths: |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
307 confDir.tryPath (userPath.toString ~ "/conf", true); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
308 if (extraConfPath) confDir.tryPath (extraConfPath); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
309 |
151
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
310 if (dataDir.pathsLen==0) throw new mdeException ("Fatal: no data path found!"); |
e785e98d3b78
Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
311 if (confDir.pathsLen==0) throw new mdeException ("Fatal: no conf path found!"); |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
312 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
313 for (int i = dataDir.pathsLen - 1; i >= 0; --i) { |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
314 FilePath font = FilePath (dataDir.paths[i] ~ "fonts"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
315 if (font.exists && font.isFolder) |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
316 fontPaths[iFP++] = font; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
317 } |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
318 fontPaths.length = iFP; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
319 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
320 // Logging path: |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
321 logDir = userPath.toString; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
322 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
323 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
324 private { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
325 class PathException : mdeException { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
326 this(char[] msg) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
327 super (msg); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
328 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
329 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
330 |
107
20f7d813bb0f
Translation: now has a file for each locale, instead of a file for each section. Items updated; all strings translated.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
106
diff
changeset
|
331 // The maximum number of paths for any one "directory". |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
332 const MAX_PATHS = 4; |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
333 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
334 /* Try each path in succession, returning the first to exist and be a folder. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
335 * If none are valid and create is true, will try creating each in turn. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
336 * If still none are valid, throws. */ |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
337 FilePath findPath (bool create, char[][] paths ...) { |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
338 FilePath[] fps; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
339 fps.length = paths.length; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
340 foreach (i,path; paths) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
341 FilePath pv = new FilePath (path); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
342 if (pv.exists && pv.isFolder) return pv; // got a valid path |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
343 fps[i] = pv; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
344 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
345 if (create) { // try to create a folder, using each path in turn until succesful |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
346 foreach (fp; fps) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
347 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
348 return fp.create; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
349 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
350 catch (Exception e) {} |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
351 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
352 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
353 // no valid path... |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
354 char[] msg = "Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:"; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
355 foreach (path; paths) msg ~= " \"" ~ path ~ '\"'; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
356 throw new PathException (msg); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
357 } |
134
7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
358 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
359 //END Path resolution |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
360 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
361 /// Thrown when makeMTReader couldn't find a file. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
362 class NoFileException : MTFileIOException { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
363 this (char[] msg) { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
364 super(msg); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
68
diff
changeset
|
365 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
366 } |