How do you make an updater from http API...
How do you make an updater
Started by IsaacTBeast, Mar 15 2014 04:48 PM
3 replies to this topic
#1
Posted 15 March 2014 - 04:48 PM
#2
Posted 15 March 2014 - 11:05 PM
You can do this with any website, but for what I'm going to say here, we'll use Pastebin.
Make sure you have a pastebin account and are logged in (pastebin.com) as this will ensure you can edit your files. Post all the files you want updateable to pastebin *on the website* whilst logged in. DO NOT USE PASTEBIN PUT!
If you don't already have these files on the computer you're working on, you can download it with pastebin get. Use the FS api to open the file you're going to update. Then, use readAll to put the entire contents into a string. Now, use:
So what have we done? We've:
Make sure you have a pastebin account and are logged in (pastebin.com) as this will ensure you can edit your files. Post all the files you want updateable to pastebin *on the website* whilst logged in. DO NOT USE PASTEBIN PUT!
If you don't already have these files on the computer you're working on, you can download it with pastebin get. Use the FS api to open the file you're going to update. Then, use readAll to put the entire contents into a string. Now, use:
local f = http.get("http://pastebin.com/raw.php?i=PBCODE") --# Opens up the website as if it were a file
local fl = f.readAll() --# Reads the entire contents of the website and places them in a variable
f.close() --# Closes the website
Make sure to replace PBCODE with the code on pastebin, and f and fl with variables of your choice. Then you can simply use: if u ~= fl then --# Checks to see if u (the file we're updating) and fl (the version on pastebin) are the same if not, the other stuff happens.
fs.delete("file") --# So, if they're not the same, delete the old file,
local nf = fs.open("file","w") --# open it back up,
nf.write(fl) --# write the new code to it,
nf.close() --# and close it again.
end
Make sure to replace u with the variable you used at the start for the contents of the file we're updating, fl to the variable you used for the contents of the file on pastebin, file to the name of the file we're updating and nf to the variable of your choice. Repeat for all files you want to update. When you want to update a file, log in to our pastebin account, go into 'my pastes' and edit it.So what have we done? We've:
- Posted a file to pastebin.
- Saved the entire contents of a file to a variable.
- Opened up pastebin and saved the entire contents of the pastebin copy to another variable.
- Compared the pastebin copy to the computer's copy.
- If they weren't the same, we deleted the old copy on the computer and replaced it with the copy on pastebin.
Code for updating an entire folder's contents
Edited by Shnupbups100, 16 March 2014 - 01:00 AM.
#3
Posted 16 March 2014 - 01:57 AM
READ THE COMPUTERCRAFT WIKI! Each API has working examples of how to use each function within them!
#4
Posted 16 March 2014 - 01:58 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











