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

Commit 92e8cd1

Browse files
committed
Clean up deprecated methods.
1 parent 051874f commit 92e8cd1

File tree

1 file changed

+33
-58
lines changed

1 file changed

+33
-58
lines changed

SMSGameCore.mm

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -307,73 +307,51 @@ - (NSData *)serializeStateWithError:(NSError **)outError
307307
unsigned char *bytes = (unsigned char *)malloc(length);
308308

309309
if(smsSaveState(bytes, length))
310-
{
311310
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+
}];
312317
}
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;
328320
}
329321

330322
- (BOOL)deserializeState:(NSData *)state withError:(NSError **)outError
331323
{
332324
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+
}];
343331
}
344332

345333
return NO;
346334
}
347-
348-
349-
335+
350336
if(smsLoadState((unsigned char *)[state bytes], saveStateSize))
351-
{
352337
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+
}];
353344
}
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;
368347
}
369348

370349
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
371350
{
372351
int saveStateSize = smsSavestateSize();
373352
NSMutableData *stateData = [NSMutableData dataWithLength:saveStateSize];
374353

375-
if(!smsSaveState((unsigned char *)[stateData mutableBytes], saveStateSize))
376-
{
354+
if(!smsSaveState((unsigned char *)[stateData mutableBytes], saveStateSize)) {
377355
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
378356
NSLocalizedDescriptionKey : @"Save state data could not be written",
379357
NSLocalizedRecoverySuggestionErrorKey : @"The emulator could not write the state data."
@@ -382,26 +360,23 @@ - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(B
382360
return;
383361
}
384362

385-
__autoreleasing NSError *error = nil;
363+
NSError *error = nil;
386364
BOOL success = [stateData writeToFile:fileName options:NSDataWritingAtomic error:&error];
387-
388365
block(success, success ? nil : error);
389366
}
390367

391368
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
392369
{
393-
__autoreleasing NSError *error = nil;
370+
NSError *error;
394371
NSData *data = [NSData dataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafe | NSDataReadingUncached error:&error];
395372

396-
if(data == nil)
397-
{
373+
if(data == nil) {
398374
block(NO, error);
399375
return;
400376
}
401377

402378
int saveStateSize = smsSavestateSize();
403-
if(saveStateSize != [data length])
404-
{
379+
if(saveStateSize != [data length]) {
405380
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreStateHasWrongSizeError userInfo:@{
406381
NSLocalizedDescriptionKey : @"Save state has wrong file size.",
407382
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 (^)
410385
return;
411386
}
412387

413-
if(!smsLoadState((unsigned char *)[data bytes], saveStateSize))
414-
{
388+
if(!smsLoadState((unsigned char *)[data bytes], saveStateSize)) {
415389
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
416390
NSLocalizedDescriptionKey : @"The save state data could not be read",
417391
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"Could not read the file state in %@.", fileName]
@@ -423,7 +397,6 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
423397
block(YES, nil);
424398
}
425399

426-
427400
#pragma mark Input
428401

429402
- (oneway void)didPushSMSButton:(OESMSButton)button forPlayer:(NSUInteger)player
@@ -443,10 +416,12 @@ - (oneway void)didReleaseSMSButton:(OESMSButton)button forPlayer:(NSUInteger)pla
443416
}
444417

445418
- (oneway void)didPushSMSResetButton
446-
{}
419+
{
420+
}
447421

448422
- (oneway void)didReleaseSMSResetButton
449-
{}
423+
{
424+
}
450425

451426
- (oneway void)didPushSMSStartButton
452427
{

0 commit comments

Comments
 (0)