Mercurial > projects > mde
annotate mde/resource/paths.d @ 27:0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Implemented GUI code to load windows from file with a basic widget and draw.
Fixed a bug in mde.resource.paths.mdeDirectory.makeMTReader when called with readOrder == PRIORITY.HIGH_ONLY.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 04 Apr 2008 17:07:38 +0100 |
parents | 611f7b9063c6 |
children | b5fadd8d930b |
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. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 * Internally to mde code other than code dealing directly with files and this module, paths are |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 * relative to the mde directory. This module transforms those paths to absolute 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
|
20 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 * Additionally, the intention is to look for all files in two directories: the installation (i.e. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 * main data) directory and a user directory (for user-specific configuration). Besides exposing |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 * both paths and checking in which valid files exist, this module provides some extra 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
|
24 * functionality to simplify correct reading and writing. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 * Currently the paths are found as follows: (see codeDoc/paths.txt) |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
28 /* Implementation note: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 * All paths are stored internally as strings, rather than as an instance of FilePath/PathView once |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 * 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
|
31 * FilePaths for adjusted paths should be no slower than mutating existing ones. */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 module mde.resource.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
|
33 |
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 import mde.exception; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 import mde.mergetag.Reader; |
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 import mde.mergetag.Writer; |
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.mergetag.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
|
38 import mde.mergetag.exception; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 import tango.io.FilePath; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 import tango.util.log.Log : Log, Logger; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 import tango.stdc.stdlib; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 import tango.stdc.stringz; |
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 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 /** 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
|
46 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 * 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
|
48 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
|
49 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 /** 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
|
51 * |
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
|
52 * 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
|
53 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
54 * 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
|
55 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
|
56 { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 /** Creates an MT reader for each file. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 * |
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 * 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
|
60 * 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
|
61 * (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
|
62 * readOrder = Read the highest priority or lowest priority files first? For correct merging, |
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 * this should be LOW_HIGH when newly-read items override old ones (as is the case |
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 * with DefaultData) and HIGH_LOW when the first-read items survive. Thus override |
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 * order needs to be the same for each section, except the header which is always |
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 * read with LOW_HIGH order. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
67 * Alternately, for files which shouldn't be |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
68 * merged where only the highest priority file should be read, pass 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
|
69 * 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
|
70 * 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
|
71 */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 IReader makeMTReader (char[] file, PRIORITY readOrder, DataSet ds = null, bool rdHeader = false) |
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 { |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
74 if (readOrder == PRIORITY.HIGH_ONLY) { |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
75 foreach_reverse (path; paths) { // starting with highest-priority path... |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
76 try { |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
77 return makeReader (path~file, ds, rdHeader); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
78 } |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
79 catch (MTFileIOException) {} // Ignore errors regarding no file for now. |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
80 } |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
81 throw new MTFileIOException ("Unable to find the file: "~file~"[.mtt|mtb]"); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
82 } |
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
|
83 else return new mdeReader (file, readOrder, ds, rdHeader, 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
|
84 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
85 |
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 /** 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
|
87 * |
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 * 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
|
89 * 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
|
90 * (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
|
91 * 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
|
92 */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
93 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
|
94 { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
95 // FIXME: use highest priority writable 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
|
96 return makeWriter (paths[pathsLen-1] ~ file, ds, WriterMethod.Text); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
97 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
98 |
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 /** Check whether the given file exists under any path with either .mtt or .mtb 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
|
100 bool exists (char[] file) { |
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 for (uint i = 0; i < pathsLen; ++i) { |
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 if (FilePath (paths[i]~file~".mtt").exists) return 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
|
103 if (FilePath (paths[i]~file~".mtb").exists) return 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
|
104 } |
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 return false; |
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 } |
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 private: |
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 // 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
|
111 void addPath (char[] 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
|
112 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
|
113 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
114 |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
115 // 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
|
116 bool tryPath (char[] path, bool create = false) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
117 FilePath fp = FilePath (path); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
118 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
|
119 paths[pathsLen++] = path~'/'; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
120 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
121 } else if (create) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
122 try { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
123 fp.create; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
124 paths[pathsLen++] = fp.toString~'/'; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
125 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
126 } catch (Exception e) { |
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
|
127 logger.error ("Creating path "~path~" failed:"); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
128 logger.error (e.msg); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
129 } |
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
|
130 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
131 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
|
132 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
133 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
134 // 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
|
135 // 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
|
136 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
|
137 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
|
138 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
139 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
140 /** 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
|
141 mdeDirectory dataDir, confDir; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
142 char[] logDir; |
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
|
143 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
144 //BEGIN Path resolution |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
145 static this() { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
146 logger = Log.getLogger ("mde.resource.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
|
147 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
148 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
149 // These are used several times: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
150 const DATA = "/data"; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
151 const CONF = "/conf"; |
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 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
153 version (linux) { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
154 void resolvePaths () { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 // Home 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
|
156 char[] HOME = fromStringz (getenv (toStringz ("HOME"))); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
157 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
158 // Base paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
159 // Static data (must exist): |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
160 PathView staticPath = findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data"); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
161 // Config (can just use defaults if necessary, so long as we can save afterwards): |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
162 PathView 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
|
163 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
164 // Static data paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
165 dataDir.addPath (staticPath.toString); // we know this is valid anyway |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
166 dataDir.tryPath (userPath.toString ~ DATA); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
167 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); |
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
|
168 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
169 // Configuration paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
170 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
|
171 confDir.tryPath ("/etc/mde"); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
172 confDir.tryPath (userPath.toString ~ CONF, true); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
173 if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!"); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
174 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
175 // Logging path: |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
176 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
|
177 } |
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 } else version (Windows) { |
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 void resolvePaths () { |
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 static assert (false, "No registry code"); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
181 |
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 // Base 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
|
183 char[] userPath = `...`; |
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 char[] installPath = `registryInstallPath or "."`; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
185 char[] staticPath = findPath (installPath ~ DATA); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
186 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
187 // Static data paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
188 dataDir.addPath (staticPath.toString); // we know this is valid anyway |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
189 dataDir.tryPath (userPath.toString ~ DATA); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
190 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
191 |
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
|
192 // Configuration 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
|
193 confDir.tryPath (staticPath.toString ~ CONF); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
194 bool sysConf = confDir.tryPath (installPath ~ CONF); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
195 confDir.tryPath (userPath.toString ~ CONF, !sysConf); // create if no system conf dir |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
196 if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!"); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
197 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
198 // Logging path: |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
199 logDir = userPath; |
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 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
201 } else { |
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 static assert (false, "Platform is not linux or Windows: no support for paths on this platform yet!"); |
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 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
204 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
205 private: |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
206 // The maximum number of paths for any one "directory". |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
207 // There are NO CHECKS that this is not exceeded. |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
208 const MAX_PATHS = 3; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
209 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
210 Logger logger; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
211 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
212 /* Try each path in succession, returning the first to exist and be a folder. |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
213 * If none are valid and create is true, will try creating each in turn. |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
214 * If still none are valid, throws. */ |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
215 PathView findPath (bool create, char[][] paths ...) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
216 foreach (path; paths) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
217 PathView pv = new FilePath (path); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
218 if (pv.exists && pv.isFolder) return pv; // got a valid path |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
219 } |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
220 if (create) { // try to create a folder, using each path in turn until succesful |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
221 foreach (path; paths) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
222 PathView pv = new FilePath (path); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
223 try { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
224 return pv; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
225 } |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
226 catch (Exception e) {} |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
227 } |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
228 } |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
229 // no valid path... |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
230 logger.fatal ("Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:"); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
231 foreach (path; paths) logger.fatal ('\t' ~ path); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
232 throw new mdeException ("Unable to resolve a required path (see log for details)."); |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
233 } |
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 //END Path resolution |
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 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
236 /** A special adapter for reading from multiple mergetag files with the same relative path to an |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
237 * mdeDirectory simultaneously. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
238 */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
239 class mdeReader : IReader |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
240 { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
241 private this (char[] file, PRIORITY readOrder, DataSet ds, bool rdHeader, 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
|
242 in { assert (readOrder == PRIORITY.LOW_HIGH || readOrder == PRIORITY.HIGH_LOW); } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
243 body { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
244 rdOrder = readOrder; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
245 if (ds is null) ds = new 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
|
246 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
247 foreach (path; 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
|
248 try { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
249 IReader r = makeReader (path~file, ds, rdHeader); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
250 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
251 readers[readersLen++] = r; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
252 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
253 catch (MTFileIOException) {} // Ignore errors regarding no file for now. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
255 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
256 if (readersLen == 0) { // totally failed to find any valid files |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
257 throw new MTFileIOException ("Unable to find the file: "~file~"[.mtt|mtb]"); |
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
|
258 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
259 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
260 // This is simply the easiest way of adjusting the reading order: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
261 if (readOrder == PRIORITY.HIGH_LOW) readers[0..readersLen].reverse; |
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 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
263 |
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 DataSet dataset () { /// Get the 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
|
265 return readers[0].dataset; // all readers share the same 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
|
266 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
267 void dataset (DataSet ds) { /// Set the 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
|
268 for (uint i = 0; i < readersLen; ++i) readers[i].dataset (ds); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
269 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
270 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
271 void dataSecCreator (IDataSection delegate (ID) dsC) { /// Set the dataSecCreator |
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 for (uint i = 0; i < readersLen; ++i) readers[i].dataSecCreator = dsC; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
273 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
274 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
275 /** Get identifiers for all sections. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
276 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
277 * Note: the identifiers from all sections in all files are just strung together, starting with |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
278 * the highest-priority file. */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
279 ID[] getSectionNames () { |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
280 ID[] names; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
281 for (int i = readersLen-1; i >= 0; --i) names ~= readers[i].getSectionNames; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
282 return names; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
283 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
284 void read () { /// Commence reading |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
285 for (uint i = 0; i < readersLen; ++i) readers[i].read(); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
286 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
287 void read (ID[] secSet) { /// ditto |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
288 for (uint i = 0; i < readersLen; ++i) readers[i].read(secSet); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
289 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
290 void read (View!(ID) secSet) { /// ditto |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
291 for (uint i = 0; i < readersLen; ++i) readers[i].read(secSet); |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
292 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
293 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
294 private: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
295 IReader[MAX_PATHS] readers; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
296 ubyte readersLen = 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
|
297 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
298 PRIORITY rdOrder; |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
299 } |