Skip to content

Commit 4738291

Browse files
committed
Update to NSURL API
1 parent bbb2b35 commit 4738291

1 file changed

Lines changed: 42 additions & 42 deletions

File tree

Classes/PCSX2GameCore.mm

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ @interface PCSX2GameCore ()
8181
@implementation PCSX2GameCore {
8282
@package
8383
bool hasInitialized;
84-
NSString* gamePath;
85-
NSString* stateToLoad;
84+
NSURL* gamePath;
85+
NSURL* stateToLoad;
8686
NSString* DiscID;
8787
NSString* DiscRegion;
8888
NSString* DiscSubRegion;
@@ -94,7 +94,7 @@ @implementation PCSX2GameCore {
9494
//Multi-disc booting.
9595
NSUInteger _maxDiscs;
9696
NSMutableArray<NSString*> *_allCueSheetFiles;
97-
NSString *basePath;
97+
NSURL *basePath;
9898
// Display modes.
9999
NSMutableDictionary <NSString *, id> *_displayModes;
100100
OEIntRect screenRect;
@@ -114,24 +114,24 @@ - (instancetype)init
114114
return self;
115115
}
116116

117-
static NSString *binCueFix(NSString *path)
117+
static NSURL *binCueFix(NSURL *path)
118118
{
119119
if ([[path pathExtension] caseInsensitiveCompare:@"cue"] == NSOrderedSame) {
120120
// Assume the bin file is the same as the cue.
121-
return [[path stringByDeletingPathExtension] stringByAppendingPathExtension:@"bin"];
121+
return [[path URLByDeletingPathExtension] URLByAppendingPathExtension:@"bin"];
122122
}
123123
return path;
124124
}
125125

126-
- (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
126+
- (BOOL)loadFileAtURL:(NSURL *)url error:(NSError **)error
127127
{
128128
// PCSX2 can't handle cue files... but can read bin files
129-
if ([[path pathExtension] caseInsensitiveCompare:@"cue"] == NSOrderedSame) {
129+
if ([[url pathExtension] caseInsensitiveCompare:@"cue"] == NSOrderedSame) {
130130
// Assume the bin file is the same name as the cue.
131-
gamePath = [[path stringByDeletingPathExtension] stringByAppendingPathExtension:@"bin"];
132-
} else if([path.pathExtension.lowercaseString isEqualToString:@"m3u"]) {
133-
basePath = path.stringByDeletingLastPathComponent;
134-
NSString *m3uString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
131+
gamePath = [[url URLByDeletingPathExtension] URLByAppendingPathExtension:@"bin"];
132+
} else if([url.pathExtension.lowercaseString isEqualToString:@"m3u"]) {
133+
basePath = url.URLByDeletingLastPathComponent;
134+
NSString *m3uString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
135135
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@".*\\.cue|.*\\.ccd|.*\\.iso" options:NSRegularExpressionCaseInsensitive error:nil];
136136
NSUInteger numberOfMatches = [regex numberOfMatchesInString:m3uString options:0 range:NSMakeRange(0, m3uString.length)];
137137

@@ -151,22 +151,22 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
151151

152152
if (_allCueSheetFiles.count <= 0) {
153153
if (error) {
154-
*error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadROMError userInfo:@{NSFilePathErrorKey: path}];
154+
*error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadROMError userInfo:@{NSFilePathErrorKey: url.path}];
155155
}
156156

157157
return false;
158158
} else {
159-
NSString *ToPassBack = [basePath stringByAppendingPathComponent:_allCueSheetFiles.firstObject];
160-
ToPassBack = [binCueFix(ToPassBack) stringByStandardizingPath];
159+
NSURL *ToPassBack = [basePath URLByAppendingPathComponent:_allCueSheetFiles.firstObject];
160+
ToPassBack = [binCueFix(ToPassBack) URLByStandardizingPath];
161161

162162
gamePath = ToPassBack;
163163
}
164164
} else {
165-
gamePath = [path copy];
165+
gamePath = [url copy];
166166
}
167167

168168
//Lets get the Disc ID with some Magic out of PCSX2 CDVD :)
169-
VMManager::ChangeDisc(CDVD_SourceType::Iso, path.fileSystemRepresentation);
169+
VMManager::ChangeDisc(CDVD_SourceType::Iso, url.fileSystemRepresentation);
170170
std::string DiscName;
171171
GetPS2ElfName(DiscName);
172172

@@ -185,7 +185,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
185185

186186
- (void)setupEmulation
187187
{
188-
const std::string pcsx2ini([[self.supportDirectoryPath stringByAppendingPathComponent:@"inis"] stringByAppendingPathComponent:@"PCSX2.ini"].fileSystemRepresentation);
188+
const std::string pcsx2ini([[self.supportDirectory URLByAppendingPathComponent:@"inis" isDirectory:YES] URLByAppendingPathComponent:@"PCSX2.ini" isDirectory:NO].fileSystemRepresentation);
189189
s_base_settings_interface = std::make_unique<INISettingsInterface>(std::move(pcsx2ini));
190190
Host::Internal::SetBaseSettingsLayer(s_base_settings_interface.get());
191191

@@ -200,25 +200,25 @@ - (void)setupEmulation
200200
EmuConfig.LoadSave(wrapper);
201201
}
202202

203-
NSString *path = self.batterySavesDirectoryPath;
204-
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]) {
205-
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL];
203+
NSURL *url = self.batterySavesDirectory;
204+
if (![[NSFileManager defaultManager] fileExistsAtPath:url.path isDirectory:NULL]) {
205+
[[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:NULL];
206206
}
207207

208-
EmuFolders::MemoryCards = path.fileSystemRepresentation;
209-
EmuFolders::Bios = self.biosDirectoryPath.fileSystemRepresentation;
208+
EmuFolders::MemoryCards = url.fileSystemRepresentation;
209+
EmuFolders::Bios = self.biosDirectory.fileSystemRepresentation;
210210
EmuFolders::AppRoot = [[NSBundle bundleForClass:[self class]] resourceURL].fileSystemRepresentation;
211-
EmuFolders::DataRoot = self.supportDirectoryPath.fileSystemRepresentation;
212-
EmuFolders::Settings = [self.supportDirectoryPath stringByAppendingPathComponent:@"inis"].fileSystemRepresentation;
211+
EmuFolders::DataRoot = self.supportDirectory.fileSystemRepresentation;
212+
EmuFolders::Settings = [self.supportDirectory URLByAppendingPathComponent:@"inis" isDirectory:YES].fileSystemRepresentation;
213213
EmuFolders::Resources = [[NSBundle bundleForClass:[self class]] resourceURL].fileSystemRepresentation;
214-
EmuFolders::Cache = [self.supportDirectoryPath stringByAppendingPathComponent:@"Cache"].fileSystemRepresentation;
215-
EmuFolders::Snapshots = [self.supportDirectoryPath stringByAppendingPathComponent:@"snaps"].fileSystemRepresentation;
216-
EmuFolders::Savestates = [self.supportDirectoryPath stringByAppendingPathComponent:@"sstates"].fileSystemRepresentation;
217-
EmuFolders::Logs = [self.supportDirectoryPath stringByAppendingPathComponent:@"Logs"].fileSystemRepresentation;
218-
EmuFolders::Cheats = [self.supportDirectoryPath stringByAppendingPathComponent:@"Cheats"].fileSystemRepresentation;
219-
EmuFolders::CheatsWS = [self.supportDirectoryPath stringByAppendingPathComponent:@"cheats_ws"].fileSystemRepresentation;
220-
EmuFolders::Covers = [self.supportDirectoryPath stringByAppendingPathComponent:@"Covers"].fileSystemRepresentation;
221-
EmuFolders::GameSettings = [self.supportDirectoryPath stringByAppendingPathComponent:@"gamesettings"].fileSystemRepresentation;
214+
EmuFolders::Cache = [self.supportDirectory URLByAppendingPathComponent:@"Cache" isDirectory:YES].fileSystemRepresentation;
215+
EmuFolders::Snapshots = [self.supportDirectory URLByAppendingPathComponent:@"snaps" isDirectory:YES].fileSystemRepresentation;
216+
EmuFolders::Savestates = [self.supportDirectory URLByAppendingPathComponent:@"sstates" isDirectory:YES].fileSystemRepresentation;
217+
EmuFolders::Logs = [self.supportDirectory URLByAppendingPathComponent:@"Logs" isDirectory:YES].fileSystemRepresentation;
218+
EmuFolders::Cheats = [self.supportDirectory URLByAppendingPathComponent:@"Cheats" isDirectory:YES].fileSystemRepresentation;
219+
EmuFolders::CheatsWS = [self.supportDirectory URLByAppendingPathComponent:@"cheats_ws" isDirectory:YES].fileSystemRepresentation;
220+
EmuFolders::Covers = [self.supportDirectory URLByAppendingPathComponent:@"Covers" isDirectory:YES].fileSystemRepresentation;
221+
EmuFolders::GameSettings = [self.supportDirectory URLByAppendingPathComponent:@"gamesettings" isDirectory:YES].fileSystemRepresentation;
222222
EmuFolders::EnsureFoldersExist();
223223

224224
EmuConfig.Mcd[0].Enabled = true;
@@ -318,7 +318,7 @@ - (void)startEmulation
318318
if(VMManager::Initialize(params)){
319319
hasInitialized = true;
320320
VMManager::SetState(VMState::Running);
321-
if ([stateToLoad length] > 0)
321+
if ([stateToLoad.path length] > 0)
322322
VMManager::LoadState(stateToLoad.fileSystemRepresentation);
323323

324324
[NSThread detachNewThreadSelector:@selector(runVMThread) toTarget:self withObject:nil];
@@ -464,30 +464,30 @@ - (oneway void)didReleasePS2Button:(OEPS2Button)button forPlayer:(NSUInteger)pla
464464

465465

466466
#pragma mark Save States
467-
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
467+
- (void)loadStateFromFileAtURL:(NSURL *)fileURL completionHandler:(void (^)(BOOL, NSError *))block
468468
{
469469
if (!VMManager::HasValidVM()){
470-
stateToLoad = fileName;
470+
stateToLoad = fileURL;
471471
return;
472472
}
473473

474474
WaitRequested = true;
475475
while(isExecuting)
476476
usleep(50);
477477

478-
bool success = VMManager::LoadState(fileName.fileSystemRepresentation);
478+
bool success = VMManager::LoadState(fileURL.fileSystemRepresentation);
479479
WaitRequested = false;
480480

481-
block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{NSLocalizedDescriptionKey: @"PCSX2 Could not load the current state.", NSFilePathErrorKey: fileName}]);
481+
block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{NSLocalizedDescriptionKey: @"PCSX2 Could not load the current state.", NSFilePathErrorKey: fileURL.path}]);
482482
}
483483

