Skip to content

Commit 1e5f408

Browse files
yungcomputerchairCakeLancelot
authored andcommitted
Add config option to LauncherSettings for deleting old game caches
committed from 🇯🇵
1 parent 7c9360c commit 1e5f408

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

app/settings/LauncherSettingsTab.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ export default function LauncherSettingsTab({
182182
}))
183183
}
184184
/>
185+
<SettingControlDropdown
186+
id="delete_old_game_caches"
187+
name="Delete old game caches on upgrades"
188+
options={[
189+
{ key: "yes", value: true, label: "Yes" },
190+
{ key: "no", value: false, label: "No" },
191+
]}
192+
defaultKey="no"
193+
oldValue={currentSettings.delete_old_game_caches}
194+
value={settings.delete_old_game_caches}
195+
onChange={(value) =>
196+
setSettings((current) => ({
197+
...current!,
198+
delete_old_game_caches: value,
199+
}))
200+
}
201+
/>
185202
<SettingControlDropdown
186203
id="launch_behavior"
187204
name="Launch behavior"

app/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type LauncherSettings = {
3838
check_for_updates: boolean;
3939
use_offline_caches: boolean;
4040
verify_offline_caches: boolean;
41+
delete_old_game_caches: boolean;
4142
launch_behavior: string;
4243
game_cache_path: string;
4344
offline_cache_path: string;

src-tauri/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub struct LauncherSettings {
3232
#[serde(default = "util::false_fn")]
3333
pub verify_offline_caches: bool,
3434

35+
#[serde(default = "util::false_fn")]
36+
pub delete_old_game_caches: bool,
37+
3538
#[serde(default)]
3639
pub launch_behavior: LaunchBehavior,
3740

@@ -48,6 +51,7 @@ impl Default for LauncherSettings {
4851
theme: None,
4952
use_offline_caches: true,
5053
verify_offline_caches: false,
54+
delete_old_game_caches: false,
5155
launch_behavior: LaunchBehavior::Hide,
5256
game_cache_path: util::get_default_cache_dir(),
5357
offline_cache_path: util::get_default_offline_cache_dir(),

src-tauri/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ 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 {
433+
if let Err(e) = util::delete_dir(&parent_cache_dir) {
434+
warn!(
435+
"Failed to delete cache for parent version {}: {}",
436+
parent_uuid, e
437+
);
438+
} else {
439+
info!(
440+
"Deleted cache for parent version {}",
441+
parent_uuid
442+
);
443+
}
444+
}
432445
}
433446
}
434447
}

src-tauri/src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ pub(crate) fn copy_dir(src: &PathBuf, dest: &PathBuf) -> Result<()> {
147147
Ok(())
148148
}
149149

150+
pub(crate) fn delete_dir(dir: &PathBuf) -> Result<()> {
151+
if dir.exists() {
152+
std::fs::remove_dir_all(dir)?;
153+
}
154+
Ok(())
155+
}
156+
150157
pub(crate) fn is_dir_empty(dir: &PathBuf) -> Result<bool> {
151158
match std::fs::read_dir(dir) {
152159
Ok(mut entries) => Ok(entries.next().is_none()),

0 commit comments

Comments
 (0)