Skip to content

Commit c5ab923

Browse files
committed
fix: normalize game path handling for macOS installation and improve path verification
1 parent 087aac9 commit c5ab923

4 files changed

Lines changed: 223 additions & 56 deletions

File tree

src/celemod-ui/src/states.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const createPersistedStateByKey = <T>(key: string, defaultValue: T) => createPer
141141
export const [initMirror, useMirror, currentMirror] = createPersistedStateByKey('mirror', 'wegfan')
142142
export const [initGamePath, useGamePath] = createPersistedState<string>('', storage => {
143143
if (storage?.root?.lastGamePath)
144-
return storage.root.lastGamePath
144+
return callRemote("normalize_game_path", storage.root.lastGamePath)
145145
const paths = callRemote("get_celeste_dirs").split("\n").filter((v: string | null) => v);
146146
return paths[0]
147147
}, (storage, data, save) => {
@@ -157,4 +157,4 @@ export const [initSearchSort, useSearchSort] = createPersistedStateByKey<'new' |
157157

158158
export const [initAutoDisableNewMods, useAutoDisableNewMods] = createPersistedStateByKey('autoDisableNewMods', false)
159159

160-
export const [initModComments, useModComments] = createPersistedStateByKey('modComments', {})
160+
export const [initModComments, useModComments] = createPersistedStateByKey('modComments', {})

src/celemod-ui/src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ export const selectGamePath = (successCallback) => {
134134
// strip file:// and Celeste.exe
135135
const prefix = "file://".length;
136136
const decoded = decodeURI(res);
137-
const path = dirname(decoded.slice(prefix));
137+
const path = callRemote("normalize_game_path", dirname(decoded.slice(prefix)));
138+
if (!callRemote("verify_celeste_install", path)) {
139+
alert("Invalid Celeste install path.");
140+
return;
141+
}
138142
console.log("Selected", path);
139143
successCallback(path);
140144
return path;

src/everest.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn get_everest_version(game_path: &str) -> Option<i32> {
116116
Some(str)
117117
}
118118

119-
let game_path = resolve_everest_install_path(Path::new(game_path));
119+
let game_path = Path::new(game_path);
120120

121121
check_file(game_path.join("Celeste.exe"))
122122
.or_else(|| {
@@ -205,26 +205,6 @@ fn run_command(
205205
Ok(())
206206
}
207207

208-
fn resolve_everest_install_path(game_path: &Path) -> PathBuf {
209-
#[cfg(target_os = "macos")]
210-
{
211-
let bundled_resources = game_path
212-
.join("Celeste.app")
213-
.join("Contents")
214-
.join("Resources");
215-
if bundled_resources.exists() {
216-
return bundled_resources;
217-
}
218-
219-
let resources = game_path.join("Contents").join("Resources");
220-
if resources.exists() {
221-
return resources;
222-
}
223-
}
224-
225-
game_path.to_path_buf()
226-
}
227-
228208
#[cfg(target_os = "windows")]
229209
fn installer_name() -> anyhow::Result<&'static str> {
230210
match std::env::consts::ARCH {
@@ -253,7 +233,7 @@ pub fn download_and_install_everest(
253233

254234
let temp_path = std::env::temp_dir().join("everest.zip");
255235
let temp_path = temp_path.to_str().unwrap();
256-
let game_path = resolve_everest_install_path(std::path::Path::new(game_path));
236+
let game_path = std::path::Path::new(game_path);
257237
let cancel_flag = Arc::new(AtomicBool::new(false));
258238

259239
ureq::download_file_with_progress(

0 commit comments

Comments
 (0)