Skip to content

Commit

Permalink
Various fixes to UNC path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jan 30, 2024
1 parent b019a17 commit 5f9d240
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 52 deletions.
12 changes: 7 additions & 5 deletions include/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ extern std::vector<HANDLE> vWatchHandles[UITab_ALL];

// Generic Utilities

std::string SKIF_Util_ToLower (std::string_view input);
std:: string SKIF_Util_ToLower (std:: string_view input);
std::wstring SKIF_Util_ToLowerW (std::wstring_view input);
std::string SKIF_Util_ToUpper (std::string_view input);
std:: string SKIF_Util_ToUpper (std:: string_view input);
std::wstring SKIF_Util_ToUpperW (std::wstring_view input);
std::wstring SKIF_Util_GetErrorAsWStr (DWORD error = GetLastError ( ), HMODULE module = NULL);
void SKIF_Util_GetErrorAsMsgBox (std::wstring winTitle = L"Error detected", std::wstring preMsg = L"", DWORD error = GetLastError ( ), HMODULE module = NULL);
Expand All @@ -47,14 +47,16 @@ int SKIF_Util_CompareVersionStrings (std::wstring string1, std

// Filenames

std::string SKIF_Util_StripInvalidFilenameChars (std:: string name);
std:: string SKIF_Util_StripInvalidFilenameChars (std:: string name);
std::wstring SKIF_Util_StripInvalidFilenameChars (std::wstring name);
std::string SKIF_Util_ReplaceInvalidFilenameChars (std:: string name, char replacement);
std:: string SKIF_Util_ReplaceInvalidFilenameChars (std:: string name, char replacement);
std::wstring SKIF_Util_ReplaceInvalidFilenameChars (std::wstring name, wchar_t replacement);
std:: string SKIF_Util_NormalizeFullPath (std:: string string);
std::wstring SKIF_Util_NormalizeFullPath (std::wstring string);

// Usernames
std::wstring SKIF_Util_StripPersonalData (std::wstring input);
std:: string SKIF_Util_StripPersonalData (std:: string input);
std::wstring SKIF_Util_StripPersonalData (std::wstring input);
void SKIF_Util_Debug_LogUserNames (void);


Expand Down
17 changes: 3 additions & 14 deletions src/stores/Steam/steam_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,7 @@ SK_Steam_GetLibraries (steam_library_t** ppLibraries)

if (! lib_path.empty ())
{
// Strip double backslashes characters from the string
try
{
lib_path = std::regex_replace (lib_path, std::wregex(LR"(\\\\)"), LR"(\)");
}
catch (const std::exception& e)
{
UNREFERENCED_PARAMETER(e);
}
lib_path = SKIF_Util_NormalizeFullPath (lib_path);

wcsncpy_s (
(wchar_t *)steam_lib_paths [steam_libs++], MAX_PATH,
Expand Down Expand Up @@ -692,7 +684,7 @@ SK_UseManifestToGetAppName (app_record_s *app)

if (! app->Steam_ManifestData.empty ())
{
//PLOG_VERBOSE << "Parsing manifest for AppID: " << appid;
//PLOG_VERBOSE << "Parsing manifest for AppID: " << app->id;

std::string app_name =
SK_Steam_KeyValues::getValue (
Expand Down Expand Up @@ -1059,10 +1051,7 @@ SK_UseManifestToGetInstallDir (app_record_s *app)
PathCombineW (path, app_root,
app_path.c_str ());

app->install_dir = path;

//std::replace(app->install_dir.begin(), app->install_dir.end(), '/', '\\'); // Replaces slashes
app->install_dir = std::filesystem::path(path).lexically_normal();
app->install_dir = SKIF_Util_NormalizeFullPath (path);
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/stores/Steam/vdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <utility/fsutil.h>
#include <regex>
#include <stores/Steam/steam_library.h>
#include <filesystem>

const int SKIF_STEAM_APPID = 1157970;

Expand Down Expand Up @@ -297,19 +298,6 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector <std::pair < std::stri
pAppRecord->install_dir =
SK_UseManifestToGetInstallDir (pAppRecord);

try
{
// Replace forward slashes with backslashes
std::replace (pAppRecord->install_dir.begin(), pAppRecord->install_dir.end(), '/', '\\');

// Strip double backslashes characters from the string
pAppRecord->install_dir = std::regex_replace (pAppRecord->install_dir, std::wregex(LR"(\\\\)"), LR"(\)");
}
catch (const std::exception& e)
{
UNREFERENCED_PARAMETER(e);
}

for (auto& finished_section : section.finished_sections)
{
if (finished_section.keys.empty ())
Expand Down Expand Up @@ -663,6 +651,8 @@ skValveDataFile::getAppInfo ( uint32_t appid, std::vector <std::pair < std::stri
if (launch.executable.empty())
continue;

launch.executable = std::filesystem::path(launch.executable).lexically_normal();

// Filter launch configurations requiring a beta branch that the user do not have
if (! launch.branches.empty() && launch.branches.count (pAppRecord->branch) == 0)
launch.valid = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4788,6 +4788,10 @@ SKIF_UI_Tab_DrawLibrary (void)

if (SKIF_Steam_UpdateAppState (&app.second))
app.second._status.dwTimeLastChecked = SKIF_Util_timeGetTime1 ( ) + 333UL; // _RefreshInterval

// Set uninstalled apps id to 0 so that they are filtered out
if (! app.second._status.installed)
app.second.id = 0;
}

// Only bother opening the application manifest
Expand Down Expand Up @@ -4968,6 +4972,14 @@ SKIF_UI_Tab_DrawLibrary (void)
// Update ImGuiLabelAndID and ImGuiPushID
app.second.ImGuiLabelAndID = SK_FormatString("%s###%i-%i", app.first.c_str(), (int)app.second.store, app.second.id);
app.second.ImGuiPushID = SK_FormatString("###%i-%i", (int)app.second.store, app.second.id);

#if 0
PLOG_DEBUG << "\nGame Titles: (" << app.second.id << ")"
<< "\nOriginal : " << SK_UTF8ToWideChar(app.second.names.original)
<< "\nCleaned : " << SK_UTF8ToWideChar(app.second.names.clean)
<< "\nNormal : " << SK_UTF8ToWideChar(app.second.names.normal)
<< "\nImGuiLID : " << SK_UTF8ToWideChar(app.second.ImGuiLabelAndID);
#endif
}

// Check if install folder exists (but not for Xbox games or Special K)
Expand Down
76 changes: 56 additions & 20 deletions src/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,42 @@ SKIF_Util_ReplaceInvalidFilenameChars (std::string name, char replacement)
return name;
}

std::wstring
SKIF_Util_NormalizeFullPath (std::wstring string)
{
// Are we dealing with a network path? (\\server\share)
bool isUNCpath = PathIsNetworkPathW (string.c_str());

// "Clean" the path... But also removes one of the initial two backslashes
// in an UNC path if the path begins with four backslashes (\\\\server\\share)
string = std::filesystem::path(string).lexically_normal();

// If we are dealing with an UNC path that is no more,
// we need to fix the initial missing backslash...
if (isUNCpath && ! PathIsNetworkPathW (string.c_str()))
string.insert(0, 1, '\\');

return string;
}

std::string
SKIF_Util_NormalizeFullPath (std::string string)
{
// Are we dealing with a network path? (\\server\share)
bool isUNCpath = PathIsNetworkPathA (string.c_str());

// "Clean" the path... But also removes one of the initial two backslashes
// in an UNC path if the path begins with four backslashes (\\\\server\\share)
string = std::filesystem::path(string).lexically_normal().string();

// If we are dealing with an UNC path that is no more,
// we need to fix the initial missing backslash...
if (isUNCpath && ! PathIsNetworkPathA (string.c_str()))
string.insert(0, 1, '\\');

return string;
}


// Usernames / Machine Name

Expand Down Expand Up @@ -581,26 +617,6 @@ SKIF_UtilInt_IniUserMachineStrip (void)
}
}

std::wstring
SKIF_Util_StripPersonalData (std::wstring input)
{
SKIF_UtilInt_IniUserMachineStrip ( );

if (! userDisName.empty())
input = std::regex_replace (input, std::wregex (userDisName.c_str()), replDisName.c_str()); // Strip Display Name first as it is most likely to include the profile/SAM account name

if (! userProfile.empty())
input = std::regex_replace (input, std::wregex (userProfile.c_str()), replProfile.c_str());

if (! userSamName.empty())
input = std::regex_replace (input, std::wregex (userSamName.c_str()), replSamName.c_str());

if (! machineName.empty())
input = std::regex_replace (input, std::wregex (machineName.c_str()), replMacName.c_str());

return input;
}

std::string
SKIF_Util_StripPersonalData (std::string input)
{
Expand All @@ -621,6 +637,26 @@ SKIF_Util_StripPersonalData (std::string input)
return input;
}

std::wstring
SKIF_Util_StripPersonalData (std::wstring input)
{
SKIF_UtilInt_IniUserMachineStrip ( );

if (! userDisName.empty())
input = std::regex_replace (input, std::wregex (userDisName.c_str()), replDisName.c_str()); // Strip Display Name first as it is most likely to include the profile/SAM account name

if (! userProfile.empty())
input = std::regex_replace (input, std::wregex (userProfile.c_str()), replProfile.c_str());

if (! userSamName.empty())
input = std::regex_replace (input, std::wregex (userSamName.c_str()), replSamName.c_str());

if (! machineName.empty())
input = std::regex_replace (input, std::wregex (machineName.c_str()), replMacName.c_str());

return input;
}

void
SKIF_Util_Debug_LogUserNames (void)
{
Expand Down

0 comments on commit 5f9d240

Please sign in to comment.