-
Notifications
You must be signed in to change notification settings - Fork 10
/
COImageLoader_temp.m
652 lines (594 loc) · 21.3 KB
/
COImageLoader_temp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
#import <HetimaUnZip/HetimaUnZip.h>
#import "XADWrapper.h"
#import "XADItem.h"
#import "Controller.h"
#import "COImageLoader.h"
@interface COImageLoader(private)
-(void)content;
-(BOOL)checkArchiveContainer:(int)index;
-(void)uncompressToTempDir:(NSString*)file;
//-(BOOL)uncompressAllFileToTempDir;
@end
@implementation COImageLoader
+(NSArray *)fileTypes
{
return [NSArray arrayWithObjects:@"zip",@"cbz",@"rar",@"cbr",@"lzh",@"lha",@"7z",@"sit",@"pdf",@"cvbdl",nil];
}
+(NSArray *)archiveTypes
{
return [NSArray arrayWithObjects:@"zip",@"cbz",@"rar",@"cbr",@"lzh",@"lha",@"7z",@"sit",nil];
}
- (NSString*)displayPath
{
return displayPath;
}
- (id)initWithPath:(NSString *)path displayPath:(NSString *)dispPath readSubFolder:(BOOL)boo controller:(id)ctr;
//- (id)initWithPath:(NSString *)path displayPath:(NSString *)dispPath readSubFolder:(BOOL)boo;
{
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) return nil;
self = [super init];
if (self) {
rightPassward = NO;
controller = ctr;
tempDir = nil;
inArchiveArray = [[NSMutableArray alloc] init];
//inArchiveNameDic = [[NSMutableDictionary alloc] init];
//nameEncoding=NSShiftJISStringEncoding;
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[COImageLoader fileTypes]];
[tempArray addObjectsFromArray:[NSImage imageFileTypes]];
filterArray = [[NSArray arrayWithArray:tempArray] retain];
readSubFolder=boo;
mode=-1;
password=nil;
filePath=[path retain];
displayPath = [dispPath retain];
archiveContainer = nil;
contentPathArray = [[NSMutableArray alloc] init];
contentPathDic = [[NSMutableDictionary alloc] init];
rawContentPathArray = [[NSMutableArray alloc] init];
pdfRep = nil;
[self content];
}
return self;
}
- (id)initWithPath:(NSString *)path readSubFolder:(BOOL)boo controller:(id)ctr;
//- (id)initWithPath:(NSString *)path readSubFolder:(BOOL)boo;
{
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) return nil;
self = [super init];
if (self) {
rightPassward = NO;
controller = ctr;
tempDir = nil;
inArchiveArray = [[NSMutableArray alloc] init];
//inArchiveNameDic = [[NSMutableDictionary alloc] init];
//nameEncoding=NSShiftJISStringEncoding;
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[COImageLoader fileTypes]];
[tempArray addObjectsFromArray:[NSImage imageFileTypes]];
filterArray = [[NSArray arrayWithArray:tempArray] retain];
readSubFolder=boo;
mode=-1;
password=nil;
filePath=[path retain];
displayPath = [path retain];
archiveContainer = nil;
contentPathArray = [[NSMutableArray alloc] init];
contentPathDic = [[NSMutableDictionary alloc] init];
rawContentPathArray = [[NSMutableArray alloc] init];
pdfRep = nil;
[self content];
}
return self;
}
- (void)dealloc
{
if(tempDir) {
[[NSFileManager defaultManager] removeFileAtPath:tempDir handler:nil];
[tempDir release];
}
if(rawContentPathArray)[rawContentPathArray release];
if(inArchiveArray)[inArchiveArray release];
if(filePath)[filePath release];
if(displayPath)[displayPath release];
if(password)[password release];
if(archiveContainer)[archiveContainer release];
if(contentPathArray)[contentPathArray release];
if(contentPathDic)[contentPathDic release];
if(filterArray)[filterArray release];
if(pdfRep)[pdfRep release];
//if(mode==4)CGPDFDocumentRelease(pdfDocument);
[super dealloc];
}
#pragma mark -
- (NSString *)filePath
{
return filePath;
}
- (int)itemCount
{
if(contentPathArray) return [contentPathArray count];
return 0;
}
- (int)mode
{
return mode;
}
- (NSString*)itemPathAtIndex:(int)index
{
if ([inArchiveArray count] > 0) {
NSString *fileName = [contentPathArray objectAtIndex:index];
int i;
for (i=0; i<[inArchiveArray count]; i++) {
COImageLoader *inLoader = [inArchiveArray objectAtIndex:i];
if ([[inLoader pathArray] indexOfObject:fileName] != NSNotFound) {
return [inLoader filePath];
}
}
}
if (mode==0 || mode==3) {
return [contentPathArray objectAtIndex:index];
} else {
return filePath;
}
}
- (NSString*)itemNameAtIndex:(int)index
{
return [contentPathArray objectAtIndex:index];
}
- (BOOL)canSortByDate
{
if ([inArchiveArray count]>0) {
return NO;
}
if (mode==0 || mode==3) {
return YES;
}
return NO;
}
- (NSString *)password
{
return password;
}
- (NSMutableArray*)pathArray
{
return contentPathArray;
}
#pragma mark -
- (id)itemAtIndex:(int)index
{
if ([inArchiveArray count] > 0) {
NSString *fileName = [contentPathArray objectAtIndex:index];
int i;
for (i=0; i<[inArchiveArray count]; i++) {
COImageLoader *inLoader = [inArchiveArray objectAtIndex:i];
if ([[inLoader pathArray] indexOfObject:fileName] != NSNotFound) {
return [inLoader itemAtIndex:[[inLoader pathArray] indexOfObject:fileName]];
}
}
}
if (mode==4) {
return [[[COPDFImage alloc] initWithPDFRep:pdfRep page:index] autorelease];
} else if(mode==1|mode==2) {
NSString *rawName = [contentPathDic objectForKey:[contentPathArray objectAtIndex:index]];
NSArray* items=[archiveContainer contents];
NSData* data;
if ([rawContentPathArray indexOfObject:rawName] != NSNotFound) {
data =[[items objectAtIndex:[rawContentPathArray indexOfObject:rawName]] data];
} else {
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
}
if(data && [data length]>0){
NSImage* image = [[[NSImage allocWithZone:NULL] initWithData:data] autorelease];
if (![image bestRepresentationForDevice:nil]) {
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
}
if(image && [image isValid]){
return image;
}
} else {
if (![self checkArchiveContainer:index]) {
}
items=[archiveContainer contents];
rawName = [contentPathDic objectForKey:[contentPathArray objectAtIndex:index]];
if ([rawContentPathArray indexOfObject:rawName] != NSNotFound) {
data =[[items objectAtIndex:[rawContentPathArray indexOfObject:rawName]] data];
} else {
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
}
if(data && [data length]>0){
NSImage *image = [[[NSImage allocWithZone:NULL] initWithData:data] autorelease];
if (![image bestRepresentationForDevice:nil]) {
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
}
if(image && [image isValid]){
return image;
}
}
}
} else {
NSImage *image;
image = [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[contentPathArray objectAtIndex:index]] autorelease];
//NSImage *image = [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[contentPathArray objectAtIndex:index]] autorelease];
if (![image bestRepresentationForDevice:nil]) {
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
}
if(image && [image isValid]){
return image;
}
}
return [[[NSImage allocWithZone:NULL] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"broken" ofType:@"png"]] autorelease];
return nil;
}
#pragma mark -
- (int)nextFolder:(int)now
{
int i = now-1;
//NSLog(@"next startAt %@",[contentPathArray objectAtIndex:now-1]);
NSString *currentFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
for (i+=1;i<[contentPathArray count];i++) {
NSString *nextFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
//NSLog(@"%@",[contentPathArray objectAtIndex:i]);
if (![currentFolder isEqualToString:nextFolder]) {
//NSLog(@"found1");
return i;
}
}
for (i=0;i<[contentPathArray count];i++) {
if (i==now-1) {
//NSLog(@"notFound");
return 0;
}
NSString *nextFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
//NSLog(@"%@",[contentPathArray objectAtIndex:i]);
if (![currentFolder isEqualToString:nextFolder]) {
//NSLog(@"found2");
return i;
}
}
return 0;
//NSLog(@"next end");
}
- (int)prevFolder:(int)now
{
//NSLog(@"prev startAt %@",[contentPathArray objectAtIndex:now-1]);
NSString *currentFolder = [[contentPathArray objectAtIndex:now-1] stringByDeletingLastPathComponent];
if (now-2>0 && [currentFolder isEqualToString:[[contentPathArray objectAtIndex:now-2] stringByDeletingLastPathComponent]]) {
//1つ前も同じフォルダだったらこのフォルダの先頭を検索
NSString *prevFolder;
int i = now-1;
for (i;i>=0;i--) {
if (i == 0) return 0;
prevFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
if (![currentFolder isEqualToString:prevFolder]) {
return i+1;
}
}
} else {
//1つ前が違うフォルダだったらそっちの先頭を検索
NSString *prevFolder,*prevFolderHead;
int i = now-1;
for (i;i>=0;i--) {
prevFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
//NSLog(@"%@ %i",[contentPathArray objectAtIndex:i],i);
if (![currentFolder isEqualToString:prevFolder]) {
int ii;
for (ii=i;ii>=0;ii--) {
if (ii == 0) return 0;
prevFolderHead = [[contentPathArray objectAtIndex:ii] stringByDeletingLastPathComponent];
//NSLog(@"%@",[contentPathArray objectAtIndex:ii]);
if (![prevFolder isEqualToString:prevFolderHead]) {
//NSLog(@"found1 %i",ii+1);
return ii+1;
}
}
}
}
i=[contentPathArray count]-1;
for (i;i>=0;i--) {
if (i==now) {
//NSLog(@"notFound");
return now-1;
}
prevFolder = [[contentPathArray objectAtIndex:i] stringByDeletingLastPathComponent];
//NSLog(@"%@",[contentPathArray objectAtIndex:i]);
if (![currentFolder isEqualToString:prevFolder]) {
int ii;
for (ii=i;ii>=0;ii--) {
if (ii == 0) return 0;
prevFolderHead = [[contentPathArray objectAtIndex:ii] stringByDeletingLastPathComponent];
if (![prevFolder isEqualToString:prevFolderHead]) {
//NSLog(@"found2 %i",ii+1);
return ii+1;
}
}
}
}
}
//NSLog(@"prev end");
return now-1;
}
#pragma mark -
- (BOOL)crypted
{
if (mode==1 || mode==2)
return [archiveContainer crypted];
return NO;
}
- (void)setPassword:(NSString *)inStr
{
if (mode==0 || mode==3) {
return;
}
if(password)[password release];
password=nil;
if(inStr){
password=[inStr retain];
[archiveContainer setPassword:password];
}
}
- (BOOL)checkPassword
{
if (rightPassward) return YES;
if (mode==0 || mode==3) return YES;
if (![self crypted]) return YES;
if ([self crypted] && password==nil) return NO;
id tempData = [[[archiveContainer contents] objectAtIndex:0] data];
//tempData = nil;
if (!tempData || [tempData length]<=0 || [[[archiveContainer contents] objectAtIndex:0] path]==nil) {
if(([[filePath pathExtension] compare:@"zip" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|| ([[filePath pathExtension] compare:@"cbz" options:NSCaseInsensitiveSearch] == NSOrderedSame)) {
HetimaUnZipContainer *tempArchiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:nil] retain];
if ([[[tempArchiveContainer contents] objectAtIndex:0] path] == nil) {
[tempArchiveContainer setEncoding:NSShiftJISStringEncoding];
NSTimeInterval start;
start=[NSDate timeIntervalSinceReferenceDate];
while ([[[tempArchiveContainer contents] objectAtIndex:0] path] == nil) {
if ([NSDate timeIntervalSinceReferenceDate]-start > 1.0) {
mode = -1;
return NO;
}
[tempArchiveContainer release];
tempArchiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:nil]retain];
}
}
[tempArchiveContainer setKeepData:NO];
[tempArchiveContainer setPassword:password];
tempData = [[[tempArchiveContainer contents] objectAtIndex:0] data];
if (!tempData || [tempData length]<=0) {
[tempArchiveContainer release];
} else {
[archiveContainer release];
archiveContainer = tempArchiveContainer;
mode = 1;
rightPassward = YES;
return YES;
}
}
} else {
rightPassward = YES;
return YES;
}
return NO;
}
- (BOOL)checkAndSetPassword:(NSString *)newPassword
{
[self setPassword:newPassword];
return [self checkPassword];
}
@end
@implementation COImageLoader(private)
- (void)content
{
NSMutableArray *pathArray = [NSMutableArray array];
if ([[filePath pathExtension] compare:@"pdf" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
mode=4;
pdfRep = [[COPDFImageRep imageRepWithContentsOfFile:filePath] retain];
int pages = [pdfRep pageCount];
int i;
for (i=0;pages>i;i++) {
[contentPathArray addObject:[NSString stringWithFormat:@"%@/%i.pdf",filePath,i+1]];
}
return;
} /*else if(([[filePath pathExtension] compare:@"zip" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|| ([[filePath pathExtension] compare:@"cbz" options:NSCaseInsensitiveSearch] == NSOrderedSame)) {
mode=1;
//archiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:filterArray]retain];
archiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:nil]retain];
[archiveContainer setKeepData:NO];
[self checkArchiveContainer:0];
return;
} */else if([[COImageLoader archiveTypes] containsObject:[[filePath pathExtension] lowercaseString]]) {
mode=2;
archiveContainer=[[XADWrapper alloc] initWithPath:filePath nameEncoding:NSShiftJISStringEncoding];
[self checkArchiveContainer:0];
return;
} else if([[filePath pathExtension] compare:@"savedSearch" options:NSCaseInsensitiveSearch] == NSOrderedSame){
mode=-1;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
if([NSObject respondsToSelector:@selector(finalize)]){
mode=3;
NSDictionary *doc = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSString *raw = [doc objectForKey:@"RawQuery"];
NSArray *scope = [[doc objectForKey:@"SearchCriteria"] objectForKey:@"FXScopeArrayOfPaths"];
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, (CFStringRef)raw, NULL, NULL);
MDQuerySetSearchScope (query,(CFArrayRef)scope,0);
MDQueryExecute(query, kMDQuerySynchronous);
CFIndex count = MDQueryGetResultCount(query);
int i;
NSMutableArray *temp = [NSMutableArray array];
for (i = 0; i < count; i++) {
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query,i);
CFStringRef itemPath = MDItemCopyAttribute(item,kMDItemPath);
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:((NSString *) itemPath) isDirectory:&isDir];
if (isDir && readSubFolder) {
NSArray *ar = [[NSFileManager defaultManager] subpathsAtPath:((NSString *) itemPath)];
int ii;
for (ii=0; ii<[ar count]; ii++) {
[temp addObject:[((NSString *) itemPath) stringByAppendingPathComponent:[ar objectAtIndex:ii]]];
}
} else {
[temp addObject:((NSString *) itemPath)];
}
CFRelease(itemPath);
}
CFRelease(query);
NSArray *completeArray;
completeArray = [temp pathsMatchingExtensions:filterArray];
NSEnumerator *enu=[completeArray objectEnumerator];
id path;
while (path = [enu nextObject]) {
if([[COImageLoader fileTypes] containsObject:[[path pathExtension] lowercaseString]]){
COImageLoader *inLoader = [[[COImageLoader alloc] initWithPath:path readSubFolder:NO controller:controller] autorelease];
[pathArray addObjectsFromArray:[inLoader pathArray]];
[inArchiveArray addObject:inLoader];
} else if (path) {
[pathArray addObject:path];
}
}
[contentPathArray addObjectsFromArray:pathArray];
}
#endif
} else {
mode=0;
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDir];
if (isDir) {
NSArray *completeArray;
if (readSubFolder) {
completeArray = [NSArray arrayWithArray:[[NSFileManager defaultManager] subpathsAtPath:filePath]];
} else {
completeArray = [NSArray arrayWithArray:[[NSFileManager defaultManager] directoryContentsAtPath:filePath]];
}
completeArray = [completeArray pathsMatchingExtensions:filterArray];
NSEnumerator *enu=[completeArray objectEnumerator];
id path;
while (path = [enu nextObject]) {
path = [filePath stringByAppendingPathComponent:path];
if([[COImageLoader fileTypes] containsObject:[[path pathExtension] lowercaseString]]){
COImageLoader *inLoader = [[[COImageLoader alloc] initWithPath:path readSubFolder:NO controller:controller] autorelease];
[pathArray addObjectsFromArray:[inLoader pathArray]];
[inArchiveArray addObject:inLoader];
} else if (path) {
[pathArray addObject:path];
}
}
[contentPathArray addObjectsFromArray:pathArray];
} else {
mode=-1;
}
}
[contentPathArray sortUsingSelector:@selector(finderCompareS:)];
}
- (BOOL)checkArchiveContainer:(int)index
{
if (![self checkPassword]) [controller askInArchivePassword:self]; //pass聞きに行く
if (![self checkPassword]) return NO; //諦めた
if (!rightPassward) {
id tempData = [[[archiveContainer contents] objectAtIndex:index] data];
//tempData = nil;
if (!tempData || [tempData length]<=0){
if(([[filePath pathExtension] compare:@"zip" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|| ([[filePath pathExtension] compare:@"cbz" options:NSCaseInsensitiveSearch] == NSOrderedSame)) {
NSLog(@"noPassArchive_useHetima");
HetimaUnZipContainer *tempArchiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:nil] retain];
if ([[[tempArchiveContainer contents] objectAtIndex:index] path] == nil) {
NSLog(@"noPassArchive_pathNil");
[tempArchiveContainer setEncoding:NSShiftJISStringEncoding];
NSTimeInterval start;
start=[NSDate timeIntervalSinceReferenceDate];
while ([[[tempArchiveContainer contents] objectAtIndex:index] path] == nil) {
NSLog(@"noPassArchive_loop");
if ([NSDate timeIntervalSinceReferenceDate]-start > 1.0) {
mode = -1;
return NO;
}
[tempArchiveContainer release];
tempArchiveContainer=[[HetimaUnZipContainer unZipContainerWithZipFile:filePath listOnlyRealFile:YES extensionFilter:nil]retain];
}
}
[tempArchiveContainer setKeepData:NO];
tempData = [[[tempArchiveContainer contents] objectAtIndex:0] data];
if (!tempData || [tempData length]<=0) {
NSLog(@"noPassArchive_nodata");
[tempArchiveContainer release];
} else {
NSLog(@"noPassArchive_hasdata");
[archiveContainer release];
archiveContainer = tempArchiveContainer;
mode = 1;
}
}
if (!tempData || [tempData length]<=0 || [[[archiveContainer contents] objectAtIndex:index] path]==nil) {
NSLog(@"noPassArchive_no");
mode = -1;
return NO;
}
}
}
[rawContentPathArray removeAllObjects];
[contentPathArray removeAllObjects];
[contentPathDic removeAllObjects];
NSMutableArray *pathArray = [NSMutableArray array];
NSArray *items=[archiveContainer contents];
NSEnumerator *enu = [items objectEnumerator];
id object;
while (object = [enu nextObject]) {
NSString *path = [object path];
if (path) {
[rawContentPathArray addObject:path];
if([[COImageLoader fileTypes] containsObject:[[path pathExtension] lowercaseString]]){
if ([self checkPassword]) {
[self uncompressToTempDir:path];
COImageLoader *inLoader = [[[COImageLoader alloc] initWithPath:[tempDir stringByAppendingPathComponent:path]
displayPath:[displayPath stringByAppendingPathComponent:path]
readSubFolder:NO
controller:controller] autorelease];
[pathArray addObjectsFromArray:[inLoader pathArray]];
[inArchiveArray addObject:inLoader];
}
} else {
NSString *inPath = [NSString stringWithFormat:@"%@/%@",displayPath,path];
[pathArray addObject:inPath];
[contentPathDic setObject:path forKey:inPath];
}
}
}
[contentPathArray addObjectsFromArray:[pathArray pathsMatchingExtensions:filterArray]];
[contentPathArray sortUsingSelector:@selector(finderCompareS:)];
//NSLog(@"%@",contentPathDic);
return YES;
}
- (void)createDir:(NSString*)dir
{
NSFileManager *manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:dir]) {
if (![manager fileExistsAtPath:[dir stringByDeletingLastPathComponent]]) {
[self createDir:[dir stringByDeletingLastPathComponent]];
}
[manager createDirectoryAtPath:dir attributes:nil];
}
}
- (void)uncompressToTempDir:(NSString*)fileName
{
if (!tempDir) {
const char *buffer = [[NSString stringWithFormat:@"%@/%@",NSTemporaryDirectory(),@"cooViewer.XXXXXX"] fileSystemRepresentation];
mkdtemp(buffer);
tempDir = [[NSString stringWithFormat:@"%s", buffer] retain];
}
NSArray* items=[archiveContainer contents];
NSData* data;
if ([rawContentPathArray indexOfObject:fileName] != NSNotFound) {
[self createDir:[[tempDir stringByAppendingPathComponent:fileName] stringByDeletingLastPathComponent]];
if (mode == 1) {
NSFileManager *manager = [NSFileManager defaultManager];
data =[[items objectAtIndex:[rawContentPathArray indexOfObject:fileName]] data];
BOOL temp = [manager createFileAtPath:[tempDir stringByAppendingPathComponent:fileName] contents:data attributes:nil];
} else if (mode == 2) {
BOOL temp = [archiveContainer uncompress:[rawContentPathArray indexOfObject:fileName] as:[tempDir stringByAppendingPathComponent:fileName]];
}
} else {
//NSLog(@"notFound");
}
}
@end