Skip to content

Commit 5c675dc

Browse files
yungcomputerchairCakeLancelot
authored andcommitted
Don't delete old game cache if it's in use by another server
1 parent 1e5f408 commit 5c675dc

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src-tauri/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,17 @@ async fn prep_launch(
429429
"Upgraded cache from parent version {} for {}",
430430
parent_uuid, version_uuid
431431
);
432-
if state.config.launcher.delete_old_game_caches {
432+
433+
if state.config.launcher.delete_old_game_caches
434+
&& state.get_version_use_count(parent_uuid) == 0
435+
{
433436
if let Err(e) = util::delete_dir(&parent_cache_dir) {
434437
warn!(
435438
"Failed to delete cache for parent version {}: {}",
436439
parent_uuid, e
437440
);
438441
} else {
439-
info!(
440-
"Deleted cache for parent version {}",
441-
parent_uuid
442-
);
442+
info!("Deleted cache for parent version {}", parent_uuid);
443443
}
444444
}
445445
}

src-tauri/src/state.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ impl AppState {
179179
versions.extend(imported);
180180
Ok(num_imported)
181181
}
182+
183+
pub fn get_version_use_count(&self, uuid: Uuid) -> usize {
184+
self.servers
185+
.servers
186+
.iter()
187+
.filter(|s| match &s.info {
188+
ServerInfo::Simple { version, .. } => version == &uuid.to_string(),
189+
// for endpoint servers, this is less straightforward since we don't know the versions
190+
// until we query the endpoint, and we really don't want to query every endpoint server to get this info.
191+
// we can use the user's preferred version as a best guess here
192+
// and it'll be fine since most cache upgrades happen only when a version is deprecated by a server anyway.
193+
ServerInfo::Endpoint {
194+
preferred_version, ..
195+
} => preferred_version.as_ref() == Some(&uuid.to_string()),
196+
})
197+
.count()
198+
}
182199
}
183200

184201
#[derive(Debug, Serialize, Deserialize, Clone, Default)]

0 commit comments

Comments
 (0)