Get multi-block save copying working correctly on OS X.

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85876 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\MaddTheSane_cp 2013-07-06 20:09:08 +00:00
parent 175bee7ad3
commit e58027046d
5 changed files with 66 additions and 99 deletions

View File

@ -46,8 +46,6 @@ extern NSString *const memCardChangeNumberKey;
- (IBAction)setCheckbox:(id)sender;
- (IBAction)setCheckboxInverse:(id)sender;
- (IBAction)setVideoType:(id)sender;
- (IBAction)mcdChangeClicked:(id)sender;
- (IBAction)mcdNewClicked:(id)sender;
- (NSString *)keyForSender:(id)sender;
+ (void)setMemoryCard:(int)theCard toPath:(NSString *)theFile DEPRECATED_ATTRIBUTE;

View File

@ -58,16 +58,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
}
}
- (IBAction)mcdChangeClicked:(id)sender
{
[ConfigurationController mcdChangeClicked:sender];
}
- (IBAction)mcdNewClicked:(id)sender
{
[ConfigurationController mcdNewClicked:sender];
}
+ (void)mcdChangeClicked:(id)sender
{
NSInteger tag = [sender tag];
@ -91,8 +81,7 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
[openDlg setNameFieldStringValue:[path lastPathComponent]];
if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
NSArray* urls = [openDlg URLs];
NSURL *mcdURL = [urls objectAtIndex:0];
NSURL *mcdURL = [[openDlg URLs] objectAtIndex:0];
[ConfigurationController setMemoryCard:tag toURL:mcdURL];
}
@ -123,7 +112,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
//Workaround/kludge to make sure we create a memory card before posting a notification
strlcpy(mcd, [[mcdURL path] fileSystemRepresentation], MAXPATHLEN);
CreateMcd(mcd);
[ConfigurationController setMemoryCard:tag toURL:mcdURL];
@ -160,8 +148,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[self window] center];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil];
// setup checkboxes
checkBoxDefaults = [[NSMutableDictionary alloc] init];
@ -200,7 +186,7 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
}
#ifdef __i386__
//i386 on OS X doesn't like the dynarec core
//OS X on i386 doesn't like the dynarec core
[usesDynarecCell setState:NSOffState];
[usesDynarecCell setEnabled:NO];
#endif
@ -256,7 +242,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
return nil;
}
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
NSWindow *window = [self window];

View File

@ -84,7 +84,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
#if !__has_feature(objc_arc)
[memCard1Array release];
#endif
memCard1Array = [[NSMutableArray alloc] initWithArray:a];
memCard1Array = [a mutableCopy];
}
}
@ -111,7 +111,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
#if !__has_feature(objc_arc)
[memCard2Array release];
#endif
memCard2Array = [[NSMutableArray alloc] initWithArray:a];
memCard2Array = [a mutableCopy];
}
}
@ -132,7 +132,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (int)blockCount:(int)card fromIndex:(int)idx
{
int i = 0;
int i = 1;
NSArray *memArray = nil;
if (card == 1) {
memArray = [self memCard1Array];
@ -140,8 +140,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
memArray = [self memCard2Array];
}
for (i = 0; i <= (MAX_MEMCARD_BLOCKS-idx); i++) {
PcsxrMemoryObject *obj = [memArray objectAtIndex:i];
for (i = 1; i <= (MAX_MEMCARD_BLOCKS-idx); i++) {
//Get the mem card +1 from the current card
//And check its attributes
PcsxrMemoryObject *obj = [memArray objectAtIndex:(i + idx)];
//GetMcdBlockInfo(mcd, idx+i, &b);
//printf("i=%i, mcd=%i, startblock=%i, diff=%i, flags=%x\n", i, mcd, startblock, (MAX_MEMCARD_BLOCKS-startblock), b.Flags);
@ -219,7 +221,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
} else if (foundcount >= 1) { // need to find n count consecutive blocks
foundcount = 0;
} else {
i++;
//i++;
}
//printf("formatstatus=%x\n", Info->Flags);
}
@ -228,8 +230,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
return (i-foundcount);
// no free formatted slots, try to find a deleted one
foundcount=0;
i = 0;
foundcount = i = 0;
while (i < MAX_MEMCARD_BLOCKS && foundcount < len) {
PcsxrMemoryObject *obj = [cardArray objectAtIndex:i++];
if ((obj.memFlags & 0xF0) == 0xA0) { // A2 or A6 f.e.
@ -237,7 +238,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
} else if (foundcount >= 1) { // need to find n count consecutive blocks
foundcount = 0;
} else {
i++;
//i++;
}
//printf("delstatus=%x\n", Info->Flags);
}
@ -250,51 +251,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (int)findFreeMemCardBlockInCard:(int)target_card
{
#if 0
BOOL found = NO;
NSString *blockName;
NSArray *cardArray;
if (target_card == 1) {
cardArray = [self memCard1Array];
}else {
cardArray = [self memCard2Array];
}
int i = 0;
while (i < MAX_MEMCARD_BLOCKS && found == NO) {
blockName = [[cardArray objectAtIndex:i] englishName];
//FIXME: Does this properly handle saves that span more than one block?
if ([blockName isEqualToString:@""]) {
found = YES;
} else {
i++;
}
}
if (found == YES)
return i;
// no free slots, try to find a deleted one
i = 0;
while (i < MAX_MEMCARD_BLOCKS && found == NO) {
unsigned char flags = [[cardArray objectAtIndex:i] memFlags];
if ((flags & 0xF0) != 0x50) {
found = YES;
} else {
i++;
}
}
if (found == YES)
return i;
#else
int i;
for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) {
if ([self isMemoryBlockEmptyOnCard:target_card block:i]) {
return i;
}
}
#endif
return -1;
return [self findFreeMemCardBlockInCard:target_card length:1];
}
- (IBAction)moveBlock:(id)sender
@ -333,7 +290,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
freeSlot = [self findFreeMemCardBlockInCard:toCard length:count];
if (freeSlot == -1) {
NSRunCriticalAlertPanel(NSLocalizedString(@"No Free Space", nil), [NSString stringWithFormat:NSLocalizedString(@"Memory card %d doesn't have a free block on it. Please remove some blocks on that card to continue", nil), toCard], NSLocalizedString(@"Okay", nil), nil, nil);
NSRunCriticalAlertPanel(NSLocalizedString(@"No Free Space", nil), NSLocalizedString(@"Memory card %d doesn't have %d free consecutive blocks on it. Please remove some blocks on that card to continue", nil), nil, nil, nil, count, toCard);
return;
}

