Properly handled Inbox and Boot ROMs in GBROMManager

This commit is contained in:
Lior Halphon
2025-07-20 22:42:12 +03:00
parent 5b983bc7ad
commit 1dfcdffa71
4 changed files with 33 additions and 13 deletions

View File

@@ -10,6 +10,7 @@
@property (readonly) NSString *batterySaveFile;
@property (readonly) NSString *autosaveStateFile;
@property (readonly) NSString *cheatsFile;
@property (readonly) NSArray <NSString *> *forbiddenNames;
@property (readonly) NSString *localRoot;
- (NSString *)stateFile:(unsigned)index;

View File

@@ -34,9 +34,17 @@
return self;
}
- (NSArray<NSString *> *)forbiddenNames
{
return @[@"Inbox", @"Boot ROMs"];
}
- (void)setCurrentROM:(NSString *)currentROM
{
_romFile = nil;
if ([self.forbiddenNames containsObject:currentROM]) {
currentROM = nil;
}
_currentROM = currentROM;
bool foundROM = self.romFile;
@@ -64,6 +72,9 @@
- (NSString *)romDirectoryForROM:(NSString *)romFile
{
if ([self.forbiddenNames containsObject:romFile]) {
return nil;
}
return [self.localRoot stringByAppendingPathComponent:romFile];
}
@@ -80,9 +91,10 @@
if (rom == _currentROM) {
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]];
}
@@ -149,6 +161,9 @@
- (NSString *)makeNameUnique:(NSString *)name
{
if ([self.forbiddenNames containsObject:name]) {
name = @"Imported ROM";
}
NSString *root = self.localRoot;
if (![[NSFileManager defaultManager] fileExistsAtPath:[root stringByAppendingPathComponent:name]]) return name;

View File

@@ -256,6 +256,17 @@
[self presentViewController:alert animated:true completion:nil];
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];
_renamingPath = nil;
}

View File

@@ -902,17 +902,10 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
}
NSDate *date = nil;
@try {
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
forKey:NSURLContentModificationDateKey
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);
}
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
forKey:NSURLContentModificationDateKey
error:nil];
// Reset the rewind buffer only if we switched ROMs or had the save state change externally
if (![_lastSavedROM isEqual:[GBROMManager sharedManager].currentROM] ||
![_saveDate isEqual:date]) {