This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thegreatstudio's profile picture

How do you make a updater for your program?

Started by thegreatstudio, 01 May 2013 - 09:54 PM
thegreatstudio #1
Posted 01 May 2013 - 11:54 PM
Hey guys! how do you make a updater for your program??
Meeshu #2
Posted 02 May 2013 - 12:17 AM
It depends.
1. Where is the newest version
2. Where is the version you want to update
3. Do you want to update it remotely?
thegreatstudio #3
Posted 02 May 2013 - 12:36 AM
its ok now because I figure it out now :)/>
ryetoc #4
Posted 04 May 2013 - 09:22 PM
share other people might want to know
angellus #5
Posted 05 May 2013 - 12:48 AM
Here is how I did it: I am playing on a server, so I do not have direct access to the file structure. What I did was make pastebin account so I can make and control my own pastes better. Then I wrote a simple update script that delete the old files and redownload them from pastebin everytime it was ran. I wrote it really fast and dirty, but here it is. The first value of the updateInfo is the path-to-file on the machine. The second part if the unique for the paste. The part you would enter for "pastebin get <id>". The second part is if you are updating a turtle. I keep all my computer code on floppys (easy storage), but since turtles cannot always use them, I just copy the relevant code over, if it is a turtle that it is running on.


local count = 2
local updateInfo = {}
updateInfo[1] = { "disk/file1", "URL-ID1" }
updateInfo[2] = { "disk/file2", "URL-ID2" }
local turtleCount = 2
local turtleCopy = {}
turtleCopy[1] = { "disk/fileToTurtle1", "URL-ID3" }
turtleCopy[2] = { "disk/fileToTurtle2", "URL-ID4" }
for x = 1, count do
  print("Removing " .. updateInfo[x][1] .. "...")
  shell.run("rm", updateInfo[x][1])
  print("Downloading new file from " .. updateInfo[x][2] .. " for " .. updateInfo[x][1])
  shell.run("pastebin", "get", updateInfo[x][2], updateInfo[x][1])
end
if (not (turtle == nil)) then
print()
print("Updating turtle...")
for x = 1, turtleCount do
   print("Removing " .. turtleCopy[x][2] .. " from turtle...")
   shell.run("rm", turtleCopy[x][2])
   print("Copying " .. turtleCopy[x][1] .. " to turtle...")
   shell.run("cp", turtleCopy[x][1], turtleCopy[x][2])
end
end

This above code works really well with this startup script to auto update turtles (just place the turtle beside the disk drive with the startup):


if not(turtle == nil) then
  shell.run("update")
end
H4X0RZ #6
Posted 05 May 2013 - 03:33 AM
Improvement:

local version = "x.x.x"
--you need a webhoster for the next thing
local ckeckForUpdate = http.get("http://www.example.com/currentVersion.php") --you have to enter your link
local checkForUpdate = checkForUpdate.readAll()
if not version == checkForUpdate then
--Here comes the download from pastebin
else
print("You have the newest version")
end