Mercurial > projects > mde
annotate mde/file/paths.d @ 134:7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 14:59:45 +0000 |
parents | mde/setup/paths.d@1b1e2297e2fc |
children | bc697a218716 |
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; |
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
|
39 import mde.file.mergetag.Writer; |
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.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
|
41 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
|
42 |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 } 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
|
50 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
|
51 |
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 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 } |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
58 } |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 /** Order to read files in. |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 * Values: HIGH_LOW, LOW_HIGH, HIGH_ONLY. */ |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 enum PRIORITY : byte { HIGH_LOW, LOW_HIGH, HIGH_ONLY } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 /** This struct has one instance for each "directory". |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 * |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
67 * It is the only item within this module that you should need to interact with. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
68 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
69 * In the case of confDir, the user path is guaranteed to exist (as highest priority path). */ |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
70 struct mdeDirectory |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 { |
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 /** 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
|
73 * |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 * Params: |
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 * 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
|
76 * (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
|
77 * 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
|
78 * 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
|
79 * 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
|
80 * 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
|
81 * 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
|
82 * 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
|
83 * 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
|
84 * 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
|
85 * 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
|
86 */ |
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 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
|
88 { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
89 FilePath[] files = getFiles (file, readOrder); |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
90 if (files is null) |
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
|
91 throw new NoFileException ("Unable to find the file: "~file~"[.mtt|mtb]"); |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
92 |
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
|
93 return new MTMultiReader (files, ds, rdHeader); |
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
|
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 |
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 /** 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
|
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 * 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
|
99 * 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
|
100 * (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
|
101 * 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
|
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 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
|
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 // 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
|
106 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
|
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 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
109 /** Returns a string listing the file name or names (if readOrder is not HIGH_ONLY and multiple |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
110 * matches are found), or "no file found". Intended for user output only. */ |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
111 char[] getFileName (char[] file, PRIORITY readOrder) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
112 { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
113 FilePath[] files = getFiles (file, readOrder); |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
114 if (files is null) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
115 return "no file found"; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
116 |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
117 char[] ret = files[0].toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
118 foreach (f; files[1..$]) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
119 ret ~= ", " ~ f.toString; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
120 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
121 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
122 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
123 /// 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
|
124 static void printPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
125 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
|
126 dataDir.coutPaths; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
127 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
|
128 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
|
129 Cout ("\nLog file directory:\n\t")(logDir); |
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
|
130 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
|
131 Cout ("\nFont directory:\n\t")(fontDir).newline; |
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
|
132 } else version (linux) { |
106
7f7b40fed72b
Fix & workaround for tango r4134.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
133 Cout ("\nFont files found:"); |
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
|
134 foreach (f,p; fontFiles) |
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
|
135 Cout ("\n\t")(f)("\t")(p[0..$-1]); |
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
|
136 Cout.newline; |
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
|
137 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
138 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
139 |
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
|
140 private: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
141 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
|
142 { |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
143 FilePath[] ret; |
68
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
67
diff
changeset
|
144 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
145 if (readOrder == PRIORITY.LOW_HIGH) { |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
146 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
|
147 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
|
148 if (file !is null) |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
149 ret ~= file; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
150 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
151 } else { |
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
|
152 assert (readOrder == PRIORITY.HIGH_LOW || |
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
|
153 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
|
154 |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
155 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
|
156 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
|
157 if (file !is null) |
47
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
158 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
|
159 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
|
160 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
161 } |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
162 return ret; |
e0839643ff52
New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
163 } |
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
|
164 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
165 // 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
|
166 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
|
167 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
|
168 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
|
169 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
170 |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
171 // 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
|
172 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
|
173 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
|
174 FilePath fp = FilePath (path); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
175 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
|
176 paths[pathsLen++] = path~'/'; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
177 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
178 } else if (create) { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
179 try { |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
180 fp.create; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
181 paths[pathsLen++] = fp.toString~'/'; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
182 return true; |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
183 } catch (Exception e) { |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
184 // 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
|
185 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
|
186 } |
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
|
187 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
188 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
|
189 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
190 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
191 void coutPaths () { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
192 if (pathsLen) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
193 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
|
194 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
|
195 } else |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
196 Cout ("[none]"); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
197 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
198 |
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
|
199 // 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
|
200 // 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
|
201 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
|
202 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
|
203 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
204 |
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 /** 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
|
206 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
|
207 char[] logDir; /// Directory for log files |
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
|
208 |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
209 //BEGIN Path resolution |
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
|
210 /** 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
|
211 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
|
212 /** 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 // 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
|
219 } |
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
|
220 } |
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
|
221 version (linux) { |
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
|
222 SortedMap!(char[],char[]) fontFiles; // key is file name, value is CString path |
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
|
223 /** Get the actual path of a font file, or throw NoFileException if not found. |
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
|
224 * |
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
|
225 * Returns a C string (null terminated). */ |
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
|
226 char[] getFontPath (char[] file) { |
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
|
227 char[] ret; |
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
|
228 if (fontFiles.get (file, ret)) |
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
|
229 return ret; |
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
|
230 throw new NoFileException ("Unable to find font file: "~file); |
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
|
231 } |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
232 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
233 // base-path not used on posix |
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
|
234 void resolvePaths (char[] base = "data") { |
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
|
235 // Home directory: |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
236 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
|
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 // Base paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
239 // Static data (must exist): |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
240 FilePath staticPath = |
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
|
241 findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", base); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
242 // Config (can just use defaults if necessary, so long as we can save afterwards): |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
243 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
|
244 |
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 // Static data paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
246 dataDir.addPath (staticPath.toString); // we know this is valid anyway |
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
|
247 dataDir.tryPath (userPath.toString ~ "/data"); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
248 if (extraDataPath) dataDir.tryPath (extraDataPath); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
249 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
|
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 // Configuration paths: |
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
|
252 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
|
253 confDir.tryPath ("/etc/mde"); |
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
|
254 confDir.tryPath (userPath.toString ~ "/conf", true); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
255 if (extraConfPath) confDir.tryPath (extraConfPath); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
256 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
|
257 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
258 // Logging path: |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
259 logDir = userPath.toString; |
101
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
260 |
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
|
261 // Font paths: |
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
|
262 auto fs = new 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
|
263 // Scan for directories containing truetype and type1 fonts: |
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
|
264 fs.sweep ("/usr/share/fonts", delegate bool(FilePath fp, bool isDir) |
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
|
265 { return isDir || fp.suffix == ".ttf" || fp.suffix == ".pfb"; }, |
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
|
266 true); |
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
|
267 fontFiles = new SortedMap!(char[],char[]); |
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
|
268 foreach (fp; fs.files) |
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
|
269 fontFiles.add (fp.file, fp.cString); // both strings should be slices of same memory |
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
|
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 } else version (Windows) { |
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
|
272 char[] fontDir; |
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
|
273 /** Get the actual path of a font file, or throw NoFileException if not found. |
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
|
274 * |
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
|
275 * Returns a C string (null terminated). */ |
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
|
276 char[] getFontPath (char[] file) { |
71f0f1f83620
Some path adjustments for windows (untested) and fonts. All types of option can be edited.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
277 FilePath path = new FilePath (fontDir~file); |
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
|
278 if (path.exists && !path.isFolder) |
102
ba035eba07b4
Compilation fixes for windows and unittest code.
Cyborg16@cyborg64-win.lan
parents:
101
diff
changeset
|
279 return path.cString; |
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 throw new NoFileException ("Unable to find font file: "~file); |
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
|
281 } |
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
|
282 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
283 void resolvePaths (char[] base = "./") { |
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
|
284 //FIXME: Get base path from registry |
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
|
285 |
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 // Base paths: |
67
108d123238c0
Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
287 FilePath installPath = findPath (false, base); |
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
|
288 FilePath staticPath = findPath (false, installPath.toString); |
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
|
289 FilePath userPath = findPath (true, getSpecialPath(CSIDL_LOCAL_APPDATA) ~ "/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
|
290 |
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 // Static data paths: |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
292 dataDir.addPath (staticPath.toString); // we know this is valid anyway |
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
|
293 dataDir.tryPath (userPath.toString ~ "/data"); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
294 if (extraDataPath) dataDir.tryPath (extraDataPath); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
295 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
296 |
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
|
297 // Configuration paths: |
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
|
298 confDir.tryPath (staticPath.toString ~ "/conf"); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
299 confDir.tryPath (installPath.append("user").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
|
300 confDir.tryPath (userPath.toString ~ "/conf", true); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
301 if (extraConfPath) confDir.tryPath (extraConfPath); |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
302 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
|
303 |
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
304 // Logging path: |
28
b5fadd8d930b
Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
305 logDir = userPath.toString; |
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
|
306 |
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
|
307 // Font path: |
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
|
308 fontDir = getSpecialPath (CSIDL_FONTS) ~ "/"; // append separator |
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
|
309 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
310 } 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
|
311 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
|
312 } |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
313 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
314 /// For command line args: these paths are added if non-null, with highest priority. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
315 char[] extraDataPath, extraConfPath; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
316 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
317 private { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
318 class PathException : mdeException { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
319 this(char[] msg) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
320 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
|
321 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
322 } |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
323 |
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
|
324 // 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
|
325 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
|
326 static assert (MTMultiReader.MAX_READERS == MAX_PATHS, "MAX_PATHS not all equal"); |
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
|
327 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
328 /* 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
|
329 * 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
|
330 * 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
|
331 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
|
332 FilePath[] fps; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 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
|
337 fps[i] = pv; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
338 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
339 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
|
340 foreach (fp; fps) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
341 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
342 return fp.create; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
343 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
344 catch (Exception e) {} |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
345 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
346 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
347 // no valid path... |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 } |
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
|
352 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
353 //END Path resolution |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
354 |
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
|
355 /// 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
|
356 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
|
357 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
|
358 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
|
359 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
360 } |