Skip to content

Commit 9963783

Browse files
committed
Fixes to CLI
- return 0 for success in dump mode - print progress of unzip mode - print progress of zip mode - fix execution description of zip mode - fix single file zipping in zip mode
1 parent 005f03c commit 9963783

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

ZipUtilities.xcodeproj/xcshareddata/xcschemes/noz -Release.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@
6161
ReferencedContainer = "container:ZipUtilities.xcodeproj">
6262
</BuildableReference>
6363
</BuildableProductRunnable>
64+
<CommandLineArguments>
65+
<CommandLineArgument
66+
argument = "-z -o /Users/nobrien/Doxygen.zip -i /Applications/Doxygen.app -m Brotli -l 12"
67+
isEnabled = "NO">
68+
</CommandLineArgument>
69+
<CommandLineArgument
70+
argument = "-z -o /Users/nobrien/Desktop/Doxygen.app.tar.zip -i /Users/nobrien/Desktop/Doxygen.app.tar -m Brotli -l 12"
71+
isEnabled = "NO">
72+
</CommandLineArgument>
73+
</CommandLineArguments>
6474
<AdditionalOptions>
6575
</AdditionalOptions>
6676
</LaunchAction>

ZipUtilities.xcodeproj/xcshareddata/xcschemes/noz.xcscheme

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@
6666
argument = "-A"
6767
isEnabled = "NO">
6868
</CommandLineArgument>
69+
<CommandLineArgument
70+
argument = "-z -i -m Brotli -l 12 /Applications/Doxygen.app -o /Users/nobrien/Doxygen.zip"
71+
isEnabled = "NO">
72+
</CommandLineArgument>
73+
<CommandLineArgument
74+
argument = "-z -o /Users/nobrien/Doxygen.zip -i -m Brotli -l 12 /Applications/Doxygen.app"
75+
isEnabled = "NO">
76+
</CommandLineArgument>
77+
<CommandLineArgument
78+
argument = "-z -o /Users/nobrien/Doxygen.zip -i /Applications/Doxygen.app -m Brotli -l 12"
79+
isEnabled = "NO">
80+
</CommandLineArgument>
81+
<CommandLineArgument
82+
argument = "-z -o /Users/nobrien/Desktop/Doxygen.app.tar.zip -i /Users/nobrien/Desktop/Doxygen.app.tar -m Brotli -l 12"
83+
isEnabled = "NO">
84+
</CommandLineArgument>
6985
<CommandLineArgument
7086
argument = "-D -L -i ~/Desktop/Maniac\ Mansion/Maniac_Mansion.zip"
7187
isEnabled = "NO">
@@ -76,7 +92,7 @@
7692
</CommandLineArgument>
7793
<CommandLineArgument
7894
argument = "-u"
79-
isEnabled = "YES">
95+
isEnabled = "NO">
8096
</CommandLineArgument>
8197
<CommandLineArgument
8298
argument = "-z -M Brotli 101 -c &quot;Encoded (101) using Brotli&quot; -o ~/Desktop/XC9.zip -i /Applications/Xcode_9_GM.app -m Brotli -l 10 "

noz/NOZCLIDumpMode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ + (int)run:(NOZCLIDumpModeInfo *)info
124124
}];
125125
}
126126

127-
return 1;
127+
return 0;
128128
}
129129

130130
+ (void)dumpCentralDirectory:(NOZCentralDirectory *)centralDirectory info:(NOZCLIDumpModeInfo *)info

noz/NOZCLIUnzipMode.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,19 @@ + (int)run:(NOZCLIUnzipModeInfo *)info
201201
[op start]; // will run synchronously
202202
NOZDecompressResult *result = op.result;
203203
if (result.operationError) {
204+
printf("\n");
204205
NOZCLI_printError(result.operationError);
205206
return -2;
206207
}
207208

208209
if (!result.didSucceed) {
210+
printf("\n");
209211
printf("FAILED!\n");
210212
return -2;
211213
}
212214

215+
fprintf(stdout, "\r");
216+
fflush(stdout);
213217
printf("compression ratio: %f\n", result.compressionRatio);
214218
return 0;
215219
}
@@ -228,8 +232,9 @@ + (int)run:(NOZCLIUnzipModeInfo *)info
228232
}
229233

230234
NOZProgressBlock progressBlock = ^(int64_t totalBytes, int64_t bytesComplete, int64_t bytesCompletedThisPass, BOOL *abort) {
231-
// const double progress = (double)bytesComplete / (double)totalBytes;
232-
// printf("%zi%%\n", (NSInteger)(progress * 100.));
235+
const double progress = (double)bytesComplete / (double)totalBytes;
236+
fprintf(stdout, "\r%li%%", (long)progress);
237+
fflush(stdout);
233238
};
234239
NSFileManager *fm = [NSFileManager defaultManager];
235240
NSString *tmpDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
@@ -251,9 +256,12 @@ + (int)run:(NOZCLIUnzipModeInfo *)info
251256

