mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-09 13:30:56 +02:00
Properly handled Inbox and Boot ROMs in GBROMManager
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
@property (readonly) NSString *batterySaveFile;
|
@property (readonly) NSString *batterySaveFile;
|
||||||
@property (readonly) NSString *autosaveStateFile;
|
@property (readonly) NSString *autosaveStateFile;
|
||||||
@property (readonly) NSString *cheatsFile;
|
@property (readonly) NSString *cheatsFile;
|
||||||
|
@property (readonly) NSArray <NSString *> *forbiddenNames;
|
||||||
|
|
||||||
@property (readonly) NSString *localRoot;
|
@property (readonly) NSString *localRoot;
|
||||||
- (NSString *)stateFile:(unsigned)index;
|
- (NSString *)stateFile:(unsigned)index;
|
||||||
|
@@ -34,9 +34,17 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)forbiddenNames
|
||||||
|
{
|
||||||
|
return @[@"Inbox", @"Boot ROMs"];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setCurrentROM:(NSString *)currentROM
|
- (void)setCurrentROM:(NSString *)currentROM
|
||||||
{
|
{
|
||||||
_romFile = nil;
|
_romFile = nil;
|
||||||
|
if ([self.forbiddenNames containsObject:currentROM]) {
|
||||||
|
currentROM = nil;
|
||||||
|
}
|
||||||
_currentROM = currentROM;
|
_currentROM = currentROM;
|
||||||
bool foundROM = self.romFile;
|
bool foundROM = self.romFile;
|
||||||
|
|
||||||
@@ -64,6 +72,9 @@
|
|||||||
|
|
||||||
- (NSString *)romDirectoryForROM:(NSString *)romFile
|
- (NSString *)romDirectoryForROM:(NSString *)romFile
|
||||||
{
|
{
|
||||||
|
if ([self.forbiddenNames containsObject:romFile]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
return [self.localRoot stringByAppendingPathComponent:romFile];
|
return [self.localRoot stringByAppendingPathComponent:romFile];
|
||||||
}
|
}
|
||||||
@@ -80,9 +91,10 @@
|
|||||||
if (rom == _currentROM) {
|
if (rom == _currentROM) {
|
||||||
return self.romFile;
|
return self.romFile;
|
||||||
}
|
}
|
||||||
if ([rom isEqualToString:@"Inbox"]) return nil;
|
|
||||||
if ([rom isEqualToString:@"Boot ROMs"]) return nil;
|
|
||||||
|
|
||||||
|
if ([self.forbiddenNames containsObject:rom]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
return [self romFileForDirectory:[self romDirectoryForROM:rom]];
|
return [self romFileForDirectory:[self romDirectoryForROM:rom]];
|
||||||
}
|
}
|
||||||
@@ -149,6 +161,9 @@
|
|||||||
|
|
||||||
- (NSString *)makeNameUnique:(NSString *)name
|
- (NSString *)makeNameUnique:(NSString *)name
|
||||||
{
|
{
|
||||||
|
if ([self.forbiddenNames containsObject:name]) {
|
||||||
|
name = @"Imported ROM";
|
||||||
|
}
|
||||||
NSString *root = self.localRoot;
|
NSString *root = self.localRoot;
|
||||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[root stringByAppendingPathComponent:name]]) return name;
|
if (![[NSFileManager defaultManager] fileExistsAtPath:[root stringByAppendingPathComponent:name]]) return name;
|
||||||
|
|
||||||
|
@@ -256,6 +256,17 @@
|
|||||||
[self presentViewController:alert animated:true completion:nil];
|
[self presentViewController:alert animated:true completion:nil];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ([[GBROMManager sharedManager].forbiddenNames containsObject:newName]) {
|
||||||
|
[self.tableView reloadData];
|
||||||
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Invalid Name"
|
||||||
|
message:@"This name is reserved by SameBoy or iOS. Please choose another name."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
|
||||||
|
style:UIAlertActionStyleCancel
|
||||||
|
handler:nil]];
|
||||||
|
[self presentViewController:alert animated:true completion:nil];
|
||||||
|
return;
|
||||||
|
}
|
||||||
[self renameROM:oldName toName:newName];
|
[self renameROM:oldName toName:newName];
|
||||||
_renamingPath = nil;
|
_renamingPath = nil;
|
||||||
}
|
}
|
||||||
|
@@ -902,16 +902,9 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSDate *date = nil;
|
NSDate *date = nil;
|
||||||
@try {
|
|
||||||
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
|
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
|
||||||
forKey:NSURLContentModificationDateKey
|
forKey:NSURLContentModificationDateKey
|
||||||
error:nil];
|
error:nil];
|
||||||
}
|
|
||||||
@catch (NSException *exception) {
|
|
||||||
/* fileURLWithPath: throws an exception on some crash logs. I don't know why or how to reproduce it,
|
|
||||||
but let's at least not crash. */
|
|
||||||
GB_rewind_reset(&_gb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the rewind buffer only if we switched ROMs or had the save state change externally
|
// Reset the rewind buffer only if we switched ROMs or had the save state change externally
|
||||||
if (![_lastSavedROM isEqual:[GBROMManager sharedManager].currentROM] ||
|
if (![_lastSavedROM isEqual:[GBROMManager sharedManager].currentROM] ||
|
||||||
|
Reference in New Issue
Block a user