mirror of
https://github.com/jorio/Pomme.git
synced 2024-06-08 23:29:39 +00:00
SDL fallback if Windows::GetPreferencesFolder fails
This commit is contained in:
parent
9fae17d771
commit
60f1eeaf58
|
@ -11,6 +11,7 @@
|
|||
#include "CompilerSupport/filesystem.h"
|
||||
|
||||
#if _WIN32
|
||||
#include <SDL.h>
|
||||
#include "Platform/Windows/PommeWindows.h"
|
||||
#endif
|
||||
|
||||
|
@ -173,9 +174,25 @@ OSErr FindFolder(short vRefNum, OSType folderType, Boolean createFolder, short*
|
|||
{
|
||||
#ifdef _WIN32
|
||||
path = Pomme::Platform::Windows::GetPreferencesFolder();
|
||||
if (path.empty())
|
||||
{
|
||||
const char* fallback = SDL_GetPrefPath("", "PommeFallback");
|
||||
if (fallback)
|
||||
{
|
||||
TODOMINOR2("SDL fallback path is: " << fallback);
|
||||
path = fallback;
|
||||
SDL_free((void*) fallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
TODO2("SDL fallback path failure!");
|
||||
return fnfErr;
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
const char *home = getenv("HOME");
|
||||
if (!home) {
|
||||
if (!home)
|
||||
{
|
||||
return fnfErr;
|
||||
}
|
||||
path = fs::path(home) / "Library" / "Preferences";
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
#undef NOUSER
|
||||
|
||||
#include "PommeDebug.h"
|
||||
#include "Platform/Windows/PommeWindows.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
|
||||
std::filesystem::path Pomme::Platform::Windows::GetPreferencesFolder()
|
||||
{
|
||||
wchar_t* wpath = nullptr;
|
||||
SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &wpath);
|
||||
auto path = std::filesystem::path(wpath);
|
||||
PWSTR wpath = nullptr;
|
||||
HRESULT result = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &wpath);
|
||||
|
||||
std::filesystem::path path;
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
TODO2("SHGetKnownFolderPath returned " << result);
|
||||
path = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
path = std::filesystem::path(wpath);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
TODO2("Conversion from wpath failed " << ex.what());
|
||||
path = "";
|
||||
}
|
||||
}
|
||||
|
||||
CoTaskMemFree(static_cast<void*>(wpath));
|
||||
return path;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user