Skip to content

Commit cf29603

Browse files
committed
Refactoring: CCPackageInstaller won't enable the package anymore, this is done in the CCPackageManager now.
CCPackageCocos2dEnabler will set relevant status instead of CCPackageManager.
1 parent 4515dce commit cf29603

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

cocos2d/CCPackageCocos2dEnabler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Note: This method won't check a package's status and it is meant to be used for initialization
88
* of packages on startup by the CCPackagesManager.
99
* If a package is already among the search path then it won't be added again, spritesheets and file lookups not reloaded
10+
* Sets the package's status to CCPackageStatusInstalledEnabled
1011
*
1112
* @param packages An array of CCPackage instance to be enabled
1213
*/
@@ -17,6 +18,7 @@
1718
* of remaining search paths.
1819
* Note: This method won't check a package's status and it is meant to be used for initialization
1920
* of packages on startup by the CCPackagesManager.
21+
* Sets the package's status to CCPackageStatusInstalledDisabled*
2022
*
2123
* @param packages An array of CCPackage instance to be disabled
2224
*/

cocos2d/CCPackageCocos2dEnabler.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ - (BOOL)addPackagestoSearchPath:(NSArray *)packages
3939

4040
for (CCPackage *aPackage in packages)
4141
{
42+
NSAssert(aPackage.installURL != nil, @"aPackage.installURL must not be nil for package %@", aPackage);
43+
4244
NSMutableArray *newSearchPath = [[CCFileUtils sharedFileUtils].searchPath mutableCopy];
4345
NSString *newPackagePath = aPackage.installURL.path;
4446

4547
if (![newSearchPath containsObject:newPackagePath])
4648
{
49+
[aPackage setValue:@(CCPackageStatusInstalledEnabled) forKey:NSStringFromSelector(@selector(status))];
50+
4751
[newSearchPath insertObject:newPackagePath atIndex:0];
4852
[CCFileUtils sharedFileUtils].searchPath = newSearchPath;
4953
searchPathChanged = YES;
@@ -71,6 +75,8 @@ - (void)removePackagesFromSearchPath:(NSArray *)packages
7175
NSMutableArray *newSearchPath = [[CCFileUtils sharedFileUtils].searchPath mutableCopy];
7276
NSString *packagePathToRemove = aPackage.installURL.path;
7377

78+
[aPackage setValue:@(CCPackageStatusInstalledDisabled) forKey:NSStringFromSelector(@selector(status))];
79+
7480
if ([newSearchPath containsObject:packagePathToRemove])
7581
{
7682
[newSearchPath removeObject:packagePathToRemove];

cocos2d/CCPackageInstaller.m

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,11 @@ - (BOOL)installWithError:(NSError **)error
5151
return NO;
5252
}
5353

54-
if (installData.enableOnDownload)
55-
{
56-
[self enablePackageInCocos2d];
57-
[_package setValue:@(CCPackageStatusInstalledEnabled) forKey:@"status"];
58-
}
59-
else
60-
{
61-
[_package setValue:@(CCPackageStatusInstalledDisabled) forKey:@"status"];
62-
}
54+
[_package setValue:@(CCPackageStatusInstalledDisabled) forKey:@"status"];
6355

6456
return YES;
6557
}
6658

67-
- (void)enablePackageInCocos2d
68-
{
69-
CCPackageCocos2dEnabler *packageCocos2dEnabler = [[CCPackageCocos2dEnabler alloc] init];
70-
[packageCocos2dEnabler enablePackages:@[_package]];
71-
}
72-
7359
- (BOOL)movePackageToInstallPathWithError:(NSError **)error
7460
{
7561
CCPackageInstallData *installData = [_package installData];

cocos2d/CCPackageManager.m

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,6 @@ - (void)enablePackages
156156
[packageCocos2dEnabler enablePackages:packagesToEnable];
157157
}
158158

159-
- (void)storePackagesAndPauseDownloads
160-
{
161-
CCLOGINFO(@"[PACKAGE][INFO] Packages info saved to userdefaults.");
162-
163-
[_downloadManager pauseAllDownloads];
164-
165-
[self savePackages];
166-
}
167-
168159
- (void)savePackages
169160
{
170161
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
@@ -469,6 +460,13 @@ - (BOOL)installPackage:(CCPackage *)package
469460
return NO;
470461
}
471462

463+
CCPackageInstallData *installData = [package installData];
464+
if (installData.enableOnDownload)
465+
{
466+
CCPackageCocos2dEnabler *packageCocos2dEnabler = [[CCPackageCocos2dEnabler alloc] init];
467+
[packageCocos2dEnabler enablePackages:@[package]];
468+
}
469+
472470
CCLOGINFO(@"[PACKAGE/INSTALL][INFO] Installation of package successful! Package enabled: %d", [package installData].enableOnDownload);
473471

474472
[_delegate packageInstallationFinished:package];
@@ -594,8 +592,6 @@ - (BOOL)disablePackage:(CCPackage *)package error:(NSError **)error
594592
CCPackageCocos2dEnabler *packageCocos2dEnabler = [[CCPackageCocos2dEnabler alloc] init];
595593
[packageCocos2dEnabler disablePackages:@[package]];
596594

597-
[package setValue:@(CCPackageStatusInstalledDisabled) forKey:@"status"];
598-
599595
if (![_packages containsObject:package])
600596
{
601597
[_packages addObject:package];
@@ -624,8 +620,6 @@ - (BOOL)enablePackage:(CCPackage *)package error:(NSError **)error
624620
CCPackageCocos2dEnabler *packageCocos2dEnabler = [[CCPackageCocos2dEnabler alloc] init];
625621
[packageCocos2dEnabler enablePackages:@[package]];
626622

627-
[package setValue:@(CCPackageStatusInstalledEnabled) forKey:@"status"];
628-
629623
if (![_packages containsObject:package])
630624
{
631625
[_packages addObject:package];

0 commit comments

Comments
 (0)