// // EditProjectWC.m // UUTUtils // // Created by zhuge on 2017/12/23. // Copyright © 2017年 zhuge. All rights reserved. // #import "EditProjectWC.h" #import "ProjectInfo.h" #import "TranslateUtils.h" #import "PackUtils.h" #import "AdIdNameUtils.h" #import "ZGApk.h" #import "ZGAlert.h" #import "ZGCommonUtils.h" #import "ZGFileUtils.h" #import "ZGApkToolUtils.h" #import "HttpUtils.h" #import "ZGJsonUtils.h" #import "ProjectInfo_Server_AdId.h" #define TAG_DROPVIEW_ICON 213 #define TAG_DROPVIEW_TOP 214 #define TAG_DROPVIEW_SCREENSHOT 215 @interface EditProjectWC () @property (strong) IBOutlet NSArrayController *acXibAdIdArray; @property (strong) IBOutlet NSArrayController *acPages; //@property (strong) IBOutlet NSArrayController *acConfigs; @property (strong) IBOutlet NSArrayController *configsController; @end @implementation EditProjectWC static EditProjectWC* editProjectWC = nil; - (void)windowDidLoad { [super windowDidLoad]; self.window.title = [self.projectInfo description]; editProjectWC = self; [[AdIdNameUtils shared] initWithProjectPath:self.projectInfo]; self.iconDropView.delegate = self; self.topDropView.delegate = self; self.screenShotDropView.delegate = self; [self.projectInfo loadServerData]; if(self.isHttp){ [[[HttpUtils alloc] init] requestAdConfigs:self.projectInfo.server atWindow:self.window]; }else{ [self.projectInfo.server performSelectorOnMainThread:@selector(initWithDic:) withObject:nil waitUntilDone:YES]; } [self refreshUI_Bean]; } #pragma mark init & refresh - (void) refreshUI_Bean { [self willChangeValueForKey:@"ocBean"]; self.ocBean = [[NSObjectController alloc] initWithContent:self.projectInfo]; [self didChangeValueForKey:@"ocBean"]; } #pragma mark dropview delegate - (void)dropImageView:(DropImageView *)dropImageView didSelectFile:(NSString *)filePath { ProjectInfo_Apk_Image *img = [[ProjectInfo_Apk_Image alloc] initWithPath:filePath]; switch (dropImageView.tag) { case TAG_DROPVIEW_ICON: if (img.width != 512 || img.height != 512 || img.fileSize > 1024 * 1024) { [ZGAlert alertWithMessage:@"设置失败,Icon尺寸512*512,且大小不能超过1M" window:self.window]; } else { [self.projectInfo.upload setIconWithFilePath:filePath]; } break; case TAG_DROPVIEW_TOP: if (img.width != 1024 || img.height != 500 || img.fileSize > 1024 * 1024) { [ZGAlert alertWithMessage:@"设置失败,Top尺寸1024*500,且大小不能超过1M" window:self.window]; } else { [self.projectInfo.upload setTopWithFilePath:filePath]; } break; case TAG_DROPVIEW_SCREENSHOT: if (img.fileSize > 1024 * 1024) { [ZGAlert alertWithMessage:@"设置失败,图片大小不能超过1M" window:self.window]; } else { [self.projectInfo.upload addScreenShotWithFilePath:filePath]; } break; default: break; } } - (void)dropImageView:(DropImageView *)dropImageView didSelectDirectory:(NSString *)dirPath {} #pragma mark btn - (IBAction)onTranslateBtn:(id)sender { [self.projectInfo willChangeValueForKey:@"isTranslateFinished"]; [self.projectInfo willChangeValueForKey:@"isNotTranslateFinished"]; [[[TranslateUtils alloc] init] translate:_projectInfo.local.translate]; [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications]; NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = @"UUTUtils"; notification.informativeText = @"翻译已经完成"; notification.soundName = NSUserNotificationDefaultSoundName; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; [self.projectInfo didChangeValueForKey:@"isTranslateFinished"]; [self.projectInfo didChangeValueForKey:@"isNotTranslateFinished"]; } - (IBAction)onSaveBtn:(id)sender { if ([self.projectInfo save]) { NSDictionary* dic = [self.projectInfo.server jsonDic]; if(dic == nil){ [ZGAlert alertWithError:@"保存失败" window:self.window]; }else{ NSString *adStr = [ZGJsonUtils dictionaryToString:dic]; [ZGCommonUtils copyStringToSystemBoard:adStr]; [adStr writeToFile:self.projectInfo.path.adJsonPath atomically:YES encoding:NSUTF8StringEncoding error:NULL]; [ZGAlert alertWithMessage:@"保存成功\n\n临时功能:ad字符串已保存至文件ad.json!" window:self.window]; } [[AdIdNameUtils shared] save]; } else { [ZGAlert alertWithError:@"保存失败!" window:self.window]; } } - (IBAction)onSendBtn:(id)sender { if([self.projectInfo save] && [self.projectInfo sendToServerAtWindow:self.window]){ [ZGAlert alertWithMessage:@"上传成功\n" window:self.window]; } else { [ZGAlert alertWithError:@"上传失败!" window:self.window]; } } - (IBAction)onOpenInFinderBtn:(id)sender { [ZGCommonUtils openFinder:self.projectInfo.path.root]; } - (IBAction)onUnpackOriApkBtn:(id)sender { [ZGFileUtils deleteFileOrDirectoryAtPath:self.projectInfo.path.apkCode]; [ZGApkToolUtils unpack:self.projectInfo.upload.oriApkPath toPath:self.projectInfo.path.apkCode]; self.projectInfo.apk = [[ZGApk alloc] initWithPath:self.projectInfo.path.apkCode]; [self.projectInfo.apk.manifest repaireShortPackage]; } - (IBAction)onPackBtn:(id)sender { PackUtils *packUtils = [[PackUtils alloc] initWithProjectInfo:self.projectInfo]; [packUtils pack]; } - (IBAction)onInstallRunBtn:(id)sender { NSLog(@"%@", self.projectInfo.outputApkFilePath); if (![ZGFileUtils fileExist:self.projectInfo.outputApkFilePath]) { [ZGAlert alertWithError:@"没有打包好的apk" window:self.window]; } else { [ZGApkToolUtils uninstall:self.projectInfo.apk.manifest.package]; [ZGApkToolUtils install:self.projectInfo.outputApkFilePath]; [ZGApkToolUtils run:self.projectInfo.apk.manifest.package activity:self.projectInfo.apk.manifest.mainActivityName]; } } - (IBAction)onAcConfigsCopy:(id)sender { ProjectInfo_Server_AdConfig * adConfig = [self.configsController.selectedObjects firstObject]; ProjectInfo_Server_AdConfig* newAdConfig = [adConfig copy]; [self.configsController insertObject:newAdConfig atArrangedObjectIndex:self.configsController.selectionIndex + 1]; } - (IBAction)onAdIdCopy:(id)sender { ProjectInfo_Server_AdId *adId = [[self.acXibAdIdArray selectedObjects] firstObject]; ProjectInfo_Server_AdId *newAdId = [adId copy]; [self.acXibAdIdArray insertObject:newAdId atArrangedObjectIndex:self.acXibAdIdArray.selectionIndex + 1]; } - (IBAction)onAdPageCopy:(id)sender { ProjectInfo_Server_AdConfigPage *page = [self.acPages.selectedObjects firstObject]; ProjectInfo_Server_AdConfigPage *newPage = [page copy]; [self.acPages insertObject:newPage atArrangedObjectIndex:self.acPages.selectionIndex + 1]; } - (IBAction)onExportAdWorthDic:(id)sender { NSString *str = @""; for (ProjectInfo_Server_AdId *adid in self.projectInfo.server.xibAdIdArray) { str = [str stringByAppendingFormat:@"'%@':'%@',\n", adid.adId, adid.idTypeDes_ForAdWorth]; } NSLog(@"%@", str); } #pragma - utils - (void)setHttpState:(BOOL) isHttp{ self.isHttp = isHttp; } + (void)alertWithError:(NSString*) mes{ if(editProjectWC){ [ZGAlert alertWithError:mes window:editProjectWC.window]; } } @end