if device.is_screen_locked() then device.unlock_screen() sys.msleep(5000) end screen.init(0) local serverip = "124.221.40.166" function main() local dlg = dialog() dlg:timeout(60) dlg:add_input("设备名", device.name()) dlg:add_input("服务器IP", serverip) dlg:add_checkbox("下载选项", {"main", "run", "xxt_lib"}, {"run", "xxt_lib"}) dlg:add_radio("运行选项", {"下载操作", "运行脚本"}, "运行脚本") _, selects = dlg:show() if selects["运行选项"] == "下载操作" then for _,types in ipairs(selects["下载选项"]) do _download("http://"..selects["服务器IP"].."/web/gwdz_tw/"..types..".lua", userPath().."lua/scripts/"..types..".lua") end if #selects["下载选项"] >= 3 then dialog("下载完成,手动再次运行...", 0) os.exit() else sys.toast("下载完成,自动重启脚本...") os.restart() end end if selects["运行选项"] == "运行脚本" then require("xxt_lib") require("run") _renew() _run() end end function _renew() --更新脚本 local lsbl = 0 repeat local code, headers, body = http.get("http://"..selects["服务器IP"].."/web/gwdz_tw/version.txt") if code == 200 then if body ~= nil then local ver = string.atrim(string.strip_utf8_bom(body)) if ver == run_ver then sys.toast("run_版本"..run_ver.."\nxxt_lib_版本:"..lib_ver) lsbl = 1 else sys.toast("当前版本过低,进行脚本更新...") sys.msleep(3000) for _, types in ipairs(selects["下载选项"]) do _download("http://"..selects["服务器IP"].."/web/gwdz_tw/"..types..".lua", userPath().."lua/scripts/"..types..".lua") end sys.toast("更新完成,重启脚本...") sys.msleep(3000) os.restart() end else dialog("web验证版本号不存在...", 0) os.exit() end else sys.msleep(3000) end until lsbl >= 1 end function _download(_webpath,_savepath) --下载 local lsbl = 0 repeat local done, info = http.download(_webpath, _savepath) if (done) then lsbl = 1 sys.msleep(1000) else sys.msleep(5000) end until lsbl >= 1 end main()