Skip to content

Commit 5fea437

Browse files
New config
1 parent b1f6c06 commit 5fea437

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

resources/defaults/config.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"autoupdate-check": true,
3-
"cache-swapping": true,
4-
"enable-offline-cache": true,
5-
"verify-offline-cache": false,
6-
"last-version-initialized": "1.0"
2+
"check_for_updates": true,
3+
"use_offline_caches": true
74
}

src-tauri/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ async fn prep_launch(
176176
return Err(format!("Version {} not found", version_uuid).into());
177177
};
178178

179-
let cache_dir = util::get_cache_dir_for_version(version)?;
179+
let base_cache_dir = &state.config.game_cache_path;
180+
let cache_dir = util::get_cache_dir_for_version(base_cache_dir, version)?;
180181
unsafe {
181182
env::set_var("UNITY_FF_CACHE_DIR", cache_dir);
182183
}

src-tauri/src/state.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct AppStatics {
2828
pub app_data_dir: PathBuf,
2929
pub resource_dir: PathBuf,
3030
pub ff_cache_dir: PathBuf,
31+
pub offline_cache_dir: PathBuf,
3132
pub ffrunner_log_path: PathBuf,
3233
}
3334
impl AppStatics {
@@ -39,6 +40,9 @@ impl AppStatics {
3940
let ff_cache_dir = path_resolver
4041
.resolve("ffcache", BaseDirectory::AppCache)
4142
.unwrap();
43+
let offline_cache_dir = path_resolver
44+
.resolve("offline_cache", BaseDirectory::AppCache)
45+
.unwrap();
4246
let ffrunner_log_path = path_resolver
4347
.resolve("ffrunner.log", BaseDirectory::AppCache)
4448
.unwrap();
@@ -47,6 +51,7 @@ impl AppStatics {
4751
app_data_dir,
4852
resource_dir,
4953
ff_cache_dir,
54+
offline_cache_dir,
5055
ffrunner_log_path,
5156
}
5257
}
@@ -142,33 +147,19 @@ impl AppState {
142147
}
143148
}
144149

145-
#[derive(Debug, Serialize, Deserialize, Clone)]
150+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
146151
pub struct Config {
147-
#[serde(alias = "autoupdate-check")]
148152
#[serde(default = "util::true_fn")]
149-
autoupdate_check: bool,
153+
pub check_for_updates: bool,
150154

151-
#[serde(alias = "cache-swapping")]
152155
#[serde(default = "util::true_fn")]
153-
cache_swapping: bool,
156+
pub use_offline_caches: bool,
154157

155-
#[serde(alias = "enable-offline-cache")]
156-
#[serde(default = "util::true_fn")]
157-
enable_offline_cache: bool,
158+
#[serde(default = "util::get_default_cache_dir")]
159+
pub game_cache_path: String,
158160

159-
#[serde(alias = "verify-offline-cache")]
160-
#[serde(default = "util::false_fn")]
161-
verify_offline_cache: bool,
162-
}
163-
impl Default for Config {
164-
fn default() -> Self {
165-
Self {
166-
autoupdate_check: true,
167-
cache_swapping: true,
168-
enable_offline_cache: true,
169-
verify_offline_cache: false,
170-
}
171-
}
161+
#[serde(default = "util::get_default_offline_cache_dir")]
162+
pub offline_cache_path: String,
172163
}
173164
impl Config {
174165
fn new() -> Self {

src-tauri/src/util.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,19 @@ pub fn resolve_server_addr(addr: &str) -> Result<String> {
6262
Ok(format!("{}:{}", ip, port))
6363
}
6464

65-
pub fn get_cache_dir_for_version(version: &Version) -> Result<PathBuf> {
66-
let cache_dir = get_app_statics().ff_cache_dir.clone();
65+
pub fn get_default_cache_dir() -> String {
66+
get_app_statics().ff_cache_dir.to_string_lossy().to_string()
67+
}
68+
69+
pub fn get_default_offline_cache_dir() -> String {
70+
get_app_statics()
71+
.offline_cache_dir
72+
.to_string_lossy()
73+
.to_string()
74+
}
75+
76+
pub fn get_cache_dir_for_version(base_cache_dir: &str, version: &Version) -> Result<PathBuf> {
77+
let cache_dir = PathBuf::from(base_cache_dir);
6778
let build_dir = cache_dir.join(version.get_uuid().to_string());
6879
std::fs::create_dir_all(&build_dir)?;
6980
Ok(build_dir)

0 commit comments

Comments
 (0)