Advertisement
kd8lvt

Version Updater API

Apr 21st, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. ------=WARNING=------
  2. --Just a quick warning, this MAY NOT WORK IN ITS CURRENT STATE. I am unable to test it at this exact moment. Thanks!
  3. ------=WARNING=------
  4. --Program Updater API Thingy! Yay!
  5. --This script basically just updates any pastebin program as an API :)
  6. --It could probably be MUCH better. So, yeah. Fun. ANYWAYS...
  7. -------IMPORTANT-------
  8. --Put this little snippet of code in your program that needs auto-updating!
  9. --version = *version* --(only one decimal point may be used. Commas are NOT to be used!)
  10. --function returnVersionAPI()
  11. --  return version
  12. --end
  13. -------IMPORTANT-------
  14. -------NOTE-------
  15. --The functions are written in cronological order of which you should run them!
  16. -------NOTE-------
  17. -------NOTE2-------
  18. --Your Version List MUST have this bit of code for a sort of API!
  19. --=--function getVersion(programName)
  20.   --=--return programName
  21. --=--end
  22. --This basically lets my API intrface your version list. You send my API (for example) "remoteVersion(exampleProgramName)" then your
  23. --version list sends back the version the variable has. So say exampleProgramName's version was 1. Your version list would send back 1,
  24. --as a number. IT MUST BE A NUMBER, NOT A STRING!
  25. -------NOTE2-------
  26. function findVersionList(versionListName)
  27. if fs.exists(versionListName) then
  28.   shell.run("delete ".. versionListName)
  29. end
  30. ---------------
  31. function grabTheVersionList(pastebinCode,versionListName)
  32.   shell.run("pastebin get ".. pastebinCode .." ".. versionListName)
  33. end
  34. ---------------
  35. function remoteVerison(versionListName,programName)
  36.   os.loadAPI(versionListName)
  37.   newVersion = versionlist.getVersion(programName)
  38.   if newVersion not nul then
  39.     return newVersion
  40.     shell.run("delete ".. versionListName)
  41.   else
  42.     return false
  43.   end
  44. end
  45. ---------------
  46. function findTheProgramVersion(programName)
  47.   if fs.exists(programName) then
  48.     os.loadAPI(programName)
  49.     dledVersion = programName.returnVersionAPI()
  50.     if dledVersion not nul then
  51.       return dledVersion
  52.     else
  53.       return false
  54.     end
  55.   end
  56. end
  57. ---------------
  58. function update(dledVersion,newVersion,programName) --This actually updates.
  59.   if dledVersion < newVersion then
  60.     shell.run("delete ".. programName)
  61.     shell.run("pastebin get suVzDDJG".. programName)
  62.     print("Updated from version ".. dledVerison .." to ".. newVerison .."!")
  63.     return "updated"
  64.   elseif dledVersion == newVersion then
  65.     print("You are up to date!")
  66.     return "up to date"
  67.   elseif dledVersion > newVersion then
  68.     print("Somebody forgot to update their version list!")
  69.     return "beta version?"
  70.   end
  71. end
  72. -------EXAMPLE-------
  73. --This example actually updates the updater... makes TOTAL sense, right? :P
  74. --version = 1
  75. os.loadAPI("updater")
  76. updater.findVersionList("versionlist")
  77. updater.grabTheVersionList("HmZ3GzVv","versionList")
  78. remoteVersion = updater.remoteVersion(AutoUpdater)
  79. dledVersion = updater.findTheProgramVersion("updater")
  80. updater.update(dledVersion,remoteVersion,updater)
  81. -------EXAMPLE-------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement