Commit 6b71aaa3 by Sarkizz

调整更新逻辑

parent 75aa1dcc
......@@ -117,18 +117,16 @@ open class MRUpdateManager: NSObject {
/// 重置www文件夹。从bundle中覆盖沙盒的www
open func resetFilesFolder(_ completion: (() -> Void)? = nil) {
asyncIfNeeded {
if let bundleWWW = self.bundleWWWURL {
if !self.settings.sandboxSrc.isURLExists(true) {
self.settings.sandboxSrc.syncCreate()
}
bundleWWW.syncCopy(to: self.settings.sandboxSrc)
self.sandboxUpdateURL.syncDelete()
self.sandboxBackupURL.syncDelete()
if let bundleWWW = self.bundleWWWURL {
if !self.settings.sandboxSrc.isURLExists(true) {
self.settings.sandboxSrc.syncCreate()
}
completion?()
bundleWWW.syncCopy(to: self.settings.sandboxSrc)
self.sandboxUpdateURL.syncDelete()
self.sandboxBackupURL.syncDelete()
}
completion?()
}
deinit {
......@@ -173,46 +171,34 @@ extension MRUpdateManager {
}
}
/// 检查本地文件是否有更新。
/// 根据传入类型更新本地文件。此方法总是同步执行
/// - Parameter type: 更新类型
/// - Parameter complate: 回调
public func checkLocalUpdate(_ type: UpdateType,
public func localUpdate(_ type: UpdateType,
complate: ((_ manager: MRUpdateManager, _ error: Error?) -> Void)?) {
switch type {
case .appUpgrade:
if let bundleWWW = bundleWWWURL {
asyncIfNeeded {
var error: Error?
if self.sandboxUpdateURL.isURLExists(true) {
error = self.sandboxUpdateURL.syncDelete()
}
if error == nil && self.sandboxBackupURL.isURLExists(true) {
error = self.sandboxBackupURL.syncDelete()
}
if error == nil {
error = bundleWWW.syncCopy(to: self.sandboxSrcURL)
}
self.asyncInMain {
complate?(self, error)
}
var error: Error?
if self.sandboxUpdateURL.isURLExists(true) {
error = self.sandboxUpdateURL.syncDelete()
}
} else {
asyncInMain {
complate?(self, self.error(code: -1, msg: "目录路径错误"))
if error == nil && self.sandboxBackupURL.isURLExists(true) {
error = self.sandboxBackupURL.syncDelete()
}
}
case .silence:
let operations = {
self.updateFromLocal { (error) in
self.asyncInMain {
complate?(self, error)
}
if error == nil {
error = bundleWWW.syncCopy(to: self.sandboxSrcURL)
}
complate?(self, error)
} else {
complate?(self, self.error(code: -1, msg: "目录路径错误"))
}
asyncIfNeeded {
operations()
case .silence:
self.updateFromLocal { (error) in
complate?(self, error)
}
default:
complate?(self, nil)
break
}
}
......@@ -351,6 +337,7 @@ extension MRUpdateManager {
fileURL.syncDelete()
if let data = try? Data(contentsOf: info.downloadURL),
data.md5 == info.fileHash,
data.syncWrite(to: fileURL) == nil {
progressBlock(p)
} else {
......
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