Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- библиотеки и компоненты
- local shell = require("shell")
- local filesystem = require("filesystem")
- local component = require("component")
- local gpu = component.gpu
- -- инициализация конфигов
- -- установка конфигов.
- local function setup()
- print("Настройка.\n")
- io.write("Ваш никнейм в Cloud9: ")
- username = io.read()
- io.write("Название Workspace с файлом: ")
- workspace = io.read()
- io.write("Путь к файлику в Cloud9: ")
- path = io.read()
- if not filesystem.exists("/usr/config") then
- filesystem.makeDirectory("/usr/config")
- end
- cfg_file_saving = io.open("/usr/config/c9tester.cfg", "w")
- --print("Debug: " .. cfg_file_saving)
- cfg_file_saving:write(username .. "\n" .. workspace .. "\n" .. path)
- cfg_file_saving:flush()
- cfg_file_saving:close()
- print("\nНастройка завершена.\n")
- end
- if filesystem.exists("/usr/config/c9tester.cfg") then
- -- другая функция получения строки. Спасибо eu_tomat.
- ls = io.lines("/usr/config/c9tester.cfg")
- username, workspace, path = ls(),ls(),ls()
- else
- setup()
- end
- local url = "https://preview.c9users.io/" .. username .. "/" .. workspace .. "/" .. path
- -- скачиваем файл
- shell.execute("wget -f " .. url .. " test2.tmp")
- -- выполняем
- local result, reason = shell.execute("test2.tmp")
- -- дЭбаг
- -- если всё хорошо, то спрашиваем: "Сохранить или нет?!"
- if result then
- io.write("Выполнение программы завершено. Вы хотите её сохранить? y/n > ")
- local yorn = io.read()
- if yorn == "y" then
- io.write("Введите имя файла: ")
- local filename = io.read()
- shell.execute("cp test2.tmp " .. filename)
- print("Файл сохранён.")
- end
- -- если нет, выдаём ошибку
- else
- gpu.setForeground(0xFF0000)
- print("Ошибка выполнения программы: " .. reason)
- gpu.setForeground(0xFFFFFF)
- end
- -- удаляем временный файл
- shell.execute("rm test2.tmp")
Advertisement
Add Comment
Please, Sign In to add comment