123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // ProjectInfo.m
- // UUTUtils
- //
- // Created by zhuge on 2017/12/22.
- // Copyright © 2017年 zhuge. All rights reserved.
- //
- #import "ProjectInfo.h"
- #import "DataUtils.h"
- #import "ZGFileUtils.h"
- #import "CountryInfoManager.h"
- #import "ZGApkToolUtils.h"
- #include "ZGJsonUtils.h"
- #import "HttpUtils.h"
- #import "ProjectInfo_Server_AdId.h"
- #define key_projectType @"project_type"
- #define key_projectName @"project_name"
- #define key_package @"package"
- #define key_local @"local"
- #define key_upload @"upload"
- @implementation ProjectInfo
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.projectType = @"Android";
- self.projectName = @"未命名";
- self.package = @"这是包名";
- }
- return self;
- }
- + (ProjectInfo *)createWithDir:(NSString *)dir {
- ProjectInfo *bean = [[ProjectInfo alloc] init];
- [bean init:dir];
- return bean;
- }
- -(void)init:(NSString *)dir {
- NSString *plist = [NSString stringWithFormat:@"%@/config.plist", dir];
- NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:plist];
- self.projectName = dic[key_projectName];
- self.projectType = dic[key_projectType];
- self.package = dic[key_package];
-
- // path
- self.path = [ProjectInfo_Path create:self.package];
-
- // local
- self.local = [ProjectInfo_Local create:dic[key_local]];
- self.local.translate.path = self.path;
-
- // upload
- self.upload = [[ProjectInfo_Upload alloc] initWithDic:dic[key_upload] path:self.path];
-
- // apk
- self.apk = [[ZGApk alloc] initWithPath:self.path.apkCode];
-
- // fix config
- self.fixConfigs = [[ZGApkFixConfigs alloc] init];
- }
- - (void)loadServerData {
- self.server = [ProjectInfo_Server create:self.package];
- }
- - (void)createKeystoreFile {
- self.path = [ProjectInfo_Path create:self.package];
- NSString *keystore = self.path.config.keystore;
- if (![ZGFileUtils fileExist:keystore]) {
- [ZGFileUtils createDirectoryIfNotExist:self.path.config.root];
- NSString *keystoreName = [ZGApkToolUtils genRandomKeystoreFile:[self.path.config.root stringByAppendingString:@"/"]];
- NSLog(@"创建签名文件[%@]成功!", keystoreName);
- }
- }
- - (BOOL)save {
- @try {
- NSString *rootPath = self.path.root;
- [ZGFileUtils createDirectoryIfNotExist:rootPath];
- NSString *plist = self.path.configPlist;
- NSMutableDictionary *md = [NSMutableDictionary dictionaryWithCapacity:0];
- md[key_projectType] = self.projectType;
- md[key_projectName] = self.projectName;
- md[key_package] = self.package;
- if (self.local) {
- md[key_local] = [self.local toDic];
- }
- if (self.upload) {
- md[key_upload] = [self.upload toDic];
- }
- [md writeToFile:plist atomically:YES];
- } @catch (NSException *exception) {
- NSLog(@"%@", exception.callStackSymbols);
- return false;
- }
- return true;
- }
- - (BOOL)sendToServerAtWindow:(NSWindow *)window {
- @try {
- NSDictionary *dic = [self.server jsonDic];
- if(dic == nil){
- return false;
- }
- NSString *serverStr = [ZGJsonUtils dictionaryToString:dic];
- // NSLog(@"%@", serverStr);
- [[[HttpUtils alloc] init] saveAdConfigs:serverStr forPackage:self.package atWindow:window];
- } @catch (NSException *exception) {
- NSLog(@"%@", exception.callStackSymbols);
- return false;
- }
- return true;
- }
- #pragma mark out
- - (BOOL)isTranslateFinished {
- NSString *path = self.path.config.translate;
- // 翻译目录下的文件数量与配置里的相同,说明翻译是成功的
- if ([ZGFileUtils fileExist:path]) {
- NSArray *arrTxts = [ZGFileUtils arrayOfFileAtDir:path extensionFilterArray:@[@"txt"]];
- CountryInfoManager *cim = [[CountryInfoManager alloc] init];
- return [arrTxts count] == [[cim countryInfos] count];
- }
- return NO;
- }
- - (BOOL)isNotTranslateFinished {
- return ![self isTranslateFinished];
- }
- - (NSString *)outputApkFilePath {
- return [NSString stringWithFormat:@"%@/%@_%@.apk", self.path.output, self.projectName, self.apk.yml.versionName];
- }
- - (NSString *)description {
- return [NSString stringWithFormat:@"【%@】【%@】【%@】", self.projectType, self.projectName, self.package];
- }
- #pragma mark - 按类型过滤广告id
- - (NSArray<ProjectInfo_Server_AdId *> *)allAdmobAdIds {
- NSMutableArray<ProjectInfo_Server_AdId*> *ma = [[NSMutableArray alloc] initWithCapacity:0];
- for (ProjectInfo_Server_AdId *adid in self.server.xibAdIdArray) {
- if ([adid isAdmob]) {
- [ma addObject:adid];
- }
- }
- return ma;
- }
- - (NSArray<ProjectInfo_Server_AdId *> *)allFacebookAdIds {
- NSMutableArray<ProjectInfo_Server_AdId*> *ma = [[NSMutableArray alloc] initWithCapacity:0];
- for (ProjectInfo_Server_AdId *adid in self.server.xibAdIdArray) {
- if ([adid isFacebook]) {
- [ma addObject:adid];
- }
- }
- return ma;
- }
- @end
|