252257
if (![unzipper saveRecord:record toDirectory:tmpDir options:NOZUnzipperSaveRecordOptionIgnoreIntermediatePath progressBlock:progressBlock error:&error]) {
253258
[fm removeItemAtPath:tmpDir error:NULL];
259+
printf("\n");
254260
NOZCLI_printError(error);
255261
return -2;
256262
}
263+
fprintf(stdout, "\r");
264+
fflush(stdout);
257265

258266
NSString *tmpPath = [tmpDir stringByAppendingPathComponent:record.name.lastPathComponent];
259267
NSString *dstPath = entry.outputPath ?: [info.baseOutputPath stringByAppendingPathComponent:entry.entryName];
@@ -392,7 +400,7 @@ - (NSString *)description
392400

393401
@implementation NOZCLIUnzipDecompressDelegate
394402
{
395-
NSInteger _lastProgress;
403+
long _lastProgress;
396404
}
397405

398406
- (void)decompressOperation:(NOZDecompressOperation *)op didCompleteWithResult:(NOZDecompressResult *)result
@@ -401,12 +409,13 @@ - (void)decompressOperation:(NOZDecompressOperation *)op didCompleteWithResult:(
401409

402410
- (void)decompressOperation:(NOZDecompressOperation *)op didUpdateProgress:(float)progress
403411
{
404-
const NSInteger progressInt = (NSInteger)(progress * 100.f);
412+
const long progressInt = (long)(progress * 100.f);
405413
if (progressInt == _lastProgress) {
406414
return;
407415
}
408416
_lastProgress = progressInt;
409-
// printf("%zi%%\n", progressInt);
417+
fprintf(stdout, "\r%li%%", progressInt);
418+
fflush(stdout);
410419
}
411420

412421
- (BOOL)shouldDecompressOperation:(NOZDecompressOperation *)op overwriteFileAtPath:(NSString *)path

noz/NOZCLIZipMode.m

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ + (NSString *)modeFlag
5656

5757
+ (NSString *)modeName
5858
{
59-
return @"Zip (NYI)";
59+
return @"Zip";
6060
}
6161

6262
+ (NSString *)modeExecutionDescription
6363
{
64-
return @"[zip_options] -o output_file -i [file_options] input_file1 [... [-i [file_options] intpu_fileN]]";
64+
return @"[zip_options] -o output_file -i input_file1 [file_options] [... [-i intput_fileN [file_options]]]";
6565
}
6666

6767
+ (NSUInteger)modeExtraArgumentsSectionCount
@@ -200,13 +200,17 @@ + (int)run:(NOZCLIZipModeInfo *)info
200200
// TODO - support avoiding hidden files
201201

202202
NSFileManager *fm = [NSFileManager defaultManager];
203-
NSDirectoryEnumerator *enumerator = [fm enumeratorAtPath:entryInfo.entryPath];
204-
if (!enumerator) {
203+
BOOL entryIsDirectory = NO;
204+
if (![fm fileExistsAtPath:entryInfo.entryPath isDirectory:&entryIsDirectory]) {
205+
entryIsDirectory = NO;
206+
}
207+
if (!entryIsDirectory) {
205208
NOZFileZipEntry *entry = [[NOZFileZipEntry alloc] initWithFilePath:entryInfo.entryPath];
206209
if (![self _zip:zipper entry:entry methodInfo:methodInfo entryInfo:entryInfo method:overrideMethodNumber]) {
207210
return -1;
208211
}
209212
} else {
213+
NSDirectoryEnumerator *enumerator = [fm enumeratorAtPath:entryInfo.entryPath];
210214
NSString *filePath = nil;
211215
while (nil != (filePath = enumerator.nextObject)) {
212216
NSString *fullPath = [entryInfo.entryPath stringByAppendingPathComponent:filePath];
@@ -236,11 +240,22 @@ + (BOOL)_zip:(NOZZipper *)zipper entry:(NOZFileZipEntry *)entry methodInfo:(Meth
236240
entry.comment = entryInfo.comment;
237241

238242
printf("%s ...\n", entry.filePath.UTF8String);
243+
NOZProgressBlock progress = ^(int64_t totalBytes,
244+
int64_t bytesComplete,
245+
int64_t bytesCompletedThisPass,
246+
BOOL * __nonnull abort) {
247+
fprintf(stdout, "\r%%%li", (long)(100 * ((double)bytesComplete / (double)totalBytes)));
248+
fflush(stdout);
249+
};
250+
239251
NSError *error;
240-
if (![zipper addEntry:entry progressBlock:NULL error:&error]) {
252+
if (![zipper addEntry:entry progressBlock:progress error:&error]) {
253+
printf("\n");
241254
NOZCLI_printError(error);
242255
return NO;
243256
}
257+
fprintf(stdout, "\r");
258+
fflush(stdout);
244259
return YES;
245260
}
246261

@@ -287,6 +302,8 @@ @implementation NOZCLIZipModeEntryInfo
287302
printf("%s ", arg.UTF8String);
288303
}
289304
printf("\n");
305+
fflush(stdout);
306+
return nil;
290307
}
291308
[entries addObject:entry];
292309
}

0 commit comments

Comments
 (0)