Skip to content

Commit

Permalink
Added initial central profile folder name registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jan 29, 2024
1 parent f751ef2 commit b522324
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/stores/Steam/app_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
6 changes: 5 additions & 1 deletion src/stores/Epic/epic_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ SKIF_Epic_GetInstalledAppIDs (std::vector <std::pair < std::string, app_record_s
record.store_utf8 = "Epic";
record._status.installed = true;
record.install_dir = SK_UTF8ToWideChar (jf.at ("InstallLocation"));
std::replace(record.install_dir.begin(), record.install_dir.end(), '/', '\\'); // Replaces all / with \
if (record.install_dir.rfind(LR"(\)") != record.install_dir.size() - 1)
record.install_dir += LR"(\)";

record.names.normal = jf.at ("DisplayName");
record.names.original = record.names.normal;
Expand All @@ -156,7 +160,7 @@ SKIF_Epic_GetInstalledAppIDs (std::vector <std::pair < std::string, app_record_s
lc.id = 0;
lc.valid = 1;
lc.executable = SK_UTF8ToWideChar(jf.at("LaunchExecutable")); // record.install_dir + L"\\" +
lc.executable_path = record.install_dir + L"\\" + lc.executable;
lc.executable_path = record.install_dir + lc.executable;
lc.install_dir = record.install_dir;
std::replace(lc.executable_path.begin(), lc.executable_path.end(), '/', '\\'); // Replaces all / with \
Expand Down
4 changes: 4 additions & 0 deletions src/stores/GOG/gog_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ SKIF_GOG_GetInstalledAppIDs (std::vector <std::pair < std::string, app_record_s
dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"path", 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"exeFile", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
Expand Down
22 changes: 16 additions & 6 deletions src/stores/SKIF/custom_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ int SKIF_AddCustomAppID (
record.ImGuiPushID = SK_FormatString("###%i-%i", (int)record.store, record.id);

record.install_dir = installDir;
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"(\)";

app_record_s::launch_config_s lc;
lc.id = 0;
Expand Down Expand Up @@ -215,13 +218,16 @@ bool SKIF_ModifyCustomAppID (app_record_s* pApp, std::wstring name, std::wstring
pApp->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;
Expand Down Expand Up @@ -285,6 +291,10 @@ void SKIF_GetCustomAppIDs (std::vector<std::pair<std::string, app_record_s>>* 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"
{
Expand Down
4 changes: 4 additions & 0 deletions src/stores/Steam/steam_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(\)";
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/stores/Steam/vdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector <std::pair < std::stri

// Strip double backslashes characters from the string
pAppRecord->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)
{
Expand Down Expand Up @@ -707,7 +710,7 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector <std::pair < std::stri
// TODO: Test this out properly with games with different working directories set!
// See if there's any games that uses different working directories between launch configs, but otherwise the same executable and cmd-line arguments!
if (! launch.working_dir.empty())
launch.working_dir = std::wstring (pAppRecord->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);
Expand Down
22 changes: 21 additions & 1 deletion src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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())
{
Expand Down

0 comments on commit b522324

Please sign in to comment.