From dac033e00b082f87beae92d8fd82e33d9ad49842 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 21 May 2022 22:46:04 +1000 Subject: [PATCH] iOS: Fix not storing data in application support directory, fix texture pack only loading on subsequent runs and not first Previously the iOS app wrote to the bundle directory, which while that worked on the simulator, wouldn't work on an actual device since the directory was readonly --- src/Game.c | 2 +- src/_GLShared.h | 2 ++ src/interop_ios.m | 27 +++++++-------------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Game.c b/src/Game.c index 8e29d83ea..f3ee19a98 100644 --- a/src/Game.c +++ b/src/Game.c @@ -417,7 +417,7 @@ static void Game_Load(void) { } Game_DefaultZipMissing = false; - TexturePack_ExtractCurrent(false); + TexturePack_ExtractCurrent(true); if (Game_DefaultZipMissing) { Window_ShowDialog("Missing file", "default.zip is missing, try downloading resources first.\n\nThe game will still run, but without any textures"); diff --git a/src/_GLShared.h b/src/_GLShared.h index 7aebccdcb..ea1d06738 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -32,6 +32,8 @@ void Gfx_Create(void) { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx.MaxTexWidth); Gfx.MaxTexHeight = Gfx.MaxTexWidth; Gfx.Created = true; + /* necessary for android which "loses" context when window is closed */ + Gfx.LostContext = false; GLBackend_Init(); Gfx_RestoreState(); diff --git a/src/interop_ios.m b/src/interop_ios.m index 7615da641..cb3188228 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -122,6 +122,7 @@ static cc_bool kb_active; Platform_LogConst("APPEAR"); [UIView animateWithDuration:interval animations:^{ [view_handle layoutIfNeeded]; + [controller viewWillTransitionToSize:view_handle.frame.size withTransitionCoordinator:nil]; }]; } @@ -509,28 +510,14 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* arg } cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - // TODO this is the API should actually be using.. eventually - /*NSArray* array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - if ([array count] <= 0) return ERR_NOT_SUPPORTED; + // https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html + NSArray* array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + if (array.count <= 0) return ERR_NOT_SUPPORTED; - NSString* str = [array objectAtIndex:0]; - const char* name = [str fileSystemRepresentation]; - return chdir(name) == -1 ? errno : 0;*/ + NSString* str = [array objectAtIndex:0]; + const char* path = [str fileSystemRepresentation]; - char path[NATIVE_STR_LEN + 1] = { 0 }; - uint32_t size = NATIVE_STR_LEN; - if (_NSGetExecutablePath(path, &size)) return ERR_INVALID_ARGUMENT; - - // despite what you'd assume, size is NOT changed to length of path - int len = String_CalcLen(path, NATIVE_STR_LEN); - - // get rid of filename at end of directory - for (int i = len - 1; i >= 0; i--, len--) - { - if (path[i] == '/') break; - } - - path[len] = '\0'; + mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); return chdir(path) == -1 ? errno : 0; }