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

@ -55,7 +55,7 @@ impl AnyProfile {
pub fn rename(&mut self, name: String) {
match self {
Self::OngekiProfile(p) => {
p.name = Some(name);
p.name = Some(fixed_name(&ProfileMeta { name, game: Game::Ongeki }, false));
}
}
}
@ -159,4 +159,16 @@ fn meta_from_path(path: impl AsRef<Path>) -> Option<ProfileMeta> {
}
None
}
pub fn fixed_name(meta: &ProfileMeta, prepend_new: bool) -> String {
let mut name = meta.name.trim()
.replace(" ", "-")
.replace("..", "").replace("/", "").replace("\\", "");
while prepend_new && util::profile_config_dir(&meta.game, &name).exists() {
name = format!("new-{}", name);
}
name
}

View File

@ -3,6 +3,7 @@ use tauri::AppHandle;
use tauri::Emitter;
use std::{collections::BTreeSet, path::PathBuf, process::Stdio};
use crate::model::config::BepInEx;
use crate::profiles::fixed_name;
use crate::util::PathStr;
use crate::{model::{config::{Display, DisplayMode, Network, Segatools}, misc::Game, segatools_base::segatools_base}, pkg::PkgKey, util};
use super::{Profile, ProfileMeta, ProfilePaths};
@ -27,14 +28,10 @@ pub struct OngekiProfile {
impl Profile for OngekiProfile {
fn new(name: String) -> Result<Self> {
let mut fixed_name = name.trim().replace(" ", "-");
while util::profile_config_dir(&Game::Ongeki, &name).exists() {
fixed_name = format!("new-{}", name);
}
let name = fixed_name(&ProfileMeta { name, game: Game::Ongeki }, true);
let p = OngekiProfile {
name: Some(fixed_name),
name: Some(name.clone()),
mods: BTreeSet::new(),
sgt: Segatools::default(),
display: Display::default(),
@ -43,7 +40,8 @@ impl Profile for OngekiProfile {
};
p.save()?;
std::fs::write(p.config_dir().join("segatools-base.ini"), segatools_base())?;
log::debug!("created profile-ongeki-{}", name);
log::debug!("created profile-ongeki-{}", &name);
Ok(p)
}
@ -71,7 +69,7 @@ impl Profile for OngekiProfile {
}
std::fs::write(&path, s)
.map_err(|e| anyhow!("error when writing to {:?}: {}", path, e))?;
log::info!("Written to {}", path.to_string_lossy());
log::info!("Written to {:?}", path);
Ok(())
}
@ -79,7 +77,7 @@ impl Profile for OngekiProfile {
async fn start(&self, app: AppHandle) -> Result<()> {
let ini_path = self.data_dir().join("segatools.ini");
log::debug!("With path {}", ini_path.to_string_lossy());
log::debug!("With path {:?}", ini_path);
let mut game_builder;
let mut amd_builder;