feat: the other profile buttons

This commit is contained in:
2025-03-14 00:23:47 +00:00
parent fd27000c05
commit 90ba27c967
11 changed files with 112 additions and 33 deletions

View File

@ -7,7 +7,7 @@ use crate::model::misc::Game;
use crate::pkg::{Package, PkgKey};
use crate::pkg_store::InstallResult;
use crate::profiles::ongeki::OngekiProfile;
use crate::profiles::{AnyProfile, Profile, ProfileMeta, ProfilePaths};
use crate::profiles::{self, AnyProfile, Profile, ProfileMeta, ProfilePaths};
use crate::appdata::AppData;
use crate::util;
@ -159,24 +159,63 @@ pub async fn rename_profile(
let new_meta = ProfileMeta {
game: profile.game.clone(),
name: name.clone()
name: profiles::fixed_name(&ProfileMeta { game: profile.game.clone(), name }, false)
};
if new_meta.name == profile.name {
return Ok(());
}
if new_meta.config_dir().exists() {
return Err(format!("Profile {} already exists", &name));
return Err(format!("Profile {} already exists", &new_meta.name));
}
fs::rename(profile.config_dir(), new_meta.config_dir()).await
.map_err(|e| format!("Unable to rename: {}", e))?;
if let Err(e) = fs::rename(profile.data_dir(), new_meta.data_dir()).await {
log::warn!("Unable to move data dir {}->{}: {}", &profile.name, &name, e);
log::warn!("Unable to move data dir {}->{}: {}", &profile.name, &new_meta.name, e);
}
let mut appd = state.lock().await;
if let Some(current) = &mut appd.profile {
if current.meta() == profile {
current.rename(name);
current.rename(new_meta.name);
}
}
Ok(())
}
#[tauri::command]
pub async fn duplicate_profile(profile: ProfileMeta) -> Result<(), String> {
log::debug!("invoke: duplicate_profile({:?})", profile);
let new_meta = ProfileMeta {
game: profile.game.clone(),
name: profiles::fixed_name(&profile, true)
};
util::copy_directory(profile.config_dir(), new_meta.config_dir(), false)
.map_err(|e| format!("Unable to duplicate: {}", e))?;
Ok(())
}
#[tauri::command]
pub async fn delete_profile(state: State<'_, Mutex<AppData>>, profile: ProfileMeta) -> Result<(), String> {
log::debug!("invoke: delete_profile({:?})", profile);
std::fs::remove_dir_all(profile.config_dir())
.map_err(|e| format!("Unable to delete {:?}: {}", profile.config_dir(), e))?;
if let Err(e) = std::fs::remove_dir_all(profile.data_dir()) {
log::warn!("Unable to delete: {:?} {}", profile.data_dir(), e);
}
let mut appd = state.lock().await;
if let Some(current) = &mut appd.profile {
if current.meta() == profile {
appd.profile = None;
}
}