Advertisement
Tag365

Whistler Script System Installer

Oct 26th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local MainVersionURL = "http://pastebin.com/raw.php?i=Lw73Vfin"
  2. local TestingVersionURL = ""
  3. local MainDownloadURL = "http://pastebin.com/raw.php?i=NuLBhBL3"
  4. local TestingDownloadURL = ""
  5.  
  6. local function outOfSpaceError()
  7.     error("Not enough free space available.", 0)
  8. end
  9.  
  10. local function createFolderForFile(path)
  11.     local curpath = path
  12.     local startHere = 1
  13.     while true do
  14.         local nextSlash = string.find(string.sub(path, startHere, -1), "/")
  15.         if not nextSlash then return end
  16.         nextSlash = nextSlash + startHere
  17.         local folderToCreate = string.sub(curpath, 0, nextSlash - 1)
  18.         if not fs.isDir(folderToCreate) then
  19.             local ok, err = pcall(fs.makeDir, folderToCreate)
  20.             if not ok then
  21.                 if string.find(err, "Out of space") then
  22.                     outOfSpaceError()
  23.                 end
  24.             end
  25.         end
  26.         startHere = nextSlash
  27.     end
  28. end
  29.  
  30. local function installWhistler()
  31.     print("Downloading Whistler.data...")
  32.     local handle = http.get(MainDownloadURL)
  33.     print("Loading folder structure...")
  34.     folderStructureS = handle.readAll()
  35.     handle.close()
  36.     local folderStructure = textutils.unserialize(folderStructureS)
  37.     for key, value in pairs(folderStructure) do
  38.         createFolderForFile(key)
  39.         print("Opening "..key.."...")
  40.         local file = fs.open(key, "w")
  41.         if file then
  42.             file.write(value)
  43.             local ok, err = pcall(file.close)
  44.             if not ok then
  45.                 if string.find(err, "Out of space") then
  46.                     outOfSpaceError()
  47.                 end
  48.             end
  49.         end
  50.         sleep()
  51.     end
  52.     print("Updating startup file...")
  53.     local handle = fs.open("startup", "a") or fs.open("startup", "w")
  54.     if handle then
  55.         handle.write('shell.run("Whistler/startup")')
  56.         handle.close()
  57.     end
  58.     print("Starting...")
  59.     shell.run("Whistler/startup")
  60. end
  61.  
  62. installWhistler()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement