Reinified

UpdateLogin

Jun 18th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = login/login
  2.  
  3. --pastebin functions
  4. function get_pastebin_id(file_path)
  5.   local file = fs.open(file_path, "r")
  6.   local id = file.readLine():match("--pastebin:([a-zA-Z0-9]*)")
  7.  
  8.   return id
  9. end
  10.  
  11. function get_paste(id)
  12.  
  13.   local response = http.get("http://pastebin.com/raw/" .. textutils.urlEncode(id))
  14.        
  15.   if response then
  16.     local content = response.readAll()
  17.     response.close()
  18.     return content
  19.   else
  20.     printError("Unable to get update. Are you online?")
  21.     error()
  22.   end
  23. end
  24.  
  25. function get_updated_content(file_path)
  26.   if get_pastebin_id(file_path) then --if pastebin
  27.     return get_paste(get_pastebin_id(file_path)) --return updated paste
  28.   else
  29.     print("Unable to find pastebin id. Please do not edit the login file.")
  30.   end
  31. end
  32.  
  33. function update_file(file_path)
  34.   local content = get_updated_content(file_path)
  35.  
  36.   if content then
  37.     local backup_path = file_path .. ".outdated"
  38.  
  39.     if fs.exists(backup_path) then
  40.       print("Backup / Older file exists.")
  41.       print("Would you like to overwrite it?")
  42.       write("[Y/N] ")
  43.       local answer = read()
  44.      
  45.       if answer == "y" or answer == "Y" or answer == "" then
  46.         print("overwriting")
  47.         fs.delete(backup_path)
  48.         fs.move(file_path, file_path .. ".backup")
  49.       else
  50.         print("Cancelled.")
  51.         error()
  52.       end
  53.     else
  54.       fs.move(file_path, file_path .. ".outdated")
  55.     end
  56.     local file = fs.open(file_path, "w")
  57.     file.write(content)
  58.     file.close()
  59.   else
  60.     return
  61.   end
  62. end
  63.  
  64. if args[1] then
  65.   if fs.exists(shell.resolve(args[1])) then
  66.     update_file(shell.resolve(args[1]))
  67.   else
  68.     printError("Where's your login/login file?")
  69.     error()
  70.   end
  71. else
  72.   print("This is the dumbest error in the world and this should never ever happen. Contact me immediately if it does.")
  73.   error()
  74. end
Advertisement
Add Comment
Please, Sign In to add comment