Skip to content

Commit b0b62ac

Browse files
author
jrapoport
committed
Support keyed files
Adds support for keyed files as well as more flexible and robust searching. Now you can have “foo”->”bar” in the theme and search all bundles for “foo” of type “dat”, in addition to falling back to the main bundle. If key “foo” is not found, “foo” is assumed to be the file name. Still supports files of keys with the type appended, e.g. “foo.dat” as well as the exiting methods (without type) for backwards compatibility.
1 parent fbd93c0 commit b0b62ac

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

AWLThemeManager/AWLThemeManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
//file path in the current theme bundle
3737
- (NSString*)filePathForFileName:(NSString*)fileName;
38+
- (NSString *)filePathForFileName:(NSString *)fileName ofType:(NSString*) type;
3839
- (NSString*)filePathForFileName:(NSString *)fileName forTheme:(NSString*)themeName;
40+
- (NSString*)filePathForFileName:(NSString *)name ofType:(NSString*) type forTheme:(NSString*)themeName;
3941

4042
@end

AWLThemeManager/AWLThemeManager.m

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,54 @@ - (id)objectForKey:(NSString *)key forTheme:(NSString*)themeName
268268
return obj;
269269
}
270270

271+
//Keep for back compat
271272
- (NSString *)filePathForFileName:(NSString *)fileName
272273
{
273274
return [self filePathForFileName:fileName forTheme:self.currentTheme];
274275
}
275276

276-
- (NSString*)filePathForFileName:(NSString *)fileName forTheme:(NSString*)themeName
277+
- (NSString *)filePathForFileName:(NSString *)fileName ofType:(NSString*) type
277278
{
278-
if ([self isValidString:themeName] == NO || [self isValidString:fileName] == NO) {
279+
return [self filePathForFileName:fileName ofType:type forTheme:self.currentTheme];
280+
}
281+
282+
//Keep for back compat
283+
- (NSString*)filePathForFileName:(NSString *)name forTheme:(NSString*)themeName
284+
{
285+
return [self filePathForFileName:name ofType:nil forTheme:themeName];
286+
}
287+
288+
- (NSString*)filePathForFileName:(NSString *)name ofType:(NSString*) type forTheme:(NSString*)themeName
289+
{
290+
if ([self isValidString:themeName] == NO || [self isValidString:name] == NO) {
279291
return nil;
280292
}
281293

294+
NSString *fileName = [self objectForKey:name forTheme:themeName];
282295

283-
NSFileManager *fileManger = [NSFileManager defaultManager];
284-
NSString *themePath = self.themeList[themeName];
285-
NSString *filePath = [themePath stringByAppendingPathComponent:fileName];
286-
if ([fileManger fileExistsAtPath:filePath] == NO) {
287-
NSString *baseTheme = self.themeRelationship[themeName];
288-
filePath = [self filePathForFileName:fileName forTheme:baseTheme];
296+
if (fileName == nil) {
297+
fileName = name;
298+
}
299+
300+
NSBundle* themeBundle = [NSBundle bundleWithPath:self.themeList[themeName]];
301+
NSString* filePath = [themeBundle pathForResource: fileName ofType: type];
302+
303+
if (filePath == nil) {
304+
NSFileManager *fileManger = [NSFileManager defaultManager];
305+
NSString *themePath = self.themeList[themeName];
306+
NSString *tmpPath = [themePath stringByAppendingPathComponent:name];
307+
if ([fileManger fileExistsAtPath:tmpPath]) {
308+
filePath = tmpPath;
309+
}
310+
else {
311+
NSString *baseTheme = self.themeRelationship[themeName];
312+
filePath = [self filePathForFileName:name ofType:type forTheme:baseTheme];
313+
}
314+
}
315+
316+
if (filePath == nil) {
317+
NSBundle* bundle = [NSBundle mainBundle];
318+
filePath = [bundle pathForResource: fileName ofType: type];
289319
}
290320

291321
return filePath;

0 commit comments

Comments
 (0)