@@ -307,73 +307,51 @@ - (NSData *)serializeStateWithError:(NSError **)outError
307
307
unsigned char *bytes = (unsigned char *)malloc (length);
308
308
309
309
if (smsSaveState (bytes, length))
310
- {
311
310
return [NSData dataWithBytesNoCopy: (void *)bytes length: length];
311
+
312
+ if (outError) {
313
+ *outError = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreCouldNotSaveStateError userInfo: @{
314
+ NSLocalizedDescriptionKey : @" Save state data could not be written" ,
315
+ NSLocalizedRecoverySuggestionErrorKey : @" The emulator could not write the state data."
316
+ }];
312
317
}
313
- else
314
- {
315
- if (outError)
316
- {
317
-
318
- *outError = [NSError errorWithDomain: OEGameCoreErrorDomain
319
- code: OEGameCoreCouldNotSaveStateError
320
- userInfo: @{
321
- NSLocalizedDescriptionKey : @" Save state data could not be written" ,
322
- NSLocalizedRecoverySuggestionErrorKey : @" The emulator could not write the state data."
323
- }];
324
- }
325
-
326
- return nil ;
327
- }
318
+
319
+ return nil ;
328
320
}
329
321
330
322
- (BOOL )deserializeState : (NSData *)state withError : (NSError **)outError
331
323
{
332
324
size_t saveStateSize = smsSavestateSize ();
333
- if (saveStateSize != [state length ])
334
- {
335
- if (outError)
336
- {
337
- *outError = [NSError errorWithDomain: OEGameCoreErrorDomain
338
- code: OEGameCoreStateHasWrongSizeError
339
- userInfo: @{
340
- NSLocalizedDescriptionKey : @" Save state data has the wrong size." ,
341
- NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat: @" The size of the save state does not have the right size, %ld expected, got: %ld ." , saveStateSize, [state length ]]
342
- }];
325
+ if (saveStateSize != [state length ]) {
326
+ if (outError) {
327
+ *outError = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreStateHasWrongSizeError userInfo: @{
328
+ NSLocalizedDescriptionKey : @" Save state data has the wrong size." ,
329
+ NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat: @" The size of the save state does not have the right size, %ld expected, got: %ld ." , saveStateSize, [state length ]]
330
+ }];
343
331
}
344
332
345
333
return NO ;
346
334
}
347
-
348
-
349
-
335
+
350
336
if (smsLoadState ((unsigned char *)[state bytes ], saveStateSize))
351
- {
352
337
return YES ;
338
+
339
+ if (outError) {
340
+ *outError = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreCouldNotLoadStateError userInfo: @{
341
+ NSLocalizedDescriptionKey : @" The save state data could not be read" ,
342
+ NSLocalizedRecoverySuggestionErrorKey : @" Could not read the save state data."
343
+ }];
353
344
}
354
- else
355
- {
356
- if (outError)
357
- {
358
- *outError = [NSError errorWithDomain: OEGameCoreErrorDomain
359
- code: OEGameCoreCouldNotLoadStateError
360
- userInfo: @{
361
- NSLocalizedDescriptionKey : @" The save state data could not be read" ,
362
- NSLocalizedRecoverySuggestionErrorKey : @" Could not read the save state data."
363
- }];
364
- }
365
-
366
- return NO ;
367
- }
345
+
346
+ return NO ;
368
347
}
369
348
370
349
- (void )saveStateToFileAtPath : (NSString *)fileName completionHandler : (void (^)(BOOL , NSError *))block
371
350
{
372
351
int saveStateSize = smsSavestateSize ();
373
352
NSMutableData *stateData = [NSMutableData dataWithLength: saveStateSize];
374
353
375
- if (!smsSaveState ((unsigned char *)[stateData mutableBytes ], saveStateSize))
376
- {
354
+ if (!smsSaveState ((unsigned char *)[stateData mutableBytes ], saveStateSize)) {
377
355
NSError *error = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreCouldNotSaveStateError userInfo: @{
378
356
NSLocalizedDescriptionKey : @" Save state data could not be written" ,
379
357
NSLocalizedRecoverySuggestionErrorKey : @" The emulator could not write the state data."
@@ -382,26 +360,23 @@ - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(B
382
360
return ;
383
361
}
384
362
385
- __autoreleasing NSError *error = nil ;
363
+ NSError *error = nil ;
386
364
BOOL success = [stateData writeToFile: fileName options: NSDataWritingAtomic error: &error];
387
-
388
365
block (success, success ? nil : error);
389
366
}
390
367
391
368
- (void )loadStateFromFileAtPath : (NSString *)fileName completionHandler : (void (^)(BOOL , NSError *))block
392
369
{
393
- __autoreleasing NSError *error = nil ;
370
+ NSError *error;
394
371
NSData *data = [NSData dataWithContentsOfFile: fileName options: NSDataReadingMappedIfSafe | NSDataReadingUncached error: &error];
395
372
396
- if (data == nil )
397
- {
373
+ if (data == nil ) {
398
374
block (NO , error);
399
375
return ;
400
376
}
401
377
402
378
int saveStateSize = smsSavestateSize ();
403
- if (saveStateSize != [data length ])
404
- {
379
+ if (saveStateSize != [data length ]) {
405
380
NSError *error = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreStateHasWrongSizeError userInfo: @{
406
381
NSLocalizedDescriptionKey : @" Save state has wrong file size." ,
407
382
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat: @" The size of the file %@ does not have the right size, %d expected, got: %ld ." , fileName, saveStateSize, [data length ]],
@@ -410,8 +385,7 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
410
385
return ;
411
386
}
412
387
413
- if (!smsLoadState ((unsigned char *)[data bytes ], saveStateSize))
414
- {
388
+ if (!smsLoadState ((unsigned char *)[data bytes ], saveStateSize)) {
415
389
NSError *error = [NSError errorWithDomain: OEGameCoreErrorDomain code: OEGameCoreCouldNotLoadStateError userInfo: @{
416
390
NSLocalizedDescriptionKey : @" The save state data could not be read" ,
417
391
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat: @" Could not read the file state in %@ ." , fileName]
@@ -423,7 +397,6 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
423
397
block (YES , nil );
424
398
}
425
399
426
-
427
400
#pragma mark Input
428
401
429
402
- (oneway void )didPushSMSButton : (OESMSButton)button forPlayer : (NSUInteger )player
@@ -443,10 +416,12 @@ - (oneway void)didReleaseSMSButton:(OESMSButton)button forPlayer:(NSUInteger)pla
443
416
}
444
417
445
418
- (oneway void )didPushSMSResetButton
446
- {}
419
+ {
420
+ }
447
421
448
422
- (oneway void )didReleaseSMSResetButton
449
- {}
423
+ {
424
+ }
450
425
451
426
- (oneway void )didPushSMSStartButton
452
427
{
0 commit comments