EcpmConfigInitWC.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // EcpmConfigInitWC.m
  3. // UUTUtils2.1
  4. //
  5. // Created by zhuge on 2020/7/14.
  6. // Copyright © 2020 dym. All rights reserved.
  7. //
  8. #import "EcpmConfigInitWC.h"
  9. #import "EcpmConfigInit.h"
  10. #import "NSString+NSString_CountryCode.h"
  11. #import "EcpmInitBean.h"
  12. #import "AdIdNameUtils.h"
  13. #import "AdIdNameInCSVUtils.h"
  14. #import "EcpmConfigInitExporter.h"
  15. #import "ZGCommonUtils.h"
  16. @interface EcpmConfigInitWC ()
  17. @property (strong) EcpmConfigInit *config;
  18. @property (weak) IBOutlet NSTextField *tf_admob;
  19. @property (weak) IBOutlet NSTextField *tf_facebook;
  20. @property (weak) IBOutlet NSTextField *lb_admob;
  21. @property (weak) IBOutlet NSTextField *lb_facebook;
  22. @property (weak) IBOutlet NSTableView *tv_admob;
  23. @property (strong) NSArrayController *ac_admob;
  24. @property (weak) IBOutlet NSTableView *tv_facebook;
  25. @property (strong) NSArrayController *ac_facebook;
  26. @end
  27. @implementation EcpmConfigInitWC
  28. - (void)windowDidLoad {
  29. [super windowDidLoad];
  30. // 设置Title
  31. self.window.title = [self.projectInfo description];
  32. // 绑定名字
  33. [[AdIdNameUtils shared] initWithProjectPath:self.projectInfo];
  34. [[AdIdNameInCSVUtils shared] initWithProjectPath:self.projectInfo];
  35. // 加载Server数据
  36. [self.projectInfo loadServerData];
  37. [self.projectInfo.server initWithDic:nil];
  38. // csv文件配置
  39. self.config = [[EcpmConfigInit alloc] init];
  40. // 检测ecpm文件
  41. [self onTextChanged_admob:nil];
  42. [self onTextChanged_facebook:nil];
  43. // admob名字配置
  44. NSArray<ProjectInfo_Server_AdId*> *arrAdmobIds = [self.projectInfo allAdmobAdIds];
  45. NSMutableArray<EcpmInitBean*> *maAdmobBean = [[NSMutableArray alloc] initWithCapacity:0];
  46. for (ProjectInfo_Server_AdId *adid in arrAdmobIds) {
  47. EcpmInitBean *bean = [[EcpmInitBean alloc] initWithAdId:adid];
  48. [maAdmobBean addObject:bean];
  49. }
  50. self.ac_admob = [[NSArrayController alloc] initWithContent:maAdmobBean];
  51. // facebook 名字配置
  52. NSMutableArray<EcpmInitBean*> *maFacebookBean = [NSMutableArray arrayWithCapacity:0];
  53. for (ProjectInfo_Server_AdId *adid in [self.projectInfo allFacebookAdIds]) {
  54. EcpmInitBean *bean = [[EcpmInitBean alloc] initWithAdId:adid];
  55. [maFacebookBean addObject:bean];
  56. }
  57. self.ac_facebook = [[NSArrayController alloc] initWithContent:maFacebookBean];
  58. // 绑定表格
  59. NSArray *arrProperties = @[@"idIndex", @"adName", @"adId", @"worthMul", @"nameInCSV"];
  60. NSDictionary *dicOptions = @{
  61. NSContinuouslyUpdatesValueBindingOption : @(YES)
  62. };
  63. for (NSString *property in arrProperties) {
  64. NSString *keyPath = [NSString stringWithFormat:@"arrangedObjects.%@", property];
  65. [[self.tv_admob tableColumnWithIdentifier:property] bind:NSValueBinding toObject:self.ac_admob withKeyPath:keyPath options:dicOptions];
  66. [[self.tv_facebook tableColumnWithIdentifier:property] bind:NSValueBinding toObject:self.ac_facebook withKeyPath:keyPath options:dicOptions];
  67. }
  68. }
  69. #pragma mark - 文本框
  70. - (IBAction)onTextChanged_admob:(id)sender {
  71. self.config.isAdmobOK = NO;
  72. self.lb_admob.stringValue = @"";
  73. NSString *path = self.tf_admob.stringValue;
  74. NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  75. NSArray *arrLines = [content componentsSeparatedByString:@"\n"];
  76. if (arrLines.count >= 1) {
  77. NSString *firstLine = [arrLines firstObject];
  78. NSArray *arr = [firstLine componentsSeparatedByString:@","];
  79. if (arr.count == 3) {
  80. self.config.isAdmobOK = YES;
  81. self.lb_admob.stringValue = @"ok";
  82. } else {
  83. self.lb_admob.stringValue = @"列数不对";
  84. }
  85. } else {
  86. if (sender == nil) {
  87. self.tf_admob.stringValue = @"";
  88. self.lb_admob.stringValue = @"csv拖入文本框后按回车";
  89. } else {
  90. self.lb_admob.stringValue = @"文件为空";
  91. }
  92. }
  93. }
  94. - (IBAction)onTextChanged_facebook:(id)sender {
  95. self.config.isFacebookOK = NO;
  96. self.lb_facebook.stringValue = @"";
  97. NSString *path = self.tf_facebook.stringValue;
  98. NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  99. NSArray *arrLines = [content componentsSeparatedByString:@"\n"];
  100. if (arrLines.count >= 1) {
  101. NSString *firstLine = [arrLines firstObject];
  102. NSArray *arr = [firstLine componentsSeparatedByString:@","];
  103. if (arr.count == 3) {
  104. self.config.isFacebookOK = YES;
  105. self.lb_facebook.stringValue = @"ok";
  106. } else {
  107. self.lb_facebook.stringValue = @"列数不对";
  108. }
  109. } else {
  110. if (sender == nil) {
  111. self.tf_facebook.stringValue = @"";
  112. self.lb_facebook.stringValue = @"csv拖入文本框后按回车";
  113. } else {
  114. self.lb_facebook.stringValue = @"文件为空";
  115. }
  116. }
  117. }
  118. #pragma mark - 按钮
  119. - (IBAction)onBtnExport:(id)sender {
  120. NSString *str = [self.config isCanExport];
  121. if ([str isEqualToString:@"ok"]) {
  122. EcpmConfigInitExporter *exporter = [[EcpmConfigInitExporter alloc] init];
  123. NSString *str = [exporter doExport:self.projectInfo admobFilePath:self.tf_admob.stringValue facebookFilePath:self.tf_facebook.stringValue];
  124. [str writeToFile:self.projectInfo.path.adWorthJsonPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  125. [ZGCommonUtils openFinder:self.projectInfo.path.adWorthJsonPath];
  126. } else {
  127. NSLog(@"%@", str);
  128. }
  129. }
  130. // 保存广告Id在csv中的名字
  131. - (IBAction)onBtnSave:(id)sender {
  132. [[AdIdNameInCSVUtils shared] save];
  133. }
  134. @end