未验证 提交 2b32e581 编写于 作者: Y yixiangboy 提交者: GitHub

Merge pull request #18 from toss156/master

修复清理本地数据问题和优化文件名过长时的展示
......@@ -45,8 +45,8 @@
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"确定要删除本地数据") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *homeDir = NSHomeDirectory();
[DoraemonUtil clearFileWithPath:homeDir];
[weakSelf.cellBtn renderUIWithRightContent:@"正在清理中"];
[DoraemonUtil clearLocalDatas];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.cellBtn renderUIWithRightContent:[self getHomeDirFileSize]];
});
......
......@@ -56,8 +56,9 @@
self.fileTypeIcon.frame = CGRectMake(kDoraemonSizeFrom750(32), [[self class] cellHeight]/2-self.fileTypeIcon.doraemon_height/2, self.fileTypeIcon.doraemon_width, self.fileTypeIcon.doraemon_height);
self.fileTitleLabel.text = model.name;
self.fileTitleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
[self.fileTitleLabel sizeToFit];
self.fileTitleLabel.frame = CGRectMake(self.fileTypeIcon.doraemon_right+kDoraemonSizeFrom750(32), [[self class] cellHeight]/2-self.fileTitleLabel.doraemon_height/2, DoraemonScreenWidth-120, self.fileTitleLabel.doraemon_height);
self.fileTitleLabel.frame = CGRectMake(self.fileTypeIcon.doraemon_right+kDoraemonSizeFrom750(32), [[self class] cellHeight]/2-self.fileTitleLabel.doraemon_height/2, DoraemonScreenWidth-150, self.fileTitleLabel.doraemon_height);
DoraemonUtil *util = [[DoraemonUtil alloc] init];
[util getFileSizeWithPath:model.path];
......
......@@ -48,6 +48,7 @@
- (void)initUI{
self.title = DoraemonLocalizedString(@"沙盒浏览器");
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.bigTitleView.doraemon_bottom, self.view.doraemon_width, self.view.doraemon_height-self.bigTitleView.doraemon_bottom) style:UITableViewStylePlain];
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
......
......@@ -39,4 +39,6 @@
//删除某一路径下的所有文件
+ (void)clearFileWithPath:(NSString *)path;
+ (void)clearLocalDatas;
@end
......@@ -169,7 +169,27 @@
//删除某一路径下的所有文件
+ (void)clearFileWithPath:(NSString *)path{
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:path error:nil];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
for (NSString *file in files) {
NSError *error;
NSString *filePath = [path stringByAppendingPathComponent:file];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
if (!error) {
NSLog(@"remove file: %@", file);
}
}
}
}
+ (void)clearLocalDatas {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *homePath = NSHomeDirectory();
NSArray *folders = @[@"Documents", @"Library", @"tmp"];
for (NSString *folder in folders) {
[DoraemonUtil clearFileWithPath:[homePath stringByAppendingPathComponent:folder]];
}
});
}
@end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册