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

[API] Dropbox "synchronization"

Started by kelevra.1337, 13 February 2014 - 04:14 PM
kelevra.1337 #1
Posted 13 February 2014 - 05:14 PM
Hey everybody,

Recently i started playing on a server and of cause started playing with CC as well. It soon became annoying to get the updated files from my local editor to the server via pastebin so i made a really small util to download stuff from dropbox.

IMPORTANT NOTE:

you get the right dropbox link by clicking on "share link" and replacing "www" with "dl"
ex.
original: https://www.dropbox....dasdas/test.lua
correct: https://dl.dropbox.c...dasdas/test.lua


local Version = 2.7
local dDl = "https://dl.dropbox.com/s/somerandomstring/example.lua"

function getVersion()
return Version
end

function getDl()
return dDl
end

function getUpdate(filename,dl)
local newV = http.get(dl)
local update = fs.open("update","w")
update.write(newV.readAll())
update.close()
fs.move(filename,"old")
fs.move("update",filename)
fs.delete("old")
end

function genUpdater(filename,dl)
if not dl then dl = dDl end
local updater = fs.open("updater","w")
updater.write('local dDl = "'..dl..'" \nfunction getUpdate(filename,dl) \n local newV = http.get(dl) \n local update = fs.open("update","w") \n update.write(newV.readAll()) \n update.close() \n fs.move(filename,"old") \n fs.move("update",filename) \n fs.delete("old") \nend \n')
updater.write('getUpdate("'..filename..'",dDl)')
updater.close()
end

getUpdate will download a file and replaces and old file with it, genUpdater will generate a program called updater. This will one-click update or "sync" the specified file.
I found this usefull on many occasions already and hope someone here will, too

Edit: fixed some stupid mistakes
Edited on 14 February 2014 - 06:47 AM
surferpup #2
Posted 14 February 2014 - 04:22 AM
Cool. I will have to try it.
awsmazinggenius #3
Posted 14 February 2014 - 09:15 AM
No, you get a dropbox download link by replacing www with dl, dropbox.com with dropboxusercontent.com and adding ?dl=1 to the end of the link.
kelevra.1337 #4
Posted 14 February 2014 - 09:19 AM
i dont see your problem, i looked it up and it worked the way i did it.
WorldObserver #5
Posted 16 February 2014 - 03:09 AM
Ok, this is something i was looking for.

I had an idea of a script that re-downloads the lua from pastebin, because you can edit the script and the url code remains the same, but this is a good solution too :)/>

Now i'll give it a try, big thanks for sharing.