Created
November 9, 2023 02:56
-
-
Save fellowgeek/65c536d2aebc5531649ac32a62ebd632 to your computer and use it in GitHub Desktop.
Retroarch TVs code hack to automatically include the ROMs directory into the Apple TV app when caches disappear
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(instancetype)init { | |
NSLog(@"Init form WebServer"); | |
if ( self = [super init] ) { | |
#if TARGET_OS_IOS | |
NSString* docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; | |
#elif TARGET_OS_TV | |
// BEGIN HACK | |
NSString* docsPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; | |
NSLog(@"Updating BIOS folder."); | |
[self copyDirectory:@"BIOS"]; | |
NSLog(@"Updating ROMS folder."); | |
[self copyDirectory:@"ROMS"]; | |
// END HACK | |
#endif | |
_webUploader = [[GCDWebUploader alloc] initWithUploadDirectory:docsPath]; | |
_webUploader.allowHiddenItems = YES; | |
} | |
return self; | |
} | |
// Function to copy assets into cache directory of Apple TV | |
-(void)copyDirectory:(NSString *)directory { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSError *error; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:directory]; | |
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:directory]; | |
if (![fileManager fileExistsAtPath:documentDBFolderPath]) { | |
//Create Directory! | |
[fileManager createDirectoryAtPath:documentDBFolderPath withIntermediateDirectories:NO attributes:nil error:&error]; | |
} else { | |
NSLog(@"Directory exists! %@", documentDBFolderPath); | |
} | |
NSArray *fileList = [fileManager contentsOfDirectoryAtPath:resourceDBFolderPath error:&error]; | |
for (NSString *s in fileList) { | |
NSLog(@"Trying: %@", s); | |
NSString *newFilePath = [documentDBFolderPath stringByAppendingPathComponent:s]; | |
NSString *oldFilePath = [resourceDBFolderPath stringByAppendingPathComponent:s]; | |
if (![fileManager fileExistsAtPath:newFilePath]) { | |
NSLog(@"Copying: %@", s); | |
//File does not exist, copy it | |
[fileManager copyItemAtPath:oldFilePath toPath:newFilePath error:&error]; | |
} else { | |
NSLog(@"File exists: %@", newFilePath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment