浏览代码

Update directories (to 1.0)

Johannes Hofmann 7 年前
父节点
当前提交
1e62ec6a99
共有 3 个文件被更改,包括 22 次插入21 次删除
  1. 7
    6
      Cargo.lock
  2. 1
    1
      Cargo.toml
  3. 14
    14
      src/config.rs

+ 7
- 6
Cargo.lock 查看文件

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

+ 1
- 1
Cargo.toml 查看文件

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

+ 14
- 14
src/config.rs 查看文件

12
 static DEFAULT_TILE_SOURCES: &'static str = include_str!("../default_tile_sources.toml");
12
 static DEFAULT_TILE_SOURCES: &'static str = include_str!("../default_tile_sources.toml");
13
 
13
 
14
 lazy_static! {
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
     }
81
     }
78
 
82
 
79
     fn find_or_create() -> Result<Config, String> {
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
         let config_file = {
85
         let config_file = {
82
             let mut path = PathBuf::from(config_dir);
86
             let mut path = PathBuf::from(config_dir);
83
             path.push("config.toml");
87
             path.push("config.toml");
110
     }
114
     }
111
 
115
 
112
     fn add_tile_sources_from_default_or_create(&mut self) -> Result<(), String> {
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
         let sources_file = {
118
         let sources_file = {
115
             let mut path = PathBuf::from(config_dir);
119
             let mut path = PathBuf::from(config_dir);
116
             path.push("tile_sources.toml");
120
             path.push("tile_sources.toml");
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
     fn from_toml_str<P: AsRef<Path>>(toml_str: &str, config_path: Option<P>) -> Result<Config, String> {
149
     fn from_toml_str<P: AsRef<Path>>(toml_str: &str, config_path: Option<P>) -> Result<Config, String> {
154
         match toml_str.parse::<Value>() {
150
         match toml_str.parse::<Value>() {
155
             Ok(Value::Table(ref table)) => {
151
             Ok(Value::Table(ref table)) => {
161
                                    .ok_or_else(|| "tile_cache_dir has to be a string".to_string())?
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
 
430
 
431
 pub fn read_last_session() -> Result<Session, String> {
431
 pub fn read_last_session() -> Result<Session, String> {
432
     let session_path = {
432
     let session_path = {
433
-        let config_dir = PROJ_DIRS.config_dir();
433
+        let config_dir = proj_dirs_result()?.config_dir();
434
         let mut path = PathBuf::from(config_dir);
434
         let mut path = PathBuf::from(config_dir);
435
         path.push("last_session.toml");
435
         path.push("last_session.toml");
436
         path
436
         path
440
 
440
 
441
 pub fn save_session(session: &Session) -> Result<(), String>
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
     let session_path = {
444
     let session_path = {
445
         let mut path = PathBuf::from(config_dir);
445
         let mut path = PathBuf::from(config_dir);
446
         path.push("last_session.toml");
446
         path.push("last_session.toml");