2009-11-10 16:48:42 +01:00
|
|
|
//
|
|
|
|
// QuietUnrarAppDelegate.m
|
|
|
|
// QuietUnrar
|
|
|
|
//
|
|
|
|
// Created by Robert McGovern on 2009/09/06.
|
|
|
|
// Copyright 2009 Tarasis. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Carbon/Carbon.h>
|
|
|
|
#import "QuietUnrarAppDelegate.h"
|
|
|
|
#import "libunrar/dll.hpp"
|
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
int changeVolume(char * volumeName, int mode);
|
|
|
|
int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM parameterTwo);
|
|
|
|
|
|
|
|
int changeVolume(char * volumeName, int mode) {
|
|
|
|
NSLog(@"Volume Name: %s and mode %d", volumeName, mode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int callbackFunction(UINT message, LPARAM userData, LPARAM parameterOne, LPARAM parameterTwo) {
|
|
|
|
NSLog(@"Callback Function, args: %d, %D, %D, %D", message, userData, parameterOne, parameterTwo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-10 16:48:42 +01:00
|
|
|
@implementation QuietUnrarAppDelegate
|
|
|
|
|
|
|
|
@synthesize window;
|
|
|
|
|
2009-11-14 23:12:16 +01:00
|
|
|
- (void) applicationWillFinishLaunching:(NSNotification *)notification {
|
2009-11-10 16:48:42 +01:00
|
|
|
KeyMap map;
|
|
|
|
GetKeys(map);
|
2009-11-14 18:44:36 +01:00
|
|
|
NSLog(@"Shift or Right Shift: %d", KEYMAP_GET(map, kVKC_Shift) || KEYMAP_GET(map, kVKC_rShift));
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
|
2009-11-14 23:12:16 +01:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
|
|
// Insert code here to initialize your application
|
|
|
|
|
|
|
|
// NSLog(@"Dll Version %d\n", RARGetDllVersion());
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
|
2009-11-14 23:12:16 +01:00
|
|
|
//- (BOOL)application:(id)sender openFileWithoutUI:(NSString *)filename {
|
|
|
|
// NSLog(@"openFileWithoutUI with file: %@", filename);
|
|
|
|
// return YES;
|
|
|
|
//}
|
|
|
|
|
2009-11-10 16:48:42 +01:00
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
|
|
|
|
NSLog(@"openFile: %@", filename);
|
2009-11-14 23:12:16 +01:00
|
|
|
|
|
|
|
return [self extractRarWith:filename];
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
|
|
|
|
// for (NSString * filename in filenames) {
|
|
|
|
// NSLog(@"openFiles: %@", filename);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // If we get passed files don't open the UI
|
|
|
|
// [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
|
|
|
//}
|
|
|
|
|
2009-11-14 23:12:16 +01:00
|
|
|
- (BOOL) extractRarWith:(NSString *) filename {
|
|
|
|
char commentBuffer[BUF_LEN];
|
|
|
|
BOOL extractionSuccessful = YES;
|
|
|
|
|
|
|
|
//Determine the folder we should extract the archive to. This by default
|
|
|
|
//is the <folderContainingTheArchive>/<archiveNameWithPathExtension>
|
|
|
|
NSString * defaultFolderToExtractTo = [filename stringByDeletingPathExtension];
|
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
char * filenameCString = (char *)[filename cStringUsingEncoding:NSISOLatin1StringEncoding];
|
2009-11-14 23:12:16 +01:00
|
|
|
|
|
|
|
// Open the Archive for extraction, we set the open result to 3 so we can see it has changed
|
2009-11-15 00:18:58 +01:00
|
|
|
struct RAROpenArchiveData arcData = { filenameCString, RAR_OM_EXTRACT, 3, &commentBuffer[0], BUF_LEN, 0, 0};
|
2009-11-14 23:12:16 +01:00
|
|
|
HANDLE archive = RAROpenArchive(&arcData);
|
2009-11-15 00:18:58 +01:00
|
|
|
NSLog(@"Opening Archive %s with result %d", filenameCString, arcData.OpenResult);
|
2009-11-14 23:12:16 +01:00
|
|
|
|
|
|
|
// set call backs for if password needed or need to change volume
|
2009-11-15 00:18:58 +01:00
|
|
|
RARSetChangeVolProc(archive, &changeVolume);
|
|
|
|
RARSetCallback(archive, &callbackFunction, 0);
|
2009-11-14 23:12:16 +01:00
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
//
|
|
|
|
struct RARHeaderData headerData;
|
2009-11-14 23:12:16 +01:00
|
|
|
while (RARReadHeader(archive, &headerData) != ERAR_END_ARCHIVE) {
|
|
|
|
NSLog(@"Attempting to extract %s to %@", headerData.FileName, defaultFolderToExtractTo);
|
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
int processResult = RARProcessFile(archive, RAR_EXTRACT, (char *) [defaultFolderToExtractTo cStringUsingEncoding:NSISOLatin1StringEncoding], NULL);
|
2009-11-14 23:12:16 +01:00
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
if (processResult != 0) {
|
|
|
|
NSLog(@"Process Result was %d", processResult);
|
2009-11-14 23:12:16 +01:00
|
|
|
extractionSuccessful = NO;
|
|
|
|
|
|
|
|
// DISPLAY ERROR DIALOG, ALERT THE USER
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NSLog(@"...Extracted");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-15 00:18:58 +01:00
|
|
|
int closeResult = RARCloseArchive(archive);
|
|
|
|
NSLog(@"Closing Archive %s with result %d", filenameCString, closeResult);
|
|
|
|
|
2009-11-14 23:12:16 +01:00
|
|
|
|
|
|
|
return extractionSuccessful;
|
|
|
|
}
|
|
|
|
|
2009-11-10 16:48:42 +01:00
|
|
|
@end
|