Develop and Download Open Source Software

Browse CVS Repository

Contents of /lupin/lupin/TarPlugin/PluginTest.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Wed Jul 13 05:10:46 2005 UTC (18 years, 9 months ago) by letter
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +129 -50 lines
buildarchiveinfodict is changed to return infodict

1 /*
2 * Copyright (c) 2004-2005 The Lupin Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
8 * and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
11 * conditions and the following disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE LUPIN PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LUPIN PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21 * POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #import "PluginTest.h"
25
26
27 @implementation TarPlugin
28
29 + (id)alloc {
30 return [super alloc];
31 }
32
33 - (void)dealloc
34 {
35 if (filePath)
36 [filePath release];
37 [super dealloc];
38 }
39
40 - (NSArray*)acceptableExtensions
41 {
42 return [NSArray arrayWithObjects:@".tar",@".tgz",@".tbz",@".tar.gz",@".tar.z",@".tar.bz2",nil];
43 }
44
45 - (id)initWithFile:(NSString*)path
46 {
47 self = [super init];
48 NSString* extension = [path pathExtension];
49 if ([extension caseInsensitiveCompare:@"tar"] == NSOrderedSame) {
50 _compressed = NO;
51 _bz2Compressed = NO;
52 } else if ([extension caseInsensitiveCompare:@"bz2"] == NSOrderedSame ||
53 [extension caseInsensitiveCompare:@"tbz"] == NSOrderedSame) {
54 _compressed = YES;
55 _bz2Compressed = YES;
56 } else {
57 _compressed = YES;
58 _bz2Compressed = NO;
59 }
60 filePath = [NSString stringWithString:path];
61 [filePath retain];
62 _totalFileCount = _totalInArchiveFileCount = 0;
63 return self;
64 }
65
66 #pragma mark Plugin Information
67
68 - (NSString*)pluginName {
69 return [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"PluginName" value:@"Untitled Plugin" table:nil];
70 }
71 - (NSString*)pluginAuthorName {
72 return [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"PluginAuthor" value:@"Unnamed Person" table:nil];
73 }
74
75 - (NSString*)pluginVersion {
76 return [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"PluginVersion" value:@"ver.?" table:nil];
77 }
78
79 - (NSString*)pluginURI {
80 return [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"PluginURI" value:@"" table:nil];
81 }
82 - (NSString*)pluginEmail {
83 return [[NSBundle bundleForClass:[self class]] localizedStringForKey:@"PluginEmail" value:@"" table:nil];
84 }
85
86 - (NSAttributedString*)pluginCopyright {
87 NSURL *url = [NSURL fileURLWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"index" ofType:@"html"]];
88 NSData *data = [NSData dataWithContentsOfURL: url ];
89 return [[NSAttributedString alloc] initWithHTML: data baseURL: url documentAttributes: (NSDictionary **) NULL];
90 }
91
92 #pragma mark Archive Managing
93
94 - (LPFile*)buildArchiveInfoDict:(BOOL)hierarchy password:(NSString*)password
95 {
96 if (!filePath) {
97 return NULL;
98 }
99 NSTask* pluginTask = [[[NSTask alloc] init] autorelease];
100 NSPipe* stdoutPipe = [NSPipe pipe];
101 NSPipe* stderrPipe = [NSPipe pipe];
102 //���������������������������������������������������������������������������������������������
103 NSString* curPath = [filePath stringByDeletingLastPathComponent];
104
105 // ������(���������)���������������
106 [pluginTask setStandardOutput:stdoutPipe];
107 [pluginTask setStandardError:stderrPipe];
108
109 // ������
110 [pluginTask setLaunchPath:@"/usr/bin/tar"];
111 [pluginTask setCurrentDirectoryPath:curPath];
112 NSString* argument = _compressed ? _bz2Compressed ? @"-jtvf" : @"-ztvf" : @"-tvf";
113 [pluginTask setArguments:[NSArray arrayWithObjects:argument,filePath,nil]];
114
115 [pluginTask launch];
116
117 // ���������������������������
118 NSMutableData* data = [NSMutableData data];
119 NSData* outData,*errData;
120 while (((outData = [[stdoutPipe fileHandleForReading] availableData]) && [outData length]) ||
121 ((errData = [[stderrPipe fileHandleForReading] availableData]) && [errData length])) {
122 if ([outData length])
123 [data appendData:outData];
124 }
125 [pluginTask waitUntilExit];
126 if ([pluginTask terminationStatus] != 0) {
127 NSLog(@"buildArchiveInfoDict:Error#%d",[pluginTask terminationStatus]);
128 return NULL;
129 }
130 NSString* string = [self ascii2String:(const char*)[data bytes] length:[data length]];
131 NSArray* array = [string componentsSeparatedByString:@"\n"];
132
133 LPFile* root = [[[LPFile alloc] init] autorelease];
134 NSString* parsedString;
135 BOOL isDir;
136 unsigned int numOfChildren = 0;
137 unsigned long long totalSize = 0;
138
139 NSEnumerator* enumerator = [array objectEnumerator];
140
141 int timeLag = [[NSTimeZone localTimeZone] secondsFromGMT] / 60;
142 BOOL timeLagPN = NO;
143 if (timeLag < 0) {
144 timeLag = - timeLag;
145 timeLagPN = YES;
146 }
147 timeLag = (int)timeLag*5/3 + (timeLag % 60);
148 if (timeLagPN) timeLag = - timeLag;
149
150 while (parsedString = [enumerator nextObject]) {
151 if ([parsedString length] <= 1) break;
152 NSArray* infoArray = [parsedString componentsSeparatedByString:@" "];
153 int i;
154 isDir = [[infoArray objectAtIndex:0] hasPrefix:@"d"];
155 for (i=2;i<[infoArray count]-3;i++)
156 if ([(NSString*)[infoArray objectAtIndex:i] length] != 0) break;
157 if (i > [infoArray count]-3) break;
158 int fileSize = [[infoArray objectAtIndex:i] intValue];
159 totalSize += fileSize;
160 NSNumber* size = [NSNumber numberWithInt:fileSize];
161 NSDate* date = [NSDate dateWithString:[NSString stringWithFormat:@"%@ %@ %+.4d",[infoArray objectAtIndex:i+1],[infoArray objectAtIndex:i+2],timeLag]];
162 NSMutableString* path = [NSMutableString stringWithString:[infoArray objectAtIndex:i+3]];
163 for (i+=4;i<[infoArray count];i++) {
164 [path appendString:@" "];
165 [path appendString:[infoArray objectAtIndex:i]];
166 }
167 [root appendFile:[[LPFile alloc] init:path name:nil modifiedDate:date createdDate:nil size:size kind:nil isDir:isDir] hierarchy:hierarchy];
168 numOfChildren++;
169 _totalInArchiveFileCount++;
170 }
171
172 [root setTotalNumOfChildren:[NSNumber numberWithUnsignedInt:numOfChildren]];
173 [root setTotalSize:[NSNumber numberWithUnsignedLongLong:totalSize]];
174 return root;
175 }
176
177 //������path������������
178 - (BOOL)archiveAllUncompress:(NSString*)path exclude:(NSArray*)exclude password:(NSString*)password delegate:(id)delegate selector:(SEL)selector
179 {
180 _receiver = delegate;
181 _selector = selector;
182
183 if (!filePath) {
184 objc_msgSend(delegate, selector, LPErrorBadArgument);
185 return NO;
186 }
187
188 _stdoutArray = [[NSMutableArray array] retain];
189 _stderrArray = [[NSMutableArray array] retain];
190 _totalFileCount = _totalInArchiveFileCount;
191 if (_totalFileCount == 0) {
192 _totalFileCount = [self containFilesCount];
193 }
194
195 _pluginTask = [[NSTask alloc] init];
196
197 // ������������������������������
198 [_pluginTask setStandardOutput:[NSPipe pipe]];
199 _pluginStdoutHandle = [[[_pluginTask standardOutput] fileHandleForReading] retain];
200 [_pluginTask setStandardError:[NSPipe pipe]];
201 _pluginStderrHandle = [[[_pluginTask standardError] fileHandleForReading] retain];
202
203 [[NSNotificationCenter defaultCenter] addObserver: self
204 selector: @selector(readPipe:)
205 name: NSFileHandleReadCompletionNotification
206 object: _pluginStdoutHandle];
207 [[NSNotificationCenter defaultCenter] addObserver: self
208 selector: @selector(readPipe:)
209 name: NSFileHandleReadCompletionNotification
210 object: _pluginStderrHandle];
211 [[NSNotificationCenter defaultCenter] addObserver:self
212 selector:@selector(terminateTask:)
213 name:NSTaskDidTerminateNotification
214 object:_pluginTask];
215 [_pluginStdoutHandle readInBackgroundAndNotify];
216 [_pluginStderrHandle readInBackgroundAndNotify];
217
218 _stdoutEmpty = _stderrEmpty = _terminatedTask = NO;
219
220 //������������������������������������
221 NSString* curPath = [NSString stringWithString:path];
222 // ������
223 [_pluginTask setLaunchPath:@"/usr/bin/tar"];
224 [_pluginTask setCurrentDirectoryPath:curPath];
225 NSString* argument = _compressed ? _bz2Compressed ? @"-jxvf" : @"-zxvf" : @"-xvf";
226 NSMutableArray* extractArray = [NSMutableArray array];
227 if (exclude) {
228 NSEnumerator* enumerator = [exclude objectEnumerator];
229 NSString* excludePath;
230 while (excludePath = [enumerator nextObject]) {
231 [extractArray addObject:@"--exclude"];
232 [extractArray addObject:excludePath];
233 }
234 }
235 [extractArray addObject:argument];
236 [extractArray addObject:filePath];
237 [_pluginTask setArguments:extractArray];
238 _processMode = 2; //!���������������������������
239
240 [_pluginTask launch];
241 return YES;
242 }
243
244 //������path������������
245 - (BOOL)archiveUncompress:(NSString*)path files:(NSArray*)files password:(NSString*)password delegate:(id)delegate selector:(SEL)selector
246 {
247 _receiver = delegate;
248 _selector = selector;
249
250 if (!filePath) {
251 objc_msgSend(delegate, selector, LPErrorBadArgument);
252 return NO;
253 }
254
255 _stdoutArray = [[NSMutableArray array] retain];
256 _stderrArray = [[NSMutableArray array] retain];
257 _totalFileCount = 0;
258 NSEnumerator* enumerator = [files objectEnumerator];
259 LPFile* file;
260 while (file = [enumerator nextObject]) {
261 if ([file isDir])
262 _totalFileCount += [[file totalNumOfChildren] intValue];
263 else
264 _totalFileCount++;
265 }
266
267 _pluginTask = [[NSTask alloc] init];
268
269 // ������������������������������
270 [_pluginTask setStandardOutput:[NSPipe pipe]];
271 _pluginStdoutHandle = [[[_pluginTask standardOutput] fileHandleForReading] retain];
272 [_pluginTask setStandardError:[NSPipe pipe]];
273 _pluginStderrHandle = [[[_pluginTask standardError] fileHandleForReading] retain];
274
275 [[NSNotificationCenter defaultCenter] addObserver: self
276 selector: @selector(readPipe:)
277 name: NSFileHandleReadCompletionNotification
278 object: _pluginStdoutHandle];
279 [[NSNotificationCenter defaultCenter] addObserver: self
280 selector: @selector(readPipe:)
281 name: NSFileHandleReadCompletionNotification
282 object: _pluginStderrHandle];
283 [[NSNotificationCenter defaultCenter] addObserver:self
284 selector:@selector(terminateTask:)
285 name:NSTaskDidTerminateNotification
286 object:_pluginTask];
287 [_pluginStdoutHandle readInBackgroundAndNotify];
288 [_pluginStderrHandle readInBackgroundAndNotify];
289
290 _stdoutEmpty = _stderrEmpty = _terminatedTask = NO;
291
292 //������������������������������������������������������������������������
293 NSString* curPath = [NSString stringWithString:path];
294 // ������
295 [_pluginTask setLaunchPath:@"/usr/bin/tar"];
296 // ������������������������������������������
297 [_pluginTask setCurrentDirectoryPath:curPath];
298 NSString* argument = _compressed ? _bz2Compressed ? @"-jxvf" : @"-zxvf" : @"-xvf";
299 NSMutableArray* extractArray = [NSMutableArray arrayWithObjects:argument,filePath,nil];
300
301 enumerator = [files objectEnumerator];
302 while (file = [enumerator nextObject]) {
303 [extractArray addObject:[file path]];
304 }
305
306 [_pluginTask setArguments:extractArray]; //!������������������������������
307 _processMode = 2; //!������������������������
308
309 [_pluginTask launch];
310 return YES;
311 }
312
313 - (NSMutableData*)archiveUncompressToMemory:(LPFile*)file password:(NSString*)password
314 {
315 NSTask* pluginTask = [[[NSTask alloc] init] autorelease];
316 NSPipe* pluginPipe = [NSPipe pipe];
317
318 // ������������������������������
319 [pluginTask setStandardOutput:pluginPipe];
320 //[pluginTask setStandardError:pluginPipe];
321
322 //���������������������������������������������������������������������������������������������
323 NSString* curPath = [filePath stringByDeletingLastPathComponent];
324 // ������
325 [pluginTask setLaunchPath:@"/usr/bin/tar"];
326 [pluginTask setCurrentDirectoryPath:curPath];
327 NSString* argument = _compressed ? _bz2Compressed ? @"jxvfO" : @"zxvfO" : @"xvfO";
328 [pluginTask setArguments:[NSArray arrayWithObjects:argument,filePath,[file path],nil]];
329
330 [pluginTask launch];
331 //[pluginTask waitUntilExit];
332 NSMutableData* data = [NSMutableData data];
333 NSData* inData;
334 while ((inData = [[pluginPipe fileHandleForReading] availableData]) && [inData length]) {
335 [data appendData:inData];
336 }
337
338 return data;
339 }
340
341 - (BOOL)archiveCompress:(NSString*)path files:(NSArray*)files exclude:(NSArray*)exclude currentPath:(NSString*)currentPath compress:(LPCompress*)compress option:(NSDictionary*)option delegate:(id)delegate selector:(SEL)selector;
342 {
343 _receiver = delegate;
344 _selector = selector;
345
346 if (!filePath) {
347 objc_msgSend(delegate, selector, LPErrorBadArgument);
348 return NO;
349 }
350
351 _stdoutArray = [[NSMutableArray array] retain];
352 _stderrArray = [[NSMutableArray array] retain];
353 _totalFileCount = 0;
354 NSEnumerator* enumerator = [files objectEnumerator];
355 NSFileManager* manager = [NSFileManager defaultManager];
356 NSString* directoryPath;
357 while (directoryPath = [enumerator nextObject]) {
358 _totalFileCount += [[manager subpathsAtPath:[NSString stringWithFormat:@"%@/%@",currentPath,directoryPath]] count];
359 }
360
361 _pluginTask = [[NSTask alloc] init];
362
363 // ������������������������������
364 [_pluginTask setStandardOutput:[NSPipe pipe]];
365 _pluginStdoutHandle = [[[_pluginTask standardOutput] fileHandleForReading] retain];
366 [_pluginTask setStandardError:[NSPipe pipe]];
367 _pluginStderrHandle = [[[_pluginTask standardError] fileHandleForReading] retain];
368
369 [[NSNotificationCenter defaultCenter] addObserver: self
370 selector: @selector(readPipe:)
371 name: NSFileHandleReadCompletionNotification
372 object: _pluginStdoutHandle];
373 [[NSNotificationCenter defaultCenter] addObserver: self
374 selector: @selector(readPipe:)
375 name: NSFileHandleReadCompletionNotification
376 object: _pluginStderrHandle];
377 [[NSNotificationCenter defaultCenter] addObserver:self
378 selector:@selector(terminateTask:)
379 name:NSTaskDidTerminateNotification
380 object:_pluginTask];
381 [_pluginStdoutHandle readInBackgroundAndNotify];
382 [_pluginStderrHandle readInBackgroundAndNotify];
383
384 _stdoutEmpty = _stderrEmpty = _terminatedTask = NO;
385
386 //���������������������������������������������������������������������������������������
387 NSString* curPath = [NSString stringWithString:currentPath];
388 // ������
389 [_pluginTask setLaunchPath:@"/usr/bin/tar"];
390 // ������������������������������������������
391 [_pluginTask setCurrentDirectoryPath:curPath];
392 NSString* argument = _compressed ? _bz2Compressed ? @"-jcvf" : @"-zcvf" : @"-cvf";
393 NSMutableArray* compressArray = [NSMutableArray array];
394 if (exclude) {
395 NSEnumerator* enumerator = [exclude objectEnumerator];
396 NSString* excludePath;
397 while (excludePath = [enumerator nextObject]) {
398 [compressArray addObject:@"--exclude"];
399 [compressArray addObject:excludePath];
400 }
401 }
402 [compressArray addObject:argument];
403 [compressArray addObject:filePath];
404 [compressArray addObjectsFromArray:files];
405
406 [_pluginTask setArguments:compressArray]; //!������������������������������
407 _processMode = 3; //!���������������������������
408
409 [_pluginTask launch];
410 return YES;
411 }
412
413 //! ���������������������������������������������������������������
414 - (int)containFilesCount
415 {
416 NSTask* pluginTask = [[[NSTask alloc] init] autorelease];
417 NSPipe* pluginPipe = [NSPipe pipe];
418
419 // ������������������������������
420 [pluginTask setStandardOutput:pluginPipe];
421 //[pluginTask setStandardError:pluginPipe];
422
423 //���������������������������������������������������������������������������������������������
424 NSString* curPath = [filePath stringByDeletingLastPathComponent];
425 // ������
426 [pluginTask setLaunchPath:@"/usr/bin/tar"];
427 [pluginTask setCurrentDirectoryPath:curPath];
428 NSString* argument = _compressed ? _bz2Compressed ? @"-jtf" : @"-ztf" : @"-tf";
429 [pluginTask setArguments:[NSArray arrayWithObjects:argument,filePath,nil]];
430
431 [pluginTask launch];
432 //[pluginTask waitUntilExit];
433 NSMutableData* data = [NSMutableData data];
434 NSData* inData;
435 while ((inData = [[pluginPipe fileHandleForReading] availableData]) && [inData length]) {
436 [data appendData:inData];
437 }
438 //NSData* data = [[pluginPipe fileHandleForReading] availableData];
439 NSString* string = [self ascii2String:(const char*)[data bytes] length:[data length]];
440 NSArray* array = [string componentsSeparatedByString:@"\n"];
441 return [array count]-1;
442 }
443
444 //������������������������������������������������������������
445 - (void)readPipe:(NSNotification*)notification
446 {
447 //NSLog(@"readPipe");
448 BOOL stdoutPhase = [[notification object] isEqualTo:_pluginStdoutHandle];
449 NSData* receiveData = [[notification userInfo] objectForKey: NSFileHandleNotificationDataItem];
450 NSMutableData *data = [NSMutableData data];;
451 if (!_stdoutRestData) _stdoutRestData = [[NSMutableData data] retain];
452 if (!_stderrRestData) _stderrRestData = [[NSMutableData data] retain];
453 if (stdoutPhase && [_stdoutRestData length]) {
454 [data appendData:_stdoutRestData];
455 [data appendData:receiveData];
456 [_stdoutRestData setLength:0];
457 } else if ((!stdoutPhase) && [_stderrRestData length]) {
458 [data appendData:_stderrRestData];
459 [data appendData:receiveData];
460 [_stderrRestData setLength:0];
461 } else {
462 [data setData:receiveData];
463 }
464 NSString* string;
465 if ([data length]) {
466 if (string = [self ascii2String:(const char*)[data bytes] length:[data length]]) {
467 NSMutableArray* array = [NSMutableArray arrayWithArray:[string componentsSeparatedByString:@"\n"]];
468 NSMutableArray* printoutArray = stdoutPhase ? _stdoutArray : _stderrArray;
469 if ([printoutArray count] > 0) {
470 if ([(NSString*)[printoutArray lastObject] length] != 0) { //! ������������������������������������������������
471 NSString* jointString = [[printoutArray lastObject] stringByAppendingString:[array objectAtIndex:0]];
472 [array replaceObjectAtIndex:0 withObject:jointString];
473 }
474 [printoutArray removeLastObject];
475 }
476 [printoutArray addObjectsFromArray:array];
477 } else {
478 if (stdoutPhase) {
479 [_stdoutRestData setData:data];
480 } else {
481 [_stderrRestData setData:data];
482 }
483 }
484 if (stdoutPhase) {
485 _stdoutEmpty = NO;
486 } else {
487 _stderrEmpty = NO;
488 }
489 //���������������������������������������������������������������������������������������������������������������������������������
490 [[notification object] readInBackgroundAndNotify];
491 } else {
492 NSLog(@"Data length=0!");
493 if (stdoutPhase) {
494 _stdoutEmpty = YES;
495 if (_processMode != 4) {
496 [_stdoutRestData release];
497 _stdoutRestData = NULL;
498 }
499 } else {
500 _stderrEmpty = YES;
501 [_stderrRestData release];
502 _stderrRestData = NULL;
503 }
504 if (_stdoutEmpty && _stderrEmpty && _terminatedTask)
505 [self stopTask];
506 }
507 }
508 - (void)terminateTask:(NSNotification*)notification
509 {
510 NSLog(@"terminateTask");
511 _terminatedTask = YES;
512 if(_stdoutEmpty && _stderrEmpty){
513 [self stopTask];
514 }
515 }
516
517 - (void)stopTask
518 {
519 NSLog(@"stopTask");
520 int error = [_pluginTask terminationStatus];
521 [[NSNotificationCenter defaultCenter] removeObserver:self];
522
523 [_pluginTask release];
524 [_pluginStdoutHandle release];
525 [_pluginStderrHandle release];
526
527 if (_processMode == 1) { //! ���������������������
528 if (error != 0) {
529 objc_msgSend(_receiver, _selector, NULL, LPErrorUnknown);
530 } else {
531 LPFile* root = [[[LPFile alloc] init] autorelease];
532
533 int timeLag = [[NSTimeZone localTimeZone] secondsFromGMT] / 60;
534 BOOL timeLagPN = NO;
535 if (timeLag < 0) {
536 timeLag = - timeLag;
537 timeLagPN = YES;
538 }
539 timeLag = (int)timeLag*5/3 + (timeLag % 60);
540 if (timeLagPN) timeLag = - timeLag;
541
542 BOOL isDir;
543 unsigned int numOfChildren = 0;
544 unsigned long long totalSize = 0;
545 NSString* parsedString;
546 NSEnumerator* enumerator = [_stdoutArray objectEnumerator];
547 _totalFileCount = 0; //! ���������������������
548
549 while (parsedString = [enumerator nextObject]) {
550 if ([parsedString length] <= 1) break;
551 NSArray* infoArray = [parsedString componentsSeparatedByString:@" "];
552 int i;
553 isDir = [[infoArray objectAtIndex:0] hasPrefix:@"d"];
554 for (i=2;i<[infoArray count]-3;i++)
555 if ([(NSString*)[infoArray objectAtIndex:i] length] != 0) break;
556 if (i > [infoArray count]-3) break;
557 int fileSize = [[infoArray objectAtIndex:i] intValue];
558 totalSize += fileSize;
559 NSNumber* size = [NSNumber numberWithInt:fileSize];
560 NSDate* date = [NSDate dateWithString:[NSString stringWithFormat:@"%@ %@ %+.4d",[infoArray objectAtIndex:i+1],[infoArray objectAtIndex:i+2],timeLag]];
561 NSMutableString* path = [NSMutableString stringWithString:[infoArray objectAtIndex:i+3]];
562 for (i+=4;i<[infoArray count];i++) {
563 [path appendString:@" "];
564 [path appendString:[infoArray objectAtIndex:i]];
565 }
566 [root appendFile:[[LPFile alloc] init:path name:nil modifiedDate:date createdDate:nil size:size kind:nil isDir:isDir] hierarchy:_hierarchy];
567 numOfChildren++;
568 _totalInArchiveFileCount++;
569 }
570
571 [root setTotalNumOfChildren:[NSNumber numberWithUnsignedInt:numOfChildren]];
572 [root setTotalSize:[NSNumber numberWithUnsignedLongLong:totalSize]];
573 objc_msgSend(_receiver, _selector, root, LPErrorNoError);
574 }
575 } else if (_processMode == 2) {
576 if (error == 0) //! error���switch���������������LPError������������������
577 objc_msgSend(_receiver, _selector, 0);
578 else
579 objc_msgSend(_receiver, _selector, LPErrorUnknown);
580 } else if (_processMode == 3) {
581 if (error == 0) //! error���switch���������������LPError������������������
582 objc_msgSend(_receiver, _selector, 0);
583 else
584 objc_msgSend(_receiver, _selector, LPErrorUnknown);
585 }
586 [_stdoutArray release];
587 [_stderrArray release];
588 }
589
590 - (NSString*)ascii2String:(const char*)encodeData length:(int)length
591 {
592 char* decodeData = (char*)malloc(length*sizeof(char*));
593 int encodeIndex = 0;
594 int decodeIndex = 0;
595 while(encodeIndex<length)
596 {
597 if (encodeData[encodeIndex] == 0x5c)
598 {
599 if (encodeIndex+3>=length) {
600 free(decodeData);
601 return NULL;
602 }
603 decodeData[decodeIndex] = ((encodeData[encodeIndex+1]-'0')<<6)+((encodeData[encodeIndex+2]-'0')<<3)+(encodeData[encodeIndex+3]-'0');
604 encodeIndex+=4;
605 decodeIndex++;
606 } else {
607 decodeData[decodeIndex] = encodeData[encodeIndex];
608 encodeIndex++;
609 decodeIndex++;
610 }
611 }
612 decodeData[decodeIndex] = 0;
613 NSString* string = [NSString stringWithUTF8String:decodeData];
614 free(decodeData);
615 return string;
616 }
617
618 - (BOOL)pauseProcess
619 {
620 return NO;
621 }
622
623 - (BOOL)continueProcess
624 {
625 return NO;
626 }
627
628 - (BOOL)stopProcess
629 {
630 return NO;
631 }
632
633 #pragma mark Process Information
634 /*!
635 return whether plugin can get progress of process.
636 */
637 - (BOOL)isProgressTraversable
638 {
639 return YES;
640 }
641
642 - (NSNumber*)processInfo:(NSString**)title
643 {
644 //title���������������������������������������������������������������������������������������������������������������
645 NSLog(@"processInfo");
646 if (!_pluginTask) return nil;
647 if ([_pluginTask isRunning] && _stdoutArray) {
648 if ([_stdoutArray count] > 1) {
649 //NSLog(@"title=%@,percent=%d/%d",[_stdoutArray objectAtIndex:[_stdoutArray count]-2],[_stdoutArray count]-1,_totalFileCount);
650 *title = [NSString stringWithString:[_stdoutArray objectAtIndex:[_stdoutArray count]-2]];
651 return [NSNumber numberWithFloat:100*([_stdoutArray count]-1)/_totalFileCount];
652 } else {
653 return nil;
654 }
655 } else {
656 return [NSNumber numberWithInt:100];
657 }
658 }
659
660 #pragma mark Compress Information
661 - (NSArray*)compressInfo:(int)index
662 {
663 LPCompress* tarCompress = [[[LPCompress alloc] init:@"Tar Compress" extension:@"tar" hasOptionView:NO index:index] autorelease];
664 LPCompress* tgzCompress = [[[LPCompress alloc] init:@"Tar+gz Compress" extension:@"tgz" hasOptionView:NO index:index] autorelease];
665 return [NSArray arrayWithObjects:tarCompress,tgzCompress,nil];
666 }
667
668 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26