From f16cd65e6e1cf347cec57059d6364c934da4423c Mon Sep 17 00:00:00 2001 From: Tormak <63308171+Tormak9970@users.noreply.github.com> Date: Wed, 12 Jul 2023 16:22:06 -0500 Subject: [PATCH] fix: steam game icons now work properly --- src-tauri/src/main.rs | 18 ++++++++++++++---- src/lib/controllers/AppController.ts | 17 +++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cf35b26d..2707fe30 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -57,6 +57,11 @@ struct ChangedPath { sourcePath: String } +/// Checks if an appid belongs to a shortcut +fn is_appid_shortcut(appid: &str, shortcut_icons: &Map) -> bool { + return shortcut_icons.contains_key(appid); +} + /// Gets a grid's file name based on its type. fn get_grid_filename(app_handle: &AppHandle, appid: &str, grid_type: &str, image_type: &str) -> String { match grid_type { @@ -64,7 +69,7 @@ fn get_grid_filename(app_handle: &AppHandle, appid: &str, grid_type: &str, image "Wide Capsule" => return format!("{}{}", appid, image_type), "Hero" => return format!("{}_hero{}", appid, image_type), "Logo" => return format!("{}_logo{}", appid, image_type), - "Icon" => return format!("{}_icon{}", appid, image_type), + "Icon" => return format!("{}_icon.jpg", appid), _ => { logger::log_to_core_file(app_handle.to_owned(), format!("Unexpected grid type {}", grid_type).as_str(), 2); panic!("Unexpected grid type {}", grid_type); @@ -80,8 +85,9 @@ fn adjust_path(app_handle: &AppHandle, appid: &str, path: &str, grid_type: &str) } /// Filters the grid paths based on which have change. -fn filter_paths(app_handle: &AppHandle, steam_active_user_id: String, current_paths: &GridImageCache, original_paths: &GridImageCache) -> Vec { +fn filter_paths(app_handle: &AppHandle, steam_active_user_id: String, current_paths: &GridImageCache, original_paths: &GridImageCache, shortcut_icons: &Map) -> Vec { let grids_dir = PathBuf::from(steam::get_grids_directory(app_handle.to_owned(), steam_active_user_id)); + let lib_cache_dir = PathBuf::from(steam::get_library_cache_directory(app_handle.to_owned())); let mut res:Vec = Vec::new(); for (appid, grids_map) in current_paths.into_iter() { @@ -100,7 +106,11 @@ fn filter_paths(app_handle: &AppHandle, steam_active_user_id: String, current_pa if source_path != "REMOVE" { let adjusted_path = adjust_path(app_handle, appid.as_str(), source_path_owned.as_str(), grid_type.as_str()).replace("\\", "/"); - target_path = String::from(grids_dir.join(adjusted_path).to_str().unwrap()).replace("\\", "/"); + if grid_type == "Icon" && !is_appid_shortcut(&appid, shortcut_icons) { + target_path = String::from(lib_cache_dir.join(adjusted_path).to_str().unwrap()).replace("\\", "/"); + } else { + target_path = String::from(grids_dir.join(adjusted_path).to_str().unwrap()).replace("\\", "/"); + } } else { target_path = String::from("REMOVE"); } @@ -262,7 +272,7 @@ async fn save_changes(app_handle: AppHandle, steam_active_user_id: String, curre let original_art_dict: GridImageCache = serde_json::from_str(original_art.as_str()).unwrap(); logger::log_to_core_file(app_handle.to_owned(), "Converting current path entries to grid paths...", 0); - let paths_to_set: Vec = filter_paths(&app_handle, steam_active_user_id.clone(), ¤t_art_dict, &original_art_dict); + let paths_to_set: Vec = filter_paths(&app_handle, steam_active_user_id.clone(), ¤t_art_dict, &original_art_dict, &shortcut_icons); let paths_id_map: HashMap = paths_to_set.clone().iter().map(| entry | (format!("{}_{}", entry.appId.to_owned(), entry.gridType.to_owned()).to_string(), entry.to_owned())).collect(); logger::log_to_core_file(app_handle.to_owned(), "Current path entries converted to grid paths.", 0); diff --git a/src/lib/controllers/AppController.ts b/src/lib/controllers/AppController.ts index 4467d671..888015f6 100644 --- a/src/lib/controllers/AppController.ts +++ b/src/lib/controllers/AppController.ts @@ -212,10 +212,11 @@ export class AppController { /** * Filters and structures the library grids based on the app's needs. * @param gridsDirContents The contents of the grids dir. + * @param shortcutIds The list of loaded shortcuts ids. * @returns The filtered and structured grids dir. * ? Logging complete. */ - private static filterGridsDir(gridsDirContents: fs.FileEntry[]): [{ [appid: string]: LibraryCacheEntry }, fs.FileEntry[]] { + private static filterGridsDir(gridsDirContents: fs.FileEntry[], shortcutsIds: string[]): [{ [appid: string]: LibraryCacheEntry }, fs.FileEntry[]] { let resKeys = []; const logoConfigs = []; const res: { [appid: string]: LibraryCacheEntry } = {}; @@ -234,7 +235,8 @@ export class AppController { ToastController.showWarningToast(`Duplicate grid found. Try cleaning`); LogController.warn(`Duplicate grid found for ${appid}.`); } else { - if (gridTypeLUT[type]) { + //? Since we have to poison the cache for icons, we also don't want to load them from the grids folder. Shortcuts don't need this. + if (gridTypeLUT[type] && (type !== "icon" || shortcutsIds.includes(appid))) { if (!resKeys.includes(appid)) { resKeys.push(appid); res[appid] = {} as LibraryCacheEntry; @@ -252,13 +254,11 @@ export class AppController { * Filters and structures the library cache based on the app's needs. * @param libraryCacheContents The contents of the library cache. * @param gridsInfos The filtered grid infos. - * @param shortcuts The list of loaded shortcuts + * @param shortcutIds The list of loaded shortcuts ids. * @returns The filtered and structured library cache. * ? Logging complete. */ - private static filterLibraryCache(libraryCacheContents: fs.FileEntry[], gridsInfos: { [appid: string]: LibraryCacheEntry }, shortcuts: GameStruct[]): { [appid: string]: LibraryCacheEntry } { - const shortcutIds = Object.values(shortcuts).map((shortcut) => shortcut.appid.toString()); - + private static filterLibraryCache(libraryCacheContents: fs.FileEntry[], gridsInfos: { [appid: string]: LibraryCacheEntry }, shortcutIds: string[]): { [appid: string]: LibraryCacheEntry } { let resKeys = Object.keys(gridsInfos); const res: { [appid: string]: LibraryCacheEntry } = gridsInfos; @@ -299,11 +299,12 @@ export class AppController { */ private static async getCacheData(shortcuts: GameStruct[]): Promise<{ [appid: string]: LibraryCacheEntry }> { const gridDirContents = (await fs.readDir(await RustInterop.getGridsDirectory(get(activeUserId).toString()))); - const [filteredGrids, logoConfigs] = AppController.filterGridsDir(gridDirContents); + const shortcutIds = Object.values(shortcuts).map((shortcut) => shortcut.appid.toString()); + const [filteredGrids, logoConfigs] = AppController.filterGridsDir(gridDirContents, shortcutIds); LogController.log("Grids loaded."); const libraryCacheContents = (await fs.readDir(await RustInterop.getLibraryCacheDirectory())); - const filteredCache = AppController.filterLibraryCache(libraryCacheContents, filteredGrids, shortcuts); + const filteredCache = AppController.filterLibraryCache(libraryCacheContents, filteredGrids, shortcutIds); LogController.log("Library Cache loaded."); await AppController.cacheLogoConfigs(logoConfigs);