ObjFW  Diff

Differences From Artifact [e196e4c527]:

To Artifact [b277cdf39b]:


28
29
30
31
32
33
34

35
36
37
38
39
40
41
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+







#import "OFStdIOStream.h"

#import "OFArc.h"
#import "GZIPArchive.h"
#import "LHAArchive.h"
#import "TarArchive.h"
#import "ZIPArchive.h"
#import "ZooArchive.h"

#import "OFCreateDirectoryFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"
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
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







-
-
+
+









-
+







		[stream writeString: @"\n"];
		[stream writeLine: OF_LOCALIZED(@"full_usage",
		    @"Options:\n"
		    @"    -a  --append      Append to archive\n"
		    @"    -c  --create      Create archive\n"
		    @"    -C  --directory=  Extract into the specified "
		    @"directory\n"
		    @"    -E  --encoding=   The encoding used by the archive "
		    "(only tar and lha files)\n"
		    @"    -E  --encoding=   The encoding used by the archive\n"
		    @"                      (only tar, lha and zoo files)\n"
		    @"    -f  --force       Force / overwrite files\n"
		    @"    -h  --help        Show this help\n"
		    @"    -l  --list        List all files in the archive\n"
		    @"    -n  --no-clobber  Never overwrite files\n"
		    @"    -p  --print       Print one or more files from the "
		    @"archive\n"
		    @"    -q  --quiet       Quiet mode (no output, except "
		    @"errors)\n"
		    @"    -t  --type=       Archive type (gz, lha, tar, tgz, "
		    @"zip)\n"
		    @"zip, zoo)\n"
		    @"    -v  --verbose     Verbose output for file list\n"
		    @"    -x  --extract     Extract files")];
	}

	[OFApplication terminateWithStatus: status];
}

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
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







+
+

-
-
+
+

-
+

-
-
-
+
+
+
+

-
+

+
+







			    @"file", e.path,
			    @"error", error)];
			[OFApplication terminateWithStatus: 1];
		}
	}

	if (type == nil || [type isEqual: @"auto"]) {
		OFString *lowercasePath = path.lowercaseString;

		/* This one has to be first for obvious reasons */
		if ([path hasSuffix: @".tar.gz"] || [path hasSuffix: @".tgz"] ||
		    [path hasSuffix: @".TAR.GZ"] || [path hasSuffix: @".TGZ"])
		if ([lowercasePath hasSuffix: @".tar.gz"] ||
		    [lowercasePath hasSuffix: @".tgz"])
			type = @"tgz";
		else if ([path hasSuffix: @".gz"] || [path hasSuffix: @".GZ"])
		else if ([lowercasePath hasSuffix: @".gz"])
			type = @"gz";
		else if ([path hasSuffix: @".lha"] ||
		    [path hasSuffix: @".lzh"] || [path hasSuffix: @".lzs"] ||
		    [path hasSuffix: @".pma"])
		else if ([lowercasePath hasSuffix: @".lha"] ||
		    [lowercasePath hasSuffix: @".lzh"] ||
		    [lowercasePath hasSuffix: @".lzs"] ||
		    [lowercasePath hasSuffix: @".pma"])
			type = @"lha";
		else if ([path hasSuffix: @".tar"] || [path hasSuffix: @".TAR"])
		else if ([lowercasePath hasSuffix: @".tar"])
			type = @"tar";
		else if ([lowercasePath hasSuffix: @".zoo"])
			type = @"zoo";
		else
			type = @"zip";
	}

	@try {
		if ([type isEqual: @"gz"])
			archive = [GZIPArchive archiveWithPath: path
595
596
597
598
599
600
601





602
603
604
605
606
607
608
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619







+
+
+
+
+







			archive = [TarArchive archiveWithPath: path
						       stream: GZIPStream
							 mode: modeString
						     encoding: encoding];
		} else if ([type isEqual: @"zip"])
			archive = [ZIPArchive archiveWithPath: path
						       stream: file
							 mode: modeString
						     encoding: encoding];
		else if ([type isEqual: @"zoo"])
			archive = [ZooArchive archiveWithPath: path
						       stream: file
							 mode: modeString
						     encoding: encoding];
		else {
			[OFStdErr writeLine: OF_LOCALIZED(
			    @"unknown_archive_type",
			    @"Unknown archive type: %[type]",
			    @"type", type)];