Skip to content

Commit

Permalink
fix: steam path validation now works on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 3, 2024
1 parent d4e94cb commit b827f13
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
30 changes: 29 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,33 @@ async fn clean_grids(app_handle: AppHandle, steam_path: String, steam_active_use
}


#[tauri::command]
// Validates the steam install path
async fn validate_steam_path(app_handle: AppHandle, target_path: String) -> bool {
let pre_canonicalized_path: PathBuf = PathBuf::from(&target_path);
let steam_path: PathBuf = pre_canonicalized_path.canonicalize().expect("Should have been able to resolve target path.");
let steam_path_str: String = steam_path.to_str().expect("Should have been able to convert pathbuf to string").to_owned();

add_path_to_scope(app_handle, steam_path_str).await;

if steam_path.exists() {
let contents_res = fs::read_dir(steam_path);
let mut contents = contents_res.ok().expect("Should have been able to read the provided directory.");

return contents.any(| entry_res | {
if entry_res.is_ok() {
let entry = entry_res.ok().expect("Entry should have been ok");

return entry.file_name().eq_ignore_ascii_case("steam.exe") || entry.file_name().eq_ignore_ascii_case("steam.sh");
}

return false;
});
}

return false;
}

#[tauri::command]
/// Adds the provided path to Tauri FS and Asset scope.
async fn add_path_to_scope(app_handle: AppHandle, target_path: String) -> bool {
Expand Down Expand Up @@ -637,7 +664,8 @@ fn main() {
save_changes,
write_shortcuts,
download_grid,
clean_grids
clean_grids,
validate_steam_path
])
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
println!("{}, {argv:?}, {cwd}", app.package_info().name);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/controllers/RustInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,13 @@ export class RustInterop {
static async writeAppTiles(appIconsPaths: Record<string, string>, appTilePaths: Record<string, string>): Promise<string[]> {
return JSON.parse(await invoke<string>("write_app_tiles", { newTilesStr: JSON.stringify(appIconsPaths), tilePathsStr: JSON.stringify(appTilePaths) }));
}

/**
* Checks if the provided path is a valid steam installation.
* @param targetPath The path to validate.
* @returns True if the path is a valid steam install.
*/
static async validateSteamPath(targetPath: string): Promise<boolean> {
return await invoke<boolean>("validate_steam_path", { targetPath: targetPath });
}
}
9 changes: 1 addition & 8 deletions src/lib/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,7 @@ export async function restartApp(): Promise<void> {
* @returns True if the path is a valid install.
*/
export async function validateSteamPath(steamPath: string): Promise<boolean> {
const normalized = await path.normalize(steamPath);
const wasAdded = await RustInterop.addPathToScope(normalized);
if (wasAdded && await fs.exists(normalized)) {
const contents = (await fs.readDir(normalized)).map((entry) => entry.name);
return contents.includes("steam.exe") || contents.includes("steam.sh");
}

return false;
return await RustInterop.validateSteamPath(steamPath);
}


Expand Down

0 comments on commit b827f13

Please sign in to comment.