Skip to content

Commit

Permalink
Changed how the UI cache is handled
Browse files Browse the repository at this point in the history
- Split SKIF_Lib_SummaryCache into two components:
  - One part is part of app_record_s
  - One part is part of SKIF_InjectionContext
- The injection summary is now safer to access since it's always per-app
- Merged Steam and general Injection Summary evaluation functions
- Reduced GetModuleFileName() calls
- Fixed various bugs as well (e.g. full DLL path not appearing)
  • Loading branch information
Aemony committed Jan 23, 2024
1 parent 0d92c63 commit 952caef
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 506 deletions.
37 changes: 37 additions & 0 deletions include/stores/Steam/app_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ struct app_record_s {
Localized = 0x2,
Unknown = 0x0
} type = Type::Unknown;
std:: string type_utf8 = "Unknown";

std::wstring shorthand;
std:: string shorthand_utf8; // Converted to utf-8 from utf-16
Expand Down Expand Up @@ -346,6 +347,42 @@ struct app_record_s {
std:: string getTimeAsCStrUTF8 (void);
};


// Cached data
struct CloudPath
{
std::wstring path;
std:: string path_utf8;
std:: string label;

CloudPath (int i, std::wstring p)
{
path = p;
path_utf8 = SK_WideCharToUTF8 (p);
label =
SK_FormatString ("%s###CloudUFS.%d", path_utf8.c_str(), i);
};
};

using branch_t =
std::pair <std::string, branch_record_s>;

// This struct holds the cache for the right click context menu
struct {
int numSecondaryLaunchConfigs = 0; // Secondary launch options
bool profileFolderExists = false;
bool screenshotsFolderExists = false;
std::wstring wsScreenshotDir = L"";
std::vector <CloudPath> cloud_paths; // Steam Auto-Cloud
std::multimap <int64_t, branch_t> branches; // Steam Branches

// PCGamingWiki
std::wstring pcgwValue;
std::wstring pcgwLink;

std::string label_version; // type_version
} ui;

