Commit 6b71aaa3 by Sarkizz

调整更新逻辑

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