From 63ba94e547be4ad96771d751e588b3cf1d44a8dd Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 6 Jan 2018 16:04:11 +0100 Subject: [PATCH] Re-added fallback code if SHGetFolderPathA fails (like in stock code, falls back to "data" directory) --- DDraw/dllmain.cpp | 15 --------------- SilentPatch/Common_ddraw.cpp | 12 +++++++++--- SilentPatchSA/SilentPatchSA.cpp | 14 ++++++++++---- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index 8906259..12d2d21 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -30,21 +30,6 @@ extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, R 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() { static char aNoDesktopMode[64]; diff --git a/SilentPatch/Common_ddraw.cpp b/SilentPatch/Common_ddraw.cpp index e970d0c..61a8d80 100644 --- a/SilentPatch/Common_ddraw.cpp +++ b/SilentPatch/Common_ddraw.cpp @@ -16,9 +16,15 @@ namespace Common { if ( cUserFilesPath[0] == '\0' ) { - SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); - PathAppendA(cUserFilesPath, *ppUserFilesDir); - CreateDirectoryA(cUserFilesPath, nullptr); + if ( SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath) == S_OK ) + { + PathAppendA(cUserFilesPath, *ppUserFilesDir); + CreateDirectoryA(cUserFilesPath, nullptr); + } + else + { + strcpy_s(cUserFilesPath, "data"); + } } return cUserFilesPath; } diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index da77dc4..7c11503 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -716,11 +716,17 @@ char* GetMyDocumentsPathSA() static bool initPath = [&] () { char** const ppUserFilesDir = AddressByVersion(0x74503F, 0x74586F, 0x77EE50, 0x77902B, 0x778F1B); - char cTmpPath[MAX_PATH]; + if ( SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, ppTempBufPtr) == S_OK ) + { + PathAppendA(ppTempBufPtr, *ppUserFilesDir); + CreateDirectoryA(ppTempBufPtr, nullptr); + } + else + { + strcpy_s(ppTempBufPtr, MAX_PATH, "data"); + } - SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, ppTempBufPtr); - PathAppendA(ppTempBufPtr, *ppUserFilesDir); - CreateDirectoryA(ppTempBufPtr, nullptr); + char cTmpPath[MAX_PATH]; strcpy_s(cTmpPath, ppTempBufPtr); PathAppendA(cTmpPath, "Gallery");