View difference between Paste ID: 08bxKFnE and 1niw24Vd
SHOW: | | - or go back to the newest paste.
1-
updateloop = 0
1+
local update_name = "updateV5"
2-
updateargs = {...} 
2+
3-
--udlstbl = {"updateprogram", "pastelink", "udloc", "startupls", "strtprg"}
3+
4
5-
updateprogram = updateargs[1]
5+
local gui_url = "0UkEdCjY"
6-
pastelink = updateargs[2]
6+
local farm_url = "ZW6q8wWs"
7-
udloc = updateargs[3]
7+
local goto_url = "a3GBewNp"
8-
startupls = updateargs[4]
8+
if fs.exists("AndysPrograms/api"..update_name) == false then
9-
strtprg = updateargs[5]
9+
    fs.makeDir("AndysPrograms/api")
10
    shell.run("cd","AndysPrograms/api")
11-
function printud()
11+
    shell.run("pastebin","get","uBa2UnVT",update_name)
12-
    term.clear()
12+
    shell.run("cd","..")
13-
    term.setCursorPos(1,1)
13+
    shell.run("cd","..")
14-
    print("Updating...")
14+
15
shell.run("AndysPrograms/api/"..update_name, "gui", gui_url, "AndysPrograms/api/gui", "none", "none")
16-
printud()
16+
if fs.exists("AndysPrograms/api/pastebin_silent/ps") == false then
17-
local _, countsl = string.gsub(udloc,"/","")
17+
    fs.makeDir("AndysPrograms/api/pastebin_silent")
18-
countslw = countsl + 1
18+
    shell.run("cd","AndysPrograms/api/pastebin_silent")
19-
for i=1,countslw do
19+
    shell.run("pastebin","get","Zp2CC5qM","ps")
20-
    shell.run("cd", "..")
20+
    shell.run("cd","..")
21-
    printud()
21+
    shell.run("cd","..")
22
    shell.run("cd","..")
23-
numprogargs = 6
23+
24-
if #updateargs > 5 then
24+
25-
    progargs = {}
25+
launcherargs = {...}
26-
    for i=numprogargs,#updateargs do
26+
local farm_prog_progress = "init"
27-
        table.insert(progargs, updateargs[i])
27+
while loadedguilib ~= 1 do
28
    if os.loadAPI("AndysPrograms/api/gui/gui") then
29
        --print("loaded gui lib")
30-
while true do
30+
        loadedguilib = 1
31-
    if fs.isDir(udloc) == false then
31+
    else
32-
        fs.makeDir(udloc)
32+
        print(" NOTloaded gui lib")
33
    end
34-
    shell.run("cd", udloc)
34+
35-
    if fs.exists(udloc.."/"..updateprogram.."new") then
35+
36-
        shell.run("delete",updateprogram.."new") 
36+
function get_running()
37-
        printud()
37+
	return andy_farm_program_running
38
end
39-
    shell.run("pastebin","get",pastelink,updateprogram.."new")
39+
function set_running(n)
40-
    printud()
40+
	andy_farm_program_running = n
41-
    --print(udloc.."/"..updateprogram.."new")
41+
42-
    if fs.exists(udloc.."/"..updateprogram.."new") then
42+
43-
        if fs.exists(udloc.."/"..updateprogram.."old") then
43+
44-
            shell.run("delete",updateprogram.."old")
44+
fudargs = "sleep(5)\nshell.run(\"farm\", \"noset\")"
45-
            printud()
45+
--print (fudargs)
46
--sleep (5)
47-
        if fs.exists(udloc.."/"..updateprogram) then
47+
farmlauncherloop = 1
48-
            shell.run("rename",updateprogram,updateprogram.."old")
48+
stopfarm = 0 
49-
            printud()
49+
errhnd = 0
50
function call_farm()
51-
        shell.run("rename",updateprogram.."new",updateprogram)
51+
    farm.startfarm(launcherargs)
52-
        if fs.exists(udloc.."/"..updateprogram) then
52+
53-
            break
53+
function running_check()
54
    while _G.andy_farm_program_running == 1 do
55
        sleep(0.03)
56-
    if fs.exists(udloc.."/"..updateprogram) then
56+
57-
        if updateloop > 20 then
57+
58-
            break
58+
function para_farm()
59
    parallel.waitForAny(call_farm,running_check)
60
end
61-
    if fs.exists(udloc.."/"..updateprogram.."old") then
61+
62-
        if updateloop > 30 then
62+
function errhndlr(err)
63-
            shell.run("rename",updateprogram.."old",updateprogram)
