Minor tidy ups. Ran through converters for Modern Objective-C and ARC. Removed couple of depreciated warnings.
This commit is contained in:
parent
def0536866
commit
c78276aeeb
|
@ -521,6 +521,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
CODE_SIGN_IDENTITY = "-";
|
CODE_SIGN_IDENTITY = "-";
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
|
@ -551,6 +552,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
CODE_SIGN_IDENTITY = "-";
|
CODE_SIGN_IDENTITY = "-";
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
|
|
|
@ -24,15 +24,15 @@ enum
|
||||||
#define BUF_LEN 64000
|
#define BUF_LEN 64000
|
||||||
|
|
||||||
@interface QuietUnrarAppDelegate : NSObject <NSApplicationDelegate> {
|
@interface QuietUnrarAppDelegate : NSObject <NSApplicationDelegate> {
|
||||||
NSWindow *window;
|
NSWindow *__weak window;
|
||||||
NSView *passwordView;
|
NSView *__weak passwordView;
|
||||||
|
|
||||||
NSSecureTextField * passwordField;
|
NSSecureTextField * __weak passwordField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (assign) IBOutlet NSWindow *window;
|
@property (weak) IBOutlet NSWindow *window;
|
||||||
@property (assign) IBOutlet NSView *passwordView;
|
@property (weak) IBOutlet NSView *passwordView;
|
||||||
@property (assign) IBOutlet NSSecureTextField * passwordField;
|
@property (weak) IBOutlet NSSecureTextField * passwordField;
|
||||||
|
|
||||||
- (BOOL) extractRarWith:(NSString *) filename;
|
- (BOOL) extractRarWith:(NSString *) filename;
|
||||||
- (BOOL) shouldFileBeReplaced:(NSString *) filename;
|
- (BOOL) shouldFileBeReplaced:(NSString *) filename;
|
||||||
|
|
|
@ -23,11 +23,11 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
// mode will either be
|
// mode will either be
|
||||||
// RAR_VOL_NOTIFY that just notifies us that the volume has changed
|
// RAR_VOL_NOTIFY that just notifies us that the volume has changed
|
||||||
// RAR_VOL_ASK indicates that a volume is needed and the library is asking for it.
|
// RAR_VOL_ASK indicates that a volume is needed and the library is asking for it.
|
||||||
//
|
//
|
||||||
// in both case volumeName is that name of the volume (for instance .r00)
|
// in both case volumeName is that name of the volume (for instance .r00)
|
||||||
//
|
//
|
||||||
// Note in the event of a volume being missing, there is no way to indicate to the
|
// Note in the event of a volume being missing, there is no way to indicate to the
|
||||||
// library that you have found it. You would need to block the copy, let the user find the
|
// library that you have found it. You would need to block the copy, let the user find the
|
||||||
// volume, copy it to where the other volumes are and unblock to let the library
|
// volume, copy it to where the other volumes are and unblock to let the library
|
||||||
// continue processing
|
// continue processing
|
||||||
int changeVolume(char * volumeName, int mode) {
|
int changeVolume(char * volumeName, int mode) {
|
||||||
|
@ -66,7 +66,7 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
KeyMap map;
|
KeyMap map;
|
||||||
GetKeys(map);
|
GetKeys(map);
|
||||||
if (KEYMAP_GET(map, kVKC_Shift) || KEYMAP_GET(map, kVKC_rShift))
|
if (KEYMAP_GET(map, kVKC_Shift) || KEYMAP_GET(map, kVKC_rShift))
|
||||||
NSLog(@"Shift or Right Shift");
|
NSLog(@"Shift or Right Shift");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||||
|
@ -77,9 +77,9 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
// Call one at a time for each file selected when app is run
|
// Call one at a time for each file selected when app is run
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
|
||||||
//NSLog(@"openFile: %@", filename);
|
//NSLog(@"openFile: %@", filename);
|
||||||
|
|
||||||
[self extractRarWith:filename];
|
[self extractRarWith:filename];
|
||||||
|
|
||||||
// Always return YES even if there is an error to avoid dialog indicating unable to
|
// Always return YES even if there is an error to avoid dialog indicating unable to
|
||||||
// handle files of type RAR if the archive is corrupt or part of it is missing
|
// handle files of type RAR if the archive is corrupt or part of it is missing
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -87,12 +87,12 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
|
|
||||||
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *) arrayOfFilenames {
|
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *) arrayOfFilenames {
|
||||||
// NSLog(@"openFiles: %@", arrayOfFilenames);
|
// NSLog(@"openFiles: %@", arrayOfFilenames);
|
||||||
|
|
||||||
for (NSString * filename in arrayOfFilenames) {
|
for (NSString * filename in arrayOfFilenames) {
|
||||||
BOOL extracted = [self extractRarWith:filename];
|
BOOL extracted = [self extractRarWith:filename];
|
||||||
if (extracted) {
|
if (extracted) {
|
||||||
//[GrowlApplicationBridge setGrowlDelegate:@""];
|
//[GrowlApplicationBridge setGrowlDelegate:@""];
|
||||||
|
|
||||||
// [GrowlApplicationBridge
|
// [GrowlApplicationBridge
|
||||||
// notifyWithTitle:@"QuietUnrar: Extraction Complete"
|
// notifyWithTitle:@"QuietUnrar: Extraction Complete"
|
||||||
// description:[NSString stringWithFormat:@"The archive %@ was successfully extracted", filename]
|
// description:[NSString stringWithFormat:@"The archive %@ was successfully extracted", filename]
|
||||||
|
@ -105,53 +105,52 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark "Main"
|
#pragma mark "Main"
|
||||||
- (BOOL) extractRarWith:(NSString *) filename {
|
- (BOOL) extractRarWith:(NSString *) filename {
|
||||||
quietUnrar = (void *) self;
|
|
||||||
char commentBuffer[BUF_LEN];
|
char commentBuffer[BUF_LEN];
|
||||||
BOOL extractionSuccessful = YES;
|
BOOL extractionSuccessful = YES;
|
||||||
struct RARHeaderData headerData;
|
struct RARHeaderData headerData;
|
||||||
NSString * lastExtractedFilename = @"";
|
NSString * lastExtractedFilename = @"";
|
||||||
NSString * currentFilename;
|
NSString * currentFilename;
|
||||||
|
|
||||||
//Determine the folder we should extract the archive to. This by default
|
//Determine the folder we should extract the archive to. This by default
|
||||||
//is the <folderContainingTheArchive>/<archiveNameWithPathExtension>
|
//is the <folderContainingTheArchive>/<archiveNameWithPathExtension>
|
||||||
NSString * folderToExtractTo = [filename stringByDeletingPathExtension];
|
NSString * folderToExtractTo = [filename stringByDeletingPathExtension];
|
||||||
|
|
||||||
// Open the Archive for extraction, we set the open result to 3 so we can see it has changed
|
// Open the Archive for extraction, we set the open result to 3 so we can see it has changed
|
||||||
char * filenameCString = (char *)[filename cStringUsingEncoding:NSISOLatin1StringEncoding];
|
char * filenameCString = (char *)[filename cStringUsingEncoding:NSISOLatin1StringEncoding];
|
||||||
struct RAROpenArchiveData arcData = { filenameCString, RAR_OM_EXTRACT, 3, &commentBuffer[0], BUF_LEN, 0, 0};
|
struct RAROpenArchiveData arcData = { filenameCString, RAR_OM_EXTRACT, 3, &commentBuffer[0], BUF_LEN, 0, 0};
|
||||||
|
|
||||||
HANDLE archive = RAROpenArchive(&arcData);
|
HANDLE archive = RAROpenArchive(&arcData);
|
||||||
//NSLog(@"Opening Archive %s with result %d", filenameCString, arcData.OpenResult);
|
//NSLog(@"Opening Archive %s with result %d", filenameCString, arcData.OpenResult);
|
||||||
|
|
||||||
// set call backs for if password needed or need to change volume
|
// set call backs for if password needed or need to change volume
|
||||||
RARSetChangeVolProc(archive, &changeVolume);
|
RARSetChangeVolProc(archive, &changeVolume);
|
||||||
RARSetCallback(archive, &callbackFunction, (LPARAM)archive);
|
RARSetCallback(archive, &callbackFunction, (LPARAM)archive);
|
||||||
|
|
||||||
while (RARReadHeader(archive, &headerData) != ERAR_END_ARCHIVE) {
|
while (RARReadHeader(archive, &headerData) != ERAR_END_ARCHIVE) {
|
||||||
//NSLog(@"Attempting to extract %s to %@", headerData.FileName, folderToExtractTo);
|
//NSLog(@"Attempting to extract %s to %@", headerData.FileName, folderToExtractTo);
|
||||||
|
|
||||||
int processResult = 0;
|
int processResult = 0;
|
||||||
BOOL extractFile = YES;
|
BOOL extractFile = YES;
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
currentFilename = [NSString stringWithCString:(const char *) headerData.FileName encoding:NSISOLatin1StringEncoding];
|
currentFilename = [NSString stringWithCString:(const char *) headerData.FileName encoding:NSISOLatin1StringEncoding];
|
||||||
|
|
||||||
NSFileManager * fileManager = [NSFileManager defaultManager];
|
NSFileManager * fileManager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
if ([fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/%s", folderToExtractTo, headerData.FileName] isDirectory:&isDir] ) {
|
if ([fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/%s", folderToExtractTo, headerData.FileName] isDirectory:&isDir] ) {
|
||||||
// If we have already processed the file once and the user has told us to skip
|
// If we have already processed the file once and the user has told us to skip
|
||||||
// don't ask them again, even though we've changed volumes. Otherwise
|
// don't ask them again, even though we've changed volumes. Otherwise
|
||||||
// ask the user what to do.
|
// ask the user what to do.
|
||||||
if ([lastExtractedFilename isEqualToString:currentFilename] ||
|
if ([lastExtractedFilename isEqualToString:currentFilename] ||
|
||||||
isDir ||
|
isDir ||
|
||||||
![self shouldFileBeReplaced:currentFilename]) {
|
![self shouldFileBeReplaced:currentFilename]) {
|
||||||
extractFile = NO;
|
extractFile = NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSLog(@"Last filename %@, currentFilename %@, equality %d", lastExtractedFilename, currentFilename, [lastExtractedFilename isEqualToString:currentFilename]);
|
// NSLog(@"Last filename %@, currentFilename %@, equality %d", lastExtractedFilename, currentFilename, [lastExtractedFilename isEqualToString:currentFilename]);
|
||||||
|
|
||||||
if (extractFile) {
|
if (extractFile) {
|
||||||
//NSLog(@"...Extracting");
|
//NSLog(@"...Extracting");
|
||||||
processResult = RARProcessFile(archive, RAR_EXTRACT, (char *) [folderToExtractTo cStringUsingEncoding:NSISOLatin1StringEncoding], NULL);
|
processResult = RARProcessFile(archive, RAR_EXTRACT, (char *) [folderToExtractTo cStringUsingEncoding:NSISOLatin1StringEncoding], NULL);
|
||||||
|
@ -161,18 +160,18 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
// Curious behavior by the lib, you have SKIP a file number of times (4 in my test example) before
|
// Curious behavior by the lib, you have SKIP a file number of times (4 in my test example) before
|
||||||
// it is skipped. However if you extract it is only processed once.
|
// it is skipped. However if you extract it is only processed once.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processResult != 0) {
|
if (processResult != 0) {
|
||||||
NSLog(@"Error: Process Result was %d", processResult);
|
NSLog(@"Error: Process Result was %d", processResult);
|
||||||
extractionSuccessful = NO;
|
extractionSuccessful = NO;
|
||||||
break;
|
break;
|
||||||
// DISPLAY ERROR DIALOG, ALERT THE USER
|
// DISPLAY ERROR DIALOG, ALERT THE USER
|
||||||
}
|
}
|
||||||
|
|
||||||
lastExtractedFilename = currentFilename;
|
lastExtractedFilename = currentFilename;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RARCloseArchive(archive);
|
RARCloseArchive(archive);
|
||||||
//NSLog(@"Closing Archive %s with result %d", filenameCString, closeResult);
|
//NSLog(@"Closing Archive %s with result %d", filenameCString, closeResult);
|
||||||
|
|
||||||
|
@ -183,21 +182,20 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
// returns YES or NO
|
// returns YES or NO
|
||||||
- (BOOL) shouldFileBeReplaced:(NSString *) filename {
|
- (BOOL) shouldFileBeReplaced:(NSString *) filename {
|
||||||
BOOL result = NO;
|
BOOL result = NO;
|
||||||
|
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
[alert addButtonWithTitle:@"Overwrite"];
|
[alert addButtonWithTitle:@"Overwrite"];
|
||||||
NSButton * skipButton = [alert addButtonWithTitle:@"Skip"];
|
NSButton * skipButton = [alert addButtonWithTitle:@"Skip"];
|
||||||
[skipButton setKeyEquivalent:@"\e"];
|
[skipButton setKeyEquivalent:@"\e"];
|
||||||
[alert setMessageText:[NSString stringWithFormat:@"Overwrite %@?", filename]];
|
[alert setMessageText:[NSString stringWithFormat:@"Overwrite %@?", filename]];
|
||||||
[alert setInformativeText:[NSString stringWithFormat:@"The file already exists. Do you wish to extract it again, overwriting the original file?", filename]];
|
[alert setInformativeText:[NSString stringWithFormat:@"The file %@ already exists. Do you wish to extract it again, overwriting the original file?", filename]];
|
||||||
[alert setAlertStyle:NSWarningAlertStyle];
|
[alert setAlertStyle:NSAlertStyleWarning];
|
||||||
|
|
||||||
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
||||||
result = YES;
|
result = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
[alert release];
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,37 +205,37 @@ int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM
|
||||||
[alert addButtonWithTitle:@"OK"];
|
[alert addButtonWithTitle:@"OK"];
|
||||||
[alert setMessageText:[NSString stringWithFormat:@"Archive part %s is missing.", volume]];
|
[alert setMessageText:[NSString stringWithFormat:@"Archive part %s is missing.", volume]];
|
||||||
[alert setInformativeText:@"Unable to extract all files from RAR archive as part of it is missing"];
|
[alert setInformativeText:@"Unable to extract all files from RAR archive as part of it is missing"];
|
||||||
[alert setAlertStyle:NSCriticalAlertStyle];
|
[alert setAlertStyle:NSAlertStyleCritical];
|
||||||
|
|
||||||
[alert runModal];
|
[alert runModal];
|
||||||
|
|
||||||
[alert release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a dialog with a custom view with a NSSecureTextField which is displayed
|
// Creates a dialog with a custom view with a NSSecureTextField which is displayed
|
||||||
// to the user so they can provide a password. Returns the entered password or nil
|
// to the user so they can provide a password. Returns the entered password or nil
|
||||||
- (NSString *) requestArchivePassword {
|
- (NSString *) requestArchivePassword {
|
||||||
if (!passwordView) {
|
if (!passwordView) {
|
||||||
[NSBundle loadNibNamed:@"PasswordView" owner:self];
|
|
||||||
|
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
|
||||||
|
|
||||||
|
[bundle loadNibNamed:@"PasswordView" owner:self topLevelObjects: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString * password = nil;
|
NSString * password = nil;
|
||||||
|
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
[alert addButtonWithTitle:@"OK"];
|
[alert addButtonWithTitle:@"OK"];
|
||||||
[alert addButtonWithTitle:@"Cancel"];
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
[alert setMessageText:@"Archive Requires a password"];
|
[alert setMessageText:@"Archive Requires a password"];
|
||||||
[alert setInformativeText:@"To extract the contents of this archive a password is required."];
|
[alert setInformativeText:@"To extract the contents of this archive a password is required."];
|
||||||
[alert setAccessoryView:passwordView];
|
[alert setAccessoryView:passwordView];
|
||||||
[alert setAlertStyle:NSWarningAlertStyle];
|
[alert setAlertStyle:NSAlertStyleWarning];
|
||||||
|
|
||||||
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
||||||
password = [passwordField stringValue];
|
password = [passwordField stringValue];
|
||||||
[password autorelease];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[alert release];
|
|
||||||
|
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ void PASCAL RARSetCallback(HANDLE hArcData,UNRARCALLBACK Callback,LPARAM UserD
|
||||||
void PASCAL RARSetChangeVolProc(HANDLE hArcData,CHANGEVOLPROC ChangeVolProc);
|
void PASCAL RARSetChangeVolProc(HANDLE hArcData,CHANGEVOLPROC ChangeVolProc);
|
||||||
void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataProc);
|
void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataProc);
|
||||||
void PASCAL RARSetPassword(HANDLE hArcData,char *Password);
|
void PASCAL RARSetPassword(HANDLE hArcData,char *Password);
|
||||||
int PASCAL RARGetDllVersion();
|
int PASCAL RARGetDllVersion(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue