Programist135

[New] Cloud9 Editor

May 24th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. -- библиотеки и компоненты
  2.  
  3. local shell = require("shell")
  4. local filesystem = require("filesystem")
  5. local component = require("component")
  6. local gpu = component.gpu
  7.  
  8. -- инициализация конфигов
  9.  
  10. -- установка конфигов.
  11. local function setup()
  12.   print("Настройка.\n")
  13.   io.write("Ваш никнейм в Cloud9: ")
  14.   username = io.read()
  15.   io.write("Название Workspace с файлом: ")
  16.   workspace = io.read()
  17.   io.write("Путь к файлику в Cloud9: ")
  18.   path = io.read()
  19.   if not filesystem.exists("/usr/config") then
  20.     filesystem.makeDirectory("/usr/config")
  21.   end
  22.   cfg_file_saving = io.open("/usr/config/c9tester.cfg", "w")
  23.   --print("Debug: " .. cfg_file_saving)
  24.   cfg_file_saving:write(username .. "\n" .. workspace .. "\n" .. path)
  25.   cfg_file_saving:flush()
  26.   cfg_file_saving:close()
  27.   print("\nНастройка завершена.\n")
  28. end
  29.  
  30. if filesystem.exists("/usr/config/c9tester.cfg") then
  31.   -- другая функция получения строки. Спасибо eu_tomat.
  32.   ls = io.lines("/usr/config/c9tester.cfg")
  33.   username, workspace, path = ls(),ls(),ls()
  34. else
  35.   setup()
  36. end
  37.  
  38. local url = "https://preview.c9users.io/" .. username .. "/" .. workspace .. "/" .. path
  39.  
  40. -- скачиваем файл
  41. shell.execute("wget -f " .. url .. " test2.tmp")
  42. -- выполняем
  43. local result, reason = shell.execute("test2.tmp")
  44.  
  45. -- дЭбаг
  46.  
  47. -- если всё хорошо, то спрашиваем: "Сохранить или нет?!"
  48. if result then
  49.     io.write("Выполнение программы завершено. Вы хотите её сохранить? y/n > ")
  50.     local yorn = io.read()
  51.     if yorn == "y" then
  52.       io.write("Введите имя файла: ")
  53.       local filename = io.read()
  54.       shell.execute("cp test2.tmp " .. filename)
  55.       print("Файл сохранён.")
  56.     end
  57. -- если нет, выдаём ошибку
  58. else
  59.     gpu.setForeground(0xFF0000)
  60.     print("Ошибка выполнения программы: " .. reason)
  61.     gpu.setForeground(0xFFFFFF)
  62. end
  63.  
  64. -- удаляем временный файл
  65. shell.execute("rm test2.tmp")
Advertisement
Add Comment
Please, Sign In to add comment