From 614a88ca3b16b30f49aae31deefebe69142fb2b5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 29 Jul 2024 14:50:57 -0400 Subject: [PATCH] SDL_IOFromFile: Apple targets no longer use the app bundle's resources dir. Fixes #8403. --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 16 ------ docs/README-migration.md | 2 + src/file/SDL_iostream.c | 9 +-- src/file/cocoa/SDL_iostreambundlesupport.h | 30 ---------- src/file/cocoa/SDL_iostreambundlesupport.m | 65 ---------------------- 5 files changed, 3 insertions(+), 119 deletions(-) delete mode 100644 src/file/cocoa/SDL_iostreambundlesupport.h delete mode 100644 src/file/cocoa/SDL_iostreambundlesupport.m diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index f13182b501..cb0d184592 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -229,8 +229,6 @@ A7D8B58723E2514300DCD162 /* SDL_joystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A7D023E2513E00DCD162 /* SDL_joystick_c.h */; }; A7D8B5B723E2514300DCD162 /* controller_type.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A7D923E2513E00DCD162 /* controller_type.h */; }; A7D8B5BD23E2514300DCD162 /* SDL_iostream.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A7DB23E2513F00DCD162 /* SDL_iostream.c */; }; - A7D8B5C323E2514300DCD162 /* SDL_iostreambundlesupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A7DD23E2513F00DCD162 /* SDL_iostreambundlesupport.h */; }; - A7D8B5C923E2514300DCD162 /* SDL_iostreambundlesupport.m in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A7DE23E2513F00DCD162 /* SDL_iostreambundlesupport.m */; }; A7D8B5CF23E2514300DCD162 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A7E123E2513F00DCD162 /* SDL_syspower.m */; }; A7D8B5D523E2514300DCD162 /* SDL_syspower.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A7E223E2513F00DCD162 /* SDL_syspower.h */; }; A7D8B5E723E2514300DCD162 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A7E723E2513F00DCD162 /* SDL_power.c */; }; @@ -789,8 +787,6 @@ A7D8A7D023E2513E00DCD162 /* SDL_joystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_joystick_c.h; sourceTree = ""; }; A7D8A7D923E2513E00DCD162 /* controller_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = controller_type.h; sourceTree = ""; }; A7D8A7DB23E2513F00DCD162 /* SDL_iostream.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_iostream.c; sourceTree = ""; }; - A7D8A7DD23E2513F00DCD162 /* SDL_iostreambundlesupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_iostreambundlesupport.h; sourceTree = ""; }; - A7D8A7DE23E2513F00DCD162 /* SDL_iostreambundlesupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_iostreambundlesupport.m; sourceTree = ""; }; A7D8A7E123E2513F00DCD162 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_syspower.m; sourceTree = ""; }; A7D8A7E223E2513F00DCD162 /* SDL_syspower.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_syspower.h; sourceTree = ""; }; A7D8A7E723E2513F00DCD162 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_power.c; sourceTree = ""; }; @@ -1884,21 +1880,11 @@ A7D8A7DA23E2513E00DCD162 /* file */ = { isa = PBXGroup; children = ( - A7D8A7DC23E2513F00DCD162 /* cocoa */, A7D8A7DB23E2513F00DCD162 /* SDL_iostream.c */, ); path = file; sourceTree = ""; }; - A7D8A7DC23E2513F00DCD162 /* cocoa */ = { - isa = PBXGroup; - children = ( - A7D8A7DD23E2513F00DCD162 /* SDL_iostreambundlesupport.h */, - A7D8A7DE23E2513F00DCD162 /* SDL_iostreambundlesupport.m */, - ); - path = cocoa; - sourceTree = ""; - }; A7D8A7DF23E2513F00DCD162 /* power */ = { isa = PBXGroup; children = ( @@ -2462,7 +2448,6 @@ F3F7D9152933074E00816151 /* SDL_revision.h in Headers */, A7D8BA3123E2514400DCD162 /* SDL_rotate.h in Headers */, F3F7D9652933074E00816151 /* SDL_iostream.h in Headers */, - A7D8B5C323E2514300DCD162 /* SDL_iostreambundlesupport.h in Headers */, F3F7D9492933074E00816151 /* SDL_scancode.h in Headers */, F3F7D94D2933074E00816151 /* SDL_sensor.h in Headers */, A7D8A98D23E2514000DCD162 /* SDL_sensor_c.h in Headers */, @@ -2877,7 +2862,6 @@ F3F528CD2C29E1C300E6CC26 /* s_isnan.c in Sources */, F3F07D5A269640160074468B /* SDL_hidapi_luna.c in Sources */, A7D8BBD523E2574800DCD162 /* SDL_uikitclipboard.m in Sources */, - A7D8B5C923E2514300DCD162 /* SDL_iostreambundlesupport.m in Sources */, F386F6F92884663E001840AA /* SDL_utils.c in Sources */, E4F7981E2AD8D86A00669F54 /* SDL_render_unsupported.c in Sources */, A7D8AC0F23E2514100DCD162 /* SDL_video.c in Sources */, diff --git a/docs/README-migration.md b/docs/README-migration.md index e38fc7cc0d..1e69aa85ed 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1510,6 +1510,8 @@ SDL_IOStream *SDL_RWFromFP(FILE *fp, SDL_bool autoclose) The internal `FILE *` is available through a standard SDL_IOStream property, for streams made through SDL_IOFromFile() that use stdio behind the scenes; apps use this pointer at their own risk and should make sure that SDL and the app are using the same C runtime. +On Apple platforms, SDL_RWFromFile (now called SDL_IOFromFile) no longer tries to read from inside the app bundle's resource directory, instead now using the specified path unchanged. One can use SDL_GetBasePath() to find the resource directory on these platforms. + The functions SDL_ReadU8(), SDL_ReadU16LE(), SDL_ReadU16BE(), SDL_ReadU32LE(), SDL_ReadU32BE(), SDL_ReadU64LE(), and SDL_ReadU64BE() now return SDL_TRUE if the read succeeded and SDL_FALSE if it didn't, and store the data in a pointer passed in as a parameter. diff --git a/src/file/SDL_iostream.c b/src/file/SDL_iostream.c index 0b0ecdfe5c..ef1d21d240 100644 --- a/src/file/SDL_iostream.c +++ b/src/file/SDL_iostream.c @@ -44,11 +44,6 @@ struct SDL_IOStream SDL_PropertiesID props; }; - -#ifdef SDL_PLATFORM_APPLE -#include "cocoa/SDL_iostreambundlesupport.h" -#endif /* SDL_PLATFORM_APPLE */ - #ifdef SDL_PLATFORM_3DS #include "n3ds/SDL_iostreamromfs.h" #endif /* SDL_PLATFORM_3DS */ @@ -650,9 +645,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode) #elif defined(HAVE_STDIO_H) { - #if defined(SDL_PLATFORM_APPLE) - FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode); - #elif defined(SDL_PLATFORM_WINRT) + #if defined(SDL_PLATFORM_WINRT) FILE *fp = NULL; fopen_s(&fp, file, mode); #elif defined(SDL_PLATFORM_3DS) diff --git a/src/file/cocoa/SDL_iostreambundlesupport.h b/src/file/cocoa/SDL_iostreambundlesupport.h deleted file mode 100644 index e7b337a75a..0000000000 --- a/src/file/cocoa/SDL_iostreambundlesupport.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2024 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifdef SDL_PLATFORM_APPLE - -#include - -#ifndef SDL_iostreambundlesupport_h -#define SDL_iostreambundlesupport_h -FILE *SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode); -#endif -#endif diff --git a/src/file/cocoa/SDL_iostreambundlesupport.m b/src/file/cocoa/SDL_iostreambundlesupport.m deleted file mode 100644 index 93a7b4349a..0000000000 --- a/src/file/cocoa/SDL_iostreambundlesupport.m +++ /dev/null @@ -1,65 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2024 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_internal.h" - -#ifdef SDL_PLATFORM_APPLE -#import - -#include "SDL_iostreambundlesupport.h" - -/* For proper macOS applications, the resources are contained inside the application bundle. - So the strategy is to first check the application bundle for the file, then fallback to the current working directory. - Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app. - We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework, - but we would somehow need to know what the bundle identifiers we need to search are. - Also, note the bundle layouts are different for iPhone and Mac. -*/ -FILE *SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode) -{ - @autoreleasepool { - FILE *fp = NULL; - NSFileManager *file_manager; - NSString *resource_path; - NSString *ns_string_file_component; - NSString *full_path_with_file_to_try; - - /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */ - if (SDL_strchr(mode, 'r') == NULL) { - return fopen(file, mode); - } - - file_manager = [NSFileManager defaultManager]; - resource_path = [[NSBundle mainBundle] resourcePath]; - - ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; - - full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; - if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) { - fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); - } else { - fp = fopen(file, mode); - } - - return fp; - } -} - -#endif /* SDL_PLATFORM_APPLE */