struct specialk_config_s {
std::wstring profile_dir;
std::set <std::string> screenshots; // utf8 path
Expand Down
101 changes: 1 addition & 100 deletions include/tabs/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,103 +25,4 @@
#include <utility/games.h>
#include <stores/Steam/app_record.h>

void SKIF_UI_Tab_DrawLibrary (void);

// Cached struct used to hold calculated data across frames
struct SKIF_Lib_SummaryCache
{
// Cached data
struct CloudPath
{
std::wstring path;
std:: string path_utf8;
std:: string label;

CloudPath (int i, std::wstring p)
{
path = p;
path_utf8 = SK_WideCharToUTF8 (p);
label =
SK_FormatString ("%s###CloudUFS.%d", path_utf8.c_str(), i);
};
};

using branch_t =
std::pair < std::string,
app_record_s::branch_record_s >;

// This struct holds the cache for the right click context menu
struct {
int numSecondaryLaunchConfigs = 0; // Secondary launch options
bool profileFolderExists = false;
bool screenshotsFolderExists = false;
std::wstring wsScreenshotDir = L"";
std::vector <CloudPath> cloud_paths; // Steam Auto-Cloud
std::multimap <int64_t, branch_t> branches; // Steam Branches

// PCGamingWiki
std::wstring pcgwValue;
std::wstring pcgwLink;
} menu;

enum class CachedType {
Global = 0x1,
Local = 0x2,
Unknown = 0x0
};

struct {
CachedType type = CachedType::Unknown;
std::string type_utf8;
std::string type_version;
struct {
std::string text;
ImColor color;
ImColor color_hover;
} status;
std::string hover_text;
} injection;

std::string config_repo;

/*
struct {
std::wstring shorthand;
std::string shorthand_utf8; // Converted to utf-8 from utf-16
std::wstring root_dir;
std::string root_dir_utf8; // Converted to utf-8 from utf-16
std::wstring full_path;
std::string full_path_utf8; // Converted to utf-8 from utf-16
} config;
struct {
std::wstring shorthand;
std::string shorthand_utf8; // Converted to utf-8 from utf-16
std::wstring version;
std::string version_utf8; // Converted to utf-8 from utf-16
std::wstring full_path;
std::string full_path_utf8; // Converted to utf-8 from utf-16
} dll;
*/

AppId_t app_id = 0;
DWORD running = 0;
DWORD updating = 0;
bool service = false;
bool autostop = false;

void Refresh (app_record_s* pApp, std::set <std::string> apptickets);

// Functions
static SKIF_Lib_SummaryCache& GetInstance (void)
{
static SKIF_Lib_SummaryCache instance;
return instance;
}

SKIF_Lib_SummaryCache (SKIF_Lib_SummaryCache const&) = delete; // Delete copy constructor
SKIF_Lib_SummaryCache (SKIF_Lib_SummaryCache&&) = delete; // Delete move constructor

private:
SKIF_Lib_SummaryCache (void) { }; // Do nothing
};
void SKIF_UI_Tab_DrawLibrary (void);
10 changes: 10 additions & 0 deletions include/utility/injection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cstdio>
#include <array>
#include <string>
#include <imgui/imgui.h>

// Singleton struct
struct SKIF_InjectionContext {
Expand Down Expand Up @@ -56,6 +57,14 @@ struct SKIF_InjectionContext {
int pid32 = 0,
pid64 = 0;

// Used for the quick toggle / status summary when a game is selected
struct {
ImColor color;
ImColor color_hover;
std::string text;
std::string hover_tip;
} ui_game_summary;

enum RunningState
{
Stopped = 0,
Expand Down Expand Up @@ -94,6 +103,7 @@ struct SKIF_InjectionContext {
void _GlobalInjectionCtl (void);
void _StartAtLogonCtrl (void);
void _SetTaskbarOverlay (bool show);
void _RefreshUIQuickToggle (bool active);
bool _TestUserList (const char* wszExecutable, bool whitelist_);

bool WhitelistPath (std::string fullPath);
Expand Down
31 changes: 15 additions & 16 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,14 @@ void SKIF_Shell_CreateNotifyToast (UINT type, std::wstring message, std::wstring

void SKIF_Shell_CreateJumpList (void)
{
static SKIF_CommonPathsCache& _path_cache = SKIF_CommonPathsCache::GetInstance ( );

CComPtr <ICustomDestinationList> pDestList; // The jump list
CComPtr <IObjectCollection> pObjColl; // Object collection to hold the custom tasks.
CComPtr <IShellLink> pLink; // Reused for the custom tasks
CComPtr <IObjectArray> pRemovedItems; // Not actually used since we don't carry custom destinations
PROPVARIANT pv; // Used to give the custom tasks a title
UINT cMaxSlots; // Not actually used since we don't carry custom destinations

TCHAR szExePath[MAX_PATH + 2];
GetModuleFileName (NULL, szExePath, _countof(szExePath)); // Set the executable path

// Create a jump list COM object.
if (SUCCEEDED (pDestList.CoCreateInstance (CLSID_DestinationList)))
Expand All @@ -962,9 +961,9 @@ void SKIF_Shell_CreateJumpList (void)
{
CComQIPtr <IPropertyStore> pPropStore = pLink.p; // The link title is kept in the object's property store, so QI for that interface.

pLink ->SetPath (szExePath);
pLink ->SetPath (_path_cache.skif_executable);
pLink ->SetArguments (L"Start Temp"); // Set the arguments
pLink ->SetIconLocation (szExePath, 1); // Set the icon location.
pLink ->SetIconLocation (_path_cache.skif_executable, 1); // Set the icon location.
pLink ->SetDescription (L"Starts the injection service and\n"
L"stops it after injection."); // Set the link description (tooltip on the jump list item)
InitPropVariantFromString (L"Start Service", &pv);
Expand All @@ -981,9 +980,9 @@ void SKIF_Shell_CreateJumpList (void)
{
CComQIPtr <IPropertyStore> pPropStore = pLink.p; // The link title is kept in the object's property store, so QI for that interface.

pLink ->SetPath (szExePath);
pLink ->SetPath (_path_cache.skif_executable);
pLink ->SetArguments (L"Start"); // Set the arguments
pLink ->SetIconLocation (szExePath, 1); // Set the icon location.
pLink ->SetIconLocation (_path_cache.skif_executable, 1); // Set the icon location.
pLink ->SetDescription (L"Starts the injection service but\n"
L"does not stop it after injection."); // Set the link description (tooltip on the jump list item)
InitPropVariantFromString (L"Start Service (manual stop)", &pv);
Expand All @@ -1000,9 +999,9 @@ void SKIF_Shell_CreateJumpList (void)
{
CComQIPtr <IPropertyStore> pPropStore = pLink.p; // The link title is kept in the object's property store, so QI for that interface.

pLink ->SetPath (szExePath);
pLink ->SetPath (_path_cache.skif_executable);
pLink ->SetArguments (L"Stop"); // Set the arguments
pLink ->SetIconLocation (szExePath, 2); // Set the icon location.
pLink ->SetIconLocation (_path_cache.skif_executable, 2); // Set the icon location.
pLink ->SetDescription (L"Stops the injection service"); // Set the link description (tooltip on the jump list item)
InitPropVariantFromString (L"Stop Service", &pv);
pPropStore->SetValue (PKEY_Title, pv); // Set the title property.
Expand Down Expand Up @@ -1032,9 +1031,9 @@ void SKIF_Shell_CreateJumpList (void)
{
CComQIPtr <IPropertyStore> pPropStore = pLink.p; // The link title is kept in the object's property store, so QI for that interface.

pLink ->SetPath (szExePath);
pLink ->SetPath (_path_cache.skif_executable);
pLink ->SetArguments (L"RunUpdater"); // Set the arguments
pLink ->SetIconLocation (szExePath, 0); // Set the icon location.
pLink ->SetIconLocation (_path_cache.skif_executable, 0); // Set the icon location.
pLink ->SetDescription (L"Checks for any available updates"); // Set the link description (tooltip on the jump list item)
InitPropVariantFromString (L"Check for Updates", &pv);
pPropStore->SetValue (PKEY_Title, pv); // Set the title property.
Expand Down Expand Up @@ -1066,9 +1065,9 @@ void SKIF_Shell_CreateJumpList (void)
{
CComQIPtr <IPropertyStore> pPropStore = pLink.p; // The link title is kept in the object's property store, so QI for that interface.

pLink ->SetPath (szExePath);
pLink ->SetPath (_path_cache.skif_executable);
pLink ->SetArguments (L"Quit"); // Set the arguments
pLink ->SetIconLocation (szExePath, 0); // Set the icon location.
pLink ->SetIconLocation (_path_cache.skif_executable, 0); // Set the icon location.
//pLink ->SetDescription (L"Closes the application"); // Set the link description (tooltip on the jump list item)
InitPropVariantFromString (L"Exit", &pv);
pPropStore->SetValue (PKEY_Title, pv); // Set the title property.
Expand Down Expand Up @@ -1097,10 +1096,10 @@ void SKIF_Shell_CreateJumpList (void)

void SKIF_Shell_AddJumpList (std::wstring name, std::wstring path, std::wstring parameters, std::wstring directory, std::wstring icon_path, bool bService)
{
static SKIF_CommonPathsCache& _path_cache = SKIF_CommonPathsCache::GetInstance ( );

CComPtr <IShellLink> pLink; // Reused for the custom tasks
PROPVARIANT pv; // Used to give the custom tasks a title
TCHAR szExePath[MAX_PATH + 2];
GetModuleFileName (NULL, szExePath, _countof(szExePath)); // Set the executable path

if (SUCCEEDED (pLink.CoCreateInstance (CLSID_ShellLink)))
{
Expand All @@ -1122,7 +1121,7 @@ void SKIF_Shell_AddJumpList (std::wstring name, std::wstring path, std::wstring
parameters = SK_FormatStringW (LR"("%ws" %ws)", path.c_str(), parameters.c_str());
}

pLink ->SetPath (szExePath); // Point to SKIF.exe
pLink ->SetPath (_path_cache.skif_executable); // Point to SKIF.exe
pLink ->SetArguments (parameters.c_str()); // Set the arguments

if (! directory.empty())
Expand Down
17 changes: 7 additions & 10 deletions src/stores/Steam/steam_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,11 @@ SKIF_Steam_GetInjectionStrategy (app_record_s* pApp)
if (PathFileExistsW ((test_path + LR"(\SpecialK.Central)").c_str ()))
launch.injection.config.type = ConfigType::Centralized;
else
launch.injection.config = { ConfigType::Localized, test_path };
{
launch.injection.config.type = ConfigType::Localized;
launch.injection.config.root_dir = test_path;
launch.injection.config.root_dir_utf8 = SK_WideCharToUTF8 (launch.injection.config.root_dir);
}

launch.injection.config.shorthand = dll.name + L".ini";
launch.injection.config.shorthand_utf8 = SK_WideCharToUTF8 (launch.injection.config.shorthand);
Expand Down Expand Up @@ -1617,15 +1621,8 @@ SKIF_Steam_GetInjectionStrategy (app_record_s* pApp)

pApp->specialk.injection.config.type =
ConfigType::Centralized;

wchar_t wszPathToSelf [MAX_PATH + 2] = { };
GetModuleFileNameW (0, wszPathToSelf, MAX_PATH);
PathRemoveFileSpecW ( wszPathToSelf);
PathAppendW ( wszPathToSelf,
bIs64Bit ? L"SpecialK64.dll"
: L"SpecialK32.dll" );

pApp->specialk.injection.dll.full_path = wszPathToSelf;

pApp->specialk.injection.dll.full_path = SK_FormatStringW (LR"(%ws\%ws)", _path_cache.specialk_install, (bIs64Bit) ? L"SpecialK64.dll" : L"SpecialK32.dll");
pApp->specialk.injection.dll.full_path_utf8 = SK_WideCharToUTF8 (pApp->specialk.injection.dll.full_path);
pApp->specialk.injection.dll.version =
bIs64Bit ? _inject.SKVer64
Expand Down
Loading

0 comments on commit 952caef

Please sign in to comment.