Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local term = require("term")
- local computer = require("computer")
- local shell = require("shell")
- -- Цвета
- local color_background = 0x000000 -- черный фон
- local color_logo = 0xFF7EF2 -- светло-фиолетовый для логотипа
- local color_folder_installed = 0x7BC97E -- цвет директории, в которой скачены все 3 файла
- local color_folder_installing = 0xEBFF08 -- цвет директории, в которой сейчас устанавливается программа
- local color_folder_pending = 0x565656 -- цвет директории, где не установлены все 3 программы
- local color_file_installed = 0x7BC97E -- цвет установленного файла
- local color_file_installing = 0xEBFF08 -- цвет устанавливаемого файла
- local color_file_pending = 0x9E9E9E -- цвет файла, который еще не установлен и ждет своей очереди
- local color_loading_bar = 0xFF00E5 -- цвет загрузки
- local color_loading_bar_fill = 0xFF7EF2 -- цвет заполнения загрузки
- local color_text = 0xFFFFFF
- -- Параметры экрана и отступы
- local resolution_width = 105
- local resolution_height = 29
- local logo_x = 18
- local logo_y = 3
- local header_x = 29
- local header_y = 8
- local progress_bar_x = 24
- local progress_bar_y = 20
- -- Установка разрешения экрана
- gpu.setResolution(resolution_width, resolution_height)
- local screenWidth, screenHeight = gpu.getResolution()
- -- Функция для проверки наличия файла
- local function checkFile(path)
- local file = io.open(path, "r")
- if file then
- io.close(file)
- return true
- else
- return false
- end
- end
- -- Функция для скачивания файла с Pastebin
- local function downloadFile(address, path)
- local result, reason = shell.execute("pastebin get " .. address .. " " .. path)
- return result, reason
- end
- -- Функция для отображения прогресс-бара
- local function displayProgress(progress, total)
- local width = 62 -- Ширина прогресс-бара
- local filled = math.floor((progress / total) * width)
- gpu.setForeground(color_loading_bar)
- gpu.set(progress_bar_x, progress_bar_y, "┌" .. string.rep("─", width) .. "┐")
- gpu.set(progress_bar_x, progress_bar_y + 1, "│" .. string.rep("█", filled) .. string.rep(" ", width - filled) .. "│")
- gpu.set(progress_bar_x, progress_bar_y + 2, "└" .. string.rep("─", width) .. "┘")
- end
- -- Функция для отображения статуса файлов
- local function displayFiles(files, currentDir, currentFile)
- local folderWidth = math.floor(screenWidth / 3)
- local positions = {
- ["/home/"] = {x = folderWidth / 2 - 7, y = 12},
- ["/.lib/"] = {x = folderWidth * 3 / 2 - 7, y = 12},
- ["/etc/"] = {x = folderWidth * 5 / 2 - 7, y = 12}
- }
- for dir, fileList in pairs(files) do
- local pos = positions[dir]
- local x, y = pos.x, pos.y
- local allFilesInstalled = true
- for _, file in ipairs(fileList) do
- if not checkFile(dir .. file.name) then
- allFilesInstalled = false
- break
- end
- end
- local dirColor = allFilesInstalled and color_folder_installed or color_folder_pending
- if dir == currentDir then
- dirColor = color_folder_installing
- end
- gpu.setForeground(dirColor)
- gpu.set(x, y, "┌─" .. dir)
- gpu.set(x, y + 1, "│")
- for i, file in ipairs(fileList) do
- local fullPath = dir .. file.name
- local color = (dir == currentDir and file.name == currentFile) and color_file_installing or
- (checkFile(fullPath) and color_file_installed or color_file_pending)
- gpu.setForeground(color)
- gpu.set(x, y + 1 + i, "◉ " .. file.name)
- end
- gpu.setForeground(dirColor)
- gpu.set(x, y + 1 + #fileList + 1, "└───────────────┘")
- end
- gpu.setForeground(color_text) -- Сброс цвета на белый
- end
- -- Функция для центрирования текста
- local function centerText(y, text, color)
- local textLength = #text
- local x = math.floor((screenWidth - textLength) / 2)
- gpu.setForeground(color)
- gpu.set(x, y, text)
- end
- -- Файлы для проверки и их адреса на Pastebin
- local files = {
- ["/home/"] = {
- {name = "paste.lua", address = "zTNAcwhm"},
- {name = "xedit.lua", address = "zTNAcwhm"},
- {name = "3d.lua", address = "zTNAcwhm"}
- },
- ["/.lib/"] = {
- {name = "header.lua", address = "3BAehD3r"},
- {name = "data.json", address = "kZ8HAxFh"},
- {name = "dkjson.lua", address = "Lm5qcyHU"}
- },
- ["/etc/"] = {
- {name = "boot.lua"},
- {name = "autorun.lua"},
- {name = "config.json"}
- }
- }
- -- Основная логика программы
- gpu.setResolution(resolution_width, resolution_height) -- Установить разрешение экрана
- term.clear() -- Очистка экрана
- gpu.setBackground(color_background)
- -- Отображение логотипа
- gpu.set(logo_x, logo_y, "_______ ______ __ __ _______ _______ _______ _____ _______")
- gpu.set(logo_x, logo_y + 1, "| |_____/ \\_/ |______ | |_____| | | | |______")
- gpu.set(logo_x, logo_y + 2, "|_____ | \\_ | ______| | | | |_____ |_____| ______|")
- -- Отображение подзаголовка
- gpu.set(header_x, header_y, "Восстановление системы. Проверка начальных файлов:")
- -- Анимация установки файлов
- local function installFiles()
- for dir, fileList in pairs(files) do
- for _, file in ipairs(fileList) do
- term.clear()
- -- Отображение логотипа
- gpu.set(logo_x, logo_y, "_______ ______ __ __ _______ _______ _______ _____ _______")
- gpu.set(logo_x, logo_y + 1, "| |_____/ \\_/ |______ | |_____| | | | |______")
- gpu.set(logo_x, logo_y + 2, "|_____ | \\_ | ______| | | | |_____ |_____| ______|")
- -- Отображение подзаголовка
- gpu.set(header_x, header_y, "Восстановление системы. Проверка начальных файлов:")
- -- Отображение файлов
- displayFiles(files, dir, file.name)
- -- Скачивание файла
- if file.address then
- downloadFile(file.address, dir .. file.name)
- end
- -- Отображение прогресс-бара
- local startTime = computer.uptime()
- while (computer.uptime() - startTime) <= 2 do -- Загрузка в течение 2 секунд
- displayProgress(computer.uptime() - startTime, 2)
- os.sleep(0.05) -- Обновление каждые 50 миллисекунд
- end
- displayProgress(2, 2) -- Завершение прогресса
- end
- end
- end
- installFiles()
- centerText(23, "Система будет перезагружена.", color_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement