mirror of https://github.com/LIJI32/SameBoy.git
Allow importing ROMs and Files app interaction
This commit is contained in:
parent
322ead9b93
commit
21f21f6bc7
|
@ -15,5 +15,5 @@
|
||||||
- (NSString *)batterySaveFileForROM:(NSString *)rom;
|
- (NSString *)batterySaveFileForROM:(NSString *)rom;
|
||||||
- (NSString *)autosaveStateFileForROM:(NSString *)rom;
|
- (NSString *)autosaveStateFileForROM:(NSString *)rom;
|
||||||
- (NSString *)stateFile:(unsigned)index forROM:(NSString *)rom;
|
- (NSString *)stateFile:(unsigned)index forROM:(NSString *)rom;
|
||||||
|
- (NSString *)importROM:(NSString *)romFile keepOriginal:(bool)keep;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -114,4 +114,50 @@
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)importROM:(NSString *)romFile keepOriginal:(bool)keep
|
||||||
|
{
|
||||||
|
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\([^)]+\\)|\\[[^\\]]+\\]" options:0 error:nil];
|
||||||
|
NSString *friendlyName = [[romFile lastPathComponent] stringByDeletingPathExtension];
|
||||||
|
friendlyName = [regex stringByReplacingMatchesInString:friendlyName options:0 range:NSMakeRange(0, [friendlyName length]) withTemplate:@""];
|
||||||
|
friendlyName = [friendlyName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||||
|
|
||||||
|
NSString *root = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject;
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:[root stringByAppendingPathComponent:friendlyName]]) {
|
||||||
|
unsigned i = 2;
|
||||||
|
while (true) {
|
||||||
|
NSString *attempt = [friendlyName stringByAppendingFormat:@" %u", i];
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:[root stringByAppendingPathComponent:attempt]]) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
friendlyName = attempt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *romFolder = [root stringByAppendingPathComponent:friendlyName];
|
||||||
|
[[NSFileManager defaultManager] createDirectoryAtPath:romFolder
|
||||||
|
withIntermediateDirectories:false
|
||||||
|
attributes:nil
|
||||||
|
error:nil];
|
||||||
|
|
||||||
|
NSString *newROMPath = [romFolder stringByAppendingPathComponent:romFile.lastPathComponent];
|
||||||
|
|
||||||
|
NSError *error = nil;
|
||||||
|
|
||||||
|
if (keep) {
|
||||||
|
[[NSFileManager defaultManager] linkItemAtPath:romFile
|
||||||
|
toPath:newROMPath
|
||||||
|
error:&error];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[[NSFileManager defaultManager] moveItemAtPath:romFile
|
||||||
|
toPath:newROMPath
|
||||||
|
error:&error];
|
||||||
|
}
|
||||||
|
NSLog(@"%@", error);
|
||||||
|
|
||||||
|
return friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -316,7 +316,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
|
||||||
/* Convert the screenshot to a CGImageRef */
|
/* Convert the screenshot to a CGImageRef */
|
||||||
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data.bytes, data.length, NULL);
|
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data.bytes, data.length, NULL);
|
||||||
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
||||||
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
|
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast;
|
||||||
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
||||||
|
|
||||||
CGImageRef iref = CGImageCreate(width,
|
CGImageRef iref = CGImageCreate(width,
|
||||||
|
@ -473,4 +473,21 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
|
||||||
{
|
{
|
||||||
GB_set_palette(&_gb, [self userPalette]);
|
GB_set_palette(&_gb, [self userPalette]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
|
||||||
|
{
|
||||||
|
[self stop];
|
||||||
|
NSString *potentialROM = [[url.path stringByDeletingLastPathComponent] lastPathComponent];
|
||||||
|
if ([[[GBROMManager sharedManager] romFileForROM:potentialROM].stringByStandardizingPath isEqualToString:url.path.stringByStandardizingPath]) {
|
||||||
|
[GBROMManager sharedManager].currentROM = potentialROM;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[GBROMManager sharedManager].currentROM =
|
||||||
|
[[GBROMManager sharedManager] importROM:url.path
|
||||||
|
keepOriginal:[options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue]];
|
||||||
|
}
|
||||||
|
[self loadROM];
|
||||||
|
[self start];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
105
iOS/Info.plist
105
iOS/Info.plist
|
@ -48,5 +48,110 @@
|
||||||
</dict>
|
</dict>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.games</string>
|
<string>public.app-category.games</string>
|
||||||
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
|
<true/>
|
||||||
|
<key>UIFileSharingEnabled</key>
|
||||||
|
<true/>
|
||||||
|
<key>UISupportsDocumentBrowser</key>
|
||||||
|
<true/>
|
||||||
|
<key>CFBundleDocumentTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>gb</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Game Boy Game</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>com.github.liji32.sameboy.gb</string>
|
||||||
|
</array>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>gbc</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Game Boy Color Game</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>com.github.liji32.sameboy.gbc</string>
|
||||||
|
</array>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>isx</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Game Boy ISX File</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>com.github.liji32.sameboy.isx</string>
|
||||||
|
</array>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
<key>UTExportedTypeDeclarations</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>UTTypeConformsTo</key>
|
||||||
|
<array>
|
||||||
|
<string>public.data</string>
|
||||||
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>Game Boy Game</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>com.github.liji32.sameboy.gb</string>
|
||||||
|
<key>UTTypeTagSpecification</key>
|
||||||
|
<dict>
|
||||||
|
<key>public.filename-extension</key>
|
||||||
|
<array>
|
||||||
|
<string>gb</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>UTTypeConformsTo</key>
|
||||||
|
<array>
|
||||||
|
<string>public.data</string>
|
||||||
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>Game Boy Color Game</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>com.github.liji32.sameboy.gbc</string>
|
||||||
|
<key>UTTypeTagSpecification</key>
|
||||||
|
<dict>
|
||||||
|
<key>public.filename-extension</key>
|
||||||
|
<array>
|
||||||
|
<string>gbc</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>UTTypeConformsTo</key>
|
||||||
|
<array>
|
||||||
|
<string>public.data</string>
|
||||||
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>Game Boy ISX File</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>com.github.liji32.sameboy.isx</string>
|
||||||
|
<key>UTTypeTagSpecification</key>
|
||||||
|
<dict>
|
||||||
|
<key>public.filename-extension</key>
|
||||||
|
<array>
|
||||||
|
<string>isx</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
Loading…
Reference in New Issue