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

Need help making my program updater

Started by Dutch, 06 April 2015 - 09:06 AM
Dutch #1
Posted 06 April 2015 - 11:06 AM
Hello, I recently made a program updater. But I want it to ONLY update when there is a new version available. How can I do this?

Pastebin Link: http://pastebin.com/Me7bcBiB

Updater Code:
Spoiler


term.setBackgroundColor(colors.lightGray) -- Sets the background color
term.clear() -- Clears the screen
term.setCursorPos(1,1) -- Resets the position of the cursor

textutils.slowPrint("Welcome to Dutch's Update Program,") -- Slowly prints a message to the screen
textutils.slowPrint("Or DUP for short.")
sleep(2) -- Puts a pause between the commands
print(" ")
textutils.slowPrint("Using this Program you can easily Update")
textutils.slowPrint("any supported Program!")
sleep(2)
print(" ")

if fs.exists("dpps") == true then
	textutils.slowPrint("The following Programs were detected:")
	sleep(1)
	continue = true
else
	textutils.slowPrint("No supported Programs detected")
	print(" ")
	sleep(2)
	textutils.slowPrint("Exiting...")
	sleep(1)
	term.setBackgroundColor(colors.black)
	term.clear()
	term.setCursorPos(1,1)
end

if continue == true then

	if fs.exists("dpps") == true then -- Checks for the DPPS file
		textutils.slowPrint("Dutch's Password Protection System")
	end

	print(" ")
	sleep(2)
	textutils.slowWrite("Do you want to update Y/N: ") -- Slowly prints a message to your screen and allowing you to type in a string
	local event, key = os.pullEvent( "key" )
entered = key
	while 2>1 do -- Creates an infinite loop

		if entered == keys.y then
			print(" ")
			textutils.slowPrint("Updating...")
			fs.delete("dpps") -- Deletes the old DPPS
			print(" ")
			shell.run("pastebin get E0ptaFmE dpps") -- Downloads the new DPPS
			print(" ")
			sleep(2)
			textutils.slowPrint("Done Updating!")
			print(" ")
			sleep(2)
			textutils.slowPrint("Thanks for using DUP!")
			print(" ")
			sleep(2)
			textutils.slowWrite("Press any key to exit!")
			os.pullEvent("key") -- Waits for you to press a key
			term.setBackgroundColor(colors.black)
			term.clear()
			term.setCursorPos(1,1)
		break -- Stops the loop

		elseif entered == keys.n then
			print(" ")
			textutils.slowPrint("Thanks for using DUP!")
			print(" ")
			sleep(2)
			textutils.slowWrite("Press any key to exit!")
			os.pullEvent("key")
			term.setBackgroundColor(colors.black)
			term.clear()
			term.setCursorPos(1,1)
		break

		end

	end

end


(P.S. I am a ComputerCraft noob)
HPWebcamAble #2
Posted 06 April 2015 - 04:09 PM
You could have a pastebin that has the current version number, and another that actually has the latest program version

When the program goes to update, it checks the first pastebin, and compares its version with the pastebin. If the pastebin is newer, then it downloads the full program file.
Edited on 06 April 2015 - 02:10 PM