Skip to content

Commit 1a439a3

Browse files
committed
fix: normalize mod folder paths on macOS
1 parent 406c489 commit 1a439a3

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/celemod-ui/src/states.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const [initGamePath, useGamePath] = createPersistedState<string>('', stor
145145
const paths = callRemote("get_celeste_dirs").split("\n").filter((v: string | null) => v);
146146
return paths[0]
147147
}, (storage, data, save) => {
148+
data = callRemote("normalize_game_path", data)
148149
storage.root.lastGamePath = data
149150
save()
150151
})

src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,20 @@ fn normalize_game_path(path: &str) -> String {
540540
.to_string()
541541
}
542542

543+
fn normalize_mods_folder_path(path: &str) -> String {
544+
let path = Path::new(path);
545+
if path.file_name().and_then(|v| v.to_str()) == Some("Mods") {
546+
if let Some(game_path) = path.parent() {
547+
return normalize_game_path_buf(game_path)
548+
.join("Mods")
549+
.to_string_lossy()
550+
.to_string();
551+
}
552+
}
553+
554+
path.to_string_lossy().to_string()
555+
}
556+
543557
fn normalize_game_path_buf(path: &Path) -> PathBuf {
544558
#[cfg(target_os = "macos")]
545559
{
@@ -654,6 +668,7 @@ impl Handler {
654668
_use_cn_proxy: bool,
655669
multi_thread: bool,
656670
) {
671+
let mods_dir = normalize_mods_folder_path(&mods_dir);
657672
if let Err(e) = std::fs::create_dir_all(&mods_dir) {
658673
eprintln!("Failed to create mods dir {}: {}", mods_dir, e);
659674
}
@@ -1044,6 +1059,7 @@ impl Handler {
10441059

10451060
fn get_installed_miaonet(&self, mods_folder_path: String, callback: sciter::Value) {
10461061
std::thread::spawn(move || {
1062+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
10471063
let installed = get_installed_mods_sync(mods_folder_path)
10481064
.into_iter()
10491065
.any(|p| p.name == "MiaoNet");
@@ -1053,6 +1069,7 @@ impl Handler {
10531069

10541070
fn get_installed_mods(&self, mods_folder_path: String, callback: sciter::Value) {
10551071
std::thread::spawn(move || {
1072+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
10561073
let installed_mods = get_installed_mods_sync(mods_folder_path);
10571074
callback
10581075
.call(
@@ -1066,6 +1083,7 @@ impl Handler {
10661083

10671084
fn get_invalid_zip_mod_files(&self, mods_folder_path: String, callback: sciter::Value) {
10681085
std::thread::spawn(move || {
1086+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
10691087
let invalid_mods = get_invalid_zip_mod_files(&mods_folder_path);
10701088
callback
10711089
.call(
@@ -1079,6 +1097,7 @@ impl Handler {
10791097

10801098
fn check_all_mod_contents(&self, mods_folder_path: String, callback: sciter::Value) {
10811099
std::thread::spawn(move || {
1100+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
10821101
check_all_mod_contents(&mods_folder_path, &mut |progress| {
10831102
callback
10841103
.call(
@@ -1334,6 +1353,7 @@ impl Handler {
13341353

13351354
fn rm_mod(&self, mods_folder_path: String, mod_name: String) {
13361355
std::thread::spawn(move || {
1356+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
13371357
if let Err(e) = rm_mod(&mods_folder_path, &mod_name) {
13381358
eprintln!("Failed to remove mod: {}", e);
13391359
}
@@ -1375,6 +1395,7 @@ impl Handler {
13751395
callback: sciter::Value,
13761396
) {
13771397
std::thread::spawn(move || {
1398+
let mods_folder_path = normalize_mods_folder_path(&mods_folder_path);
13781399
let file_names: Vec<String> = serde_json::from_str(&file_names).unwrap_or_default();
13791400
let result = match delete_mod_files(&mods_folder_path, &file_names) {
13801401
Ok(()) => "Success".to_string(),

0 commit comments

Comments
 (0)