Browse Source

[ios] Expose app's data

pull/3693/head
JBerg 4 years ago committed by Anders Jenbo
parent
commit
f31258400a
  1. 4
      CMakeLists.txt
  2. 4
      Packaging/apple/Info.plist
  3. 11
      Source/platform/ios/ios_paths.h
  4. 30
      Source/platform/ios/ios_paths.m
  5. 12
      Source/utils/paths.cpp

4
CMakeLists.txt

@ -548,6 +548,10 @@ set(libdevilutionx_SRCS
Source/storm/storm_svid.cpp
Source/miniwin/misc_msg.cpp)
if(IOS)
list(APPEND libdevilutionx_SRCS Source/platform/ios/ios_paths.m)
endif()
if(USE_SDL1)
list(APPEND libdevilutionx_SRCS Source/utils/sdl2_to_1_2_backports.cpp)
endif()

4
Packaging/apple/Info.plist

@ -44,5 +44,9 @@
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
</dict>
</plist>

11
Source/platform/ios/ios_paths.h

@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern char *IOSGetPrefPath();
#ifdef __cplusplus
}
#endif

30
Source/platform/ios/ios_paths.m

@ -0,0 +1,30 @@
#import <Foundation/Foundation.h>
#include "ios_paths.h"
#ifdef __cplusplus
extern "C" {
#endif
char *IOSGetPrefPath()
{
@autoreleasepool {
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([array count] > 0) {
NSString *str = [array objectAtIndex:0];
str = [str stringByAppendingString:@"/"];
const char *base = [str fileSystemRepresentation];
char *copy = malloc(strlen(base) + 1);
strcpy(copy, base);
return copy;
}
return "";
}
}
#ifdef __cplusplus
}
#endif

12
Source/utils/paths.cpp

@ -6,6 +6,10 @@
#include "utils/log.hpp"
#include "utils/sdl_ptrs.h"
#ifdef __IPHONEOS__
#include "platform/ios/ios_paths.h"
#endif
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
@ -66,10 +70,14 @@ const std::string &BasePath()
const std::string &PrefPath()
{
if (!prefPath) {
#ifndef __IPHONEOS__
prefPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
if (FileExistsAndIsWriteable("diablo.ini")) {
prefPath = std::string("./");
}
#else
prefPath = FromSDL(IOSGetPrefPath());
#endif
}
return *prefPath;
}
@ -77,10 +85,14 @@ const std::string &PrefPath()
const std::string &ConfigPath()
{
if (!configPath) {
#ifndef __IPHONEOS__
configPath = FromSDL(SDL_GetPrefPath("diasurgical", "devilution"));
if (FileExistsAndIsWriteable("diablo.ini")) {
configPath = std::string("./");
}
#else
configPath = FromSDL(IOSGetPrefPath());
#endif
}
return *configPath;
}

Loading…
Cancel
Save