From 65b071eb862e49fb470bc8b1f0505bb20833847a Mon Sep 17 00:00:00 2001 From: Grant Erickson Date: Thu, 3 Sep 2009 23:29:50 -0700 Subject: [PATCH] If no suitable packages or bundles are found to be installed, Sparkle will install the first package it finds in the distribution archive. --- SUInstaller.m | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/SUInstaller.m b/SUInstaller.m index a070d882..870663c4 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -38,6 +38,7 @@ // Search subdirectories for the application NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[host bundlePath] lastPathComponent], *alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]]; BOOL isPackage = NO; + NSString *fallbackPackagePath = nil; NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:updateFolder]; while ((currentFile = [dirEnum nextObject])) { @@ -49,12 +50,20 @@ newAppDownloadPath = currentPath; break; } - else if (([[currentFile pathExtension] isEqualToString:@"pkg"] || [[currentFile pathExtension] isEqualToString:@"mpkg"]) && - [[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]]) + else if ([[currentFile pathExtension] isEqualToString:@"pkg"] || + [[currentFile pathExtension] isEqualToString:@"mpkg"]) { - isPackage = YES; - newAppDownloadPath = currentPath; - break; + if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]]) + { + isPackage = YES; + newAppDownloadPath = currentPath; + break; + } + else + { + // Remember any other non-matching packages we have seen should we need to use one of them as a fallback. + fallbackPackagePath = currentPath; + } } else { @@ -72,6 +81,14 @@ if ([self _isAliasFolderAtPath:currentPath]) [dirEnum skipDescendents]; } + + // We don't have a valid path. Try to use the fallback package. + + if (newAppDownloadPath == nil && fallbackPackagePath != nil) + { + isPackage = YES; + newAppDownloadPath = fallbackPackagePath; + } if (newAppDownloadPath == nil) {