Skip to content

Commit 756e7b6

Browse files
committed
Fix #25
Fix crash bug in network cache
1 parent 09979f2 commit 756e7b6

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

RemoteCloud/RemoteCloud/FileCache.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,23 +341,23 @@ public class FileCache {
341341
do {
342342
if let items = try context.fetch(fetchrequest) as? [FileCacheItem], items.count > 0 {
343343
var delItems = [FileCacheItem]()
344-
self.diskQueue.async {
345-
for item in items {
346-
if delSize > incSize {
347-
break
348-
}
349-
guard let target = item.filename?.uuidString else {
350-
continue
351-
}
344+
for item in items {
345+
if delSize > incSize {
346+
break
347+
}
348+
guard let target = item.filename?.uuidString else {
349+
continue
350+
}
351+
delSize += Int(item.chunkSize)
352+
delItems += [item]
353+
self.diskQueue.async {
352354
let target_path = base.appendingPathComponent(String(target.prefix(2)), isDirectory: true).appendingPathComponent(String(target.prefix(4).suffix(2)), isDirectory: true).appendingPathComponent(target)
353355
do {
354356
try FileManager.default.removeItem(at: target_path)
355357
}
356358
catch {
357359
print(error)
358360
}
359-
delSize += Int(item.chunkSize)
360-
delItems += [item]
361361
}
362362
}
363363
for item in delItems {

ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@
748748
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
749749
CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements;
750750
CODE_SIGN_STYLE = Automatic;
751-
CURRENT_PROJECT_VERSION = 66;
751+
CURRENT_PROJECT_VERSION = 67;
752752
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
753753
DEVELOPMENT_TEAM = 7A9X38B4YU;
754754
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
@@ -783,7 +783,7 @@
783783
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
784784
CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements;
785785
CODE_SIGN_STYLE = Automatic;
786-
CURRENT_PROJECT_VERSION = 66;
786+
CURRENT_PROJECT_VERSION = 67;
787787
DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES;
788788
DEVELOPMENT_TEAM = 7A9X38B4YU;
789789
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;

ccViewer/ccViewer/TableViewControllerSetting.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class TableViewControllerSetting: UITableViewController, UITextFieldDelegate {
103103
[NSLocalizedString("Ignore overlay subtiles", comment: ""),
104104
NSLocalizedString("Auto select streams", comment: "")],
105105
[NSLocalizedString("Current cache size", comment: ""),
106-
NSLocalizedString("Cache limit", comment: "")],
106+
NSLocalizedString("Cache limit", comment: ""),
107+
NSLocalizedString("Purge cache", comment: "")],
107108
[NSLocalizedString("View online help", comment: ""),
108109
NSLocalizedString("View privacy policy", comment: ""),
109110
NSLocalizedString("Version", comment: ""),
@@ -302,6 +303,8 @@ class TableViewControllerSetting: UITableViewController, UITextFieldDelegate {
302303
cell.detailTextLabel?.text = NSLocalizedString("Not use", comment: "")
303304
}
304305
cell.accessoryType = .disclosureIndicator
306+
case 2:
307+
break;
305308
default:
306309
break
307310
}
@@ -395,6 +398,8 @@ class TableViewControllerSetting: UITableViewController, UITextFieldDelegate {
395398
}
396399
}
397400
present(contentVC, animated: true, completion: nil)
401+
case 2:
402+
deleteCache()
398403
default:
399404
break
400405
}
@@ -466,7 +471,28 @@ class TableViewControllerSetting: UITableViewController, UITextFieldDelegate {
466471
*/
467472

468473
// MARK: - internal
469-
474+
475+
func deleteCache() {
476+
let alert = UIAlertController(title: NSLocalizedString("Purge cache", comment: ""),
477+
message: NSLocalizedString("Delete all internal cache", comment: ""),
478+
preferredStyle: .alert)
479+
let cancelAction = UIAlertAction(title: NSLocalizedString("Abort", comment: ""), style: .cancel)
480+
let defaultAction = UIAlertAction(title: NSLocalizedString("Delete", comment: ""),
481+
style: .destructive,
482+
handler:{ action in
483+
DispatchQueue.global().async {
484+
CloudFactory.shared.cache.deleteAllCache()
485+
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
486+
self.tableView.reloadData()
487+
}
488+
}
489+
})
490+
alert.addAction(cancelAction)
491+
alert.addAction(defaultAction)
492+
493+
present(alert, animated: true)
494+
}
495+
470496
func deleteAllData() {
471497
let alert = UIAlertController(title: NSLocalizedString("Clear all Auth and Cache", comment: ""),
472498
message: NSLocalizedString("Delete all Auth infomation, Delete all internal cache, Delete all user setting in this app", comment: ""),

0 commit comments

Comments
 (0)