diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-10-10 18:21:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 18:21:12 +0200 |
commit | 255ce14f3c36f5e1f2bf5e8242070d0129f15ac1 (patch) | |
tree | 390f740edd697b205dd643fb425df4106020ccdf /src-tauri | |
parent | 1815aa8c99deb25bee576c39f3758a1f42e7f4b0 (diff) | |
download | FlightCore-255ce14f3c36f5e1f2bf5e8242070d0129f15ac1.tar.gz FlightCore-255ce14f3c36f5e1f2bf5e8242070d0129f15ac1.zip |
feat: Add button to delete profile (#603)
This adds a button and corresponding logic to delete an existing profile
Spliced out from #444
Co-authored-by: Jan <sentrycraft123@gmail.com>
Diffstat (limited to 'src-tauri')
-rw-r--r-- | src-tauri/src/main.rs | 1 | ||||
-rw-r--r-- | src-tauri/src/northstar/profile.rs | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 66bb98d2..47cfee6a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -160,6 +160,7 @@ fn main() { get_available_northstar_versions, northstar::profile::fetch_profiles, northstar::profile::validate_profile, + northstar::profile::delete_profile, ]) .run(tauri::generate_context!()) { diff --git a/src-tauri/src/northstar/profile.rs b/src-tauri/src/northstar/profile.rs index 78e734d0..b0c6c418 100644 --- a/src-tauri/src/northstar/profile.rs +++ b/src-tauri/src/northstar/profile.rs @@ -74,3 +74,20 @@ pub fn validate_profile(game_install: GameInstall, profile: String) -> bool { profile_dir.is_dir() } + +#[tauri::command] +pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), String> { + // Check if the Profile actually exists + if !validate_profile(game_install.clone(), profile.clone()) { + return Err(format!("{} is not a valid Profile", profile)); + } + + log::info!("Deleting Profile {}", profile); + + let profile_path = format!("{}/{}", game_install.game_path, profile); + + match std::fs::remove_dir_all(profile_path) { + Ok(()) => Ok(()), + Err(err) => Err(format!("Failed to delete Profile: {}", err)), + } +} |