//
// ViewController.m
// hhhhh
//
// Created by allan on 2019/5/24.
// Copyright © 2019 allan. All rights reserved.
//
#import "ViewController.h"
#import "YCDownloadDB.h"
NSFileManager *__fm(void) {
return [NSFileManager defaultManager];
}
NSString *__docPath(void) {
return NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
}
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSFileManager *fm = __fm();
NSString *docPath = __docPath();
// 深度搜索
NSArray<NSString *> *subPaths = [fm subpathsAtPath:docPath];
NSLog(@"%@\n\n",subPaths);
NSString *labsSourcePath;
NSString *jsSourcePath;
NSString *imgSourcePath;
NSString *soundSourcePath;
NSString *fontsSourcePath;
for (NSString *subPath in subPaths) {
if ([subPath hasPrefix:[YCDownloadDB tagNameLabs]] && [subPath hasSuffix:[YCDownloadDB tagNameLabs]]) {
labsSourcePath = subPath;
}
if ([subPath hasPrefix:[YCDownloadDB tagNameDist]]) {
if ([subPath hasSuffix:@"js"]) {
jsSourcePath = subPath;
}
if ([subPath hasSuffix:@"img"]) {
imgSourcePath = subPath;
}
if ([subPath hasSuffix:@"sound"]) {
soundSourcePath = subPath;
}
}
if ([subPath hasPrefix:[YCDownloadDB tagNameFonts]] && [subPath hasSuffix:[YCDownloadDB tagNameFonts]]) {
fontsSourcePath = subPath;
}
}
NSString *basePath = docPath;
NSString *js = [basePath stringByAppendingPathComponent:jsSourcePath];
NSString *img = [basePath stringByAppendingPathComponent:imgSourcePath];
NSString *sound = [basePath stringByAppendingPathComponent:soundSourcePath];
NSString *labs = [basePath stringByAppendingPathComponent:labsSourcePath];
NSString *fonts = [basePath stringByAppendingPathComponent:fontsSourcePath];
NSString *kejian = [docPath stringByAppendingPathComponent:@"kejian"];
NSString *commonWebPath = [kejian stringByAppendingPathComponent:@"common_web"];
BOOL isDir;
if (!([fm fileExistsAtPath:commonWebPath isDirectory:&isDir] && isDir)) {
NSError *error;
[fm createDirectoryAtPath:commonWebPath withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"%@", error);
}
if ([fm fileExistsAtPath:commonWebPath isDirectory:&isDir] && isDir) {
NSString *des = [commonWebPath stringByAppendingPathComponent:fonts.lastPathComponent];
[self coverDes:des fromSource:fonts];
}
NSString *desDistPath = [kejian stringByAppendingPathComponent:@"common_web/dist"];
if (!([fm fileExistsAtPath:desDistPath isDirectory:&isDir] && isDir)) {
NSError *error;
[fm createDirectoryAtPath:desDistPath withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"%@", error);
}
if ([fm fileExistsAtPath:desDistPath isDirectory:&isDir] && isDir) {
NSError *error;
[self coverDes:[desDistPath stringByAppendingPathComponent:js.lastPathComponent] fromSource:js];
[self coverDes:[desDistPath stringByAppendingPathComponent:img.lastPathComponent] fromSource:img];
[self coverDes:[desDistPath stringByAppendingPathComponent:sound.lastPathComponent] fromSource:sound];
}
// NSError *error;
// 只返回下一层的子目录
// NSArray<NSString *> *contents = [fm contentsOfDirectoryAtPath:docPath error:&error];
// NSLog(@"%@",contents);
// for (NSString *content in contents) {
// NSString *tmpContent = [docPath stringByAppendingPathComponent:contents];
// BOOL isDir;
// // 存在且是文件夹
// if ([fm fileExistsAtPath:tmpContent isDirectory:&isDir] && isDir) {
// // 移动
// }
// }
NSLog(@"1");
// Do any additional setup after loading the view, typically from a nib.
}
- (void)coverDes:(NSString *)des fromSource:(NSString *)source {
NSFileManager *fm = __fm();
NSError *error;
if ([fm fileExistsAtPath:des]) {
NSString *des1 = [NSString stringWithFormat:@"%@1", des];
[fm moveItemAtPath:des toPath:des1 error:&error];
if (!error) {
[fm copyItemAtPath:source toPath:des error:&error];
if (!error) {
[fm removeItemAtPath:des1 error:&error];
}
}
}
else {
[fm copyItemAtPath:source toPath:des error:&error];
}
NSLog(@"%@", error);
}
@end