Skip to content

Commit 2983112

Browse files
committed
CCPackageHelper added to extract currentOS method from CCPackageManager.
currentOS now a class method.
1 parent 7e838fa commit 2983112

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@
599599
E0F924711224140400EF2362 /* CCTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E0F9246F1224140400EF2362 /* CCTexturePVR.h */; };
600600
E0F924721224140400EF2362 /* CCTexturePVR.m in Sources */ = {isa = PBXBuildFile; fileRef = E0F924701224140400EF2362 /* CCTexturePVR.m */; };
601601
E0F92AC41224559800EF2362 /* CCNS.h in Headers */ = {isa = PBXBuildFile; fileRef = E0F92AC31224559800EF2362 /* CCNS.h */; };
602+
E525F0F74C7C69C4371E20EE /* CCPackageHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E525F9EA4B5DD37D0418869E /* CCPackageHelper.m */; };
603+
E525FCC2CF72D3667DE4D71B /* CCPackageHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = E525FF8C7C018BF691F36044 /* CCPackageHelper.h */; };
602604
FC39962219C3BBCF00C93E5E /* libObjectAL (Android).a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC39961F19C3B92F00C93E5E /* libObjectAL (Android).a */; };
603605
FC64014019C79716003E595A /* libObjectAL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC39961B19C3B92F00C93E5E /* libObjectAL.a */; };
604606
/* End PBXBuildFile section */
@@ -1031,6 +1033,8 @@
10311033
E0F9246F1224140400EF2362 /* CCTexturePVR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTexturePVR.h; sourceTree = "<group>"; };
10321034
E0F924701224140400EF2362 /* CCTexturePVR.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCTexturePVR.m; sourceTree = "<group>"; };
10331035
E0F92AC31224559800EF2362 /* CCNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNS.h; sourceTree = "<group>"; };
1036+
E525F9EA4B5DD37D0418869E /* CCPackageHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCPackageHelper.m; sourceTree = "<group>"; };
1037+
E525FF8C7C018BF691F36044 /* CCPackageHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPackageHelper.h; sourceTree = "<group>"; };
10341038
FC39961319C3B92F00C93E5E /* ObjectAL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ObjectAL.xcodeproj; path = external/ObjectAL/ObjectAL/ObjectAL.xcodeproj; sourceTree = "<group>"; };
10351039
FC55599F1991A26300E29CCE /* libogg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libogg.a; path = "external/ogg/android/ogg/build/Debug-android/libogg.a"; sourceTree = "<group>"; };
10361040
/* End PBXFileReference section */
@@ -1478,6 +1482,8 @@
14781482
83E1A85719C8AC56000A3BCA /* Download */,
14791483
83E1A85919C8AC6A000A3BCA /* Unzip */,
14801484
83E1A85819C8AC65000A3BCA /* Install */,
1485+
E525FF8C7C018BF691F36044 /* CCPackageHelper.h */,
1486+
E525F9EA4B5DD37D0418869E /* CCPackageHelper.m */,
14811487
);
14821488
name = Packages;
14831489
sourceTree = "<group>";
@@ -1977,6 +1983,7 @@
19771983
B78AE46817E7AF1C0028BE0B /* CCScrollView.h in Headers */,
19781984
B78AE46C17E7AF6C0028BE0B /* UITouch+CC.h in Headers */,
19791985
B7D2730F1822F4AA0054849B /* CCBKeyframe.h in Headers */,
1986+
E525FCC2CF72D3667DE4D71B /* CCPackageHelper.h in Headers */,
19801987
);
19811988
runOnlyForDeploymentPostprocessing = 0;
19821989
};
@@ -2422,6 +2429,7 @@
24222429
B78AE46D17E7AF6C0028BE0B /* UITouch+CC.m in Sources */,
24232430
D33803E318032ECE0072D8FE /* CCPhysicsBody.m in Sources */,
24242431
D268FE12198078FF00ECBCD0 /* CCEffectHue.m in Sources */,
2432+
E525F0F74C7C69C4371E20EE /* CCPackageHelper.m in Sources */,
24252433
);
24262434
runOnlyForDeploymentPostprocessing = 0;
24272435
};

