Skip to content

Commit

Permalink
* Improve failure condition when AppData wasn't found.
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 2, 2024
1 parent fb06761 commit 40e5e44
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,57 @@ int GetProfilePictureSize()
return g_ProfilePictureSize;
}

void SetupCachePathIfNeeded()
void FindBasePath()
{
TCHAR pwStr[MAX_PATH];
pwStr[0] = 0;
LPCTSTR p1 = NULL, p2 = NULL;

if (SUCCEEDED(ri::SHGetFolderPath(g_Hwnd, CSIDL_APPDATA, NULL, 0, pwStr)))
{
SetBasePath(MakeStringFromTString(pwStr));

p1 = ConvertCppStringToTString(GetBasePath());
p2 = ConvertCppStringToTString(GetCachePath());

// if these already exist, it's fine..
if (!CreateDirectory(p1, NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
goto _failure;
}
if (!CreateDirectory(p2, NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
goto _failure;
}
}
else
{
MessageBox(g_Hwnd, TmGetTString(IDS_NO_APPDATA), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR);
SetBasePath("");
SetBasePath(".");
}
return;
_failure:
MessageBox(g_Hwnd, TmGetTString(IDS_NO_CACHE_DIR), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR);

SetBasePath(".");

if (p1) free((void*)p1);
if (p2) free((void*)p2);
}

return;
_failure:
MessageBox(g_Hwnd, TmGetTString(IDS_NO_CACHE_DIR), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR);
void SetupCachePathIfNeeded()
{
FindBasePath();

SetBasePath("");
LPCTSTR p1 = NULL, p2 = NULL;
p1 = ConvertCppStringToTString(GetBasePath());
p2 = ConvertCppStringToTString(GetCachePath());

// if these already exist, it's fine..
if (!CreateDirectory(p1, NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
goto _failure;
}
if (!CreateDirectory(p2, NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
goto _failure;
}

if (p1) free((void*)p1);
if (p2) free((void*)p2);

return;
_failure:
MessageBox(g_Hwnd, TmGetTString(IDS_NO_CACHE_DIR), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR);
}

DiscordInstance* g_pDiscordInstance;
Expand Down

0 comments on commit 40e5e44

Please sign in to comment.