Compare commits

...

3 Commits

Author SHA1 Message Date
Iliyas Jorio
83d8e04520 Optional case-sensitive FSSpec 2023-09-19 21:02:57 +02:00
Iliyas Jorio
5358bfea27 User-configurable POMME_DEBUG_ constants 2023-09-19 21:02:36 +02:00
Iliyas Jorio
60f1eeaf58 SDL fallback if Windows::GetPreferencesFolder fails 2023-09-17 21:26:05 +02:00
4 changed files with 82 additions and 11 deletions

View File

@ -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";

View File

@ -180,6 +180,18 @@ static bool CaseInsensitiveAppendToPath(
return true;
}
#if POMME_CASE_SENSITIVE_FSSPEC
if (!skipFiles)
{
fs::path candidateResourcePath = naiveConcat;
candidateResourcePath += ".rsrc";
if (fs::is_regular_file(candidateResourcePath))
{
path = naiveConcat;
return true;
}
}
#else
// Convert path element to uppercase for case-insensitive comparisons
const auto uppercaseElement = UppercaseCopy(element);
@ -211,6 +223,7 @@ static bool CaseInsensitiveAppendToPath(
return true;
}
}
#endif
path = naiveConcat;
return false;

View File

@ -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;
}

View File

@ -6,13 +6,33 @@
#include <sstream>
#include <cstdint>
#define POMME_DEBUG_MEMORY false
#define POMME_DEBUG_SOUND false
#define POMME_DEBUG_PICT false
#define POMME_DEBUG_FILES false
#define POMME_DEBUG_RESOURCES false
#define POMME_DEBUG_INPUT false
#define POMME_DEBUG_3DMF false
#if !defined(POMME_DEBUG_MEMORY)
#define POMME_DEBUG_MEMORY 0
#endif
#if !defined(POMME_DEBUG_SOUND)
#define POMME_DEBUG_SOUND 0
#endif
#if !defined(POMME_DEBUG_PICT)
#define POMME_DEBUG_PICT 0
#endif
#if !defined(POMME_DEBUG_FILES)
#define POMME_DEBUG_FILES 0
#endif
#if !defined(POMME_DEBUG_RESOURCES)
#define POMME_DEBUG_RESOURCES 0
#endif
#if !defined(POMME_DEBUG_INPUT)
#define POMME_DEBUG_INPUT 0
#endif
#if !defined(POMME_DEBUG_3DMF)
#define POMME_DEBUG_3DMF 0
#endif
#define POMME_GENLOG(define, prefix) if (!define) {} else std::cout << "[" << prefix << "] " << __func__ << ":\t"
#define POMME_GENLOG_NOPREFIX(define) if (!define) {} else std::cout