1
#import <Foundation/Foundation.h>
4
#import "NSString+Custom.h"
5
#import "Preferences.h"
6
#import "NSArray+Custom.h"
8
@interface LhaArchive (PrivateAPI)
9
- (NSData *)dataByRunningLha;
12
@implementation LhaArchive : Archive
15
* register our supported file extensions with our superclass.
19
[self registerFileExtension:@"lha" forArchiveClass:self];
22
+ (NSString *)unarchiveExecutable
24
return [Preferences lhaExecutable];
28
* lha archives <em>do</em> contain info about compression ratio.
35
+ (NSString *)archiveType
40
//------------------------------------------------------------------------------
41
// expanding the archive
42
//------------------------------------------------------------------------------
43
- (int)expandFiles:(NSArray *)files withPathInfo:(BOOL)usePathInfo toPath:(NSString *)path
50
if (usePathInfo == NO)
52
argString = [argString stringByAppendingString:@"i"];
55
argString = [argString stringByAppendingString:@"w="];
56
argString = [argString stringByAppendingString:path];
58
args = [NSMutableArray array];
59
[args addObject:argString];
60
[args addObject:[self path]];
64
NSEnumerator *cursor = [files objectEnumerator];
65
while ((fileInfo = [cursor nextObject]) != nil)
67
[args addObject:[fileInfo fullPath]];
71
return [self runUnarchiverWithArguments:args];
74
- (NSArray *)listContents
79
NSMutableArray *results = [NSMutableArray array];
80
NSData *data = [self dataByRunningLha];
81
NSString *string = [[[NSString alloc] initWithData:data
82
encoding:NSASCIIStringEncoding] autorelease];
83
NSArray *lines = [string componentsSeparatedByString:@"\n"];
85
// take out first 2 lines (header) and last 2 lines (footer)
86
lines = [lines subarrayWithRange:NSMakeRange(2, [lines count] - 2)];
87
lines = [lines subarrayWithRange:NSMakeRange(0, [lines count] - 3)];
89
cursor = [lines objectEnumerator];
90
while ((line = [cursor nextObject]) != nil)
94
NSString *path, *ratio, *month, *day, *year, *dateString;
98
if ([line hasSuffix:@"/"])
100
// skip directory entries
104
components = [line componentsSeparatedByString:@" "];
105
components = [components arrayByRemovingEmptyStrings];
107
length = [[components objectAtIndex:3] intValue];
108
path = [components objectAtIndex:10];
109
ratio = [components objectAtIndex:4];
111
month = [components objectAtIndex:7];
112
day = [components objectAtIndex:8];
113
year = [components objectAtIndex:9];
114
dateString = [NSString stringWithFormat:@"%@ %@ %@", month, day, year];
115
date = [NSCalendarDate dateWithString:dateString calendarFormat:@"%b %d %Y"];
117
info = [FileInfo newWithPath:path date:date size:[NSNumber numberWithInt:length]
119
[results addObject:info];
125
//------------------------------------------------------------------------------
127
//------------------------------------------------------------------------------
128
- (NSData *)dataByRunningLha
131
NSArray *args = [NSArray arrayWithObjects:@"v", [self path], nil];
132
data = [self dataByRunningUnachiverWithArguments:args];
133
NSLog(@"dataByRunningLha: %@", data);