Commit dc7ad5d5 by Sarkizz

修正更新逻辑

parent c81b5c4d
......@@ -116,7 +116,7 @@ open class MRUpdateManager: NSObject {
}
/// 重置www文件夹。从bundle中覆盖沙盒的www
open func resetFilesFolder() {
open func resetFilesFolder(_ completion: (() -> Void)? = nil) {
asyncIfNeeded {
if let bundleWWW = self.bundleWWWURL {
if !self.settings.sandboxSrc.isURLExists(true) {
......@@ -127,6 +127,7 @@ open class MRUpdateManager: NSObject {
self.sandboxUpdateURL.syncDelete()
self.sandboxBackupURL.syncDelete()
}
completion?()
}
}
......@@ -219,7 +220,11 @@ extension MRUpdateManager {
/// 移除backup文件夹,并且从update文件夹中更新www文件
/// - Parameter complate: 回调
public func updateFromLocal(_ complate:((_ error: Error?) -> Void)?) {
sandboxBackupURL.syncDelete()
if sandboxBackupURL.isURLExists() {
sandboxBackupURL.syncDeleteItems(filter: nil)
} else {
sandboxBackupURL.syncCreate()
}
if let error = sandboxWWWURL.syncMoveItems(to: sandboxBackupURL) {
complate?(error)
} else {
......@@ -235,9 +240,11 @@ extension MRUpdateManager {
/// 检查传入文件路径的完整性,如果不完整,从bundle中获取www覆盖沙盒中的www
/// - Parameter file: 需要检查的文件路径
public func recoverFromBundleIfFileIncomplete(_ file: URL) {
public func recoverFromBundleIfFileIncomplete(_ file: URL, completion: (() -> Void)? = nil) {
if !checkFilesIntegrity(file) {
resetFilesFolder()
resetFilesFolder(completion)
} else {
completion?()
}
}
}
......@@ -317,7 +324,7 @@ extension MRUpdateManager {
var isUpdateError = false
for i in 0 ..< infos.count {
let info = infos[i]
let p = Float(i)/Float(infos.count)
let p = Float(i)/Float(infos.count-1)
let fileURL = updateURL.appendingPathComponent(info.fileName)
//Step 2
......@@ -326,11 +333,13 @@ extension MRUpdateManager {
continue
}
//先创建必要的文件路径
self.createFolder(with: info.fileName, in: updateURL)
//Step 3
let fileURLInWWW = wwwURL.appendingPathComponent(info.fileName)
if fileURLInWWW.isURLExists(),
self.isSameHash(with: fileURLInWWW, hash: info.fileHash) {
self.createFolder(with: info.fileName, in: updateURL)
let distURL = fileURL.deletingLastPathComponent()
if fileURLInWWW.syncCopy(to: distURL) == nil,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment