Commit dc7ad5d5 by Sarkizz

修正更新逻辑

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