cocos2d/CCPackage.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,20 @@
4141
*
4242
* @param name Name of the package
4343
* @param resolution Resolution of the package
44-
* @param os OS of the package
44+
* @param remoteURL Remote URL of the package
45+
*
46+
* @return New instance of CCPackage
47+
*/
48+
- (instancetype)initWithName:(NSString *)name
49+
resolution:(NSString *)resolution
50+
remoteURL:(NSURL *)remoteURL;
51+
52+
/**
53+
* Creates a new instance of a package.
54+
*
55+
* @param name Name of the package
56+
* @param resolution Resolution of the package
57+
* @param os OS of the package, usally determined internally
4558
* @param remoteURL Remote URL of the package
4659
*
4760
* @return New instance of CCPackage

cocos2d/CCPackage.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import "CCPackage.h"
22
#import "CCPackageInstallData.h"
33
#import "CCPackage+InstallData.h"
4+
#import "CCPackageHelper.h"
45

56

67
NSUInteger PACKAGE_SERIALIZATION_VERSION = 1;
@@ -48,6 +49,14 @@ - (instancetype)initWithName:(NSString *)name resolution:(NSString *)resolution
4849
return self;
4950
}
5051

52+
- (instancetype)initWithName:(NSString *)name resolution:(NSString *)resolution remoteURL:(NSURL *)remoteURL
53+
{
54+
return [[CCPackage alloc] initWithName:name
55+
resolution:resolution
56+
os:[CCPackageHelper currentOS]
57+
remoteURL:remoteURL];
58+
}
59+
5160
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
5261
{
5362
CCPackage *package = [[CCPackage alloc] initWithName:dictionary[PACKAGE_SERIALIZATION_KEY_NAME]

cocos2d/CCPackageHelper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <Foundation/Foundation.h>
2+
3+
4+
@interface CCPackageHelper : NSObject
5+
6+
+ (NSString *)currentOS;
7+
8+
@end

cocos2d/CCPackageHelper.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#import "CCPackageHelper.h"
2+
3+
4+
@implementation CCPackageHelper
5+
6+
+ (NSString *)currentOS
7+
{
8+
#ifdef __CC_PLATFORM_IOS
9+
return @"iOS";
10+
11+
#elif defined(__CC_PLATFORM_MAC)
12+
return @"Mac";
13+
14+
#elif defined(__CC_PLATFORM_ANDROID)
15+
return @"Android";
16+
17+
#endif
18+
return nil;
19+
}
20+
21+
@end

cocos2d/CCPackageManager.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "CCPackage+InstallData.h"
1010
#import "CCPackageCocos2dEnabler.h"
1111
#import "ccMacros.h"
12+
#import "CCPackageHelper.h"
1213

1314

1415
@interface CCPackageManager()
@@ -181,7 +182,7 @@ - (CCPackage *)downloadPackageWithName:(NSString *)name resolution:(NSString *)r
181182
{
182183
NSAssert(_baseURL != nil, @"baseURL must not be nil");
183184

184-
NSString *packageName = [NSString stringWithFormat:@"%@-%@-%@.zip", name, [self currentOS], resolution];
185+
NSString *packageName = [NSString stringWithFormat:@"%@-%@-%@.zip", name, [CCPackageHelper currentOS], resolution];
185186
NSURL *remoteURL = [_baseURL URLByAppendingPathComponent:packageName];
186187

187188
return [self downloadPackageWithName:name resolution:resolution remoteURL:remoteURL enableAfterDownload:enableAfterDownload];
@@ -209,10 +210,10 @@ - (CCPackage *)downloadPackageWithName:(NSString *)name resolution:(NSString *)r
209210
return aPackage;
210211
}
211212

212-
CCPackage *package = [[CCPackage alloc] initWithName:name resolution:resolution os:[self currentOS] remoteURL:remoteURL];
213213
CCPackageInstallData *installData = [[CCPackageInstallData alloc] initWithPackage:package];
214214
installData.enableOnDownload = enableAfterDownload;
215215
[package setInstallData:installData];
216+
CCPackage *package = [[CCPackage alloc] initWithName:name resolution:resolution remoteURL:remoteURL];
216217

217218
[_packages addObject:package];
218219

0 commit comments

Comments
 (0)