mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Test the best chosen appcast item
This commit is contained in:
1 parent
8a04cc726f
commit
004ac3f9ae
6 files changed
+56
-16
No files matched your search
Vendored
+1
-1
@@ -24,7 +24,7 @@
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host;
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui;
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
+ (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui;
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac;
|
||||
|
||||
Vendored
+19
-13
@@ -82,12 +82,20 @@
|
||||
return comparator;
|
||||
}
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id<SUVersionComparison>)comparator
|
||||
{
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
SUAppcastItem *item = nil;
|
||||
for(SUAppcastItem *candidate in appcastItems) {
|
||||
if ([[self class] hostSupportsItem:candidate]) {
|
||||
if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) {
|
||||
item = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui
|
||||
+ (BOOL)hostSupportsItem:(SUAppcastItem *)ui
|
||||
{
|
||||
if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) &&
|
||||
([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; }
|
||||
@@ -106,6 +114,11 @@
|
||||
return minimumVersionOK && maximumVersionOK;
|
||||
}
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
{
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
|
||||
{
|
||||
NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey];
|
||||
@@ -115,7 +128,7 @@
|
||||
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
{
|
||||
return ui && [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
|
||||
return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
|
||||
}
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac
|
||||
@@ -140,18 +153,11 @@
|
||||
else // If not, we'll take care of it ourselves.
|
||||
{
|
||||
// Find the best supported update
|
||||
id<SUVersionComparison> comparator = [self versionComparator];
|
||||
for(SUAppcastItem *candidate in ac.items) {
|
||||
if ([self hostSupportsItem:candidate]) {
|
||||
if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) {
|
||||
item = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
item = [[self class] bestAppcastItemFromAppcastItems:ac.items withComparator:[self versionComparator]];
|
||||
|
||||
if (item) {
|
||||
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) {
|
||||
self.nonDeltaUpdateItem = item;
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
{
|
||||
// We don't check to see if this update's been skipped, because the user explicitly *asked* if he had the latest version.
|
||||
return [self hostSupportsItem:ui] && [self isItemNewer:ui];
|
||||
return [[self class] hostSupportsItem:ui] && [self isItemNewer:ui];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,10 +8,25 @@
|
||||
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
|
||||
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" sparkle:version="2.0" />
|
||||
</item>
|
||||
<!-- The best chosen release -->
|
||||
<item>
|
||||
<title>Version 3.0</title>
|
||||
<pubDate>Sat, 26 Jul 2014 15:20:12 +0000</pubDate>
|
||||
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" sparkle:version="3.0" />
|
||||
</item>
|
||||
<!-- A release testing minimumSystemVersion -->
|
||||
<item>
|
||||
<title>Version 4.0</title>
|
||||
<pubDate>Sat, 26 Jul 2014 15:20:13 +0000</pubDate>
|
||||
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" sparkle:version="4.0" />
|
||||
<sparkle:minimumSystemVersion>17.0.0</sparkle:minimumSystemVersion>
|
||||
</item>
|
||||
<!-- A joke release testing maximumSystemVersion -->
|
||||
<item>
|
||||
<title>Version 5.0</title>
|
||||
<pubDate>Sat, 26 Jul 2014 15:20:14 +0000</pubDate>
|
||||
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" sparkle:version="5.0" />
|
||||
<sparkle:maximumSystemVersion>2.0.0</sparkle:maximumSystemVersion>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -20,14 +20,24 @@ class SUAppcastTest: XCTestCase {
|
||||
do {
|
||||
let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
|
||||
|
||||
XCTAssertEqual(2, items.count);
|
||||
XCTAssertEqual(4, items.count);
|
||||
|
||||
XCTAssertEqual("Version 2.0", items[0].title);
|
||||
XCTAssertEqual("desc", items[0].itemDescription);
|
||||
|
||||
// This is the best release matching our system version
|
||||
XCTAssertEqual("Version 3.0", items[1].title);
|
||||
XCTAssertNil(items[1].itemDescription);
|
||||
|
||||
XCTAssertEqual("Version 4.0", items[2].title);
|
||||
XCTAssertNil(items[2].itemDescription);
|
||||
|
||||
XCTAssertEqual("Version 5.0", items[3].title);
|
||||
XCTAssertNil(items[3].itemDescription);
|
||||
|
||||
let bestAppcastItem = SUBasicUpdateDriver.bestAppcastItemFromAppcastItems(items, withComparator: SUStandardVersionComparator.defaultComparator())
|
||||
|
||||
XCTAssertEqual(bestAppcastItem, items[1])
|
||||
} catch let err as NSError {
|
||||
NSLog("%@", err);
|
||||
XCTFail(err.localizedDescription);
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#import "SUFileManager.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
|
||||
// Duplicated to avoid exporting a private symbol from SUFileManager
|
||||
static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
|
||||
@@ -23,6 +26,12 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine";
|
||||
|
||||
@end
|
||||
|
||||
@interface SUBasicUpdateDriver (Private)
|
||||
|
||||
+ (SUAppcastItem *)bestAppcastItemFromAppcastItems:(NSArray *)appcastItems withComparator:(id<SUVersionComparison>)comparator;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface SUAppcast (Private)
|
||||
- (NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp;
|
||||
|
||||
Reference in new issue
Block a user