通過編寫一個快速而又髒的遞歸文件重新保護來解決此問題。我已經證實,僅僅對我的項目目錄運行這個修復了我看到的459錯誤。這是相關的代碼,以幫助任何人。
- (IBAction) btnGo_Pressed:(id) sender {
// The path to search is specified by the user
NSString *path = self.txtPathToSearch.stringValue;
// Recursively find all files within it
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *subpaths = [fileManager subpathsOfDirectoryAtPath:path error:nil];
// Look for pngs
int totalImagesResaved = 0;
for (int j=0; j<[subpaths count]; j++) {
NSString *fullPath = [path stringByAppendingPathComponent:[subpaths objectAtIndex:j]];
// See if this path ends with a ".png"
if ([fullPath compare:@".png" options:NSCaseInsensitiveSearch range:NSMakeRange([fullPath length] - 4, 4)] == NSOrderedSame) {
// Got one. Now resave it as a png
NSImage *image = [[NSImage alloc] initWithContentsOfFile:fullPath];
[self saveImage:image asPngWithPath:fullPath];
totalImagesResaved++;
}
}
// Status report
NSAlert *alert = [NSAlert alertWithMessageText:@"Done" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Encountened %li paths. Resaved %i .pngs.", (unsigned long)[subpaths count], totalImagesResaved];
[alert runModal];
}
- (void) saveImage:(NSImage *) image asPngWithPath:(NSString *) path
{
// Cache the reduced image
NSData *imageData = [image TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
imageData = [imageRep representationUsingType:NSPNGFileType properties:nil];
[imageData writeToFile:path atomically:YES];
}
感謝您的回覆。你是否在說蘋果將一個壞版本的pngcrush與特定版本的XCode捆綁在一起?我從來沒有故意安裝它。 –
他們增加了功能到真正的pngcrush,並使其成爲Xcode SDK的一部分。這發生在幾年前,據我所知現在仍然是2014年的情況。 –
然後,我想我不明白你的最後一句話。你說過「有些應用程序(包括Apple版本的」pngcrush「)可以解決問題。」但是你不是說蘋果版本的pngcrush是造成這個問題的原因嗎? –