ProjectInfo_Upload.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // ProjectInfo_Upload.m
  3. // UUTUtils
  4. //
  5. // Created by zhuge on 2017/12/27.
  6. // Copyright © 2017年 zhuge. All rights reserved.
  7. //
  8. #import "ProjectInfo_Upload.h"
  9. #import "ZGFileUtils.h"
  10. #import "ProjectInfo_Path.h"
  11. #define key_oriApkPath @"ori_apk_path"
  12. #define MARK_ICON @"playstore.png"
  13. #define MARK_TOP @"top"
  14. #define MARK_SCREENSHOT @"screenshot_"
  15. @implementation ProjectInfo_Upload
  16. - (ProjectInfo_Upload *)initWithDic:(NSDictionary *)dic path:(ProjectInfo_Path *)path {
  17. self.path = path;
  18. self.oriApkPath = dic[key_oriApkPath];
  19. self.maScreenShots = [NSMutableArray arrayWithCapacity:0];
  20. if ([ZGFileUtils fileExist:self.path.config.icon]) {
  21. self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.icon];
  22. } else {
  23. self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath: [[NSBundle mainBundle] pathForResource:@"DropImageHere.png" ofType:nil]];
  24. }
  25. if ([ZGFileUtils fileExist:self.path.config.top]) {
  26. self.top = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.top];
  27. } else {
  28. self.top = [[ProjectInfo_Apk_Image alloc] initWithPath: [[NSBundle mainBundle] pathForResource:@"DropImageHere.png" ofType:nil]];
  29. }
  30. NSArray *arrImgs = [ZGFileUtils arrayOfFileAtDir:self.path.config.root extensionFilterArray:@[@"png", @"jpg"]];
  31. for (NSString *imgPath in arrImgs) {
  32. NSString *fileName = [imgPath lastPathComponent];
  33. if ([fileName hasPrefix:MARK_SCREENSHOT]) {
  34. [self.maScreenShots addObject:[[ProjectInfo_Apk_Image alloc] initWithPath:imgPath]];
  35. }
  36. }
  37. return self;
  38. }
  39. - (NSDictionary *)toDic {
  40. return @{
  41. key_oriApkPath : self.oriApkPath ? self.oriApkPath : @""
  42. };
  43. }
  44. - (void)setIconWithFilePath:(NSString *)filePath {
  45. [ZGFileUtils copyFileFromPath:filePath toPath:self.path.config.icon];
  46. self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.icon];
  47. }
  48. - (void)setTopWithFilePath:(NSString *)filePath {
  49. [ZGFileUtils copyFileFromPath:filePath toPath:self.path.config.top];
  50. self.top = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.top];
  51. }
  52. - (void)addScreenShotWithFilePath:(NSString *)filePath {
  53. NSInteger nowHave = [self.maScreenShots count];
  54. NSString *toFilePath = [NSString stringWithFormat:@"%@/%@%02ld.jpg", self.path.config.root, MARK_SCREENSHOT, (nowHave + 1)];
  55. [ZGFileUtils copyFileFromPath:filePath toPath:toFilePath];
  56. [self willChangeValueForKey:@"maScreenShots"];
  57. [self.maScreenShots addObject:[[ProjectInfo_Apk_Image alloc] initWithPath:toFilePath]];
  58. [self didChangeValueForKey:@"maScreenShots"];
  59. }
  60. @end