mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Add version command for BinaryDelta and for patches
This commit is contained in:
1 parent
ba75b79a97
commit
b780b476c6
3 files changed
+74
-18
No files matched your search
Vendored
+1
@@ -100,6 +100,7 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Applying version %u.%u patch...\n", majorDiffVersion, minorDiffVersion);
|
||||
fprintf(stderr, "Verifying source...");
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -211,6 +211,7 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Creating version %u.%u patch...\n", majorVersion, minorVersion);
|
||||
fprintf(stderr, "Processing %s...", [source fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+72
-18
@@ -10,31 +10,38 @@
|
||||
#include "SUBinaryDeltaCreate.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
#define VERBOSE_FLAG @"--verbose"
|
||||
#define VERSION_FLAG @"--version"
|
||||
|
||||
static void printUsage(void)
|
||||
#define CREATE_COMMAND @"create"
|
||||
#define APPLY_COMMAND @"apply"
|
||||
#define VERSION_COMMAND @"version"
|
||||
#define VERSION_ALTERNATE_COMMAND @"--version"
|
||||
|
||||
static void printUsage(NSString *programName)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, "BinaryDelta create [--verbose --version=<version>] <before-tree> <after-tree> <patch-file>\n");
|
||||
fprintf(stderr, "BinaryDelta apply [--verbose] <before-tree> <after-tree> <patch-file>\n");
|
||||
fprintf(stderr, "%s create [--verbose --version=<version>] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
|
||||
fprintf(stderr, "%s apply [--verbose] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
|
||||
fprintf(stderr, "%s version [<patch-file>]\n", [programName UTF8String]);
|
||||
}
|
||||
|
||||
static int runCreateCommand(NSArray *args)
|
||||
static int runCreateCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
if (args.count < 3 || args.count > 5) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 4 && ![args[0] isEqualToString:VERBOSE_FLAG] && ![args[0] hasPrefix:VERSION_FLAG]) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 5 && ![args[1] isEqualToString:VERBOSE_FLAG] && ![args[1] hasPrefix:VERSION_FLAG]) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -53,7 +60,7 @@ static int runCreateCommand(NSArray *args)
|
||||
if (versionField) {
|
||||
versionComponents = [versionField componentsSeparatedByString:@"="];
|
||||
if (versionComponents.count != 2) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -79,15 +86,15 @@ static int runCreateCommand(NSArray *args)
|
||||
return createBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], patchVersion, verbose);
|
||||
}
|
||||
|
||||
static int runApplyCommand(NSArray *args)
|
||||
static int runApplyCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
if (args.count < 3 || args.count > 4) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 4 && ![args[0] isEqualToString:VERBOSE_FLAG]) {
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -109,12 +116,57 @@ static int runApplyCommand(NSArray *args)
|
||||
return applyBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], verbose);
|
||||
}
|
||||
|
||||
static int runVersionCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
if (args.count > 1) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 0) {
|
||||
fprintf(stdout, "%u.%u\n", LATEST_DELTA_DIFF_MAJOR_VERSION, latestMinorVersionForMajorVersion(LATEST_DELTA_DIFF_MAJOR_VERSION));
|
||||
} else {
|
||||
NSString *patchFile = args[0];
|
||||
xar_t x = xar_open([patchFile fileSystemRepresentation], READ);
|
||||
if (!x) {
|
||||
fprintf(stderr, "Unable to open patch %s\n", [patchFile fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY)) {
|
||||
const char *value = 0;
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
majorDiffVersion = (SUBinaryDeltaMajorVersion)[@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "%u.%u\n", majorDiffVersion, minorDiffVersion);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int __unused argc, char __unused *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count < 3) {
|
||||
printUsage();
|
||||
NSString *programName = [args[0] lastPathComponent];
|
||||
|
||||
if (args.count < 2) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -122,13 +174,15 @@ int main(int __unused argc, char __unused *argv[])
|
||||
NSArray *commandArguments = [args subarrayWithRange:NSMakeRange(2, args.count - 2)];
|
||||
|
||||
int result;
|
||||
if ([command isEqualToString:@"create"]) {
|
||||
result = runCreateCommand(commandArguments);
|
||||
} else if ([command isEqualToString:@"apply"]) {
|
||||
result = runApplyCommand(commandArguments);
|
||||
if ([command isEqualToString:CREATE_COMMAND]) {
|
||||
result = runCreateCommand(programName, commandArguments);
|
||||
} else if ([command isEqualToString:APPLY_COMMAND]) {
|
||||
result = runApplyCommand(programName, commandArguments);
|
||||
} else if ([command isEqualToString:VERSION_COMMAND] || [command isEqualToString:VERSION_ALTERNATE_COMMAND]) {
|
||||
result = runVersionCommand(programName, commandArguments);
|
||||
} else {
|
||||
result = 1;
|
||||
printUsage();
|
||||
printUsage(programName);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user