Browse Source

热更新 新增文件和删除文件

gongyan 3 years ago
parent
commit
c75f84e005

+ 13 - 3
LuaDemo/Assets/BundleResource/LuaScripts/Update/SUpdateManager.lua.txt

@@ -200,12 +200,22 @@ function SUpdateManager.tryCalcUpdateResInfoLogic()
     local willDownloadFileList = {}
     for _, oneFileInfo in pairs(rVersionInfo.fileInfo) do
         local lFile = localResourceCache[oneFileInfo.fileName]
-        if lFile ~= nil and lFile.hashInfo ~= oneFileInfo.hashInfo then
+        -- lFile == nil => add file     edit file
+        if lFile == nil or (lFile ~= nil and lFile.hashInfo ~= oneFileInfo.hashInfo) then
             willDownloadFileCount = willDownloadFileCount + 1
             willDownloadBytes = willDownloadBytes + oneFileInfo.fileSize
             willDownloadFileList[oneFileInfo.fileName] = oneFileInfo
         end
+        -- remove file
+        localResourceCache[oneFileInfo.fileName] = nil
     end
+
+    for _, removeFileInfo in pairs(localResourceCache) do
+        willDownloadFileCount = willDownloadFileCount + 1
+        willDownloadBytes = willDownloadBytes + removeFileInfo.fileSize
+        willDownloadFileList[removeFileInfo.fileName] = removeFileInfo
+    end
+
     SUpdateManager._willDownloadBytes = willDownloadBytes
     SUpdateManager._willDownloadFileList = willDownloadFileList
     SUpdateManager._willDownloadFileCount = willDownloadFileCount
@@ -272,7 +282,7 @@ function SUpdateManager.tryDownloadResourceLogic()
             downloadSpeed = CS.SFramework.SToolFunctionR.GetDownloadSpeed(fileDownloadBytes, CS.UnityEngine.Time.realtimeSinceStartup - downloadStartTime)
             -- update download info to show information.
             local stateMessage = string.format(
-                "Downloading: %s From %s \nPercent: %d Speed:%s",
+                "Downloading: %s From %s \nPercent: %.2f Speed:%s",
                 fileName, donwloadLink, downloadPercent * 100, downloadSpeed
             )
             eventDispatchCenter:DispatchEvent(eventDispatchCenter.EventType.UPDATE_STATE_INFO, stateMessage)
@@ -324,7 +334,7 @@ function SUpdateManager.tryFinishLogic()
     LoadResource("scenes/start.unity")
     --LoadResource("scenes/gameb.unity")
     --CS.UnityEngine.SceneManagement.SceneManager.LoadScene("GameA")
-    CS.UnityEngine.SceneManagement.SceneManager.LoadScene("GameA")
+    CS.UnityEngine.SceneManagement.SceneManager.LoadScene("Start")
 end
 
 function SUpdateManager.ProcessUpdate()