// // ProjectInfo_Upload.m // UUTUtils // // Created by zhuge on 2017/12/27. // Copyright © 2017年 zhuge. All rights reserved. // #import "ProjectInfo_Upload.h" #import "ZGFileUtils.h" #import "ProjectInfo_Path.h" #define key_oriApkPath @"ori_apk_path" #define MARK_ICON @"playstore.png" #define MARK_TOP @"top" #define MARK_SCREENSHOT @"screenshot_" @implementation ProjectInfo_Upload - (ProjectInfo_Upload *)initWithDic:(NSDictionary *)dic path:(ProjectInfo_Path *)path { self.path = path; self.oriApkPath = dic[key_oriApkPath]; self.maScreenShots = [NSMutableArray arrayWithCapacity:0]; if ([ZGFileUtils fileExist:self.path.config.icon]) { self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.icon]; } else { self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath: [[NSBundle mainBundle] pathForResource:@"DropImageHere.png" ofType:nil]]; } if ([ZGFileUtils fileExist:self.path.config.top]) { self.top = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.top]; } else { self.top = [[ProjectInfo_Apk_Image alloc] initWithPath: [[NSBundle mainBundle] pathForResource:@"DropImageHere.png" ofType:nil]]; } NSArray *arrImgs = [ZGFileUtils arrayOfFileAtDir:self.path.config.root extensionFilterArray:@[@"png", @"jpg"]]; for (NSString *imgPath in arrImgs) { NSString *fileName = [imgPath lastPathComponent]; if ([fileName hasPrefix:MARK_SCREENSHOT]) { [self.maScreenShots addObject:[[ProjectInfo_Apk_Image alloc] initWithPath:imgPath]]; } } return self; } - (NSDictionary *)toDic { return @{ key_oriApkPath : self.oriApkPath ? self.oriApkPath : @"" }; } - (void)setIconWithFilePath:(NSString *)filePath { [ZGFileUtils copyFileFromPath:filePath toPath:self.path.config.icon]; self.icon = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.icon]; } - (void)setTopWithFilePath:(NSString *)filePath { [ZGFileUtils copyFileFromPath:filePath toPath:self.path.config.top]; self.top = [[ProjectInfo_Apk_Image alloc] initWithPath:self.path.config.top]; } - (void)addScreenShotWithFilePath:(NSString *)filePath { NSInteger nowHave = [self.maScreenShots count]; NSString *toFilePath = [NSString stringWithFormat:@"%@/%@%02ld.jpg", self.path.config.root, MARK_SCREENSHOT, (nowHave + 1)]; [ZGFileUtils copyFileFromPath:filePath toPath:toFilePath]; [self willChangeValueForKey:@"maScreenShots"]; [self.maScreenShots addObject:[[ProjectInfo_Apk_Image alloc] initWithPath:toFilePath]]; [self didChangeValueForKey:@"maScreenShots"]; } @end