Skip to content

Commit

Permalink
tvOS: Add Settings.app option to reset retroarch.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven committed Oct 31, 2024
1 parent 5cc9721 commit 15cdf3e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -569,6 +571,7 @@
926C77E221FD1E6700103EDE /* Assets.xcassets */,
926C77E421FD1E6700103EDE /* Info.plist */,
073DB2892B8706490001BA32 /* RetroArchTV.entitlements */,
071212C72C6FD65B00F1B4B0 /* Settings.bundle */,
);
path = tvOS;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
21 changes: 21 additions & 0 deletions pkg/apple/tvOS/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Restore Default Config</string>
<key>Key</key>
<string>restore_default_config</string>
<key>DefaultValue</key>
<false/>
</dict>
</array>
</dict>
</plist>
Binary file added pkg/apple/tvOS/Settings.bundle/en.lproj/Root.strings
Binary file not shown.
32 changes: 32 additions & 0 deletions ui/drivers/ui_cocoatouch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 15cdf3e

Please sign in to comment.