Selaa lähdekoodia

Update directories (to 1.0)

Johannes Hofmann 7 vuotta sitten
vanhempi
commit
1e62ec6a99
3 muutettua tiedostoa jossa 22 lisäystä ja 21 poistoa
  1. 7
    6
      Cargo.lock
  2. 1
    1
      Cargo.toml
  3. 14
    14
      src/config.rs

+ 7
- 6
Cargo.lock Näytä tiedosto

@@ -284,8 +284,8 @@ version = "0.1.0"
284 284
 dependencies = [
285 285
  "cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
286 286
  "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
287
- "directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
288
- "env_logger 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
287
+ "directories 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
288
+ "env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
289 289
  "gl 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
290 290
  "gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
291 291
  "glutin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -303,9 +303,10 @@ dependencies = [
303 303
 
304 304
 [[package]]
305 305
 name = "directories"
306
-version = "0.10.0"
306
+version = "1.0.1"
307 307
 source = "registry+https://github.com/rust-lang/crates.io-index"
308 308
 dependencies = [
309
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
309 310
  "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
310 311
 ]
311 312
 
@@ -342,7 +343,7 @@ dependencies = [
342 343
 
343 344
 [[package]]
344 345
 name = "env_logger"
345
-version = "0.5.11"
346
+version = "0.5.12"
346 347
 source = "registry+https://github.com/rust-lang/crates.io-index"
347 348
 dependencies = [
348 349
  "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1777,13 +1778,13 @@ dependencies = [
1777 1778
 "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
1778 1779
 "checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b"
1779 1780
 "checksum deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)" = "32c8120d981901a9970a3a1c97cf8b630e0fa8c3ca31e75b6fd6fd5f9f427b31"
1780
-"checksum directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc2561db021b6f1321d0f16b67ed28ce843ef4610dfaa432e3ffa2e8a3050ebf"
1781
+"checksum directories 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b106a38a9bf6c763c6c2e2c3332ab7635da453a68a6babca776386b3b287d338"
1781 1782
 "checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a"
1782 1783
 "checksum downcast-rs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "18df8ce4470c189d18aa926022da57544f31e154631eb4cfe796aea97051fe6c"
1783 1784
 "checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
1784 1785
 "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
1785 1786
 "checksum encoding_rs 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98fd0f24d1fb71a4a6b9330c8ca04cbd4e7cc5d846b54ca74ff376bc7c9f798d"
1786
-"checksum env_logger 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "7873e292d20e8778f951278972596b3df36ac72a65c5b406f6d4961070a870c1"
1787
+"checksum env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f4d7e69c283751083d53d01eac767407343b8b69c4bd70058e08adc2637cb257"
1787 1788
 "checksum flate2 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "37847f133aae7acf82bb9577ccd8bda241df836787642654286e79679826a54b"
1788 1789
 "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
1789 1790
 "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"

+ 1
- 1
Cargo.toml Näytä tiedosto

@@ -13,7 +13,7 @@ license = "GPL-3.0"
13 13
 [dependencies]
14 14
 cgmath = "0.16"
15 15
 clap = "2.29"
16
-directories = "0.10"
16
+directories = "1.0"
17 17
 env_logger = "0.5.0-rc.2"
18 18
 gl = "0.10"
19 19
 glutin = "0.18"

+ 14
- 14
src/config.rs Näytä tiedosto

@@ -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");