Skip to content

Commit edcf969

Browse files
committed
Bugfix for CCPackage and persistency.
There was a wrong key used to determine enabledOnDownload. InstallURL property was mandatory causing some issues. EnabledOnDownload is mandatory now, InstallURL is not.
1 parent fdef185 commit edcf969

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

UnitTests/CCPackageTests.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ - (void)testInitWithDictionary
7474
XCTAssertTrue(package.enableOnDownload);
7575
}
7676

77+
- (void)testInitWithDictionaryMinimumValuesSet
78+
{
79+
NSDictionary *dictionary = @{
80+
@"name" : @"DLC",
81+
@"resolution" : @"tablethd",
82+
@"os" : @"iOS",
83+
@"remoteURL" : @"http://foo.fake",
84+
@"status" : @(CCPackageStatusInitial),
85+
@"enableOnDownload" : @(NO)
86+
};
87+
88+
CCPackage *package = [[CCPackage alloc] initWithDictionary:dictionary];
89+
90+
CCAssertEqualStrings(package.name, @"DLC");
91+
CCAssertEqualStrings(package.resolution, @"tablethd");
92+
CCAssertEqualStrings(package.os, @"iOS");
93+
XCTAssertEqualObjects(package.remoteURL, [NSURL URLWithString:@"http://foo.fake"]);
94+
XCTAssertNil(package.installURL);
95+
XCTAssertEqual(package.status, CCPackageStatusInitial);
96+
XCTAssertNil(package.localDownloadURL);
97+
XCTAssertNil(package.unzipURL);
98+
XCTAssertNil(package.folderName);
99+
XCTAssertFalse(package.enableOnDownload);
100+
}
101+
77102
- (void)testToDictionary
78103
{
79104
CCPackage *package = [[CCPackage alloc] initWithName:@"DLC"

cocos2d/CCPackage.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ - (instancetype)initWithName:(NSString *)name resolution:(NSString *)resolution
3434
self.os = os;
3535
self.remoteURL = remoteURL;
3636
self.status = CCPackageStatusInitial;
37+
self.enableOnDownload = NO;
3738
}
3839

3940
return self;
@@ -62,8 +63,13 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
6263
os:dictionary[PACKAGE_SERIALIZATION_KEY_OS]
6364
remoteURL:[NSURL URLWithString:dictionary[PACKAGE_SERIALIZATION_KEY_REMOTE_URL]]];
6465

65-
package.installURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL]];
6666
package.status = (CCPackageStatus) [dictionary[PACKAGE_SERIALIZATION_KEY_STATUS] unsignedIntegerValue];
67+
package.enableOnDownload = [dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] boolValue];
68+
69+
if (dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL])
70+
{
71+
package.installURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL]];
72+
}
6773

6874
if (dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_DOWNLOAD_URL])
6975
{
@@ -80,11 +86,6 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
8086
package.folderName = dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME];
8187
}
8288

83-
if (dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME])
84-
{
85-
package.enableOnDownload = [dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] boolValue];
86-
}
87-
8889
return package;
8990
}
9091

@@ -103,6 +104,8 @@ - (NSDictionary *)toDictionary
103104
dictionary[PACKAGE_SERIALIZATION_KEY_OS] = _os;
104105
dictionary[PACKAGE_SERIALIZATION_KEY_REMOTE_URL] = [_remoteURL absoluteString];
105106
dictionary[PACKAGE_SERIALIZATION_KEY_VERSION] = @(PACKAGE_SERIALIZATION_VERSION);
107+
dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] = @(_enableOnDownload);
108+
106109
if (_installURL)
107110
{
108111
dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL] = [_installURL path];
@@ -123,8 +126,6 @@ - (NSDictionary *)toDictionary
123126
dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME] = _folderName;
124127
}
125128

126-
dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] = @(_enableOnDownload);
127-
128129
return dictionary;
129130
}
130131

0 commit comments

Comments
 (0)