-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQHQResourceManager.m
100 lines (84 loc) · 3.74 KB
/
QHQResourceManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// QHQResourceManager.m
//
// Created by lujianwen on 2018/12/3.
// Copyright © 2018 All rights reserved.
//
#import "QHQResourceManager.h"
#import "QHQUtility.h"
@implementation QHQResourceManager
+ (instancetype)defaultManager {
static QHQResourceManager *_manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_manager = [[QHQResourceManager alloc] init];
});
return _manager;
}
- (void)unpressFileWithPath:(NSString *)filePath {
NSString *fileDir = filePath.stringByDeletingPathExtension;
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]) {
NSBlockOperation *unzipOperation = [NSBlockOperation blockOperationWithBlock:^{
[SSZipArchive unzipFileAtPath:filePath toDestination:fileDir delegate:self];
}];
[[QHQUtility shareOperationQueue] addOperation:unzipOperation];
} else {
NSLog(@"The filePath error... file is not exist...");
}
}
+ (NSData *)fetchResourceWithFilePath:(NSString *)filePath {
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:filePath]) {
return nil;
}
return [fm contentsAtPath:filePath];
}
+ (NSData *)fetchTabBarResourceWithFileName:(NSString *)fileName inFolder:(NSString *)folder{
return [QHQResourceManager fetchResourceWithFilePath:[QHQResourceManager getTabBarResourcePathWithFileName:fileName inFolder:folder]];
}
+ (NSData *)fetchSplashResourceWithFileName:(NSString *)fileName inFolder:(NSString *)folder{
return [QHQResourceManager fetchResourceWithFilePath:[QHQResourceManager getSplashResourcePathWithFileName:fileName inFolder:folder]];
}
+ (NSString *)getTabBarResourcePathWithFileName:(NSString *)fileName inFolder:(NSString *)folder{
NSString *fileDir = [DocumentDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",TabBarResourcePath,folder]];
return [fileDir stringByAppendingPathComponent:fileName];
}
+ (NSString *)getSplashResourcePathWithFileName:(NSString *)fileName inFolder:(NSString *)folder{
NSString *fileDir = [DocumentDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",SplashResourcePath,folder]];
return [fileDir stringByAppendingPathComponent:fileName];
}
+ (BOOL)isExistsOfTabBarResourceWithName:(NSString *)name {
NSString *fileDir = [DocumentDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@",TabBarResourcePath,name]];
return [[NSFileManager defaultManager] fileExistsAtPath:fileDir];
}
+ (void)removeFileWithFilePath:(NSString *)filePath {
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:filePath error:nil];
}
+ (void)removeFilesWithPath:(NSString *)path ignoreFileNames:(NSArray *)fileNames {
NSFileManager * fileManger = [NSFileManager defaultManager];
BOOL isDir = NO;
BOOL isExist = [fileManger fileExistsAtPath:path isDirectory:&isDir];
if (isExist) {
if (isDir) {
NSArray *dirArray = [fileManger contentsOfDirectoryAtPath:path error:nil];
for (NSString *fileName in dirArray) {
if (![fileNames containsObject:fileName]) {
}
}
}else{
NSLog(@"this path is not directory...");
}
}else{
NSLog(@"this path is not exist...");
}
}
#pragma mark - SSZipArchiveDelegate
- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath {
NSString *key = [path lastPathComponent];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
[QHQResourceManager removeFileWithFilePath:path];
}
@end