помогите

rertlop

Участник
Автор темы
47
3
Версия MoonLoader
Другое
хелпаните, нужна помощ в коде.
Почему не работает автообновление? проверял все множество раз, не помогает, помогите пожалуйста



Код:
script_name('test')
script_author('bababab')
script_version('1.0')

require "lib.moonloader"

local dlstatus = require('moonloader').download_status
local inicfg = require("inicfg")
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8



local cfgName = "\\test.ini"

local cfg = inicfg.load({
    main = {
        theme = 0
    },
}, "test")


if not doesFileExist('moonloader/config/test.ini') then inicfg.save(cfg, cfgName) end

local menu = 14
local color = '{00b052}'
local result = imgui.ImInt(cfg.main.theme)


local main_window_state = imgui.ImBool(false)


update_state = false

local script_vers = 1
local script_vers_text = "1.00"

local update_url = "ссыкла"
local update_path = getWorkingDirectory() .. "/update.ini" 

local script_url = "ссылка"
local script_path = thisScript().path



function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    if cfg.main.theme == 0 then themeSettings(0) color = '{ff4747}'
    elseif cfg.main.theme == 1 then themeSettings(1) color = '{9370DB}'
    elseif cfg.main.theme == 2 then themeSettings(2) color = '{F3F3F3}'
    else cfg.main.theme = 0 themeSettings(0) color = '{ff4747}' end

    sampRegisterChatCommand("test", cmd_imgui)
    sampAddChatMessage(''..color..'[test]{ffffff} успешно загружен! Активаия:'..color..' /test ', -1)

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    downloadUrlToFile(update_url, update_path, function(id, status)
        if status == dlstatus.STATUS_ENDDOWNLOADDATA then
            updateIni = inicfg.load(nil, update_path)
            if tonumber(updateIni.info.vers) > script_vers then
                sampAddChatMessage(''..color..'[test] Есть обновление! Версия: ' .. updateIni.info.vers_text, -1)
                update_state = true
            end
            os.remove(update_path)
        end
    end)   


    imgui.Process = false

    -------------------------------------------------------------------

    while true do
      wait(0)

        if update_state then
            downloadUrlToFile(script_url, script_path, function(id, status)
                if status == dlstatus.STATUS_ENDDOWNLOADDATA then
                    sampAddChatMessage(''..color..'[test] Скрипт успешно обновлен!', -1)
                    thisScript():reload()
                end
            end)
            break
        end     

      if main_window_state.v == false then
          imgui.Process = false
      end   
    end
end