Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.

Commit f5997e9

Browse files
committed
Improve errors in TwoMBit.
1 parent d368007 commit f5997e9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

SMSGameCore.mm

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,15 @@ - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(B
301301
int saveStateSize = smsSavestateSize();
302302
NSMutableData *stateData = [NSMutableData dataWithLength:saveStateSize];
303303

304-
smsSaveState((unsigned char *)[stateData mutableBytes], saveStateSize);
304+
if(!smsSaveState((unsigned char *)[stateData mutableBytes], saveStateSize))
305+
{
306+
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
307+
NSLocalizedDescriptionKey : @"Save state data could not be written",
308+
NSLocalizedRecoverySuggestionErrorKey : @"The emulator could not write the state data."
309+
}];
310+
block(NO, error);
311+
return;
312+
}
305313

306314
__autoreleasing NSError *error = nil;
307315
BOOL success = [stateData writeToFile:fileName options:NSDataWritingAtomic error:&error];
@@ -323,17 +331,20 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
323331
int saveStateSize = smsSavestateSize();
324332
if(saveStateSize != [data length])
325333
{
326-
// FIXME: Provide constants for error handling in OpenEmu SDK.
327-
NSError *error = [NSError errorWithDomain:@"org.openemu.GameCore.Load" code:-10 userInfo:
328-
@{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, saveStateSize, [data length]] }];
334+
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreStateHasWrongSizeError userInfo:@{
335+
NSLocalizedDescriptionKey : @"Save state has wrong file size.",
336+
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, saveStateSize, [data length]],
337+
}];
329338
block(NO, error);
330339
return;
331340
}
332341

333342
if(!smsLoadState((unsigned char *)[data bytes], saveStateSize))
334343
{
335-
NSError *error = [NSError errorWithDomain:@"org.openemu.GameCore.Load" code:-10 userInfo:
336-
@{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Could not read the file state in %@.", fileName] }];
344+
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
345+
NSLocalizedDescriptionKey : @"The save state data could not be read",
346+
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"Could not read the file state in %@.", fileName]
347+
}];
337348
block(NO, error);
338349
return;
339350
}

0 commit comments

Comments
 (0)