Skip to content

Commit 69b1717

Browse files
committed
Clean up deprecated methods.
1 parent 17374d5 commit 69b1717

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

VecXGL/VectrexGameCore.m

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
6868
return YES;
6969
}
7070

71-
- (void)executeFrameSkippingFrame:(BOOL)skip
71+
- (void)executeFrame
7272
{
7373
// late init of the overlay
7474

@@ -84,11 +84,6 @@ - (void)executeFrameSkippingFrame:(BOOL)skip
8484
glFlush();
8585
}
8686

87-
- (void)executeFrame
88-
{
89-
[self executeFrameSkippingFrame:NO];
90-
}
91-
9287
- (void)startEmulation
9388
{
9489
if(!isRunning)
@@ -116,52 +111,35 @@ - (void)resetEmulation
116111
vecx_reset();
117112
}
118113

119-
- (BOOL)saveStateToFileAtPath:(NSString *)fileName
114+
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
120115
{
121-
FILE *saveFile = fopen([fileName UTF8String], "wb");
122-
123116
VECXState *state = saveVecxState();
124-
125-
long bytesWritten = fwrite(state, sizeof(char), sizeof(VECXState), saveFile);
126-
127-
if(bytesWritten != sizeof(VECXState))
128-
{
129-
NSLog(@"Couldn't write state");
130-
return NO;
131-
}
132-
133-
fclose(saveFile);
134-
135-
free(state);
136-
137-
return YES;
117+
NSData *data = [NSData dataWithBytesNoCopy:state length:sizeof(VECXState) freeWhenDone:YES];
118+
119+
NSError *error;
120+
BOOL succeeded = [data writeToFile:fileName options:0 error:&error];
121+
block(succeeded, error);
138122
}
139123

140-
- (BOOL)loadStateFromFileAtPath:(NSString *)fileName
124+
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
141125
{
142-
FILE *saveFile = fopen([fileName UTF8String], "rb");
143-
144-
if(saveFile == NULL)
145-
{
146-
NSLog(@"Could not open state file");
147-
return NO;
126+
NSError *error;
127+
NSMutableData *data = [NSMutableData dataWithContentsOfFile:fileName options:0 error:&error];
128+
129+
if (!data) {
130+
block(NO, error);
131+
return;
148132
}
149-
150-
VECXState *state = malloc(sizeof(VECXState));
151-
152-
if(!fread(state, sizeof(char), sizeof(VECXState), saveFile))
153-
{
154-
NSLog(@"Couldn't read file");
155-
return NO;
133+
134+
if (sizeof(VECXState) != data.length) {
135+
block(NO, [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
136+
NSLocalizedFailureReasonErrorKey: @"THe size of the saved file is different from the size of the state.",
137+
}]);
138+
return;
156139
}
157-
158-
fclose(saveFile);
159-
140+
141+
VECXState *state = (void *)data.bytes;
160142
loadVecxState(state);
161-
162-
free(state);
163-
164-
return YES;
165143
}
166144

167145
- (OEIntSize)aspectSize

0 commit comments

Comments
 (0)