EditProjectWC.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // EditProjectWC.m
  3. // UUTUtils
  4. //
  5. // Created by zhuge on 2017/12/23.
  6. // Copyright © 2017年 zhuge. All rights reserved.
  7. //
  8. #import "EditProjectWC.h"
  9. #import "ProjectInfo.h"
  10. #import "TranslateUtils.h"
  11. #import "PackUtils.h"
  12. #import "AdIdNameUtils.h"
  13. #import "ZGApk.h"
  14. #import "ZGAlert.h"
  15. #import "ZGCommonUtils.h"
  16. #import "ZGFileUtils.h"
  17. #import "ZGApkToolUtils.h"
  18. #import "HttpUtils.h"
  19. #import "ZGJsonUtils.h"
  20. #import "ProjectInfo_Server_AdId.h"
  21. #define TAG_DROPVIEW_ICON 213
  22. #define TAG_DROPVIEW_TOP 214
  23. #define TAG_DROPVIEW_SCREENSHOT 215
  24. @interface EditProjectWC ()
  25. @property (strong) IBOutlet NSArrayController *acXibAdIdArray;
  26. @property (strong) IBOutlet NSArrayController *acPages;
  27. //@property (strong) IBOutlet NSArrayController *acConfigs;
  28. @property (strong) IBOutlet NSArrayController *configsController;
  29. @end
  30. @implementation EditProjectWC
  31. static EditProjectWC* editProjectWC = nil;
  32. - (void)windowDidLoad {
  33. [super windowDidLoad];
  34. self.window.title = [self.projectInfo description];
  35. editProjectWC = self;
  36. [[AdIdNameUtils shared] initWithProjectPath:self.projectInfo];
  37. self.iconDropView.delegate = self;
  38. self.topDropView.delegate = self;
  39. self.screenShotDropView.delegate = self;
  40. [self.projectInfo loadServerData];
  41. if(self.isHttp){
  42. [[[HttpUtils alloc] init] requestAdConfigs:self.projectInfo.server atWindow:self.window];
  43. }else{
  44. [self.projectInfo.server performSelectorOnMainThread:@selector(initWithDic:) withObject:nil waitUntilDone:YES];
  45. }
  46. [self refreshUI_Bean];
  47. }
  48. #pragma mark init & refresh
  49. - (void) refreshUI_Bean {
  50. [self willChangeValueForKey:@"ocBean"];
  51. self.ocBean = [[NSObjectController alloc] initWithContent:self.projectInfo];
  52. [self didChangeValueForKey:@"ocBean"];
  53. }
  54. #pragma mark dropview delegate
  55. - (void)dropImageView:(DropImageView *)dropImageView didSelectFile:(NSString *)filePath {
  56. ProjectInfo_Apk_Image *img = [[ProjectInfo_Apk_Image alloc] initWithPath:filePath];
  57. switch (dropImageView.tag) {
  58. case TAG_DROPVIEW_ICON:
  59. if (img.width != 512 || img.height != 512 || img.fileSize > 1024 * 1024) {
  60. [ZGAlert alertWithMessage:@"设置失败,Icon尺寸512*512,且大小不能超过1M" window:self.window];
  61. } else {
  62. [self.projectInfo.upload setIconWithFilePath:filePath];
  63. }
  64. break;
  65. case TAG_DROPVIEW_TOP:
  66. if (img.width != 1024 || img.height != 500 || img.fileSize > 1024 * 1024) {
  67. [ZGAlert alertWithMessage:@"设置失败,Top尺寸1024*500,且大小不能超过1M" window:self.window];
  68. } else {
  69. [self.projectInfo.upload setTopWithFilePath:filePath];
  70. }
  71. break;
  72. case TAG_DROPVIEW_SCREENSHOT:
  73. if (img.fileSize > 1024 * 1024) {
  74. [ZGAlert alertWithMessage:@"设置失败,图片大小不能超过1M" window:self.window];
  75. } else {
  76. [self.projectInfo.upload addScreenShotWithFilePath:filePath];
  77. }
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. - (void)dropImageView:(DropImageView *)dropImageView didSelectDirectory:(NSString *)dirPath {}
  84. #pragma mark btn
  85. - (IBAction)onTranslateBtn:(id)sender {
  86. [self.projectInfo willChangeValueForKey:@"isTranslateFinished"];
  87. [self.projectInfo willChangeValueForKey:@"isNotTranslateFinished"];
  88. [[[TranslateUtils alloc] init] translate:_projectInfo.local.translate];
  89. [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
  90. NSUserNotification *notification = [[NSUserNotification alloc] init];
  91. notification.title = @"UUTUtils";
  92. notification.informativeText = @"翻译已经完成";
  93. notification.soundName = NSUserNotificationDefaultSoundName;
  94. [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
  95. [self.projectInfo didChangeValueForKey:@"isTranslateFinished"];
  96. [self.projectInfo didChangeValueForKey:@"isNotTranslateFinished"];
  97. }
  98. - (IBAction)onSaveBtn:(id)sender {
  99. if ([self.projectInfo save]) {
  100. NSDictionary* dic = [self.projectInfo.server jsonDic];
  101. if(dic == nil){
  102. [ZGAlert alertWithError:@"保存失败" window:self.window];
  103. }else{
  104. NSString *adStr = [ZGJsonUtils dictionaryToString:dic];
  105. [ZGCommonUtils copyStringToSystemBoard:adStr];
  106. [adStr writeToFile:self.projectInfo.path.adJsonPath atomically:YES encoding:NSUTF8StringEncoding error:NULL];
  107. [ZGAlert alertWithMessage:@"保存成功\n\n临时功能:ad字符串已保存至文件ad.json!" window:self.window];
  108. }
  109. [[AdIdNameUtils shared] save];
  110. } else {
  111. [ZGAlert alertWithError:@"保存失败!" window:self.window];
  112. }
  113. }
  114. - (IBAction)onSendBtn:(id)sender {
  115. if([self.projectInfo save] && [self.projectInfo sendToServerAtWindow:self.window]){
  116. [ZGAlert alertWithMessage:@"上传成功\n" window:self.window];
  117. } else {
  118. [ZGAlert alertWithError:@"上传失败!" window:self.window];
  119. }
  120. }
  121. - (IBAction)onOpenInFinderBtn:(id)sender {
  122. [ZGCommonUtils openFinder:self.projectInfo.path.root];
  123. }
  124. - (IBAction)onUnpackOriApkBtn:(id)sender {
  125. [ZGFileUtils deleteFileOrDirectoryAtPath:self.projectInfo.path.apkCode];
  126. [ZGApkToolUtils unpack:self.projectInfo.upload.oriApkPath toPath:self.projectInfo.path.apkCode];
  127. self.projectInfo.apk = [[ZGApk alloc] initWithPath:self.projectInfo.path.apkCode];
  128. [self.projectInfo.apk.manifest repaireShortPackage];
  129. }
  130. - (IBAction)onPackBtn:(id)sender {
  131. PackUtils *packUtils = [[PackUtils alloc] initWithProjectInfo:self.projectInfo];
  132. [packUtils pack];
  133. }
  134. - (IBAction)onInstallRunBtn:(id)sender {
  135. NSLog(@"%@", self.projectInfo.outputApkFilePath);
  136. if (![ZGFileUtils fileExist:self.projectInfo.outputApkFilePath]) {
  137. [ZGAlert alertWithError:@"没有打包好的apk" window:self.window];
  138. } else {
  139. [ZGApkToolUtils uninstall:self.projectInfo.apk.manifest.package];
  140. [ZGApkToolUtils install:self.projectInfo.outputApkFilePath];
  141. [ZGApkToolUtils run:self.projectInfo.apk.manifest.package activity:self.projectInfo.apk.manifest.mainActivityName];
  142. }
  143. }
  144. - (IBAction)onAcConfigsCopy:(id)sender {
  145. ProjectInfo_Server_AdConfig * adConfig = [self.configsController.selectedObjects firstObject];
  146. ProjectInfo_Server_AdConfig* newAdConfig = [adConfig copy];
  147. [self.configsController insertObject:newAdConfig atArrangedObjectIndex:self.configsController.selectionIndex + 1];
  148. }
  149. - (IBAction)onAdIdCopy:(id)sender {
  150. ProjectInfo_Server_AdId *adId = [[self.acXibAdIdArray selectedObjects] firstObject];
  151. ProjectInfo_Server_AdId *newAdId = [adId copy];
  152. [self.acXibAdIdArray insertObject:newAdId atArrangedObjectIndex:self.acXibAdIdArray.selectionIndex + 1];
  153. }
  154. - (IBAction)onAdPageCopy:(id)sender {
  155. ProjectInfo_Server_AdConfigPage *page = [self.acPages.selectedObjects firstObject];
  156. ProjectInfo_Server_AdConfigPage *newPage = [page copy];
  157. [self.acPages insertObject:newPage atArrangedObjectIndex:self.acPages.selectionIndex + 1];
  158. }
  159. - (IBAction)onExportAdWorthDic:(id)sender {
  160. NSString *str = @"";
  161. for (ProjectInfo_Server_AdId *adid in self.projectInfo.server.xibAdIdArray) {
  162. str = [str stringByAppendingFormat:@"'%@':'%@',\n", adid.adId, adid.idTypeDes_ForAdWorth];
  163. }
  164. NSLog(@"%@", str);
  165. }
  166. #pragma - utils
  167. - (void)setHttpState:(BOOL) isHttp{
  168. self.isHttp = isHttp;
  169. }
  170. + (void)alertWithError:(NSString*) mes{
  171. if(editProjectWC){
  172. [ZGAlert alertWithError:mes window:editProjectWC.window];
  173. }
  174. }
  175. @end