|
|
@@ -12,7 +12,11 @@ static DEFAULT_CONFIG: &'static str = "";
|
|
12
|
12
|
static DEFAULT_TILE_SOURCES: &'static str = include_str!("../default_tile_sources.toml");
|
|
13
|
13
|
|
|
14
|
14
|
lazy_static! {
|
|
15
|
|
- static ref PROJ_DIRS: ProjectDirs = ProjectDirs::from("", "", "DeltaMap");
|
|
|
15
|
+ static ref PROJ_DIRS: Option<ProjectDirs> = ProjectDirs::from("", "", "DeltaMap");
|
|
|
16
|
+}
|
|
|
17
|
+
|
|
|
18
|
+fn proj_dirs_result() -> Result<&'static ProjectDirs, String> {
|
|
|
19
|
+ PROJ_DIRS.as_ref().ok_or_else(|| "could not retrieve project directories".to_string())
|
|
16
|
20
|
}
|
|
17
|
21
|
|
|
18
|
22
|
|
|
|
@@ -77,7 +81,7 @@ impl Config {
|
|
77
|
81
|
}
|
|
78
|
82
|
|
|
79
|
83
|
fn find_or_create() -> Result<Config, String> {
|
|
80
|
|
- let config_dir = PROJ_DIRS.config_dir();
|
|
|
84
|
+ let config_dir = proj_dirs_result()?.config_dir();
|
|
81
|
85
|
let config_file = {
|
|
82
|
86
|
let mut path = PathBuf::from(config_dir);
|
|
83
|
87
|
path.push("config.toml");
|
|
|
@@ -110,7 +114,7 @@ impl Config {
|
|
110
|
114
|
}
|
|
111
|
115
|
|
|
112
|
116
|
fn add_tile_sources_from_default_or_create(&mut self) -> Result<(), String> {
|
|
113
|
|
- let config_dir = PROJ_DIRS.config_dir();
|
|
|
117
|
+ let config_dir = proj_dirs_result()?.config_dir();
|
|
114
|
118
|
let sources_file = {
|
|
115
|
119
|
let mut path = PathBuf::from(config_dir);
|
|
116
|
120
|
path.push("tile_sources.toml");
|
|
|
@@ -142,14 +146,6 @@ impl Config {
|
|
142
|
146
|
}
|
|
143
|
147
|
}
|
|
144
|
148
|
|
|
145
|
|
- /// Returns a tile cache directory path at a standard location. The returned path may not
|
|
146
|
|
- /// exist.
|
|
147
|
|
- fn default_tile_cache_dir() -> PathBuf {
|
|
148
|
|
- let mut path = PathBuf::from(PROJ_DIRS.cache_dir());
|
|
149
|
|
- path.push("tiles");
|
|
150
|
|
- path
|
|
151
|
|
- }
|
|
152
|
|
-
|
|
153
|
149
|
fn from_toml_str<P: AsRef<Path>>(toml_str: &str, config_path: Option<P>) -> Result<Config, String> {
|
|
154
|
150
|
match toml_str.parse::<Value>() {
|
|
155
|
151
|
Ok(Value::Table(ref table)) => {
|
|
|
@@ -161,7 +157,11 @@ impl Config {
|
|
161
|
157
|
.ok_or_else(|| "tile_cache_dir has to be a string".to_string())?
|
|
162
|
158
|
)
|
|
163
|
159
|
},
|
|
164
|
|
- None => Config::default_tile_cache_dir(),
|
|
|
160
|
+ None => {
|
|
|
161
|
+ let mut path = PathBuf::from(proj_dirs_result()?.cache_dir());
|
|
|
162
|
+ path.push("tiles");
|
|
|
163
|
+ path
|
|
|
164
|
+ },
|
|
165
|
165
|
}
|
|
166
|
166
|
};
|
|
167
|
167
|
|
|
|
@@ -430,7 +430,7 @@ fn create_config_file<P: AsRef<Path> + Debug>(dir_path: P, file_path: P, content
|
|
430
|
430
|
|
|
431
|
431
|
pub fn read_last_session() -> Result<Session, String> {
|
|
432
|
432
|
let session_path = {
|
|
433
|
|
- let config_dir = PROJ_DIRS.config_dir();
|
|
|
433
|
+ let config_dir = proj_dirs_result()?.config_dir();
|
|
434
|
434
|
let mut path = PathBuf::from(config_dir);
|
|
435
|
435
|
path.push("last_session.toml");
|
|
436
|
436
|
path
|
|
|
@@ -440,7 +440,7 @@ pub fn read_last_session() -> Result<Session, String> {
|
|
440
|
440
|
|
|
441
|
441
|
pub fn save_session(session: &Session) -> Result<(), String>
|
|
442
|
442
|
{
|
|
443
|
|
- let config_dir = PROJ_DIRS.config_dir();
|
|
|
443
|
+ let config_dir = proj_dirs_result()?.config_dir();
|
|
444
|
444
|
let session_path = {
|
|
445
|
445
|
let mut path = PathBuf::from(config_dir);
|
|
446
|
446
|
path.push("last_session.toml");
|