caihong_client/lua_probject/base_project/Game/ExtendHotupdate.lua

173 lines
6.2 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local function __ShowTip(_version_view,text, callback)
local ctr_state = _version_view:GetController("state")
ctr_state.selectedIndex = 1
_version_view:GetChild("tex_tip").text = text
_version_view:GetChild("btn_ok").onClick:Set(function()
ctr_state.selectedIndex = 0
if (callback ~= null) then
callback:DynamicInvoke()
end
end)
local btn_close = _version_view:GetChild("btn_close")
if btn_close then
btn_close.onClick:Set(function()
_version_view:Dispose()
_version_view = nil
end)
end
end
local function __update_check_size(data, onback, _version_view)
print("===================updateCheck")
local tex_tip = _version_view:GetChild("tex_info")
local totalSize = 0
for k, game_data in ipairs(data) do
local asset_path = game_data["bundle"]:gsub("\r\n", "")
asset_path = string.gsub(asset_path, "%.", "/")
local local_version = Version.DEFUALT
local server_version = Version(game_data["version"])
local version_update = Hotupdate(asset_path .. "/", local_version, server_version)
version_update.AssetName = game_data["name"]
version_update:SetTipCallback(function(text, callback)
__ShowTip(_version_view, text, callback)
end)
version_update:LoadAssetSize()
local onesize = 100/#data
while (not version_update.Done) do
_version_view:GetChild("pb_progress").value = onesize * (k-1) + onesize * version_update.Progress
coroutine.step()
end
game_data["size"] = version_update.Size
totalSize = totalSize + version_update.Size
end
onback(totalSize, true)
end
local function __update_check(data, onback, _version_view)
print("===================updateCheck")
local tex_tip = _version_view:GetChild("tex_info")
local download_size = 0
for k, game_data in ipairs(data) do
local asset_path = game_data["bundle"]:gsub("\r\n", "")
asset_path = string.gsub(asset_path, "%.", "/")
local local_version = Version.DEFUALT
local server_version = Version(game_data["version"])
local version_update = Hotupdate(asset_path .. "/", local_version, server_version)
version_update.AssetName = game_data["name"]
version_update:SetTipCallback(function(text,callback)
__ShowTip(_version_view,text, callback)
end)
version_update:LoadAsset()
while (not version_update.Done) do
if game_data["size"] then
printlog("lingmeng down", download_size, version_update.Progress, game_data["size"])
onback(
download_size + (version_update.Progress > 1 and 1 or version_update.Progress) * game_data["size"],
false)
else
onback(version_update.Progress, false)
tex_tip.text = version_update.TextTip
end
coroutine.step()
end
download_size = download_size + game_data["size"]
ResourcesManager.ReadAssetConfig(asset_path)
end
onback(1, true)
end
ExtendHotupdate = {
-- 正常
VERSION_NORMAL = 0,
-- 下载
VERSION_DOWN = 1,
-- 更新
VERSION_UPDATE = 2,
}
function ExtendHotupdate.UpdateGameList(list, callback)
if (not GameApplication.Instance.buildApp) then
callback()
return
end
local _version_view = UIPackage.CreateObjectFromURL("ui://Hotupdate/Version")
_version_view.x = (GRoot.inst.width - _version_view.width) / 2
_version_view:GetChild("tex_info").text = "正在检查资源中。。。"
local _pd = _version_view:GetChild("pb_progress")
_pd.value = 0
GRoot.inst:AddChild(_version_view)
local toltal_size = 0
coroutine.start(__update_check_size, list, function(totalSize, finish)
if (finish) then
toltal_size = totalSize
coroutine.start(__update_check, list, function(progress, finish)
if (finish) then
_pd.value = 100
callback()
_version_view:Dispose()
_version_view = nil
else
_pd.value = progress / toltal_size * 100
_version_view:GetChild("tex_info").text = string.format("正在下载资源(%.1fMB / %.1fMB", progress / 1024 / 1024,
toltal_size / 1024 / 1024)
end
end, _version_view)
end
end, _version_view)
end
function ExtendHotupdate.UpdateGame(data,callback)
if (not GameApplication.Instance.buildApp) then
ExtendManager.UpdateExtend(data)
if callback then callback() end
return
end
ViewUtil.CloseModalWait()
NetResetConnectWindow.CloseNetReset()
local _version_view = UIPackage.CreateObjectFromURL("ui://Common/ExtendHotUpdate")
_version_view:GetChild("tex_info").text = "正在检查资源中。。。"
local _pd = _version_view:GetChild("pb_progress")
_pd.value = 0
_version_view:AddRelation(GRoot.inst, RelationType.Size)
GRoot.inst:AddChild(_version_view)
_version_view:MakeFullScreen()
coroutine.start(__update_check,{data}, function(progress, finish)
_pd.value = progress * 100
if (finish) then
ExtendManager.UpdateExtend(data)
if callback then callback() end
_version_view:Dispose()
end
end, _version_view)
end
function ExtendHotupdate.CheckVersion(game_data)
if (not GameApplication.Instance.buildApp) then
ExtendManager.UpdateExtend(game_data)
return ExtendHotupdate.VERSION_NORMAL
end
if (not game_data) then
return ExtendHotupdate.VERSION_DOWN
end
local asset_path = game_data.bundle
asset_path = string.gsub(asset_path,'%.', '/')
local local_version = Hotupdate.GetLocalVersion(asset_path.. "/")
local server_version =Version(game_data.version)
if not local_version then
return ExtendHotupdate.VERSION_DOWN
end
if local_version:ContainAll(server_version) then
return ExtendHotupdate.VERSION_UPDATE
end
ResourcesManager.ReadAssetConfig(asset_path)
ExtendManager.UpdateExtend(game_data)
return ExtendHotupdate.VERSION_NORMAL
end