diff --git a/SpriteBuilder/ccBuilder/CCBFileUtil.h b/SpriteBuilder/ccBuilder/CCBFileUtil.h index 87e6f4b51..bccc04fd4 100644 --- a/SpriteBuilder/ccBuilder/CCBFileUtil.h +++ b/SpriteBuilder/ccBuilder/CCBFileUtil.h @@ -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 diff --git a/SpriteBuilder/ccBuilder/CCBFileUtil.m b/SpriteBuilder/ccBuilder/CCBFileUtil.m index cc2799963..2399061dd 100644 --- a/SpriteBuilder/ccBuilder/CCBFileUtil.m +++ b/SpriteBuilder/ccBuilder/CCBFileUtil.m @@ -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 diff --git a/SpriteBuilder/ccBuilder/CCBProjectCreator.h b/SpriteBuilder/ccBuilder/CCBProjectCreator.h index e3ee29728..5951e45b1 100644 --- a/SpriteBuilder/ccBuilder/CCBProjectCreator.h +++ b/SpriteBuilder/ccBuilder/CCBProjectCreator.h @@ -11,6 +11,5 @@ @interface CCBProjectCreator : NSObject - (BOOL) createDefaultProjectAtPath:(NSString*)fileName engine:(CCBTargetEngine)engine programmingLanguage:(CCBProgrammingLanguage)language; --(void) cleanupProjectAtPath:(NSString*)fileName; @end diff --git a/SpriteBuilder/ccBuilder/CCBProjectCreator.m b/SpriteBuilder/ccBuilder/CCBProjectCreator.m index d42df0000..4b9ec18b9 100644 --- a/SpriteBuilder/ccBuilder/CCBProjectCreator.m +++ b/SpriteBuilder/ccBuilder/CCBProjectCreator.m @@ -8,6 +8,7 @@ #import "CCBProjectCreator.h" #import "AppDelegate.h" +#import "CCBFileUtil.h" @implementation NSString (IdentifierSanitizer) @@ -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];