|
|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
#include <SDL.h> |
|
|
|
|
|
|
|
|
|
#include "appfat.h" |
|
|
|
|
#include "utils/file_util.h" |
|
|
|
|
#include "utils/log.hpp" |
|
|
|
|
#include "utils/sdl_ptrs.h" |
|
|
|
|
@ -10,6 +11,12 @@
|
|
|
|
|
#include "platform/ios/ios_paths.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef NXDK |
|
|
|
|
#define NOMINMAX 1 |
|
|
|
|
#define WIN32_LEAN_AND_MEAN |
|
|
|
|
#include <windows.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef USE_SDL1 |
|
|
|
|
#include "utils/sdl2_to_1_2_backports.h" |
|
|
|
|
#endif |
|
|
|
|
@ -25,15 +32,18 @@ std::optional<std::string> prefPath;
|
|
|
|
|
std::optional<std::string> configPath; |
|
|
|
|
std::optional<std::string> assetsPath; |
|
|
|
|
|
|
|
|
|
void AddTrailingSlash(std::string &path) |
|
|
|
|
{ |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
if (!path.empty() && path.back() != '\\') |
|
|
|
|
path += '\\'; |
|
|
|
|
constexpr char DirectorySeparator = '\\'; |
|
|
|
|
#define DIRECTORY_SEPARATOR_STR "\\" |
|
|
|
|
#else |
|
|
|
|
if (!path.empty() && path.back() != '/') |
|
|
|
|
path += '/'; |
|
|
|
|
constexpr char DirectorySeparator = '/'; |
|
|
|
|
#define DIRECTORY_SEPARATOR_STR "/" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
void AddTrailingSlash(std::string &path) |
|
|
|
|
{ |
|
|
|
|
if (!path.empty() && path.back() != DirectorySeparator) |
|
|
|
|
path += DirectorySeparator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string FromSDL(char *s) |
|
|
|
|
@ -47,6 +57,20 @@ std::string FromSDL(char *s)
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef NXDK |
|
|
|
|
const std::string &NxdkGetPrefPath() |
|
|
|
|
{ |
|
|
|
|
static const std::string Path = []() { |
|
|
|
|
const char *path = "E:\\UDATA\\devilutionx\\"; |
|
|
|
|
if (CreateDirectoryA(path, nullptr) == FALSE && ::GetLastError() != ERROR_ALREADY_EXISTS) { |
|
|
|
|
DirErrorDlg(path); |
|
|
|
|
} |
|
|
|
|
return path; |
|
|
|
|
}(); |
|
|
|
|
return Path; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
const std::string &BasePath() |
|
|
|
|
@ -60,13 +84,15 @@ const std::string &BasePath()
|
|
|
|
|
const std::string &PrefPath() |
|
|
|
|
{ |
|
|
|
|
if (!prefPath) { |
|
|
|
|
#ifndef __IPHONEOS__ |
|
|
|
|
#if defined(__IPHONEOS__) |
|
|
|
|
prefPath = FromSDL(IOSGetPrefPath()); |
|
|
|
|
#elif defined(NXDK) |
|
|
|
|
prefPath = NxdkGetPrefPath(); |
|
|
|
|
#else |
|
|
|
|
prefPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution")); |
|
|
|
|
if (FileExistsAndIsWriteable("diablo.ini")) { |
|
|
|
|
prefPath = std::string("./"); |
|
|
|
|
prefPath = std::string("." DIRECTORY_SEPARATOR_STR); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
prefPath = FromSDL(IOSGetPrefPath()); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
return *prefPath; |
|
|
|
|
@ -75,13 +101,15 @@ const std::string &PrefPath()
|
|
|
|
|
const std::string &ConfigPath() |
|
|
|
|
{ |
|
|
|
|
if (!configPath) { |
|
|
|
|
#ifndef __IPHONEOS__ |
|
|
|
|
#if defined(__IPHONEOS__) |
|
|
|
|
configPath = FromSDL(IOSGetPrefPath()); |
|
|
|
|
#elif defined(NXDK) |
|
|
|
|
configPath = NxdkGetPrefPath(); |
|
|
|
|
#else |
|
|
|
|
configPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution")); |
|
|
|
|
if (FileExistsAndIsWriteable("diablo.ini")) { |
|
|
|
|
configPath = std::string("./"); |
|
|
|
|
configPath = std::string("." DIRECTORY_SEPARATOR_STR); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
configPath = FromSDL(IOSGetPrefPath()); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
return *configPath; |
|
|
|
|
@ -89,12 +117,15 @@ const std::string &ConfigPath()
|
|
|
|
|
|
|
|
|
|
const std::string &AssetsPath() |
|
|
|
|
{ |
|
|
|
|
if (!assetsPath) |
|
|
|
|
if (!assetsPath) { |
|
|
|
|
#if __EMSCRIPTEN__ |
|
|
|
|
assetsPath.emplace("assets/"); |
|
|
|
|
#elif defined(NXDK) |
|
|
|
|
assetsPath.emplace("D:\\assets\\"); |
|
|
|
|
#else |
|
|
|
|
assetsPath.emplace(FromSDL(SDL_GetBasePath()) + "assets/"); |
|
|
|
|
assetsPath.emplace(FromSDL(SDL_GetBasePath()) + ("assets" DIRECTORY_SEPARATOR_STR)); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
return *assetsPath; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|