mirror of
https://github.com/patchzyy/wiicompiled
synced 2026-09-12 17:45:52 -04:00
5c76e2b0df
* feature: add apple silicon native macOS support - #81 * (macos): Fix crash This fixes a crash when viewing the rear camera * fix(macos): keep interpolated presentation on main thread * fix(macos): supply Retro-WFC payload during setup * perf(windows): compile out flat-memory fallback check * remove duplicate smoke test * test(macos): name and focus host platform tests * fix(macos): validate Retro-WFC payload cache * fix(payload): preserve staged file access failures * Limit flat-page checks to variable-page hosts --------- Co-authored-by: patchzyy <64382339+patchzyy@users.noreply.github.com>
86 lines
2.5 KiB
C++
86 lines
2.5 KiB
C++
#include "platform/host_platform.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#if defined(_WIN32)
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#include <windows.h>
|
|
#include <shlobj.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#if defined(__APPLE__)
|
|
#include <mach-o/dyld.h>
|
|
#include <pwd.h>
|
|
#endif
|
|
|
|
namespace RuntimePlatform {
|
|
|
|
std::optional<std::filesystem::path> ExecutableDirectory() noexcept {
|
|
#if defined(_WIN32)
|
|
std::wstring buffer(MAX_PATH, L'\0');
|
|
for (;;) {
|
|
const DWORD length = GetModuleFileNameW(nullptr, buffer.data(), static_cast<DWORD>(buffer.size()));
|
|
if (length == 0) {
|
|
return std::nullopt;
|
|
}
|
|
if (length < buffer.size() - 1) {
|
|
buffer.resize(length);
|
|
return std::filesystem::path(buffer).parent_path();
|
|
}
|
|
buffer.resize(buffer.size() * 2);
|
|
}
|
|
#elif defined(__APPLE__)
|
|
uint32_t size = 0;
|
|
if (_NSGetExecutablePath(nullptr, &size) != -1 || size == 0) {
|
|
return std::nullopt;
|
|
}
|
|
std::string path(size, '\0');
|
|
if (_NSGetExecutablePath(path.data(), &size) != 0) {
|
|
return std::nullopt;
|
|
}
|
|
path.resize(std::char_traits<char>::length(path.c_str()));
|
|
std::error_code ec;
|
|
const auto resolved = std::filesystem::weakly_canonical(path, ec);
|
|
return (ec ? std::filesystem::path(path) : resolved).parent_path();
|
|
#else
|
|
return std::nullopt;
|
|
#endif
|
|
}
|
|
|
|
std::filesystem::path ApplicationDataDirectory(std::string_view applicationName) {
|
|
#if defined(_WIN32)
|
|
PWSTR rawPath = nullptr;
|
|
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &rawPath)) && rawPath) {
|
|
const std::filesystem::path directory = std::filesystem::path(rawPath) / applicationName;
|
|
CoTaskMemFree(rawPath);
|
|
return directory;
|
|
}
|
|
#elif defined(__APPLE__)
|
|
if (const char* home = std::getenv("HOME"); home && *home) {
|
|
return std::filesystem::path(home) / "Library" / "Application Support" / applicationName;
|
|
}
|
|
if (const passwd* user = getpwuid(getuid()); user && user->pw_dir && *user->pw_dir) {
|
|
return std::filesystem::path(user->pw_dir) / "Library" / "Application Support" / applicationName;
|
|
}
|
|
#endif
|
|
return std::filesystem::current_path() / applicationName;
|
|
}
|
|
|
|
std::filesystem::path LogDirectory(std::string_view applicationName) {
|
|
return ApplicationDataDirectory(applicationName) / "Logs";
|
|
}
|
|
|
|
uint64_t CurrentProcessId() noexcept {
|
|
#if defined(_WIN32)
|
|
return static_cast<uint64_t>(::GetCurrentProcessId());
|
|
#else
|
|
return static_cast<uint64_t>(::getpid());
|
|
#endif
|
|
}
|
|
|
|
} // namespace RuntimePlatform
|