summaryrefslogtreecommitdiff
path: root/lua-interface-light.lua
blob: f4a019da3343914fe230d474250eeea929edbfc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
loadmodule "luaiup"
loadmodule "luahandle"

local equivalent_locales = {
    ["French"] = "frFR",
    ["FranÃais"] = "frFR",
    ["fr_FR"] = "frFR",
    ["fr_BE"] = "frFR",
}

local invite_locale = {
    ["default"] = "Please input .paq file to run",
    ["frFR"] = "Saisissez le fichier .paq pour continuer",
}

local ok_locale = {
    ["default"] = "Ok",
    ["frFR"] = "Ok",
}

local quit_locale = {
    ["default"] = "Quit",
    ["frFR"] = "Quitter",
}

local error_not_archive_locale = {
    ["default"] = "Wrong archive file type",
    ["frFR"] = "Mauvais type d'archive .paq",
}

local error_wrong_archive_locale = {
    ["default"] = "Archive doesn't contain archive_main.lua",
    ["frFR"] = "L'archive ne contient pas archive_main.lua",
}

local error_bad_lua_locale = {
    ["default"] = "archive_main.lua doesn't contain a archive_main function",
    ["frFR"] = "archive_main.lua ne contient pas de fonction archive_main",
}

local okay = false
local system_locale

local input_file_text

local function generate_dlg()
    input_file_text = iup.text {
        expand = "Horizontal",
    }
    local input_file_btn = iup.button { title = "..." }
    local invite = invite_locale.default
    system_locale = iup.GetGlobal "SYSTEMLANGUAGE"
    if type(system_locale) == "string" then
        local direct = invite_locale[system_locale]
        if direct then
            invite = direct
        else
            system_locale = equivalent_locales[system_locale]
            if system_locale then
                invite = invite_locale[system_locale]
            else
                system_locale = "default"
            end
        end
    else
        system_locale = "default"
    end
    
    function input_file_btn:action()
        local filedlg = iup.filedlg {
            filter = "*.paq",
            title = invite,
        }
        filedlg:popup()
        
        if filedlg.status + 0 == 0 then
            input_file_text.value = filedlg.value
        end
        
        return iup.DEFAULT
    end
    
    local ok_btn = iup.button { title = ok_locale[system_locale] }
    function ok_btn:action()
        okay = true
        return iup.CLOSE
    end
    local quit_btn = iup.button { title = quit_locale[system_locale] }
    function quit_btn:action()
        return iup.CLOSE
    end
    
    return iup.dialog {
        iup.vbox {
            iup.hbox {
                iup.fill{},
                iup.label { title = "Lua Interface Light", font = "Arial Bold 18" },
                iup.fill{},
            },
            iup.fill { size = "x8" },
            iup.label { title = invite },
            iup.hbox {
                input_file_text,
                input_file_btn,
            },
            iup.fill { size = "x16" },
            iup.hbox {
                ok_btn,
                iup.fill{},
                quit_btn,
                
                normalizesize = "Horizontal",
            }
        },
        
        resize = "No",
        maxbox = "No",
        minbox = "No",
        title = "Lua Interface Light",
        gap = "2",
        defaultesc = quit_btn,
        toolbox = "Yes",
        margin = "10x10",
        size = "200x",
    }
end

function lua_interface_light_main()
    local dlg = generate_dlg()
    
    dlg:show()
    iup.MainLoop()
    dlg:hide()
    
    if not okay then return end
    
    if not pcall(Archive(input_file_text.value)) then
        error(error_not_archive_locale[system_locale])
    end
    if not pcall(load "archive_main.lua") then
        error(error_wrong_archive_locale[system_locale])
    end
    if not type(archive_main) == "function" then
        error(error_bad_lua_locale[system_locale])
    end

    archive_main()
end