Skip to content

Commit

Permalink
Registry optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Feb 3, 2024
1 parent f3ce714 commit d97cfb9
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 211 deletions.
3 changes: 1 addition & 2 deletions include/stores/SKIF/custom_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <stores/Steam/app_record.h>

bool SKIF_RemoveCustomAppID (uint32_t appid);
int SKIF_AddCustomAppID (std::vector<std::pair<std::string, app_record_s>>* apps,
std::wstring name, std::wstring path, std::wstring args);
int SKIF_AddCustomAppID (std::wstring name, std::wstring path, std::wstring args);
bool SKIF_ModifyCustomAppID (app_record_s* pApp, std::wstring_view path, std::wstring_view args);
void SKIF_GetCustomAppIDs (std::vector <std::pair < std::string, app_record_s > > *apps);
4 changes: 2 additions & 2 deletions include/stores/Steam/steam_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,6 @@ void SKIF_Steam_GetInstalledAppIDs (std::vector <s
bool SKIF_Steam_HasActiveProcessChanged (std::vector <std::pair < std::string, app_record_s > > *apps, std::set <std::string> *apptickets);
SteamId3_t SKIF_Steam_GetCurrentUser (void);
DWORD SKIF_Steam_GetActiveProcess (void);
std::wstring SKIF_Steam_GetAppStateString (AppId_t appid, const wchar_t *wszStateKey);
wchar_t SKIF_Steam_GetAppStateDWORD (AppId_t appid, const wchar_t *wszStateKey, DWORD *pdwStateVal);
std::wstring SKIF_Steam_GetAppStateString (HKEY* hKey, const wchar_t *wszStateKey);
wchar_t SKIF_Steam_GetAppStateDWORD (HKEY* hKey, const wchar_t *wszStateKey, DWORD *pdwStateVal);
bool SKIF_Steam_UpdateAppState (app_record_s *pApp);
5 changes: 2 additions & 3 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ SKIF_Startup_AddGame (LPWSTR lpCmdLine)
cmdLineArgs = cmdLineArgs.substr(1);

extern std::wstring SKIF_Util_GetProductName (const wchar_t* wszName);
extern int SKIF_AddCustomAppID (std::vector<std::pair<std::string, app_record_s>>* apps,
std::wstring name, std::wstring path, std::wstring args);
extern int SKIF_AddCustomAppID (std::wstring name, std::wstring path, std::wstring args);

if (PathFileExists (cmdLine.c_str()))
{
Expand All @@ -456,7 +455,7 @@ SKIF_Startup_AddGame (LPWSTR lpCmdLine)
if (productName == L"")
productName = std::filesystem::path (cmdLine).replace_extension().filename().wstring();

SelectNewSKIFGame = (uint32_t)SKIF_AddCustomAppID (nullptr, productName, cmdLine, cmdLineArgs);
SelectNewSKIFGame = (uint32_t)SKIF_AddCustomAppID (productName, cmdLine, cmdLineArgs);

// If a running instance of SKIF already exists, terminate this one as it has served its purpose
if (SelectNewSKIFGame > 0 && _Signal._RunningInstance != 0)
Expand Down
95 changes: 51 additions & 44 deletions src/stores/GOG/gog_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,70 +67,77 @@ SKIF_GOG_GetInstalledAppIDs (std::vector <std::pair < std::string, app_record_s

if (dwResult == ERROR_SUCCESS)
{
dwSize = sizeof(szData) / sizeof(WCHAR);

if (RegGetValueW (hKey, szSubKey, L"dependsOn", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS &&
wcslen(szData) == 0) // Only handles items without a dependency (skips DLCs)
HKEY hSubKey = nullptr;

if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, SK_FormatStringW (LR"(SOFTWARE\GOG.com\Games\%ws)", szSubKey).c_str(), 0, KEY_READ | KEY_WOW64_32KEY, &hSubKey) == ERROR_SUCCESS)
{
dwSize = sizeof(szData) / sizeof(WCHAR);

if (RegGetValueW (hKey, szSubKey, L"GameID", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
if (RegGetValueW (hSubKey, NULL, L"dependsOn", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS &&
wcslen(szData) == 0) // Only handles items without a dependency (skips DLCs)
{
int appid = _wtoi(szData);
app_record_s record(appid);

record.store = app_record_s::Store::GOG;
record.store_utf8 = "GOG";
record._status.installed = true;

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"GameName", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
{
record.names.normal = SK_WideCharToUTF8(szData);
record.names.original = record.names.normal;
}

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"path", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
record.install_dir = szData;

record.install_dir = std::filesystem::path (record.install_dir).lexically_normal();

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"exeFile", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
if (RegGetValueW (hSubKey, NULL, L"GameID", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
{
app_record_s::launch_config_s lc;
lc.id = 0;
lc.valid = 1;
lc.executable = szData;
lc.install_dir = record.install_dir;
int appid = _wtoi(szData);
app_record_s record(appid);

record.store = app_record_s::Store::GOG;
record.store_utf8 = "GOG";
record._status.installed = true;

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"exe", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.executable_path = szData;
if (RegGetValueW (hSubKey, NULL, L"GameName", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
{
record.names.normal = SK_WideCharToUTF8(szData);
record.names.original = record.names.normal;
}

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"workingDir", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.working_dir = szData;
if (RegGetValueW (hSubKey, NULL, L"path", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
record.install_dir = szData;

record.install_dir = std::filesystem::path (record.install_dir).lexically_normal();

dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hKey, szSubKey, L"launchParam", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.launch_options = szData;
if (RegGetValueW (hSubKey, NULL, L"exeFile", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
{
app_record_s::launch_config_s lc;
lc.id = 0;
lc.valid = 1;
lc.executable = szData;
lc.install_dir = record.install_dir;

record.launch_configs.emplace (0, lc);
dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hSubKey, NULL, L"exe", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.executable_path = szData;

record.specialk.profile_dir = lc.executable;
record.specialk.profile_dir_utf8 = SK_WideCharToUTF8(record.specialk.profile_dir);
record.specialk.injection.injection.type = InjectionType::Global;
dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hSubKey, NULL, L"workingDir", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.working_dir = szData;

std::pair <std::string, app_record_s>
GOG(record.names.normal, record);
dwSize = sizeof(szData) / sizeof(WCHAR);
if (RegGetValueW (hSubKey, NULL, L"launchParam", RRF_RT_REG_SZ, NULL, &szData, &dwSize) == ERROR_SUCCESS)
lc.launch_options = szData;

apps->emplace_back(GOG);
record.launch_configs.emplace (0, lc);

dwRead++;
record.specialk.profile_dir = lc.executable;
record.specialk.profile_dir_utf8 = SK_WideCharToUTF8(record.specialk.profile_dir);
record.specialk.injection.injection.type = InjectionType::Global;

std::pair <std::string, app_record_s>
GOG(record.names.normal, record);

apps->emplace_back(GOG);

dwRead++;
}
}
}

RegCloseKey (hSubKey);
}
}
}
Expand Down
Loading

0 comments on commit d97cfb9

Please sign in to comment.