6 posts
Location
term.getPlayerLocation("Zacklogan")
Posted 17 January 2014 - 01:27 PM
Hi, I have a question. How would I go about creating an auto updater so it downloads the program then checks if its the same as the other download they did before and if it is not, it will replace the older one with the newest one. This would help me a lot.
Kind Regards,
zacklogan.
571 posts
Location
Some Fish Bowl in Ohio.
Posted 17 January 2014 - 01:50 PM
I'm pretty sure it is something like this.
As the program states, this isn't tested.
--THIS IS NOT TESTED--
local function versionCheck()
if version ~= 1.0 then
print"A new version is available. Would you like to download it?"
vConf = read()
if vConf == "Y" then
print"shell.run pastebin files go here"
else
print"Oh, nevermind"
end
local version = 1.0 --Makes a version
versionCheck()
print"This is a program."
print"Notice the version in the first line."
52 posts
Location
Void
Posted 17 January 2014 - 02:24 PM
Hi, I have a question. How would I go about creating an auto updater so it downloads the program then checks if its the same as the other download they did before and if it is not, it will replace the older one with the newest one. This would help me a lot.
Kind Regards,
zacklogan.
local function dofile (filename) -- we need this later.
local f = assert(loadfile(filename))
return f()
end
local function get(paste) -- This function is from pastebin program.
local response = http.get(
"http://pastebin.com/raw.php?i="..textutils.urlEncode( paste )
)
if response then
--print( "Success." )
local sResponse = response.readAll()
response.close()
return sResponse
else
print( "Update failed." )
end
end
local version = "1.6" -- Put the version in here.
local pastetoget = "ENTERYOURPASTEIDHERE" -- Enter your paste
local dataweneed = get(pastetoget)
if string.find( dataweneed, 'local version = "'..version..'"' ) then -- This if part can be commented out if you want to disable UPDATES on your own computer.
-- if you are coding it in-game etc.
-- If this happens, our program found a different version on pastebin
local handsofthedead = fs.open(".updatedprog","w")
handsofthedead.write(dataweneed)
handsofthedead.close()
fs.move(shell.getRunningProgram(),"noneedanymore")
fs.move(".updatedprog",shell.getRunningProgram() )
fs.delete("noneedanymore")
-- Process ends after here. Update done. TADAA.
-- We should add some kind of thing so user knows wtf happened
print("The program updated.")
dofile(shell.getRunningProgram())
return
end
The code above can be perfectly fine.
PS: If you are coding in-game, you will have to comment the line with checkver().
Edited on 17 January 2014 - 01:25 PM
8543 posts
Posted 17 January 2014 - 02:30 PM
This sort of thing is generally a bad idea. Updating should be a user-initiated task, especially if you are checking for updates by downloading a file from a site like pastebin rather than your own hosting.
52 posts
Location
Void
Posted 17 January 2014 - 02:46 PM
This sort of thing is generally a bad idea. Updating should be a user-initiated task, especially if you are checking for updates by downloading a file from a site like pastebin rather than your own hosting.
Why not?
6 posts
Location
term.getPlayerLocation("Zacklogan")
Posted 17 January 2014 - 06:10 PM
Thanks for all who posted. It helped a lot. An admin/mod can go ahead and lock this topic.
Kind Regards,
Zacklogan.
8543 posts
Posted 17 January 2014 - 08:01 PM
This sort of thing is generally a bad idea. Updating should be a user-initiated task, especially if you are checking for updates by downloading a file from a site like pastebin rather than your own hosting.
Why not?
Because it's rude to uselessly hammer websites you don't own, repeatedly downloading a file that very rarely changes just to see if it's changed.