diff --git a/Autoupdate/SUInstaller.m b/Autoupdate/SUInstaller.m index 609e0995..7a2aa817 100644 --- a/Autoupdate/SUInstaller.m +++ b/Autoupdate/SUInstaller.m @@ -21,6 +21,17 @@ @implementation SUInstaller +static BOOL SUFilenameMatchesAnyName(NSString *filename, NSOrderedSet *names) +{ + for (NSString *name in names) { + // This handles unicode normalization but is still a case sensitive comparison + if ([filename compare:name] == NSOrderedSame) { + return YES; + } + } + return NO; +} + + (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host #if SPARKLE_BUILD_PACKAGE_SUPPORT isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr @@ -32,8 +43,15 @@ // Search subdirectories for the application NSString *currentFile, *newAppDownloadPath = nil, - *bundleFileName = [[host bundlePath] lastPathComponent], - *alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]]; + *bundleExtension = [[host bundlePath] pathExtension]; + NSOrderedSet *hostNames = [host infoDictionaryNames]; + NSMutableOrderedSet *bundleFileNames = [NSMutableOrderedSet orderedSet]; + for (NSString *hostName in hostNames) { + NSString *bundleFileName = [hostName stringByAppendingPathExtension:bundleExtension]; + if (bundleFileName != nil) { + [bundleFileNames addObject:bundleFileName]; + } + } #if SPARKLE_BUILD_PACKAGE_SUPPORT NSString *fallbackPackagePath = nil; @@ -41,7 +59,6 @@ BOOL isGuided = YES; #endif NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder]; - NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension]; while ((currentFile = [dirEnum nextObject])) { NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile]; @@ -78,8 +95,7 @@ NSString *currentExtension = [currentFile pathExtension]; NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension]; #endif - if ([currentFilename isEqualToString:bundleFileName] || - [currentFilename isEqualToString:alternateBundleFileName]) // We found one! + if (SUFilenameMatchesAnyName(currentFilename, bundleFileNames)) // We found one! { #if SPARKLE_BUILD_PACKAGE_SUPPORT isPackage = NO; @@ -89,7 +105,7 @@ #if SPARKLE_BUILD_PACKAGE_SUPPORT } else if ([currentExtension isEqualToString:@"pkg"] || [currentExtension isEqualToString:@"mpkg"]) { - if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) { + if (SUFilenameMatchesAnyName(currentFilenameNoExtension, hostNames)) { isPackage = YES; newAppDownloadPath = currentPath; break; @@ -138,13 +154,13 @@ #endif if (!newAppDownloadPath) { - SULog(SULogLevelError, @"Searched %@ for %@.(app%@)", inUpdateFolder, bundleFileNameNoExtension, + SULog(SULogLevelError, @"Searched %@ for {%@}.(app%@) or bundle identifier %@", inUpdateFolder, [hostNames.array componentsJoinedByString:@", "], #if SPARKLE_BUILD_PACKAGE_SUPPORT @"|pkg" #else @"" #endif - ); + , host.bundle.bundleIdentifier); } return newAppDownloadPath; } diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index b0a8b425..13477928 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -32,6 +32,7 @@ SUHostDefinitionAttribute @property (readonly, nonatomic, copy) NSString *bundlePath; @property (readonly, nonatomic, copy) NSString *name; +@property (readonly, nonatomic, copy) NSOrderedSet *infoDictionaryNames; @property (readonly, nonatomic, copy) NSString *version; @property (readonly, nonatomic) BOOL validVersion; @property (readonly, nonatomic, copy) NSString *displayVersion; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 90410e2f..5147ef0f 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -140,19 +140,34 @@ static void *SUHostObservableContext = &SUHostObservableContext; return _bundle.bundlePath; } +- (NSOrderedSet *)infoDictionaryNamesStoppingAtFirstMatch:(BOOL)stopAtFirstMatch SPU_OBJC_DIRECT +{ + NSMutableOrderedSet *names = [NSMutableOrderedSet orderedSet]; + // Allow host bundle to provide a custom name + for (NSString *key in @[@"SUBundleName", @"CFBundleDisplayName", (__bridge NSString *)kCFBundleNameKey]) { + NSString *name = [self objectForInfoDictionaryKey:key ofClass:NSString.class]; + if (name.length > 0) { + [names addObject:name]; + + if (stopAtFirstMatch) { + break; + } + } + } + return [names copy]; +} + +- (NSOrderedSet *)infoDictionaryNames +{ + return [self infoDictionaryNamesStoppingAtFirstMatch:NO]; +} + - (NSString * _Nonnull)name { - NSString *name; - - // Allow host bundle to provide a custom name - name = [self objectForInfoDictionaryKey:@"SUBundleName" ofClass:NSString.class]; - if (name && name.length > 0) return name; - - name = [self objectForInfoDictionaryKey:@"CFBundleDisplayName" ofClass:NSString.class]; - if (name && name.length > 0) return name; - - name = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey ofClass:NSString.class]; - if (name && name.length > 0) return name; + NSString *name = [self infoDictionaryNamesStoppingAtFirstMatch:YES].firstObject; + if (name != nil) { + return name; + } return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension]; } diff --git a/Tests/Resources/SUUpdateValidatorTest/Both.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/Both.bundle/Contents/Info.plist index adfeae95..b10bca18 100644 --- a/Tests/Resources/SUUpdateValidatorTest/Both.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/Both.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + Both CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/Info.plist index 1637e351..d1048b49 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedBoth CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeDirectory index 601e593b..ccf37802 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeRequirements-1 b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index 3ed9ebd9..00000000 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeResources b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeResources index 820c628d..a7b727ac 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeResources +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBoth.bundle/Contents/_CodeSignature/CodeResources @@ -13,10 +13,6 @@ Resources/test-pubkey.pem - hash - - pR1EGsp5nhk1vr/xfQPT8es9ZBw= - hash2 zD/XQJu4ElPWE6sfqtzoR2vEjdfgi98j/hiRoYZqv9w= diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/Info.plist index 91b89343..7364c763 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedBothNew CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeDirectory index 52258fbf..31890dbb 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeRequirements-1 b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index 4c99058f..00000000 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeResources b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeResources index 820c628d..a7b727ac 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeResources +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedBothNew.bundle/Contents/_CodeSignature/CodeResources @@ -13,10 +13,6 @@ Resources/test-pubkey.pem - hash - - pR1EGsp5nhk1vr/xfQPT8es9ZBw= - hash2 zD/XQJu4ElPWE6sfqtzoR2vEjdfgi98j/hiRoYZqv9w= diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/Info.plist index ec0873a4..319e811b 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedInvalid CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/_CodeSignature/CodeDirectory index 88a4fb45..839510d4 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalid.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/Info.plist index f0f69b91..4dfd7832 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedInvalidOnly CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/_CodeSignature/CodeDirectory index 88a4fb45..839510d4 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedInvalidOnly.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/Info.plist index a28e3956..a39e1b06 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedOldED CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeDirectory index 573a9ce5..5a505787 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeRequirements-1 b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index 51f9b442..00000000 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOldED.bundle/Contents/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/Info.plist index 896f1cb4..47d4f024 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedOnly CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeDirectory index 88a4fb45..839510d4 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeRequirements-1 b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index 87de9d38..00000000 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnly.bundle/Contents/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/Info.plist index 75558839..5e174b84 100644 --- a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CodeSignedOnlyNew CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeDirectory b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeDirectory index 2a17b071..cfa35b0a 100644 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeDirectory and b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeDirectory differ diff --git a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeRequirements-1 b/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index ca5f2933..00000000 Binary files a/Tests/Resources/SUUpdateValidatorTest/CodeSignedOnlyNew.bundle/Contents/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/Tests/Resources/SUUpdateValidatorTest/DSAOnly.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/DSAOnly.bundle/Contents/Info.plist index f6fcd9af..f01d1091 100644 --- a/Tests/Resources/SUUpdateValidatorTest/DSAOnly.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/DSAOnly.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + DSAOnly CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/EDOnly.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/EDOnly.bundle/Contents/Info.plist index d13fad54..689e3dfc 100644 --- a/Tests/Resources/SUUpdateValidatorTest/EDOnly.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/EDOnly.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + EDOnly CFBundlePackageType BNDL CFBundleSignature diff --git a/Tests/Resources/SUUpdateValidatorTest/None.bundle/Contents/Info.plist b/Tests/Resources/SUUpdateValidatorTest/None.bundle/Contents/Info.plist index 70b7ade2..cef76aa5 100644 --- a/Tests/Resources/SUUpdateValidatorTest/None.bundle/Contents/Info.plist +++ b/Tests/Resources/SUUpdateValidatorTest/None.bundle/Contents/Info.plist @@ -4,6 +4,8 @@ CFBundleInfoDictionaryVersion 6.0 + CFBundleName + None CFBundlePackageType BNDL CFBundleSignature