From dc2a6d7bcee85481f3e53daffdb00436af01c309 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:02:43 +0100 Subject: feat: Add option to clone existing profile (#761) * add dev button to refetch profiles * add dialog box with a table of all profiles * add button to delete non default profiles to dialog box * add button to clone profile to dialog box * style: Add trailing comma * docs: Add doc comment explaining function * fix: Remove leftover testing code * fix: Delete duplicate function registration * chore: Sort Tauri function registrations alphabetically --------- Co-authored-by: Jan200101 --- src-tauri/src/northstar/profile.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src-tauri/src/northstar') diff --git a/src-tauri/src/northstar/profile.rs b/src-tauri/src/northstar/profile.rs index b0c6c418..26a32d6b 100644 --- a/src-tauri/src/northstar/profile.rs +++ b/src-tauri/src/northstar/profile.rs @@ -1,3 +1,4 @@ +use crate::util::copy_dir_all; use crate::GameInstall; // These folders are part of Titanfall 2 and @@ -91,3 +92,30 @@ pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), Err(err) => Err(format!("Failed to delete Profile: {}", err)), } } + +/// Clones a profile by simply duplicating the folder under a new name +#[tauri::command] +pub fn clone_profile( + game_install: GameInstall, + old_profile: String, + new_profile: String, +) -> Result<(), String> { + // Check if the old Profile already exists + if !validate_profile(game_install.clone(), old_profile.clone()) { + return Err(format!("{} is not a valid Profile", old_profile)); + } + + // Check that new Profile does not already exist + if validate_profile(game_install.clone(), new_profile.clone()) { + return Err(format!("{} already exists", new_profile)); + } + + log::info!("Cloning Profile {} to {}", old_profile, new_profile); + + let old_profile_path = format!("{}/{}", game_install.game_path, old_profile); + let new_profile_path = format!("{}/{}", game_install.game_path, new_profile); + + copy_dir_all(old_profile_path, new_profile_path).unwrap(); + + Ok(()) +} -- cgit v1.2.3