Mercurial > projects > mde
annotate mde/file/paths.d @ 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.
Content restrutured a lot:
New IContent module, Content module includes more functionality.
New ContentLoader module to manage content loading/saving/translation.
Translation module moved to content dir and cut down to reflect current usage.
File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen.
Font render mode and LCD filter options are now enums.
GUI loading needs to create content (and set type for enums), but doesn't save/load value.
Some setup of mainSchedule moved to mde.mainLoop.
Content callbacks are called on content change now.
ContentLists are set up implicitly from content symbols. Not as fast but much easier!
Bug-fix in the new MTTagReader.
Renamed MT *Reader maker functions to avoid confusion in paths.d.
New mde.setup.logger module to allow logger setup before any other module's static this().
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 07 Feb 2009 12:46:03 +0000 |
parents | 4084f07f2c7a |
children | e785e98d3b78 |
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 |
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
|
54 debug { |
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
|
55 import tango.util.log.Log : Log, Logger; |
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
|
56 private Logger logger; |
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
|
57 static this() { |
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
|
58 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
|
59 } |
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
|
60 } |
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
|
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 /** 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
|
63 * |
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 * 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
|
65 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
|
66 |
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 /** 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
|
68 * |
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
|
69 * 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
|
70 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
71 * 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
|
72 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
|
73 { |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
74 /** 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
|
75 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
76 * Params: |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
77 * 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
|
78 * 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
|
79 * 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
|
80 * 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
|
81 * 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
|
82 * 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
|
83 * 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
|
84 * 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
|
85 * 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
|
86 * 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
|
87 * 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
|
88 * 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
|
89 * 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
|
90 */ |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
91 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
|
92 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
|
93 } |
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 /** 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
|
96 * |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
97 * Params as for makeMTReader. |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
98 */ |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
99 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
|
100 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
|
101 } |
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 /** 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
|
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 * 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
|
106 * 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
|
107 * (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
|
108 * 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
|
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 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
|
111 { |
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 // 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
|
113 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
|
114 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
115 |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
116 /** 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
|
117 MTTagWriter makeMTTagWriter (char[] file) |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
118 { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
119 // 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
|
120 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
|
121 } |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
122 |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
123 /** 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
|
124 * 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
|
125 * for user output only. */ |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
126 char[] getFileName (char[] file, PRIORITY readOrder) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
127 { |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
128 FilePath[] files; |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
129 try { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
130 files = getFiles (file, readOrder); |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
131 } catch (NoFileException e) { |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
132 return e.msg; |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
133 } |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
134 |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
135 char[] ret = files[0].toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
136 foreach (f; files[1..$]) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
137 ret ~= ", " ~ f.toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
138 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
139 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
140 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
141 /// 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
|
142 static void printPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
143 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
|
144 dataDir.coutPaths; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 Cout.newline; |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
152 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
153 |
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
|
154 private: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
155 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
|
156 { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
157 FilePath[] ret; |
68
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
67
diff
changeset
|
158 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
159 if (readOrder == PRIORITY.LOW_HIGH) { |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
160 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
|
161 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
|
162 if (file !is null) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
163 ret ~= file; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
164 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
165 } 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
|
166 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
|
167 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
|
168 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
169 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
|
170 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
|
171 if (file !is null) |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
172 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
|
173 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
|
174 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
175 } |
136
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
176 if (ret is null) |
4084f07f2c7a
Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
135
diff
changeset
|
177 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
|
178 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
179 } |
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
|
180 |
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 // 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
|
182 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
|
183 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
|
184 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
|
185 } |
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 |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
187 // 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
|
188 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
|
189 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
|
190 FilePath fp = FilePath (path); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
191 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
|
192 paths[pathsLen++] = path~'/'; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
193 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
194 } else if (create) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
195 try { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
196 fp.create; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
197 paths[pathsLen++] = fp.toString~'/'; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
198 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
199 } catch (Exception e) { |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
200 // No logging avaiable yet: Use Stdout/Cout |
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
201 Cout ("Creating path "~path~" failed:" ~ e.msg).newline; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
202 } |
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
|
203 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
204 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
|
205 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
206 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
207 void coutPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
208 if (pathsLen) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
209 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
|
210 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
|
211 } else |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
212 Cout ("[none]"); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
213 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
214 |
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
|
215 // 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
|
216 // 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
|
217 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
|
218 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
|
219 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
220 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
221 /** 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
|
222 * |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
223 * 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
230 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
|
231 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
232 |
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
|
233 /** 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
|
234 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
|
235 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
|
236 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
|
237 |
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 //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
|
239 /// 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
|
240 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
|
241 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
242 /** 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 } |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
248 |
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
|
249 /** 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
|
250 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
|
251 /** 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 // 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
|
258 } |
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
|
259 } |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
264 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
|
265 // Home directory: |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
266 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
|
267 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
268 // 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
|
269 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
|
270 "/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
|
271 "/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
|
272 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
|
273 // 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
|
274 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
|
275 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
276 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
|
277 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
|
278 confDir.tryPath ("/etc/mde"); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
279 |
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
|
280 // 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
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 } 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
|
291 //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
|
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 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
|
294 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
|
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 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
|
297 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
|
298 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
299 // 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
|
300 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
|
301 } else { |
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 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
|
303 } |
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
|
304 |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
305 // 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
|
306 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
|
307 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
|
308 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
309 // 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
|
310 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
|
311 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
|
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 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
314 if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!"); |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
315 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
316 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
|
317 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
|
318 Cout ("considering: ")(font.toString).newline; |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
319 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
|
320 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
|
321 } |
135
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
322 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
|
323 |
bc697a218716
Somewhat unified path lookup between linux and windows and added font paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
134
diff
changeset
|
324 // 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
|
325 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
|
326 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
327 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
328 private { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
329 class PathException : mdeException { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
330 this(char[] msg) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
331 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
|
332 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
333 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
334 |
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
|
335 // 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
|
336 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
|
337 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
338 /* 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
|
339 * 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
|
340 * 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
|
341 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
|
342 FilePath[] fps; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 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
|
347 fps[i] = pv; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
348 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
349 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
|
350 foreach (fp; fps) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
351 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
352 return fp.create; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
353 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
354 catch (Exception e) {} |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
355 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
356 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
357 // no valid path... |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 } |
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
|
362 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
363 //END Path resolution |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
364 |
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
|
365 /// 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
|
366 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
|
367 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
|
368 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
|
369 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
370 } |