File: XADTest6.m

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (124 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download
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
#import "XADArchiveParser.h"
#import "NSStringPrinting.h"

NSMutableArray *reasons;
int failed=0;

@interface ArchiveTester:NSObject
{
}
@end

@implementation ArchiveTester

-(id)init
{
	if((self=[super init]))
	{
	}
	return self;
}

-(void)archiveParser:(XADArchiveParser *)parser
foundEntryWithDictionary:(NSDictionary *)dict
{
	NSNumber *dir=[dict objectForKey:XADIsDirectoryKey];
	CSHandle *fh=[parser handleForEntryWithDictionary:dict wantChecksum:YES];

	if(!dir||![dir boolValue])
	{
		if(!fh) failed++;
	}

	//[fh seekToEndOfFile];

	NSNumber *arch=[dict objectForKey:XADIsArchiveKey];
	if(arch&&[arch boolValue])
	{
		XADArchiveParser *parser=[XADArchiveParser archiveParserForHandle:fh
		name:[[dict objectForKey:XADFileNameKey] string]];

		[parser setDelegate:[[ArchiveTester new] autorelease]];
		[parser parse];
	}
}

-(void)archiveParser:(XADArchiveParser *)parser
findsFileInterestingForReason:(NSString *)reason
{
	[reasons addObject:reason];
}

-(BOOL)archiveParsingShouldStop:(XADArchiveParser *)parser
{
	return NO;
}

@end

int main(int argc,char **argv)
{
	int res=0;

	for(int i=1;i<argc;i++)
	{
		NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];

		NSString *filename=[NSString stringWithUTF8String:argv[i]];

		reasons=[NSMutableArray array];
		failed=0;

		NSString *exception=nil;
		@try {
			XADArchiveParser *parser=[XADArchiveParser archiveParserForPath:filename];

			[parser setDelegate:[[ArchiveTester new] autorelease]];

			char *pass=getenv("XADTestPassword");
			if(pass) [parser setPassword:[NSString stringWithUTF8String:pass]];

			[parser parse];
		} @catch(id e) {
			exception=[e description];
		}

		int count=[reasons count];
		if(count)
		{
			[[NSString stringWithFormat:
			@"The file \"%@\" was found to be interesting for the following %@:\n",
			filename,[reasons count]==1?@"reason":@"reasons"] print];

			for(int i=0;i<count;i++)
			{
				[[NSString stringWithFormat:@"* %@\n",
				[reasons objectAtIndex:i]] print];
			}

			res|=1;
		}

		if(failed)
		{
			[[NSString stringWithFormat:
			@"The file \"%@\" failed to extract %d %@\n",
			filename,failed,failed==1?@"entry":@"entries"] print];

			res|=2;
		}

		if(exception)
		{
			[[NSString stringWithFormat:
			@"The file \"%@\" threw exception \"%@\".\n",
			filename,exception] print];

			res|=2;
		}

		[pool release];
	}

	return res;
}