View File

@ -47,11 +47,12 @@ typedef enum _PCSXRMemFlags {
@property (readonly, arcstrong) NSString *sjisName;
@property (readonly, arcstrong) NSString *memName;
@property (readonly, arcstrong) NSString *memID;
@property (readonly) PCSXRMemFlags flagNameIndex;
@property (readonly) unsigned char memFlags;
@property (readonly, unsafe_unretained, nonatomic) NSString *flagName;
@property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName;
@property (readonly, unsafe_unretained, nonatomic) NSImage *memImage;
@property (readonly, nonatomic) int memIconCount;
@property (readonly, getter = isNotDeleted, nonatomic) BOOL notDeleted DEPRECATED_ATTRIBUTE;
@property (readonly) unsigned char memFlags;
@end

View File

@ -26,7 +26,7 @@ NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate";
@property (readwrite, nonatomic) NSInteger memImageIndex;
@property (arcstrong) NSArray *memImages;
@property PCSXRMemFlags flagNameIndex;
@property (readwrite) PCSXRMemFlags flagNameIndex;
@end
@implementation PcsxrMemoryObject
@ -143,31 +143,41 @@ static NSString *MemLabelEndLink;
} else
self.flagNameIndex = memFlagFree;
self.englishName = @(infoBlock->Title);
self.sjisName = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
@autoreleasepool {
self.memImages = [PcsxrMemoryObject imagesFromMcd:infoBlock];
}
if ([memImages count] == 0) {
self.memImageIndex = -1;
} else if ([memImages count] == 1) {
self.memImageIndex = 0;
} else {
self.memImageIndex = 0;
[[NSNotificationCenter defaultCenter] addObserverForName:memoryAnimateTimerKey object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSInteger index = memImageIndex;
if (++index >= [memImages count]) {
index = 0;
}
self.memImageIndex = index;
}];
}
self.memName = @(infoBlock->Name);
self.memID = @(infoBlock->ID);
//This prevents possible uglies in multi-save images
if (self.flagName == MemLabelLink || self.flagName == MemLabelEndLink) {
if (self.flagNameIndex == memFlagLink || self.flagNameIndex == memFlagEndLink || self.flagNameIndex == memFlagFree) {
//This prevents possible uglies in multi-save images
self.memImages = @[];
self.memImageIndex = -1;
if (flagNameIndex != memFlagFree) {
self.englishName = self.sjisName = (flagNameIndex == memFlagLink ? @"Multi-save" : @"Multi-save (end)");
} else {
self.englishName = self.sjisName = @"Free block";
}
self.memID = self.memName = @"";
} else {
self.englishName = @(infoBlock->Title);
self.sjisName = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
@autoreleasepool {
self.memImages = [PcsxrMemoryObject imagesFromMcd:infoBlock];
}
if ([memImages count] == 0) {
self.memImageIndex = -1;
} else if ([memImages count] == 1) {
self.memImageIndex = 0;
} else {
self.memImageIndex = 0;
[[NSNotificationCenter defaultCenter] addObserverForName:memoryAnimateTimerKey object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSInteger index = memImageIndex;
if (++index >= [memImages count]) {
index = 0;
}
self.memImageIndex = index;
}];
}
self.memName = @(infoBlock->Name);
self.memID = @(infoBlock->ID);
}
}
return self;
@ -232,6 +242,7 @@ NS_INLINE void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtclr)
attribMemLabelFree = [tmpStr copy];
RELEASEOBJ(tmpStr);
#ifdef DEBUG
tmpStr = [[NSMutableAttributedString alloc] initWithString:MemLabelEndLink];
SetupAttrStr(tmpStr, [NSColor blueColor]);
attribMemLabelEndLink = [tmpStr copy];
@ -246,6 +257,21 @@ NS_INLINE void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtclr)
SetupAttrStr(tmpStr, [NSColor controlTextColor]);
attribMemLabelUsed = [tmpStr copy];
RELEASEOBJ(tmpStr);
#else
tmpStr = [[NSMutableAttributedString alloc] initWithString:@"Multi-save"];
SetupAttrStr(tmpStr, [NSColor blueColor]);
attribMemLabelEndLink = [tmpStr copy];
RELEASEOBJ(tmpStr);
//tmpStr = [[NSMutableAttributedString alloc] initWithString:@"Multi-save"];
//SetupAttrStr(tmpStr, [NSColor blueColor]);
//attribMemLabelLink = [tmpStr copy];
//RELEASEOBJ(tmpStr);
attribMemLabelLink = attribMemLabelEndLink;
//display nothing
attribMemLabelUsed = [[NSAttributedString alloc] initWithString:@""];
#endif
tmpStr = [[NSMutableAttributedString alloc] initWithString:MemLabelDeleted];
SetupAttrStr(tmpStr, [NSColor redColor]);