Skip to content

Commit b35cccc

Browse files
committed
CCPackageManager cleansed of install data.
1 parent 229624f commit b35cccc

File tree

1 file changed

+24
-54
lines changed

1 file changed

+24
-54
lines changed

cocos2d/CCPackageManager.m

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
#import "CCPackageInstaller.h"
66
#import "CCPackageManagerDelegate.h"
77
#import "CCPackageConstants.h"
8-
#import "CCPackageInstallData.h"
9-
#import "CCPackage+InstallData.h"
108
#import "CCPackageCocos2dEnabler.h"
119
#import "ccMacros.h"
1210
#import "CCPackageHelper.h"
11+
#import "CCPackage_private.h"
1312

1413

1514
@interface CCPackageManager()
@@ -135,9 +134,11 @@ - (void)loadPackagesFromUserDefaults
135134
{
136135
CCPackage *aPackage = [[CCPackage alloc] initWithDictionary:aPackageDict];
137136

137+
/* TODO
138138
CCPackageInstallData *installData = [[CCPackageInstallData alloc] initWithPackage:aPackage];
139139
[aPackage setInstallData:installData];
140140
[installData populateInstallDataWithDictionary:aPackageDict];
141+
*/
141142

142143
[_packages addObject:aPackage];
143144
CCLOGINFO(@"[PACKAGE][INFO] Package info added: %@: %@", [aPackage standardIdentifier], [aPackage statusToString]);
@@ -166,16 +167,7 @@ - (void)savePackages
166167

167168
for (CCPackage *aPackage in _packages)
168169
{
169-
NSMutableDictionary *packageDict = [NSMutableDictionary dictionary];
170-
CCPackageInstallData *installData = [aPackage installData];
171-
[installData writeInstallDataToDictionary:packageDict];
172-
173-
[packageDict addEntriesFromDictionary:[aPackage toDictionary]];
174-
175-
if (packageDict)
176-
{
177-
[packagesToSave addObject:packageDict];
178-
}
170+
[packagesToSave addObject:[aPackage toDictionary]];
179171
}
180172

181173
[userDefaults setObject:packagesToSave forKey:PACKAGE_STORAGE_USERDEFAULTS_KEY];
@@ -271,7 +263,7 @@ - (BOOL)downloadPackage:(CCPackage *)package enableAfterDownload:(BOOL)enableAft
271263
[package setValue:remoteURL forKey:@"remoteURL"];
272264
}
273265

274-
[self attachNewInstallDataToPackage:package enableAfterDownload:enableAfterDownload];
266+
package.enableOnDownload = enableAfterDownload;
275267

276268
CCLOGINFO(@"[PACKAGE][INFO]: adding package to download queue: %@", package);
277269

@@ -297,7 +289,7 @@ - (CCPackage *)downloadPackageWithName:(NSString *)name resolution:(NSString *)r
297289
}
298290

299291
CCPackage *package = [[CCPackage alloc] initWithName:name resolution:resolution remoteURL:remoteURL];
300-
[self attachNewInstallDataToPackage:package enableAfterDownload:enableAfterDownload];
292+
package.enableOnDownload = enableAfterDownload;
301293

302294
[_packages addObject:package];
303295

@@ -308,13 +300,6 @@ - (CCPackage *)downloadPackageWithName:(NSString *)name resolution:(NSString *)r
308300
return package;
309301
}
310302

