Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FileUtils many bug fixes + test cases

searchPaths works as expected
search in directories work as expected
  • Loading branch information...
commit f3123a0969241c806e71122418e73f7bafe08231 1 parent 037c8b0
Ricardo Quesada ricardoquesada authored
1  Resources/Misc/resources-hd/test4.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-ipad/test2.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-ipadhd/test1.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-iphone/test6.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-mac/test2.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-machd/test1.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-wide/test5.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/resources-widehd/test3.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/searchpath1/file1.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/searchpath2/file2-hd.txt
View
@@ -0,0 +1 @@
+This is a test
1  Resources/Misc/searchpath3/resources-ipad/file3.txt
View
@@ -0,0 +1 @@
+This is a test
36 cocos2d-ios.xcodeproj/project.pbxproj
View
@@ -3110,6 +3110,15 @@
A0E2D75D164ACDC4008E2C6C /* settings-caption-tilt.png in Resources */ = {isa = PBXBuildFile; fileRef = A0E2D724164ACDC4008E2C6C /* settings-caption-tilt.png */; };
A0E2D75E164ACDC4008E2C6C /* settings-caption-touch-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = A0E2D725164ACDC4008E2C6C /* settings-caption-touch-hd.png */; };
A0E2D75F164ACDC4008E2C6C /* settings-caption-touch.png in Resources */ = {isa = PBXBuildFile; fileRef = A0E2D726164ACDC4008E2C6C /* settings-caption-touch.png */; };
+ A0E3E2BD1655E2390073F049 /* resources-hd in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2B71655E2380073F049 /* resources-hd */; };
+ A0E3E2BE1655E2390073F049 /* resources-ipad in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2B81655E2380073F049 /* resources-ipad */; };
+ A0E3E2BF1655E2390073F049 /* resources-ipadhd in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2B91655E2380073F049 /* resources-ipadhd */; };
+ A0E3E2C01655E2390073F049 /* resources-iphone in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2BA1655E2380073F049 /* resources-iphone */; };
+ A0E3E2C11655E2390073F049 /* resources-wide in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2BB1655E2380073F049 /* resources-wide */; };
+ A0E3E2C21655E2390073F049 /* resources-widehd in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2BC1655E2380073F049 /* resources-widehd */; };
+ A0E3E3001655E78E0073F049 /* searchpath1 in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2FD1655E78E0073F049 /* searchpath1 */; };
+ A0E3E3011655E78E0073F049 /* searchpath2 in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2FE1655E78E0073F049 /* searchpath2 */; };
+ A0E3E3021655E78E0073F049 /* searchpath3 in Resources */ = {isa = PBXBuildFile; fileRef = A0E3E2FF1655E78E0073F049 /* searchpath3 */; };
A0E431F31460741E00424477 /* background1-hd.jpg in Resources */ = {isa = PBXBuildFile; fileRef = E0704C29123821EE009C628B /* background1-hd.jpg */; };
A0E431F41460741E00424477 /* background2-hd.jpg in Resources */ = {isa = PBXBuildFile; fileRef = E0704C2A123821EE009C628B /* background2-hd.jpg */; };
A0E431F51460741E00424477 /* background3-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = E04C631512382E6B00A4B3E6 /* background3-hd.png */; };
@@ -6260,6 +6269,15 @@
A0E2D724164ACDC4008E2C6C /* settings-caption-tilt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings-caption-tilt.png"; sourceTree = "<group>"; };
A0E2D725164ACDC4008E2C6C /* settings-caption-touch-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings-caption-touch-hd.png"; sourceTree = "<group>"; };
A0E2D726164ACDC4008E2C6C /* settings-caption-touch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings-caption-touch.png"; sourceTree = "<group>"; };
+ A0E3E2B71655E2380073F049 /* resources-hd */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-hd"; sourceTree = "<group>"; };
+ A0E3E2B81655E2380073F049 /* resources-ipad */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-ipad"; sourceTree = "<group>"; };
+ A0E3E2B91655E2380073F049 /* resources-ipadhd */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-ipadhd"; sourceTree = "<group>"; };
+ A0E3E2BA1655E2380073F049 /* resources-iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-iphone"; sourceTree = "<group>"; };
+ A0E3E2BB1655E2380073F049 /* resources-wide */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-wide"; sourceTree = "<group>"; };
+ A0E3E2BC1655E2380073F049 /* resources-widehd */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "resources-widehd"; sourceTree = "<group>"; };
+ A0E3E2FD1655E78E0073F049 /* searchpath1 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = searchpath1; sourceTree = "<group>"; };
+ A0E3E2FE1655E78E0073F049 /* searchpath2 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = searchpath2; sourceTree = "<group>"; };
+ A0E3E2FF1655E78E0073F049 /* searchpath3 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = searchpath3; sourceTree = "<group>"; };
A0E5F8AD15C1AE5F00D44C32 /* JS Watermelon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "JS Watermelon.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A0E6415A15AB8B8B008735E6 /* Default-Landscape~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Landscape~ipad.png"; path = "bugs/Default-Landscape~ipad.png"; sourceTree = "<group>"; };
A0EB130A164ADFF70027A8A7 /* ccbResources */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ccbResources; sourceTree = "<group>"; };
@@ -9783,6 +9801,15 @@
A0F84194151D406B00EBBFCB /* Misc */ = {
isa = PBXGroup;
children = (
+ A0E3E2FD1655E78E0073F049 /* searchpath1 */,
+ A0E3E2FE1655E78E0073F049 /* searchpath2 */,
+ A0E3E2FF1655E78E0073F049 /* searchpath3 */,
+ A0E3E2B71655E2380073F049 /* resources-hd */,
+ A0E3E2B81655E2380073F049 /* resources-ipad */,
+ A0E3E2B91655E2380073F049 /* resources-ipadhd */,
+ A0E3E2BA1655E2380073F049 /* resources-iphone */,
+ A0E3E2BB1655E2380073F049 /* resources-wide */,
+ A0E3E2BC1655E2380073F049 /* resources-widehd */,
A0F841A9151D419F00EBBFCB /* issue1344-test5-hd.txt */,
A0F841AA151D419F00EBBFCB /* issue1344-test6-ipad.txt */,
A0F841AB151D419F00EBBFCB /* issue1344-test7-ipad.txt */,
@@ -14241,6 +14268,15 @@
A0A1C26415CAEA070058D96F /* Default-Landscape.png in Resources */,
A0579B991601975E00AF8A12 /* Default-568h@2x.png in Resources */,
A0579BCE16019C6000AF8A12 /* Default@2x.png in Resources */,
+ A0E3E2BD1655E2390073F049 /* resources-hd in Resources */,
+ A0E3E2BE1655E2390073F049 /* resources-ipad in Resources */,
+ A0E3E2BF1655E2390073F049 /* resources-ipadhd in Resources */,
+ A0E3E2C01655E2390073F049 /* resources-iphone in Resources */,
+ A0E3E2C11655E2390073F049 /* resources-wide in Resources */,
+ A0E3E2C21655E2390073F049 /* resources-widehd in Resources */,
+ A0E3E3001655E78E0073F049 /* searchpath1 in Resources */,
+ A0E3E3011655E78E0073F049 /* searchpath2 in Resources */,
+ A0E3E3021655E78E0073F049 /* searchpath3 in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
4 cocos2d/CCGLProgram.m
View
@@ -111,8 +111,8 @@ - (id)initWithVertexShaderByteArray:(const GLchar *)vShaderByteArray fragmentSha
- (id)initWithVertexShaderFilename:(NSString *)vShaderFilename fragmentShaderFilename:(NSString *)fShaderFilename
{
- const GLchar * vertexSource = (GLchar*) [[NSString stringWithContentsOfFile:[[CCFileUtils sharedFileUtils] fullPathFromRelativePath:vShaderFilename] encoding:NSUTF8StringEncoding error:nil] UTF8String];
- const GLchar * fragmentSource = (GLchar*) [[NSString stringWithContentsOfFile:[[CCFileUtils sharedFileUtils] fullPathFromRelativePath:fShaderFilename] encoding:NSUTF8StringEncoding error:nil] UTF8String];
+ const GLchar * vertexSource = (GLchar*) [[NSString stringWithContentsOfFile:[[CCFileUtils sharedFileUtils] fullPathIgnoringResolutionsFromRelativePath:vShaderFilename] encoding:NSUTF8StringEncoding error:nil] UTF8String];
+ const GLchar * fragmentSource = (GLchar*) [[NSString stringWithContentsOfFile:[[CCFileUtils sharedFileUtils] fullPathIgnoringResolutionsFromRelativePath:fShaderFilename] encoding:NSUTF8StringEncoding error:nil] UTF8String];
return [self initWithVertexShaderByteArray:vertexSource fragmentShaderByteArray:fragmentSource];
}
4 cocos2d/Support/CCFileUtils.h
View
@@ -137,7 +137,7 @@ enum {
@since v2.1
*/
-@property (nonatomic, copy) NSArray *searchResolutionsOrder;
+@property (nonatomic, copy) NSMutableArray *searchResolutionsOrder;
/** Array of search paths.
You can use this array to modify the search path of the resources.
@@ -147,7 +147,7 @@ enum {
@since v2.1
*/
-@property (nonatomic, copy) NSArray *searchPath;
+@property (nonatomic, copy) NSMutableArray *searchPath;
/** It determines how the "resolution resources" are to be searched.
62 cocos2d/Support/CCFileUtils.m
View
@@ -302,31 +302,6 @@ - (void) buildSearchResolutionsOrder
-(NSString*) pathForResource:(NSString*)resource ofType:(NSString *)ext inDirectory:(NSString *)subpath
{
- // Create full file name with extension)
- NSString* fileName = NULL;
- if (ext && ![ext isEqualToString:@""])
- {
- fileName = [resource stringByAppendingPathExtension:ext];
- }
- else
- {
- fileName = resource;
- }
-
- NSFileManager* fm = [NSFileManager defaultManager];
-
- // Append sub path
- if (subpath && ![subpath isEqualToString:@""])
- {
- fileName = [fileName stringByAppendingPathComponent:subpath];
- }
-
- // Default to non resolution directory
- if ([fm fileExistsAtPath:fileName])
- {
- return fileName;
- }
-
// Default to normal resource directory
return [_bundle pathForResource:resource
ofType:ext
@@ -369,12 +344,10 @@ -(NSString*) getPath:(NSString*)path forSuffix:(NSString*)suffix
if( ! [path isAbsolutePath] ) {
// pathForResource also searches in .lproj directories. issue #1230
- NSString *imageDirectory = [path stringByDeletingLastPathComponent];
-
// If the file does not exist it will return nil.
- ret = [self pathForResource:[newName lastPathComponent]
- ofType:nil
- inDirectory:imageDirectory];
+ ret = [self pathForResource:newName
+ ofType:nil
+ inDirectory:nil];
}
else if( [_fileManager fileExistsAtPath:newName] )
ret = newName;
@@ -393,20 +366,15 @@ -(NSString*) getPath:(NSString*)path forDirectory:(NSString*)directory
// only if it is not an absolute path
if( ! [path isAbsolutePath] ) {
- // pathForResource also searches in .lproj directories. issue #1230
- NSString *imageDirectory = [path stringByDeletingLastPathComponent];
-
+ // pathForResource also searches in .lproj directories. issue #1230
// If the file does not exist it will return nil.
- ret = [self pathForResource:[newName lastPathComponent]
+ ret = [self pathForResource:path
ofType:nil
- inDirectory:imageDirectory];
+ inDirectory:directory];
}
else if( [_fileManager fileExistsAtPath:newName] )
ret = newName;
- if( ! ret )
- CCLOGINFO(@"cocos2d: CCFileUtils: file not found: %@", [newName lastPathComponent] );
-
return ret;
}
@@ -490,12 +458,12 @@ -(NSString*) fullPathFromRelativePath:(NSString*)relPath resolutionType:(ccResol
*resolutionType = value.resolutionType;
return value.fullpath;
}
-
+ BOOL found = NO;
NSString *ret = @"";
for( NSString *path in _searchPath ) {
- NSString *fileWithTheme = [path stringByAppendingPathComponent:relPath];
+ NSString *fileWithPath = [path stringByAppendingPathComponent:relPath];
// Search with Suffixes
for( NSString *device in _searchResolutionsOrder ) {
@@ -503,21 +471,27 @@ -(NSString*) fullPathFromRelativePath:(NSString*)relPath resolutionType:(ccResol
if( _searchMode == kCCFileUtilsSearchSuffix ) {
// Search using suffixes
NSString *suffix = [_suffixesDict objectForKey:device];
- ret = [self getPath:fileWithTheme forSuffix:suffix];
+ ret = [self getPath:fileWithPath forSuffix:suffix];
*resolutionType = [self resolutionTypeForKey:suffix inDictionary:_suffixesDict];
} else {
// Search in subdirectories
NSString *directory = [_directoriesDict objectForKey:device];
- ret = [self getPath:fileWithTheme forDirectory:directory];
+ ret = [self getPath:fileWithPath forDirectory:directory];
*resolutionType = [self resolutionTypeForKey:directory inDictionary:_directoriesDict];
}
- if( ret )
+ if( ret ) {
+ found = YES;
break;
+ }
}
+
+ // there are 2 loops
+ if(found)
+ break;
}
- if( ! ret ) {
+ if( ! found ) {
CCLOGWARN(@"cocos2d: Warning: File not found: %@", relPath);
ret = relPath;
}
8 tests/FileUtilsTest.h
View
@@ -22,3 +22,11 @@
@interface Test1 : FileUtilsDemo
{}
@end
+
+@interface TestResolutionDirectories : FileUtilsDemo
+{}
+@end
+
+@interface TestSearchPath : FileUtilsDemo
+{}
+@end
103 tests/FileUtilsTest.m
View
@@ -14,6 +14,8 @@
static NSString *transitions[] = {
@"Issue1344",
@"Test1",
+ @"TestResolutionDirectories",
+ @"TestSearchPath",
};
Class nextAction(void);
@@ -216,6 +218,99 @@ -(NSString *) subtitle
}
@end
+#pragma mark - TestResolutionDirectories
+
+@implementation TestResolutionDirectories
+-(id) init
+{
+ if ((self=[super init]) ) {
+
+ CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
+
+ NSString *ret;
+ ccResolutionType resolution;
+
+ [sharedFileUtils purgeCachedEntries];
+ [sharedFileUtils setSearchMode:kCCFileUtilsSearchDirectory];
+
+ for( int i=1; i<7; i++) {
+ NSString *filename = [NSString stringWithFormat:@"test%d.txt", i];
+ ret = [sharedFileUtils fullPathFromRelativePath:filename resolutionType:&resolution];
+ NSLog(@"%@ -> %@ (%d)", filename, ret, resolution);
+ }
+
+ }
+ return self;
+}
+
+-(void) onExit
+{
+ [[CCFileUtils sharedFileUtils] setSearchMode:kCCFileUtilsSearchSuffix];
+ [super onExit];
+}
+
+-(NSString*) title
+{
+ return @"FileUtils: resolutions in directories";
+}
+-(NSString *) subtitle
+{
+ return @"See the console";
+}
+@end
+
+#pragma mark - TestSearchPath
+
+@implementation TestSearchPath
+-(id) init
+{
+ if ((self=[super init]) ) {
+
+ CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
+
+ NSString *ret;
+ ccResolutionType resolution;
+
+ [sharedFileUtils purgeCachedEntries];
+ NSMutableArray *searchPath = [sharedFileUtils searchPath];
+
+ [searchPath insertObject:@"searchpath3" atIndex:0];
+ [searchPath insertObject:@"searchpath2" atIndex:0];
+ [searchPath insertObject:@"searchpath1" atIndex:0];
+
+ for( int i=1; i<4; i++) {
+ NSString *filename = [NSString stringWithFormat:@"file%d.txt", i];
+ ret = [sharedFileUtils fullPathFromRelativePath:filename resolutionType:&resolution];
+ NSLog(@"%@ -> %@ (%d)", filename, ret, resolution);
+ }
+ }
+ return self;
+}
+
+-(void) onExit
+{
+
+ CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
+
+ // reset search path
+ [[sharedFileUtils searchPath] removeAllObjects];
+ [[sharedFileUtils searchPath] addObject:@""];
+
+ [sharedFileUtils setSearchMode:kCCFileUtilsSearchSuffix];
+ [super onExit];
+}
+
+-(NSString*) title
+{
+ return @"FileUtils: search path";
+}
+-(NSString *) subtitle
+{
+ return @"See the console";
+}
+@end
+
+
#pragma mark - AppDelegate - iOS
// CLASS IMPLEMENTATIONS
@@ -266,9 +361,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
navController_.navigationBarHidden = YES;
// set the Navigation Controller as the root view controller
- [window_ addSubview:navController_.view];
-// [window_ setRootViewController:navController_]; // iOS6 bug: Needs setRootViewController
-
+ [window_ setRootViewController:navController_];
+
// make main window visible
[window_ makeKeyAndVisible];
@@ -302,7 +396,7 @@ -(void) directorDidReshapeProjection:(CCDirector*)director
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
CCScene *scene = [CCScene node];
[scene addChild: [nextAction() node]];
- [director runWithScene: scene];
+ [director runWithScene:scene];
}
}
@@ -311,7 +405,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return YES;
// return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-
@end
#pragma mark -
Please sign in to comment.
Something went wrong with that request. Please try again.