Skip to content

Commit

Permalink
fix: path resolution on linux should now work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 27, 2024
1 parent 1cf42c6 commit 926ab1d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steam-art-manager",
"version": "3.6.5",
"version": "3.6.6",
"private": true,
"type": "module",
"author": {
Expand Down
6 changes: 2 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,13 @@ async fn validate_steam_path(app_handle: AppHandle, target_path: String) -> bool
#[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 {
let pre_canonicalized_path: PathBuf = PathBuf::from(&target_path);
let path_as_buf: PathBuf = PathBuf::from(&target_path);

if !pre_canonicalized_path.as_path().exists() {
if !path_as_buf.as_path().exists() {
logger::log_to_core_file(app_handle.to_owned(), format!("Error adding {} to scope. Path does not exist.", &target_path).as_str(), 2);
return false;
}

let path_as_buf: PathBuf = pre_canonicalized_path.canonicalize().expect("Should have been able to resolve target path.");

let fs_scope = app_handle.fs_scope();
let asset_scope = app_handle.asset_protocol_scope();

Expand Down
28 changes: 10 additions & 18 deletions src-tauri/src/steam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub fn get_steam_root_dir() -> Result<PathBuf, String> {
pc_home_dir = pc_home_dir.join(".steam/steam");
}

let final_path = fs::canonicalize(pc_home_dir).expect("Should have been able to resolve path with symlinks in it.");
if final_path.exists() {
// let final_path = fs::canonicalize(pc_home_dir).expect("Should have been able to resolve path with symlinks in it.");
if pc_home_dir.exists() {
return Ok(final_path);
} else {
return Err(String::from("Steam install path does not exist."));
Expand All @@ -67,8 +67,7 @@ pub fn get_grids_directory(app_handle: AppHandle, steam_path: String, steam_acti
let _ = create_dir_all(&joined_path);
}

let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize userdata/USER_ID/config/grid");
let grids_dir: String = canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
let grids_dir: String = joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");

let dir_create_res = fs::create_dir_all(grids_dir.clone());
if dir_create_res.is_err() {
Expand All @@ -86,8 +85,7 @@ pub fn get_library_cache_directory(app_handle: AppHandle, steam_path: String) ->

let steam_root: PathBuf = PathBuf::from(steam_path);
let library_cache_path: PathBuf = steam_root.join("appcache/librarycache");
let canonicalized_path: PathBuf = library_cache_path.canonicalize().expect("Should have been able to canonicalize appcache/librarycache");
let library_cache_str: String = canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
let library_cache_str: String = library_cache_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");

if library_cache_path.exists() {
return library_cache_str;
Expand All @@ -105,9 +103,8 @@ pub fn get_appinfo_path(app_handle: AppHandle, steam_path: String) -> String {

let steam_root: PathBuf = PathBuf::from(steam_path);
let joined_path: PathBuf = steam_root.join("appcache/appinfo.vdf");
let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize appcache/appinfo.vdf");

return canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
}

#[tauri::command]
Expand All @@ -119,8 +116,7 @@ pub fn get_shortcuts_path(app_handle: AppHandle, steam_path: String, steam_activ
let joined_path: PathBuf = steam_root.join("userdata").join(steam_active_user_id.to_string()).join("config/shortcuts.vdf");

if joined_path.as_path().exists() {
let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize config/shortcuts.vdf");
return canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
} else {
// * It will won't get read because it doesn't exist.
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
Expand All @@ -136,8 +132,7 @@ pub fn get_localconfig_path(app_handle: AppHandle, steam_path: String, steam_act
let joined_path: PathBuf = steam_root.join("userdata").join(steam_active_user_id.to_string()).join("config/localconfig.vdf");

if joined_path.as_path().exists() {
let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize config/localconfig.vdf");
return canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
} else {
// * It will won't get read because it doesn't exist.
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
Expand All @@ -153,8 +148,7 @@ pub fn get_sourcemod_path(app_handle: AppHandle, steam_path: String) -> String {
let joined_path: PathBuf = steam_root.join("steamapps/sourcemods");

if joined_path.as_path().exists() {
let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize steamapps/sourcemod path");
return canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
} else {
// * It will won't get read because it doesn't exist.
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
Expand All @@ -170,8 +164,7 @@ pub fn get_goldsrc_path(app_handle: AppHandle, steam_path: String) -> String {
let joined_path: PathBuf = steam_root.join("steamapps/sourcemods/Half-Life");

if joined_path.as_path().exists() {
let canonicalized_path: PathBuf = joined_path.canonicalize().expect("Should have been able to canonicalize steamapps/sourcemod/Half-Life path");
return canonicalized_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
} else {
// * It will won't get read because it doesn't exist.
return joined_path.to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
Expand Down Expand Up @@ -218,8 +211,7 @@ fn read_steam_users(steam_path: String) -> Map<String, Value> {

let steam_root: PathBuf = PathBuf::from(steam_path);

// TODO: account for if this file does not exist
let loginusers_vdf: PathBuf = steam_root.join("config/loginusers.vdf").canonicalize().expect("Should have been able to canonicalize config/loginusers.vdf");
let loginusers_vdf: PathBuf = steam_root.join("config/loginusers.vdf");
let contents: String = fs::read_to_string(loginusers_vdf).unwrap();

let id_start_matches: Vec<(usize, &str)> = contents.match_indices("\n\t\"").collect();
Expand Down
36 changes: 14 additions & 22 deletions src/lib/controllers/SettingsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,22 @@ export class SettingsController {
this.steamInstallPathSub = steamInstallPath.subscribe(async (newPath) => {
if (newPath !== this.oldSteamInstallPath) {
SettingsManager.updateSetting("steamInstallPath", newPath);
const success = await RustInterop.addPathToScope(newPath);

if (success) {
LogController.log(`Added ${newPath} to scope.`);

if (this.oldSteamInstallPath !== "") {
const shouldReloadGames = await DialogController.ask(
"Steam Install Path Changed",
"WARNING",
"A change to your Steam install path was detected, would you like to reload your games?",
"Yes",
"No"
);

if (shouldReloadGames) {
await restartApp();
}

if (this.oldSteamInstallPath !== "") {
const shouldReloadGames = await DialogController.ask(
"Steam Install Path Changed",
"WARNING",
"A change to your Steam install path was detected, would you like to reload your games?",
"Yes",
"No"
);

if (shouldReloadGames) {
await restartApp();
}

this.oldSteamInstallPath = newPath;
} else {
LogController.log(`Failed to add ${newPath} to scope.`);
ToastController.showWarningToast(`Failed to add ${newPath} to scope.`);
}

this.oldSteamInstallPath = newPath;
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/lib/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ export async function steamDialogSequence(): Promise<void> {
*/
export async function findSteamPath(savedInstallPath: string): Promise<void> {
if (savedInstallPath !== "") {
const steamInstallPathAdded = await RustInterop.addPathToScope(savedInstallPath);
const isValidInstall = await validateSteamPath(savedInstallPath);

if (steamInstallPathAdded && isValidInstall && await fs.exists(savedInstallPath)) {
if (isValidInstall) {
steamInstallPath.set(savedInstallPath);
} else {
await steamDialogSequence();
Expand Down

0 comments on commit 926ab1d

Please sign in to comment.