From 15cdf3e3349a78a7b539f826f66426c6740b5bda Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Fri, 30 Aug 2024 14:10:41 -0400 Subject: [PATCH] tvOS: Add Settings.app option to reset retroarch.cfg --- .../RetroArch_iOS13.xcodeproj/project.pbxproj | 4 +++ pkg/apple/tvOS/Settings.bundle/Root.plist | 21 ++++++++++++ .../Settings.bundle/en.lproj/Root.strings | Bin 0 -> 476 bytes ui/drivers/ui_cocoatouch.m | 32 ++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 pkg/apple/tvOS/Settings.bundle/Root.plist create mode 100644 pkg/apple/tvOS/Settings.bundle/en.lproj/Root.strings diff --git a/pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj b/pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj index 1aeeea76286..3863bf249a5 100644 --- a/pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ /* Begin PBXBuildFile section */ 07019B932CD24FF200D6C3FD /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 07C5C63E2CD167470030FBEC /* GCDWebDAVServer.m */; }; 070A88432A4E7AA9003161C0 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 070A88422A4E7AA9003161C0 /* OpenAL.framework */; }; + 071212C82C6FD65B00F1B4B0 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 071212C72C6FD65B00F1B4B0 /* Settings.bundle */; }; 0712A7722B807AE400C9765F /* TVServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0712A7712B807AE400C9765F /* TVServices.framework */; }; 0712A7762B807AE400C9765F /* ContentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 0712A7752B807AE400C9765F /* ContentProvider.m */; }; 0712A77A2B807AE400C9765F /* RetroArchTopShelfExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 0712A7702B807AE400C9765F /* RetroArchTopShelfExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -172,6 +173,7 @@ /* Begin PBXFileReference section */ 070A88422A4E7AA9003161C0 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; + 071212C72C6FD65B00F1B4B0 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; 0712A7702B807AE400C9765F /* RetroArchTopShelfExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RetroArchTopShelfExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 0712A7712B807AE400C9765F /* TVServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TVServices.framework; path = Library/Frameworks/TVServices.framework; sourceTree = DEVELOPER_DIR; }; 0712A7742B807AE400C9765F /* ContentProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentProvider.h; sourceTree = ""; }; @@ -569,6 +571,7 @@ 926C77E221FD1E6700103EDE /* Assets.xcassets */, 926C77E421FD1E6700103EDE /* Info.plist */, 073DB2892B8706490001BA32 /* RetroArchTV.entitlements */, + 071212C72C6FD65B00F1B4B0 /* Settings.bundle */, ); path = tvOS; sourceTree = ""; @@ -1448,6 +1451,7 @@ 07B7872D29E8FE8F0088B74F /* filters in Resources */, 92CC05BD21FE3C1700FF79F0 /* GCDWebUploader.bundle in Resources */, 0753AD1A2C86144200874A42 /* BaseConfig.xcconfig in Resources */, + 071212C82C6FD65B00F1B4B0 /* Settings.bundle in Resources */, 9222F2002314BA7C0097C0FD /* assets.zip in Resources */, 926C77E321FD1E6700103EDE /* Assets.xcassets in Resources */, ); diff --git a/pkg/apple/tvOS/Settings.bundle/Root.plist b/pkg/apple/tvOS/Settings.bundle/Root.plist new file mode 100644 index 00000000000..5103c4c5f8c --- /dev/null +++ b/pkg/apple/tvOS/Settings.bundle/Root.plist @@ -0,0 +1,21 @@ + + + + + StringsTable + Root + PreferenceSpecifiers + + + Type + PSToggleSwitchSpecifier + Title + Restore Default Config + Key + restore_default_config + DefaultValue + + + + + diff --git a/pkg/apple/tvOS/Settings.bundle/en.lproj/Root.strings b/pkg/apple/tvOS/Settings.bundle/en.lproj/Root.strings new file mode 100644 index 0000000000000000000000000000000000000000..1d980f2d6713c834c36d4af870f6f86fe54ec569 GIT binary patch literal 476 zcmb7=QHlaF5Jc(`i7?9k2zW~97Q{w(5c?>>S{R<$Wp3iE zVA%Bm_U#}2)9I<%r~e@37~$DxAg?(;y~{6|Xs!`!tPN^@kG1S`%~_+^GvA(mvPb{j N4tCIz{cYERNiWnaRjvR4 literal 0 HcmV?d00001 diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 606f427ad2a..dc9c681ed6f 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -672,6 +672,38 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application int argc = 1; apple_platform = self; + if ([NSUserDefaults.standardUserDefaults boolForKey:@"restore_default_config"]) + { + [NSUserDefaults.standardUserDefaults setBool:NO forKey:@"restore_default_config"]; + [NSUserDefaults.standardUserDefaults setObject:@"" forKey:@FILE_PATH_MAIN_CONFIG]; + + // Get the Caches directory path + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *cachesDirectory = [paths firstObject]; + + // Define the original and new file paths + NSString *originalPath = [cachesDirectory stringByAppendingPathComponent:@"RetroArch/config/retroarch.cfg"]; + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setDateFormat:@"HHmm-yyMMdd"]; + NSString *timestamp = [dateFormatter stringFromDate:[NSDate date]]; + NSString *newPath = [cachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"RetroArch/config/RetroArch-%@.cfg", timestamp]]; + + // File manager instance + NSFileManager *fileManager = [NSFileManager defaultManager]; + + // Check if the file exists and rename it + if ([fileManager fileExistsAtPath:originalPath]) { + NSError *error = nil; + if ([fileManager moveItemAtPath:originalPath toPath:newPath error:&error]) { + NSLog(@"File renamed to %@", newPath); + } else { + NSLog(@"Error renaming file: %@", error.localizedDescription); + } + } else { + NSLog(@"File does not exist at path %@", originalPath); + } + } + [self setDelegate:self]; /* Setup window */