484-
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
484+
- (void)saveStateToFileAtURL:(NSURL *)fileURL completionHandler:(void (^)(BOOL, NSError *))block
485485
{
486486
if (!VMManager::HasValidVM())
487487
return;
488-
bool success = VMManager::SaveState(fileName.fileSystemRepresentation, false, false);
488+
bool success = VMManager::SaveState(fileURL.fileSystemRepresentation, false, false);
489489

490-
block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{NSLocalizedDescriptionKey: @"PCSX2 Could not save the current state.", NSFilePathErrorKey: fileName}]);
490+
block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{NSLocalizedDescriptionKey: @"PCSX2 Could not save the current state.", NSFilePathErrorKey: fileURL.path}]);
491491

492492
}
493493

@@ -500,8 +500,8 @@ - (NSUInteger)discCount
500500

501501
- (void)setDisc:(NSUInteger)discNumber
502502
{
503-
NSString *ToPassBack = [basePath stringByAppendingPathComponent:_allCueSheetFiles[discNumber - 1]];
504-
ToPassBack = [binCueFix(ToPassBack) stringByStandardizingPath];
503+
NSURL *ToPassBack = [basePath URLByAppendingPathComponent:_allCueSheetFiles[discNumber - 1]];
504+
ToPassBack = [binCueFix(ToPassBack) URLByStandardizingPath];
505505

506506
gamePath = ToPassBack;
507507

0 commit comments

Comments
 (0)