Browse Source

Xbox NXDK: Handle drives

1. Automount D drive
2. Mount E drive
3. Set preference and config paths to `E:\UDATA\devilutionx`

Co-authored-by: Ryzee119 <wendland@live.com.au>
pull/4917/merge
Gleb Mazovetskiy 4 years ago
parent
commit
ace30d2085
  1. 3
      CMakeLists.txt
  2. 6
      Source/main.cpp
  3. 63
      Source/utils/paths.cpp

3
CMakeLists.txt

@ -468,6 +468,9 @@ if(UWP_LIB)
endif()
if(NXDK)
target_link_libraries(${BIN_TARGET} PRIVATE "${NXDK_DIR}/lib/libnxdk_automount_d.lib")
target_link_options(${BIN_TARGET} PRIVATE "-include:_automount_d_drive")
set(_nxdk_pkg_dir "${CMAKE_BINARY_DIR}/pkg")
set(_xbe_path "${_nxdk_pkg_dir}/default.xbe")
add_custom_command(

6
Source/main.cpp

@ -13,6 +13,9 @@
#include "platform/vita/network.h"
#include "platform/vita/random.hpp"
#endif
#ifdef NXDK
#include <nxdk/mount.h>
#endif
#ifdef GPERF_HEAP_MAIN
#include <gperftools/heap-profiler.h>
#endif
@ -40,6 +43,9 @@ extern "C" int main(int argc, char **argv)
vita_enable_network();
randombytes_vitarandom_init();
#endif
#ifdef NXDK
nxMountDrive('E', "\\Device\\Harddisk0\\Partition1\\");
#endif
#ifdef GPERF_HEAP_MAIN
HeapProfilerStart("main");
#endif

63
Source/utils/paths.cpp

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

Loading…
Cancel
Save