Re-added fallback code if SHGetFolderPathA fails (like in stock code, falls back to "data" directory)

This commit is contained in:
Silent 2018-01-06 16:04:11 +01:00
parent dfb46efa88
commit 63ba94e547
3 changed files with 19 additions and 22 deletions

View file

@ -30,21 +30,6 @@ extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, R
char** ppUserFilesDir; char** ppUserFilesDir;
char* GetMyDocumentsPath()
{
static char cUserFilesPath[MAX_PATH];
if ( cUserFilesPath[0] == '\0' )
{
SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath);
PathAppendA(cUserFilesPath, *ppUserFilesDir);
CreateDirectoryA(cUserFilesPath, nullptr);
}
return cUserFilesPath;
}
void InjectHooks() void InjectHooks()
{ {
static char aNoDesktopMode[64]; static char aNoDesktopMode[64];

View file

@ -16,10 +16,16 @@ namespace Common {
if ( cUserFilesPath[0] == '\0' ) if ( cUserFilesPath[0] == '\0' )
{ {
SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); if ( SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath) == S_OK )
{
PathAppendA(cUserFilesPath, *ppUserFilesDir); PathAppendA(cUserFilesPath, *ppUserFilesDir);
CreateDirectoryA(cUserFilesPath, nullptr); CreateDirectoryA(cUserFilesPath, nullptr);
} }
else
{
strcpy_s(cUserFilesPath, "data");
}
}
return cUserFilesPath; return cUserFilesPath;
} }

View file

@ -716,11 +716,17 @@ char* GetMyDocumentsPathSA()
static bool initPath = [&] () { static bool initPath = [&] () {
char** const ppUserFilesDir = AddressByVersion<char**>(0x74503F, 0x74586F, 0x77EE50, 0x77902B, 0x778F1B); char** const ppUserFilesDir = AddressByVersion<char**>(0x74503F, 0x74586F, 0x77EE50, 0x77902B, 0x778F1B);
char cTmpPath[MAX_PATH]; if ( SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, ppTempBufPtr) == S_OK )
{
SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, ppTempBufPtr);
PathAppendA(ppTempBufPtr, *ppUserFilesDir); PathAppendA(ppTempBufPtr, *ppUserFilesDir);
CreateDirectoryA(ppTempBufPtr, nullptr); CreateDirectoryA(ppTempBufPtr, nullptr);
}
else
{
strcpy_s(ppTempBufPtr, MAX_PATH, "data");
}
char cTmpPath[MAX_PATH];
strcpy_s(cTmpPath, ppTempBufPtr); strcpy_s(cTmpPath, ppTempBufPtr);
PathAppendA(cTmpPath, "Gallery"); PathAppendA(cTmpPath, "Gallery");