Skip to content

Commit f175d0e

Browse files
authored
tvOS: Add Settings.app option to reset retroarch.cfg (libretro#17143)
1 parent 89ca849 commit f175d0e

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* Begin PBXBuildFile section */
2424
07019B932CD24FF200D6C3FD /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 07C5C63E2CD167470030FBEC /* GCDWebDAVServer.m */; };
2525
070A88432A4E7AA9003161C0 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 070A88422A4E7AA9003161C0 /* OpenAL.framework */; };
26+
071212C82C6FD65B00F1B4B0 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 071212C72C6FD65B00F1B4B0 /* Settings.bundle */; };
2627
0712A7722B807AE400C9765F /* TVServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0712A7712B807AE400C9765F /* TVServices.framework */; };
2728
0712A7762B807AE400C9765F /* ContentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 0712A7752B807AE400C9765F /* ContentProvider.m */; };
2829
0712A77A2B807AE400C9765F /* RetroArchTopShelfExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 0712A7702B807AE400C9765F /* RetroArchTopShelfExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -172,6 +173,7 @@
172173

173174
/* Begin PBXFileReference section */
174175
070A88422A4E7AA9003161C0 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
176+
071212C72C6FD65B00F1B4B0 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
175177
0712A7702B807AE400C9765F /* RetroArchTopShelfExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RetroArchTopShelfExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
176178
0712A7712B807AE400C9765F /* TVServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TVServices.framework; path = Library/Frameworks/TVServices.framework; sourceTree = DEVELOPER_DIR; };
177179
0712A7742B807AE400C9765F /* ContentProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentProvider.h; sourceTree = "<group>"; };
@@ -569,6 +571,7 @@
569571
926C77E221FD1E6700103EDE /* Assets.xcassets */,
570572
926C77E421FD1E6700103EDE /* Info.plist */,
571573
073DB2892B8706490001BA32 /* RetroArchTV.entitlements */,
574+
071212C72C6FD65B00F1B4B0 /* Settings.bundle */,
572575
);
573576
path = tvOS;
574577
sourceTree = "<group>";
@@ -1448,6 +1451,7 @@
14481451
07B7872D29E8FE8F0088B74F /* filters in Resources */,
14491452
92CC05BD21FE3C1700FF79F0 /* GCDWebUploader.bundle in Resources */,
14501453
0753AD1A2C86144200874A42 /* BaseConfig.xcconfig in Resources */,
1454+
071212C82C6FD65B00F1B4B0 /* Settings.bundle in Resources */,
14511455
9222F2002314BA7C0097C0FD /* assets.zip in Resources */,
14521456
926C77E321FD1E6700103EDE /* Assets.xcassets in Resources */,
14531457
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>StringsTable</key>
6+
<string>Root</string>
7+
<key>PreferenceSpecifiers</key>
8+
<array>
9+
<dict>
10+
<key>Type</key>
11+
<string>PSToggleSwitchSpecifier</string>
12+
<key>Title</key>
13+
<string>Restore Default Config</string>
14+
<key>Key</key>
15+
<string>restore_default_config</string>
16+
<key>DefaultValue</key>
17+
<false/>
18+
</dict>
19+
</array>
20+
</dict>
21+
</plist>
Binary file not shown.

ui/drivers/ui_cocoatouch.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,38 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
672672
int argc = 1;
673673
apple_platform = self;
674674

675+
if ([NSUserDefaults.standardUserDefaults boolForKey:@"restore_default_config"])
676+
{
677+
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"restore_default_config"];
678+
[NSUserDefaults.standardUserDefaults setObject:@"" forKey:@FILE_PATH_MAIN_CONFIG];
679+
680+
// Get the Caches directory path
681+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
682+
NSString *cachesDirectory = [paths firstObject];
683+
684+
// Define the original and new file paths
685+
NSString *originalPath = [cachesDirectory stringByAppendingPathComponent:@"RetroArch/config/retroarch.cfg"];
686+
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
687+
[dateFormatter setDateFormat:@"HHmm-yyMMdd"];
688+
NSString *timestamp = [dateFormatter stringFromDate:[NSDate date]];
689+
NSString *newPath = [cachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"RetroArch/config/RetroArch-%@.cfg", timestamp]];
690+
691+
// File manager instance
692+
NSFileManager *fileManager = [NSFileManager defaultManager];
693+
694+
// Check if the file exists and rename it
695+
if ([fileManager fileExistsAtPath:originalPath]) {
696+
NSError *error = nil;
697+
if ([fileManager moveItemAtPath:originalPath toPath:newPath error:&error]) {
698+
NSLog(@"File renamed to %@", newPath);
699+
} else {
700+
NSLog(@"Error renaming file: %@", error.localizedDescription);
701+
}
702+
} else {
703+
NSLog(@"File does not exist at path %@", originalPath);
704+
}
705+
}
706+
675707
[self setDelegate:self];
676708

677709
/* Setup window */

0 commit comments

Comments
 (0)