311-
- (void)attachNewInstallDataToPackage:(CCPackage *)package enableAfterDownload:(BOOL)enableAfterDownload
312-
{
313-
CCPackageInstallData *installData = [[CCPackageInstallData alloc] initWithPackage:package];
314-
installData.enableOnDownload = enableAfterDownload;
315-
[package setInstallData:installData];
316-
}
317-
318303
- (CCPackage *)packageWithName:(NSString *)name
319304
{
320305
NSString *resolution = [CCPackageHelper defaultResolution];
@@ -413,29 +398,24 @@ - (void)unzipProgress:(CCPackageUnzipper *)packageUnzipper unzippedBytes:(NSUInt
413398
- (void)tidyUpAfterInstallation:(CCPackage *)package
414399
{
415400
[self removeUnzippedPackage:package];
416-
417-
[package removeInstallData];
418401
}
419402

420403
- (void)unzipPackage:(CCPackage *)package
421404
{
422-
CCPackageInstallData *installData = [package installData];
423-
NSAssert(installData, @"installData must not be nil");
424-
425405
NSFileManager *fileManager = [NSFileManager defaultManager];
426-
if ([fileManager fileExistsAtPath:installData.unzipURL.path])
406+
if ([fileManager fileExistsAtPath:package.unzipURL.path])
427407
{
428408
NSError *error;
429409
CCLOGINFO(@"[PACKAGE/UNZIP][INFO] Removing incomplete unzipped archive: %@", installData.unzipURL.path);
430-
if ([fileManager removeItemAtURL:installData.unzipURL error:&error])
410+
if ([fileManager removeItemAtURL:package.unzipURL error:&error])
431411
{
432412
CCLOG(@"[PACKAGE/UNZIP][ERROR] Removing incomplete unzipped archive: %@", error);
433413
}
434414
}
435415

436416
// Note: This is done on purpose in case a zip contains more than the expected root package folder or something completely different which can lead to a mess
437417
// The content is checked later on after unzipping finishes
438-
installData.unzipURL = [NSURL fileURLWithPath:[[NSTemporaryDirectory() stringByAppendingPathComponent:PACKAGE_REL_UNZIP_FOLDER] stringByAppendingPathComponent:[package standardIdentifier]]];
418+
package.unzipURL = [NSURL fileURLWithPath:[[NSTemporaryDirectory() stringByAppendingPathComponent:PACKAGE_REL_UNZIP_FOLDER] stringByAppendingPathComponent:[package standardIdentifier]]];
439419
CCPackageUnzipper *packageUnzipper = [[CCPackageUnzipper alloc] initWithPackage:package];
440420

441421
[_unzipTasks addObject:packageUnzipper];
@@ -454,20 +434,18 @@ - (void)removeDownloadFile:(CCPackage *)package
454434
NSFileManager *fileManager = [NSFileManager defaultManager];
455435

456436
NSError *error;
457-
CCPackageInstallData *installData = [package installData];
458-
if (![fileManager removeItemAtPath:[installData localDownloadURL].path error:&error])
437+
if (![fileManager removeItemAtPath:package.localDownloadURL.path error:&error])
459438
{
460439
CCLOG(@"[PACKAGE][ERROR] Removing download file: %@", error);
461440
}
462441
}
463442

464443
- (void)removeUnzippedPackage:(CCPackage *)package
465444
{
466-
CCPackageInstallData *installData = [package installData];
467-
NSAssert(installData.unzipURL, @"installData.unzipURL must not be nil");
445+
NSAssert(package.unzipURL, @"installData.unzipURL must not be nil");
468446

469447
NSError *error;
470-
if (![[NSFileManager defaultManager] removeItemAtURL:installData.unzipURL error:&error])
448+
if (![[NSFileManager defaultManager] removeItemAtURL:package.unzipURL error:&error])
471449
{
472450
CCLOG(@"[PACKAGE][ERROR] removing unzipped package after successful installation: %@", error);
473451
}
@@ -495,8 +473,7 @@ - (BOOL)installPackage:(CCPackage *)package
495473
return NO;
496474
}
497475

498-
CCPackageInstallData *installData = [package installData];
499-
if (installData.enableOnDownload)
476+
if (package.enableOnDownload)
500477
{
501478
CCPackageCocos2dEnabler *packageCocos2dEnabler = [[CCPackageCocos2dEnabler alloc] init];
502479
[packageCocos2dEnabler enablePackages:@[package]];
@@ -510,11 +487,10 @@ - (BOOL)installPackage:(CCPackage *)package
510487

511488
- (BOOL)determinePackageFolderNameInUnzippedFile:(CCPackage *)package error:(NSError **)error
512489
{
513-
CCPackageInstallData *installData = [package installData];
514-
NSAssert(installData.unzipURL, @"installData.unzipURL must not be nil");
490+
NSAssert(package.unzipURL, @"installData.unzipURL must not be nil");
515491

516492
NSFileManager *fileManager = [NSFileManager defaultManager];
517-
NSArray *files = [fileManager contentsOfDirectoryAtURL:installData.unzipURL
493+
NSArray *files = [fileManager contentsOfDirectoryAtURL:package.unzipURL
518494
includingPropertiesForKeys:@[NSURLIsDirectoryKey, NSURLNameKey]
519495
options:NSDirectoryEnumerationSkipsHiddenFiles | NSDirectoryEnumerationSkipsSubdirectoryDescendants
520496
error:nil];
@@ -555,31 +531,29 @@ - (void)setPackageFolderNameUndefinedError:(NSError **)error package:(CCPackage
555531

556532
- (void)setPackageEmptyError:(NSError **)error package:(CCPackage *)package
557533
{
558-
CCPackageInstallData *installData = [package installData];
559-
NSAssert(installData.unzipURL, @"installData.unzipURL must not be nil");
534+
NSAssert(package.unzipURL, @"installData.unzipURL must not be nil");
560535

561536
if (error)
562537
{
563538
*error = [NSError errorWithDomain:@"cocos2d"
564539
code:PACKAGE_ERROR_INSTALL_PACKAGE_EMPTY
565540
userInfo:
566-
@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"The zip file is empty: \"%@\"", installData.unzipURL],
541+
@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"The zip file is empty: \"%@\"", package.unzipURL],
567542
@"package" : package}];
568543
}
569544
}
570545

571546
- (BOOL)askDelegateForCustomFolderName:(CCPackage *)package files:(NSArray *)files
572547
{
573-
CCPackageInstallData *installData = [package installData];
574-
NSAssert(installData.unzipURL, @"installData.unzipURL must not be nil");
548+
NSAssert(package.unzipURL, @"installData.unzipURL must not be nil");
575549

576550
NSFileManager *fileManager = [NSFileManager defaultManager];
577551
if ([_delegate respondsToSelector:@selector(customFolderName:packageContents:)])
578552
{
579553
NSString *customFolderNameToUse = [_delegate customFolderName:package packageContents:files];
580-
if ([fileManager fileExistsAtPath:[installData.unzipURL.path stringByAppendingPathComponent:customFolderNameToUse]])
554+
if ([fileManager fileExistsAtPath:[package.unzipURL.path stringByAppendingPathComponent:customFolderNameToUse]])
581555
{
582-
installData.folderName = customFolderNameToUse;
556+
package.folderName = customFolderNameToUse;
583557
return YES;
584558
}
585559
}
@@ -588,9 +562,6 @@ - (BOOL)askDelegateForCustomFolderName:(CCPackage *)package files:(NSArray *)fil
588562

589563
- (BOOL)searchForStandardFolderNameFiles:(NSArray *)files package:(CCPackage *)package
590564
{
591-
CCPackageInstallData *installData = [package installData];
592-
NSAssert(installData != nil, @"installData must not be nil");
593-
594565
for (NSURL *fileURL in files)
595566
{
596567
NSDictionary *resourceValues = [fileURL resourceValuesForKeys:@[NSURLIsDirectoryKey, NSURLNameKey] error:nil];
@@ -599,7 +570,7 @@ - (BOOL)searchForStandardFolderNameFiles:(NSArray *)files package:(CCPackage *)p
599570

600571
if (isDir && [name isEqualToString:[package standardIdentifier]])
601572
{
602-
installData.folderName = [package standardIdentifier];
573+
package.folderName = [package standardIdentifier];
603574
return YES;
604575
}
605576
}
@@ -687,10 +658,9 @@ - (BOOL)deletePackage:(CCPackage *)package error:(NSError **)error
687658
[_downloadManager cancelDownloadOfPackage:package];
688659

689660
NSFileManager *fileManager = [NSFileManager defaultManager];
690-
CCPackageInstallData *installData = [package installData];
691-
if (installData.unzipURL
692-
&& [fileManager fileExistsAtPath:installData.unzipURL.path]
693-
&& (![fileManager removeItemAtURL:installData.unzipURL error:error]))
661+
if (package.unzipURL
662+
&& [fileManager fileExistsAtPath:package.unzipURL.path]
663+
&& (![fileManager removeItemAtURL:package.unzipURL error:error]))
694664
{
695665
return NO;
696666
}

0 commit comments

Comments
 (0)