63+
    if err == "Terminated" then
64-
            if fs.exists(udloc.."/"..updateprogram) then
64+
        stopfarm = 1
65
    else
66
        local dot = 0
67
        -- term.setCursorPos(1, 1) 
68
        -- term.clear()
69-
    updateloop = updateloop + 1
69+
        -- print("Error, Retrying"..dot)
70-
    sleep(0)
70+
        -- term.setCursorPos(1, 3) 
71
        -- print( "Error:",err)
72-
sleep(0)
72+
        -- term.setCursorPos(1, 4)
73-
countslw = countsl + 1
73+
        -- errhnd = 1
74-
for i=1,countslw do
74+
        --sleep(2 / 3)
75-
    shell.run("cd", "..")
75+
        sleep(0)
76-
    printud()
76+
77
end
78-
--print(startupls)
78+
79-
--sleep(10)
79+
80-
if startupls ~= "none" and startupls ~= nil then
80+
local function ud()
81-
    local stu = fs.open("startup.lua", "w")
81+
    shell.run("AndysPrograms/api/"..update_name, "gt", goto_url, "AndysPrograms/api", "none", "none")
82-
    stu.write(startupls)
82+
    shell.run("AndysPrograms/api/"..update_name, "farm", farm_url, "AndysPrograms/farm", "none", "no", unpack(launcherargs))
83-
    stu.close()
83+
84
ud()
85-
if strtprg == nil and strtprg == "no" and strtprg == "none" then
85+
86-
else
86+
87
88-
if progargs ~= nil then
88+
function update_start_farm()
89-
    shell.run(udloc.."/"..updateprogram.." "..unpack(progargs))
89+
    loadedguilib = 0
90-
else
90+
    while loadedguilib ~= 1 do
91-
    shell.run(udloc.."/"..updateprogram)
91+
        if os.loadAPI("AndysPrograms/api/gui/gui") then
92
            --print("loaded gui lib")
93
            loadedguilib = 1
94
        else
95
            print(" NOTloaded gui lib")
96
        end
97
    end
98
    farm_prog_progress = "not not even start"
99
    print(farm_prog_progress)
100
    while stopfarm == 0 do
101
        if _G.andy_farm_program_running == 0 then
102
            sleep(0)
103
            farm_prog_progress = "not even start"
104
            --print(farm_prog_progress)
105
            --print(get_running())
106
            -- while _G.init_gui ~= 1 do
107
                
108
            --     sleep(0.1)
109
            -- end
110
        end
111
        while _G.andy_farm_program_running == 1 do
112
            farm_prog_progress = "little even start"
113
            --print(farm_prog_progress)
114
            if stopfarm == 0 then
115
                farm_prog_progress = "little more start"
116
                --print(farm_prog_progress)
117
                local stu = fs.open("startup.lua", "w")
118
                stu.write(fudargs)
119
                stu.close()
120
                if errhnd == 0 then
121
122
                end
123
                os.loadAPI("AndysPrograms/farm/farm")
124
                if farmlauncherloop > 1 then 
125
                    launcherargs = {"noset"}
126
                end
127
                
128
                if xpcall(para_farm,errhndlr) then
129
                    ud()
130
                else
131
                    -- sleep(2)
132
                    sleep(0)
133
                    errhnd = 0
134
                    ud()
135
                end
136
137
                
138
                if errhnd ~= 0 then
139
                    sleep(0)
140
                    errhnd = 0
141
                end
142
                sleep(0) 
143
                if farmlauncherloop < 10000 then
144
                    farmlauncherloop = farmlauncherloop + 1
145
                end
146
            else
147
                break
148
            end
149
        end
150
    end
151
end
152
153
154
155
local function farm_gui_lau()
156
    gui.start_farm_gui(launcherargs)
157
end
158
159
local function start_farm_lau()
160
    farm_prog_progress = "not not not(3) even start"
161
    --print(farm_prog_progress)
162
    update_start_farm()
163
end
164
local function start_para_lau()
165
    farm_prog_progress = "not not not not(4) even start"
166
    --print(farm_prog_progress)
167
    parallel.waitForAny(farm_gui_lau, start_farm_lau)
168
end
169
170
171
while stopfarm == 0 do
172
    --update_start_farm()
173
    _G.andy_farm_program_running = 0
174
    if launcherargs[1] == "noset" then
175
        _G.andy_farm_program_running = 1
176
    end
177
178
179
    start_para_lau()
180
    stopfarm = 1
181
    --parallel.waitForAny(farm_gui_lau, start_farm_lau)
182
end