Skip to content

Commit

Permalink
moved cleanup method to CCBFileUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
LearnCocos2D committed Oct 15, 2014
1 parent 17b331e commit 1fa6b50
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 54 deletions.
2 changes: 2 additions & 0 deletions SpriteBuilder/ccBuilder/CCBFileUtil.h
Expand Up @@ -33,4 +33,6 @@
+ (void) addFilesWithExtension:(NSString*)ext inDirectory:(NSString*)dir toArray:(NSMutableArray*)array subPath:(NSString*)subPath;
+ (NSArray*) filesInResourcePathsWithExtension:(NSString*)ext;

+(void) cleanupSpriteBuilderProjectAtPath:(NSString*)fileName;

@end
66 changes: 66 additions & 0 deletions SpriteBuilder/ccBuilder/CCBFileUtil.m
Expand Up @@ -138,4 +138,70 @@ + (void) setModificationDate:(NSDate*)date forFile:(NSString*)file
[[NSFileManager defaultManager] setAttributes:attr ofItemAtPath:file error:NULL];
}

+(void) cleanupSpriteBuilderProjectAtPath:(NSString*)path
{
// The files/folders in this list will be DELETED from the project at the given path.
// This list needs to be updated/amended whenever cocos2d introduces new or renames folders whose contents are
// not needed during development of a SpriteBuilder project. See: https://github.com/spritebuilder/SpriteBuilder/issues/915
NSArray* removeItems = @[@"build",
@"cocos2d-tests-android",
@"cocos2d-tests-ios.xcodeproj",
@"cocos2d-tests-android",
@"cocos2d-tests-osx.xcodeproj",
@"cocos2d-tests.xcodeproj",
@"cocos2d-ui-tests",
@"Resources",
@"Resources-iPad",
@"Resources-Mac",
@"tools",
@"UnitTests",
@"doxygen.config",
@"doxygen.footer",
@"Default-568h@2x.png",
@"Icon.png",
@"RELEASE TODO.txt",
@"external/Chipmunk/Demo",
@"external/Chipmunk/doc",
@"external/Chipmunk/doc-src",
@"external/Chipmunk/msvc",
@"external/Chipmunk/xcode",
@"external/ObjectAL/ObjectAL/diagrams",
@"external/ObjectAL/ObjectALDemo",
@"external/ObjectAL/Sample Code",
@"external/ObjectAL/ObjectAL.pdf",
];

// removing extranous cocos2d-iphone files if existing
const NSString* const cocosPath = @"Source/libs/cocos2d-iphone";
NSFileManager* fm = [NSFileManager defaultManager];
NSString* parentPath = [path stringByDeletingLastPathComponent];
NSError* error;

// just to be sure we don't accidentally remove something when given an incorrect .ccbproj path
if ([parentPath hasSuffix:@".spritebuilder"])
{
for (NSString* removeItem in removeItems)
{
NSString* removePath = [NSString pathWithComponents:@[parentPath, cocosPath, removeItem]];

if ([fm fileExistsAtPath:removePath])
{
[fm removeItemAtPath:removePath error:&error];
if (error)
{
NSLog(@"WARNING: cleanup failed to remove path at %@ - reason: %@", removePath, error);
}
}
else
{
//NSLog(@"Developer Warning: tried to cleanup non-existent path: %@", removePath);
}
}
}
else
{
NSAssert1(nil, @"Tried to cleanup .ccbproj path whose parent folder doesn't have the .spritebuilder extension: %@", path);
}
}

@end
1 change: 0 additions & 1 deletion SpriteBuilder/ccBuilder/CCBProjectCreator.h
Expand Up @@ -11,6 +11,5 @@
@interface CCBProjectCreator : NSObject

- (BOOL) createDefaultProjectAtPath:(NSString*)fileName engine:(CCBTargetEngine)engine programmingLanguage:(CCBProgrammingLanguage)language;
-(void) cleanupProjectAtPath:(NSString*)fileName;

@end
55 changes: 2 additions & 53 deletions SpriteBuilder/ccBuilder/CCBProjectCreator.m
Expand Up @@ -8,6 +8,7 @@

#import "CCBProjectCreator.h"
#import "AppDelegate.h"
#import "CCBFileUtil.h"

@implementation NSString (IdentifierSanitizer)

Expand Down Expand Up @@ -199,63 +200,11 @@ -(BOOL) createDefaultProjectAtPath:(NSString*)fileName engine:(CCBTargetEngine)e
[apportableConfigurationContents writeToFile:apportableConfigFile atomically:YES encoding:NSUTF8StringEncoding error:&error];

// perform cleanup to remove unnecessary files which only bloat the project
[self cleanupProjectAtPath:fileName];
[CCBFileUtil cleanupSpriteBuilderProjectAtPath:fileName];

return [fm fileExistsAtPath:fileName];
}

-(void) cleanupProjectAtPath:(NSString*)fileName
{
// This list needs to be updated/amended whenever cocos2d introduces new or renames folders whose contents are
// not needed during development of a SpriteBuilder project. See: https://github.com/spritebuilder/SpriteBuilder/issues/915
NSString* cocosPath = @"Source/libs/cocos2d-iphone";
NSArray* removeItems = @[@"build",
@"cocos2d-tests-android",
@"cocos2d-tests-ios.xcodeproj",
@"cocos2d-tests-android",
@"cocos2d-tests-osx.xcodeproj",
@"cocos2d-tests.xcodeproj",
@"cocos2d-ui-tests",
@"Resources",
@"Resources-iPad",
@"Resources-Mac",
@"tools",
@"UnitTests",
@"external/Chipmunk/Demo",
@"external/Chipmunk/doc",
@"external/Chipmunk/doc-src",
@"external/Chipmunk/msvc",
@"external/Chipmunk/xcode",
@"external/ObjectAL/ObjectAL/diagrams",
@"external/ObjectAL/ObjectALDemo",
@"external/ObjectAL/Sample Code",
];

// removing extranous cocos2d-iphone files if existing
NSFileManager* fm = [NSFileManager defaultManager];
NSString* parentPath = [fileName stringByDeletingLastPathComponent];
NSError* error;

for (NSString* removeItem in removeItems)
{
NSString* removePath = [NSString pathWithComponents:@[parentPath, cocosPath, removeItem]];

if ([fm fileExistsAtPath:removePath])
{
[fm removeItemAtPath:removePath error:&error];
if (error)
{
NSLog(@"WARNING: cleanup failed to remove path: %@", removePath);
}
}
else
{
NSLog(@"Developer Warning: tried to cleanup non-existent path: %@", removePath);
}
}
}


- (void) setName:(NSString*)name inFile:(NSString*)fileName search:(NSString*)searchStr
{
NSMutableData *fileData = [NSMutableData dataWithContentsOfFile:fileName];
Expand Down

0 comments on commit 1fa6b50

Please sign in to comment.