From b522324c2398b3d56a2cd8f1f1af0b27fde8ca94 Mon Sep 17 00:00:00 2001 From: aemony Date: Mon, 29 Jan 2024 05:42:51 +0100 Subject: [PATCH] Added initial central profile folder name registry --- include/stores/Steam/app_record.h | 2 +- src/stores/Epic/epic_library.cpp | 6 +++++- src/stores/GOG/gog_library.cpp | 4 ++++ src/stores/SKIF/custom_library.cpp | 22 ++++++++++++++++------ src/stores/Steam/steam_library.cpp | 4 ++++ src/stores/Steam/vdf.cpp | 5 ++++- src/tabs/library.cpp | 22 +++++++++++++++++++++- 7 files changed, 55 insertions(+), 10 deletions(-) diff --git a/include/stores/Steam/app_record.h b/include/stores/Steam/app_record.h index 0e2baea9..e11f38ec 100644 --- a/include/stores/Steam/app_record.h +++ b/include/stores/Steam/app_record.h @@ -406,7 +406,7 @@ struct app_record_s { bool loading = false; // indicates if we are processing in a background thread bool filtered = false; // indicates if the app has been filtered out (used for search; not the same as the skif.hidden state!) bool cloud_enabled = true; // hidecloudui=false - std::wstring install_dir; + std::wstring install_dir; // Should be backslash-terminated Store store = Store::Unspecified; std::string store_utf8 = ""; diff --git a/src/stores/Epic/epic_library.cpp b/src/stores/Epic/epic_library.cpp index 875d7ade..245d15f2 100644 --- a/src/stores/Epic/epic_library.cpp +++ b/src/stores/Epic/epic_library.cpp @@ -147,6 +147,10 @@ SKIF_Epic_GetInstalledAppIDs (std::vector ImGuiLabelAndID = SK_FormatString("%s###%i-%i", pApp->names.normal.c_str(), (int)pApp->store, pApp->id); pApp->ImGuiPushID = SK_FormatString("###%i-%i", (int)pApp->store, pApp->id); - pApp->install_dir = installDir; - pApp->launch_configs[0].executable = exeFileName; + pApp->install_dir = installDir; + std::replace(pApp->install_dir.begin(), pApp->install_dir.end(), '/', '\\'); // Replaces slashes + if (pApp->install_dir.rfind(LR"(\)") != pApp->install_dir.size() - 1) + pApp->install_dir += LR"(\)"; + pApp->launch_configs[0].executable = exeFileName; pApp->launch_configs[0].executable_path = exe; - pApp->launch_configs[0].install_dir = pApp->install_dir; - pApp->launch_configs[0].working_dir = pApp->install_dir; - pApp->launch_configs[0].launch_options = args; - pApp->specialk.profile_dir = exeFileName; // THIS CAN BE WRONG!!!! + pApp->launch_configs[0].install_dir = pApp->install_dir; + pApp->launch_configs[0].working_dir = pApp->install_dir; + pApp->launch_configs[0].launch_options = args; + pApp->specialk.profile_dir = exeFileName; // THIS CAN BE WRONG!!!! } return ! failed; @@ -285,6 +291,10 @@ void SKIF_GetCustomAppIDs (std::vector>* ap if (RegGetValueW (hKey, szSubKey, L"InstallDir", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS) record.install_dir = szData; + std::replace(record.install_dir.begin(), record.install_dir.end(), '/', '\\'); // Replaces slashes + if (record.install_dir.rfind(LR"(\)") != record.install_dir.size() - 1) + record.install_dir += LR"(\)"; + dwSize = sizeof (szData) / sizeof (WCHAR); if (RegGetValueW (hKey, szSubKey, L"ExeFileName", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS) // L"Exe" { diff --git a/src/stores/Steam/steam_library.cpp b/src/stores/Steam/steam_library.cpp index 9bafb848..ab14967c 100644 --- a/src/stores/Steam/steam_library.cpp +++ b/src/stores/Steam/steam_library.cpp @@ -1060,6 +1060,10 @@ SK_UseManifestToGetInstallDir (app_record_s *app) app_path.c_str ()); app->install_dir = path; + + std::replace(app->install_dir.begin(), app->install_dir.end(), '/', '\\'); // Replaces slashes + if (app->install_dir.rfind(LR"(\)") != app->install_dir.size() - 1) + app->install_dir += LR"(\)"; } } diff --git a/src/stores/Steam/vdf.cpp b/src/stores/Steam/vdf.cpp index ea4675fd..f8044545 100644 --- a/src/stores/Steam/vdf.cpp +++ b/src/stores/Steam/vdf.cpp @@ -304,6 +304,9 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector install_dir = std::regex_replace (pAppRecord->install_dir, std::wregex(LR"(\\\\)"), LR"(\)"); + + if (pAppRecord->install_dir.rfind(LR"(\)") != pAppRecord->install_dir.size() - 1) + pAppRecord->install_dir += LR"(\)"; } catch (const std::exception& e) { @@ -707,7 +710,7 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector install_dir + LR"(\)" + launch.working_dir + L"\0\0"); + launch.working_dir = std::wstring (pAppRecord->install_dir + launch.working_dir + L"\0\0"); // Flag the launch config to be added back _launches.push_back (launch); diff --git a/src/tabs/library.cpp b/src/tabs/library.cpp index b1fb6166..a15d292d 100644 --- a/src/tabs/library.cpp +++ b/src/tabs/library.cpp @@ -4790,6 +4790,9 @@ SKIF_UI_Tab_DrawLibrary (void) PLOG_INFO << "Processing detected games..."; + HKEY hKey; + LSTATUS lsProfilesKey = RegCreateKeyW (HKEY_CURRENT_USER, LR"(SOFTWARE\Kaldaien\Special K\Profiles)", &hKey); + // Process the list of apps -- prepare their names, keyboard search, as well as remove any uninstalled entries for (auto& app : _data->apps) { @@ -5018,11 +5021,28 @@ SKIF_UI_Tab_DrawLibrary (void) } } - // Prepare for the keyboard hint / search/filter functionality if ( app.second._status.installed) + { + // Prepare for the keyboard hint / search/filter functionality InsertTrieKey (&app, &_data->labels); + + // Ensure the Profiles registry key is populated properly + if (ERROR_SUCCESS == lsProfilesKey) + { + std::wstring wsName = SK_UTF8ToWideChar(app.second.names.original); + + if (ERROR_SUCCESS != RegSetValueExW (hKey, app.second.install_dir.c_str(), 0, REG_SZ, (LPBYTE)wsName.data(), + (DWORD)wsName.size() * sizeof(wchar_t))) + { + PLOG_ERROR << "Failed adding profile name (" << wsName << ") to registry value: " << app.second.install_dir; + } + } + } } + if (ERROR_SUCCESS == lsProfilesKey) + RegCloseKey (hKey); + // Update the db.json file with any additions and whatnot if (! jsonMetaDB.is_discarded()) {