設置iphone主題 代碼

#define THEME_PLIST_PATH @"/private/var/mobile/Library/Preferences/com.saurik.WinterBoard.plist"

#define THEME_PATH @"/Library/Themes/"

 

#import <Foundation/Foundation.h>

 

NSMutableArray *getThemeInfo()

{

//獲取winterBoardplist信息

NSDictionary *saurikDict = [NSDictionary dictionaryWithContentsOfFile:THEME_PLIST_PATH];

NSMutableArray *themeArr = nil;

if (saurikDict)

{

//獲取theme列表信息

themeArr = [NSMutableArray arrayWithArray: [saurikDict objectForKey:@"Themes"]];

}

return themeArr;

}

 

//設置主題信息

NSMutableArray* changeThemeInfo(NSString* themePath)

{

if ([themePath hasSuffix:@"/"]) 

{

themePath = [themePath substringToIndex:[themePath length]-1];

}

    NSRange range = [themePath rangeOfString:@"/" options:NSBackwardsSearch];

 

NSString *themeName = themePath;

if (range.length > 0 )

themeName = [themeName substringFromIndex:range.location+range.length];

NSMutableArray *themes = getThemeInfo();

BOOL isSameTheme = FALSE;

//判斷主題是否存在於列表中

for (NSMutableDictionary *dict in themes)  

{

NSString *themeStr = [dict objectForKey:@"Name"];

if ([themeStr isEqualToString:themeName])

{

NSString *themeKey = [dict objectForKey:@"Active"];

if (themeKey)

{

[dict setObject:[NSNumber numberWithInt:![themeKey intValue]] forKey:@"Active"];

isSameTheme = YES;

break;

}

}

}

//如果是新主題

if (!isSameTheme)

{

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:TRUE], @"Active", themeName, @"Name", nil];

[themes addObject:dict];

}

return themes;

}

 

//主題應用

void applyTheme(NSString *themePath)

{

NSMutableArray *themes = changeThemeInfo(themePath);

 

NSMutableDictionary *saurikDict = [NSMutableDictionary dictionaryWithContentsOfFile:THEME_PLIST_PATH];

NSLog(@"themes == %@",themes);

if (themes)

{

[saurikDict removeObjectForKey:@"Themes"];

[saurikDict setObject:themes forKey:@"Themes"];

[saurikDict writeToFile:THEME_PLIST_PATH atomically:YES];

system("killall SpringBoard");

}

else 

{

NSLog(@"the array is nil");

}

 

}

 

 

int main(int argc, char *argv[]) 

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

if (argc < 2)

{

NSLog(@"you need a parameter");

}

NSString *themeName = nil;

if (argc == 2)

{

themeName = [NSString stringWithFormat:@"%s",argv[1]];

}

if (themeName == nil)

{

NSLog(@"your parameter is error such as: ./ThemeApply Black  **** Black not '/'");

}

else

{

NSLog(@"themeName === %@",themeName);

applyTheme(themeName);

NSLog(@"apply themeName successfully");

}

[pool release];

return 0;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章