Przeglądaj źródła

Return a writable documents directory on iOS. Contributed by att.

Lasse Öörni 11 lat temu
rodzic
commit
f120aa4be0

+ 1 - 0
Docs/Urho3D.dox

@@ -93,6 +93,7 @@ Urho3D development, contributions and bugfixes by:
 - andmar1x
 - amadeus_osa
 - atship
+- att
 - mightyCelu
 - ninjastone
 - rasteron

+ 1 - 0
Readme.txt

@@ -46,6 +46,7 @@ Urho3D development, contributions and bugfixes by:
 - andmar1x
 - amadeus_osa
 - atship
+- att
 - mightyCelu
 - ninjastone
 - rasteron

+ 2 - 1
Source/Engine/IO/FileSystem.cpp

@@ -62,6 +62,7 @@ extern "C" const char* SDL_Android_GetFilesDir();
 #endif
 #ifdef IOS
 extern "C" const char* SDL_IOS_GetResourceDir();
+extern "C" const char* SDL_IOS_GetDocumentsDir();
 #endif
 
 #include "DebugNew.h"
@@ -683,7 +684,7 @@ String FileSystem::GetUserDocumentsDir() const
     #if defined(ANDROID)
     return AddTrailingSlash(SDL_Android_GetFilesDir());
     #elif defined(IOS)
-    return AddTrailingSlash(SDL_IOS_GetResourceDir());
+    return AddTrailingSlash(SDL_IOS_GetDocumentsDir());
     #elif defined(WIN32)
     wchar_t pathName[MAX_PATH];
     pathName[0] = 0;

+ 18 - 1
Source/ThirdParty/SDL/src/video/uikit/SDL_uikitappdelegate.m

@@ -44,8 +44,9 @@ static char **forward_argv;
 static int exit_status;
 static UIWindow *launch_window;
 
-// Urho3D: added variable
+// Urho3D: added variables
 const char* resource_dir = 0;
+const char* documents_dir = 0;
 
 int main(int argc, char **argv)
 {
@@ -95,6 +96,22 @@ const char* SDL_IOS_GetResourceDir()
     return resource_dir;
 }
 
+// Urho3D: added function
+const char* SDL_IOS_GetDocumentsDir()
+{
+    if (!documents_dir)
+    {
+        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+        NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
+        
+        const char *temp = [basePath UTF8String];
+        documents_dir = malloc(strlen(temp) + 1);
+        strcpy(documents_dir, temp);
+    }
+    
+    return documents_dir;
+}
+
 static void
 SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
 {