Advertisement
crococrystal

crystal-os.lua

Jun 22nd, 2024 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local term = require("term")
  4. local computer = require("computer")
  5. local shell = require("shell")
  6.  
  7. -- Цвета
  8. local color_background = 0x000000 -- черный фон
  9. local color_logo = 0xFF7EF2 -- светло-фиолетовый для логотипа
  10. local color_folder_installed = 0x7BC97E -- цвет директории, в которой скачены все 3 файла
  11. local color_folder_installing = 0xEBFF08 -- цвет директории, в которой сейчас устанавливается программа
  12. local color_folder_pending = 0x565656 -- цвет директории, где не установлены все 3 программы
  13. local color_file_installed = 0x7BC97E -- цвет установленного файла
  14. local color_file_installing = 0xEBFF08 -- цвет устанавливаемого файла
  15. local color_file_pending = 0x9E9E9E -- цвет файла, который еще не установлен и ждет своей очереди
  16. local color_loading_bar = 0xFF00E5 -- цвет загрузки
  17. local color_loading_bar_fill = 0xFF7EF2 -- цвет заполнения загрузки
  18. local color_text = 0xFFFFFF
  19.  
  20. -- Параметры экрана и отступы
  21. local resolution_width = 105
  22. local resolution_height = 29
  23. local logo_x = 18
  24. local logo_y = 3
  25. local header_x = 29
  26. local header_y = 8
  27. local progress_bar_x = 24
  28. local progress_bar_y = 20
  29.  
  30. -- Установка разрешения экрана
  31. gpu.setResolution(resolution_width, resolution_height)
  32. local screenWidth, screenHeight = gpu.getResolution()
  33.  
  34. -- Функция для проверки наличия файла
  35. local function checkFile(path)
  36.     local file = io.open(path, "r")
  37.     if file then
  38.         io.close(file)
  39.         return true
  40.     else
  41.         return false
  42.     end
  43. end
  44.  
  45. -- Функция для скачивания файла с Pastebin
  46. local function downloadFile(address, path)
  47.     local result, reason = shell.execute("pastebin get " .. address .. " " .. path)
  48.     return result, reason
  49. end
  50.  
  51. -- Функция для отображения прогресс-бара
  52. local function displayProgress(progress, total)
  53.     local width = 62  -- Ширина прогресс-бара
  54.     local filled = math.floor((progress / total) * width)
  55.     gpu.setForeground(color_loading_bar)
  56.     gpu.set(progress_bar_x, progress_bar_y, "┌" .. string.rep("─", width) .. "┐")
  57.     gpu.set(progress_bar_x, progress_bar_y + 1, "│" .. string.rep("█", filled) .. string.rep(" ", width - filled) .. "│")
  58.     gpu.set(progress_bar_x, progress_bar_y + 2, "└" .. string.rep("─", width) .. "┘")
  59. end
  60.  
  61. -- Функция для отображения статуса файлов
  62. local function displayFiles(files, currentDir, currentFile)
  63.     local folderWidth = math.floor(screenWidth / 3)
  64.     local positions = {
  65.         ["/home/"] = {x = folderWidth / 2 - 7, y = 12},
  66.         ["/.lib/"] = {x = folderWidth * 3 / 2 - 7, y = 12},
  67.         ["/etc/"] = {x = folderWidth * 5 / 2 - 7, y = 12}
  68.     }
  69.  
  70.     for dir, fileList in pairs(files) do
  71.         local pos = positions[dir]
  72.         local x, y = pos.x, pos.y
  73.         local allFilesInstalled = true
  74.         for _, file in ipairs(fileList) do
  75.             if not checkFile(dir .. file.name) then
  76.                 allFilesInstalled = false
  77.                 break
  78.             end
  79.         end
  80.         local dirColor = allFilesInstalled and color_folder_installed or color_folder_pending
  81.         if dir == currentDir then
  82.             dirColor = color_folder_installing
  83.         end
  84.         gpu.setForeground(dirColor)
  85.         gpu.set(x, y, "┌─" .. dir)
  86.         gpu.set(x, y + 1, "│")
  87.         for i, file in ipairs(fileList) do
  88.             local fullPath = dir .. file.name
  89.             local color = (dir == currentDir and file.name == currentFile) and color_file_installing or
  90.                     (checkFile(fullPath) and color_file_installed or color_file_pending)
  91.             gpu.setForeground(color)
  92.             gpu.set(x, y + 1 + i, "◉ " .. file.name)
  93.         end
  94.         gpu.setForeground(dirColor)
  95.         gpu.set(x, y + 1 + #fileList + 1, "└───────────────┘")
  96.     end
  97.     gpu.setForeground(color_text) -- Сброс цвета на белый
  98. end
  99.  
  100. -- Функция для центрирования текста
  101. local function centerText(y, text, color)
  102.     local textLength = #text
  103.     local x = math.floor((screenWidth - textLength) / 2)
  104.     gpu.setForeground(color)
  105.     gpu.set(x, y, text)
  106. end
  107.  
  108. -- Файлы для проверки и их адреса на Pastebin
  109. local files = {
  110.     ["/home/"] = {
  111.         {name = "paste.lua", address = "zTNAcwhm"},
  112.         {name = "xedit.lua", address = "zTNAcwhm"},
  113.         {name = "3d.lua", address = "zTNAcwhm"}
  114.     },
  115.     ["/.lib/"] = {
  116.         {name = "header.lua", address = "3BAehD3r"},
  117.         {name = "data.json", address = "kZ8HAxFh"},
  118.         {name = "dkjson.lua", address = "Lm5qcyHU"}
  119.     },
  120.     ["/etc/"] = {
  121.         {name = "boot.lua"},
  122.         {name = "autorun.lua"},
  123.         {name = "config.json"}
  124.     }
  125. }
  126.  
  127. -- Основная логика программы
  128. gpu.setResolution(resolution_width, resolution_height) -- Установить разрешение экрана
  129. term.clear() -- Очистка экрана
  130. gpu.setBackground(color_background)
  131.  
  132. -- Отображение логотипа
  133. gpu.set(logo_x, logo_y, "_______  ______ __   __ _______ _______ _______              _____  _______")
  134. gpu.set(logo_x, logo_y + 1, "|       |_____/   \\_/   |______    |    |_____| |           |     | |______")
  135. gpu.set(logo_x, logo_y + 2, "|_____  |    \\_    |    ______|    |    |     | |_____      |_____| ______|")
  136.  
  137. -- Отображение подзаголовка
  138. gpu.set(header_x, header_y, "Восстановление системы. Проверка начальных файлов:")
  139.  
  140. -- Анимация установки файлов
  141. local function installFiles()
  142.     for dir, fileList in pairs(files) do
  143.         for _, file in ipairs(fileList) do
  144.             term.clear()
  145.             -- Отображение логотипа
  146.             gpu.set(logo_x, logo_y, "_______  ______ __   __ _______ _______ _______              _____  _______")
  147.             gpu.set(logo_x, logo_y + 1, "|       |_____/   \\_/   |______    |    |_____| |           |     | |______")
  148.             gpu.set(logo_x, logo_y + 2, "|_____  |    \\_    |    ______|    |    |     | |_____      |_____| ______|")
  149.             -- Отображение подзаголовка
  150.             gpu.set(header_x, header_y, "Восстановление системы. Проверка начальных файлов:")
  151.             -- Отображение файлов
  152.             displayFiles(files, dir, file.name)
  153.             -- Скачивание файла
  154.             if file.address then
  155.                 downloadFile(file.address, dir .. file.name)
  156.             end
  157.             -- Отображение прогресс-бара
  158.             local startTime = computer.uptime()
  159.             while (computer.uptime() - startTime) <= 2 do -- Загрузка в течение 2 секунд
  160.                 displayProgress(computer.uptime() - startTime, 2)
  161.                 os.sleep(0.05) -- Обновление каждые 50 миллисекунд
  162.             end
  163.             displayProgress(2, 2) -- Завершение прогресса
  164.         end
  165.     end
  166. end
  167.  
  168. installFiles()
  169.  
  170. centerText(23, "Система будет перезагружена.", color_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement