diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-12-30 21:28:37 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-12-30 21:28:37 +0000 |
| commit | 7c50a51cbf39ff5705428c6fb6d2010d9dac53d1 (patch) | |
| tree | 60adb25ab823e01b8455d77583b2dd557330c184 | |
| parent | 67804ee6d6d8d6c5d66cd9ab79346dfa56a6ffdf (diff) | |
| download | pcsxr-7c50a51cbf39ff5705428c6fb6d2010d9dac53d1.tar.gz | |
Try to figure out the .bin name from a cue sheet. If that fails, use the old method (get the .bin from the .cue file name).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@73948 e17a0e51-4ae3-4d35-97c3-1a29b211df97
| -rw-r--r-- | macosx/PcsxrController.m | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m index 48cd63e5..5e67a4b4 100644 --- a/macosx/PcsxrController.m +++ b/macosx/PcsxrController.m @@ -22,12 +22,43 @@ static NSString *HandleBinCue(NSString *toHandle) NSString *extension = [tempURL pathExtension]; NSString *newName = toHandle; if ([extension caseInsensitiveCompare:@"cue"] == NSOrderedSame) { - NSURL *temp1 = [tempURL URLByDeletingPathExtension]; + NSURL *temp1 = [tempURL URLByDeletingLastPathComponent]; + NSURL *temp2 = nil; + //Get the bin file name from the cue. + NSString *cueFile = [NSString stringWithContentsOfURL:tempURL encoding:NSUTF8StringEncoding error:nil]; + if (!cueFile) { + cueFile = [NSString stringWithContentsOfURL:tempURL encoding:NSASCIIStringEncoding error:nil]; + if (!cueFile) { + goto badCue; + } + } + + NSRange firstQuote, lastQuote, filePath; + firstQuote = [cueFile rangeOfString:@"\""]; + if (firstQuote.location == NSNotFound) { + goto badCue; + } + lastQuote = [cueFile rangeOfString:@".bin\"" options:NSCaseInsensitiveSearch]; + if (lastQuote.location == NSNotFound) { + goto badCue; + } + + filePath.location = firstQuote.location + 1; //Don't include the quote symbol + filePath.length = (lastQuote.location + 4) - (firstQuote.location + 1 ); //Include the .bin but not the first quote symbol + temp2 = [temp1 URLByAppendingPathComponent:[cueFile substringWithRange:filePath]]; + + goto goodCue; + + badCue: + //Fallback if the cue couldn't be loaded + temp1 = [tempURL URLByDeletingPathExtension]; //TODO: handle case-sensitive filesystems better - NSURL *temp2 = [temp1 URLByAppendingPathExtension:@"bin"]; + temp2 = [temp1 URLByAppendingPathExtension:@"bin"]; if (![[NSFileManager defaultManager] fileExistsAtPath:[temp2 path]]) { temp2 = [temp1 URLByAppendingPathExtension:@"BIN"]; } + + goodCue: newName = [temp2 path]; } [tempURL release]; |
