Ewgeniy

Mine OS (oldStandart)

Sep 1st, 2021 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.97 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local term = require("term")
  4. local unicode = require("unicode")
  5. local event = require("event")
  6. local fs = require("filesystem")
  7. local internet = require("internet")
  8. local seri = require("serialization")
  9. local gpu = component.gpu
  10.  
  11. -----------------Проверка компа на соответствие сис. требованиям--------------------------
  12.  
  13. --Создаем массив говна
  14. local govno = {}
  15.  
  16. print(" ")
  17. print("Analyzing computer for matching system requirements...")
  18.  
  19.  
  20. ------------------------------------------------------------------------------------------
  21.  
  22. local lang
  23.  
  24. local applications
  25.  
  26. local padColor = 0x262626
  27. local installerScale = 1
  28.  
  29. local timing = 0.2
  30.  
  31. -----------------------------СТАДИЯ ПОДГОТОВКИ-------------------------------------------
  32.  
  33.  
  34. --ЗАГРУЗОЧКА С ГИТХАБА
  35. local function getFromGitHub(url, path)
  36.   local sContent = ""
  37.   local result, response = pcall(internet.request, url)
  38.   if not result then
  39.     return nil
  40.   end
  41.  
  42.   if fs.exists(path) then fs.remove(path) end
  43.   fs.makeDirectory(fs.path(path))
  44.   local file = io.open(path, "w")
  45.  
  46.   for chunk in response do
  47.     file:write(chunk)
  48.     sContent = sContent .. chunk
  49.   end
  50.  
  51.   file:close()
  52.  
  53.   return sContent
  54. end
  55.  
  56. --БЕЗОПАСНАЯ ЗАГРУЗОЧКА
  57. local function getFromGitHubSafely(url, path)
  58.   local success, sRepos = pcall(getFromGitHub, url, path)
  59.   if not success then
  60.     io.stderr:write("Can't download \"" .. url .. "\"!\n")
  61.     return -1
  62.   end
  63.   return sRepos
  64. end
  65.  
  66. --ЗАГРУЗОЧКА С ПАСТЕБИНА
  67. local function getFromPastebin(paste, filename)
  68.   local cyka = ""
  69.   local f, reason = io.open(filename, "w")
  70.   if not f then
  71.     io.stderr:write("Failed opening file for writing: " .. reason)
  72.     return
  73.   end
  74.   --io.write("Downloading from pastebin.com... ")
  75.   local url = "http://pastebin.com/raw.php?i=" .. paste
  76.   local result, response = pcall(internet.request, url)
  77.   if result then
  78.     --io.write("success.\n")
  79.     for chunk in response do
  80.       --if not options.k then
  81.         --string.gsub(chunk, "\r\n", "\n")
  82.       --end
  83.       f:write(chunk)
  84.       cyka = cyka .. chunk
  85.     end
  86.     f:close()
  87.     --io.write("Saved data to " .. filename .. "\n")
  88.   else
  89.     f:close()
  90.     fs.remove(filename)
  91.     io.stderr:write("HTTP request failed: " .. response .. "\n")
  92.   end
  93.  
  94.   return cyka
  95. end
  96.  
  97. local GitHubUserUrl = "https://raw.githubusercontent.com/"
  98.  
  99.  
  100. --------------------------------- Стадия стартовой загрузки всего необходимого ---------------------------------
  101.  
  102.  
  103. local preLoadApi = {
  104.   { paste = "Hapalarast/MineOS/main/Lib/ECSAPI.lua", path = "lib/ECSAPI.lua" },
  105.   { paste = "Hapalarast/MineOS/main/Lib/colorlib.lua", path = "lib/colorlib.lua" },
  106.   { paste = "Hapalarast/MineOS/main/Lib/image.lua", path = "lib/image.lua" },
  107.   { paste = "Hapalarast/MineOS/main/Lib/config.lua", path = "lib/config.lua" },
  108.   { paste = "Hapalarast/MineOS/Icons/Languages.pic?raw=true", path = "MineOS/System/OS/Icons/Languages.pic" },
  109.   { paste = "Hapalarast/MineOS/Icons/OK.pic?raw=true", path = "MineOS/System/OS/Icons/OK.pic" },
  110.   { paste = "Hapalarast/MineOS/Icons/Downloading.pic?raw=true", path = "MineOS/System/OS/Icons/Downloading.pic" },
  111.   { paste = "Hapalarast/MineOS/Icons/OS_Logo.pic?raw=true", path = "MineOS/System/OS/Icons/OS_Logo.pic" },
  112. }
  113.  
  114. print("Downloading file list")
  115. applications = seri.unserialize(getFromGitHubSafely(GitHubUserUrl .. "Hapalarast/MineOS/main/Applications.txt", "MineOS/System/OS/Applications.txt"))
  116. print(" ")
  117.  
  118. for i = 1, #preLoadApi do
  119.   print("Downloading must-have files (" .. fs.name(preLoadApi[i].path) .. ")")
  120.   getFromGitHubSafely(GitHubUserUrl .. preLoadApi[i].paste, preLoadApi[i].path)
  121. end
  122.  
  123. print(" ")
  124.  
  125. package.loaded.ecs = nil
  126. package.loaded.ECSAPI = nil
  127. _G.ecs = require("ECSAPI")
  128. _G.image = require("image")
  129. _G.config = require("config")
  130.  
  131. local imageOS = image.load("MineOS/System/OS/Icons/OS_Logo.pic")
  132. local imageLanguages = image.load("MineOS/System/OS/Icons/Languages.pic")
  133. local imageDownloading = image.load("MineOS/System/OS/Icons/Downloading.pic")
  134. local imageOK = image.load("MineOS/System/OS/Icons/OK.pic")
  135.  
  136. ecs.setScale(installerScale)
  137.  
  138. local xSize, ySize = gpu.getResolution()
  139. local windowWidth = 80
  140. local windowHeight = 2 + 16 + 2 + 3 + 2
  141. local xWindow, yWindow = math.floor(xSize / 2 - windowWidth / 2), math.ceil(ySize / 2 - windowHeight / 2)
  142. local xWindowEnd, yWindowEnd = xWindow + windowWidth - 1, yWindow + windowHeight - 1
  143.  
  144.  
  145. -------------------------------------------------------------------------------------------
  146.  
  147. local function clear()
  148.   ecs.blankWindow(xWindow, yWindow, windowWidth, windowHeight)
  149. end
  150.  
  151. --ОБЪЕКТЫ
  152. local obj = {}
  153. local function newObj(class, name, ...)
  154.   obj[class] = obj[class] or {}
  155.   obj[class][name] = {...}
  156. end
  157.  
  158. local function drawButton(name, isPressed)
  159.   local buttonColor = 0x888888
  160.   if isPressed then buttonColor = ecs.colors.blue end
  161.   local d = { ecs.drawAdaptiveButton("auto", yWindowEnd - 3, 2, 1, name, buttonColor, 0xffffff) }
  162.   newObj("buttons", name, d[1], d[2], d[3], d[4])
  163. end
  164.  
  165. local function waitForClickOnButton(buttonName)
  166.   while true do
  167.     local e = { event.pull() }
  168.     if e[1] == "touch" then
  169.       if ecs.clickedAtArea(e[3], e[4], obj["buttons"][buttonName][1], obj["buttons"][buttonName][2], obj["buttons"][buttonName][3], obj["buttons"][buttonName][4]) then
  170.         drawButton(buttonName, true)
  171.         os.sleep(timing)
  172.         break
  173.       end
  174.     end
  175.   end
  176. end
  177.  
  178.  
  179. ------------------------------ВЫБОР ЯЗЫКА------------------------------------
  180.  
  181. ecs.prepareToExit()
  182.  
  183. local downloadWallpapers, showHelpTips = false, false
  184.  
  185. do
  186.  
  187.   clear()
  188.  
  189.   image.draw(math.ceil(xSize / 2 - 30), yWindow + 2, imageLanguages)
  190.  
  191.   --кнопа
  192.   drawButton("Select language",false)
  193.  
  194.   waitForClickOnButton("Select language")
  195.  
  196.   local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true, {"EmptyLine"}, {"CenterText", ecs.colors.orange, "Select language"}, {"EmptyLine"}, {"Select", 0xFFFFFF, ecs.colors.green, "Russian", "English"}, {"EmptyLine"}, {"CenterText", ecs.colors.orange, "Change some OS properties"}, {"EmptyLine"}, {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Download wallpapers", true}, {"EmptyLine"}, {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Show help tips in OS", true}, {"EmptyLine"}, {"Button", {ecs.colors.orange, 0x262626, "OK"}})
  197.   downloadWallpapers, showHelpTips = data[2], data[3]
  198.  
  199.   --УСТАНАВЛИВАЕМ НУЖНЫЙ ЯЗЫК
  200.   _G.OSSettings = { showHelpOnApplicationStart = showHelpTips, language = data[1] }
  201.   ecs.saveOSSettings()
  202.  
  203.   --Качаем язык
  204.   ecs.info("auto", "auto", " ", " Installing language packages...")
  205.   local pathToLang = "MineOS/System/OS/Installer/Language.lang"
  206.   getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/Installer/" .. _G.OSSettings.language .. ".lang", pathToLang)
  207.   getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/MineOS/License/" .. _G.OSSettings.language .. ".txt", "MineOS/System/OS/License.txt")
  208.  
  209.   --Ставим язык
  210.   lang = config.readAll(pathToLang)
  211.  
  212. end
  213.  
  214.  
  215. ------------------------------СТАВИТЬ ЛИ ОСЬ------------------------------------
  216.  
  217. do
  218.   clear()
  219.  
  220.   image.draw(math.ceil(xSize / 2 - 15), yWindow + 2, imageOS)
  221.  
  222.   --Текстик по центру
  223.   gpu.setBackground(ecs.windowColors.background)
  224.   gpu.setForeground(ecs.colors.gray)
  225.   ecs.centerText("x", yWindowEnd - 5 , lang.beginOsInstall)
  226.  
  227.   --кнопа
  228.   drawButton("->",false)
  229.  
  230.   waitForClickOnButton("->")
  231.  
  232. end
  233.  
  234. ------------------------------ЛИЦ СОГЛАЩЕНЬКА------------------------------------------
  235.  
  236. do
  237.   clear()
  238.  
  239.   --Откуда рисовать условия согл
  240.   local from = 1
  241.   local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7
  242.  
  243.   --Читаем файл с лиц соглл
  244.   local lines = {}
  245.   local file = io.open("MineOS/System/OS/License.txt", "r")
  246.   for line in file:lines() do
  247.     table.insert(lines, line)
  248.   end
  249.   file:close()
  250.  
  251.   --Штуку рисуем
  252.   ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue)
  253.  
  254.   --Инфо рисуем
  255.   --ecs.centerText("x", yWindowEnd - 5 ,"Принимаете ли вы условия лицензионного соглашения?")
  256.  
  257.   --кнопа
  258.   drawButton(lang.acceptLicense, false)
  259.  
  260.   while true do
  261.     local e = { event.pull() }
  262.     if e[1] == "touch" then
  263.       if ecs.clickedAtArea(e[3], e[4], obj["buttons"][lang.acceptLicense][1], obj["buttons"][lang.acceptLicense][2], obj["buttons"][lang.acceptLicense][3], obj["buttons"][lang.acceptLicense][4]) then
  264.         drawButton(lang.acceptLicense, true)
  265.         os.sleep(timing)
  266.         break
  267.       end
  268.     elseif e[1] == "scroll" then
  269.       if e[5] == -1 then
  270.         if from < #lines then from = from + 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  271.       else
  272.         if from > 1 then from = from - 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  273.       end
  274.     end
  275.   end
  276. end
  277.  
  278. -------------------------- Подготавливаем файловую систему ----------------------------------
  279.  
  280. --Создаем стартовые пути и прочие мелочи чисто для эстетики
  281. local desktopPath = "MineOS/Desktop/"
  282. local dockPath = "MineOS/System/OS/Dock/"
  283. local applicationsPath = "MineOS/Applications/"
  284. local picturesPath = "MineOS/Pictures/"
  285.  
  286. fs.remove(desktopPath)
  287. fs.remove(dockPath)
  288.  
  289. fs.makeDirectory(desktopPath .. "My files")
  290. fs.makeDirectory(picturesPath)
  291. fs.makeDirectory(dockPath)
  292.  
  293. --------------------------СТАДИЯ ЗАГРУЗКИ-----------------------------------
  294.  
  295. do
  296.  
  297.   local barWidth = math.floor(windowWidth * 2 / 3)
  298.   local xBar = math.floor(xSize/2-barWidth/2)
  299.   local yBar = yWindowEnd - 3
  300.  
  301.   local function drawInfo(x, y, info)
  302.     ecs.square(x, y, barWidth, 1, ecs.windowColors.background)
  303.     ecs.colorText(x, y, ecs.colors.gray, info)
  304.   end
  305.  
  306.   ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  307.  
  308.   image.draw(math.floor(xSize/2 - 33), yWindow + 2, imageDownloading)
  309.  
  310.   ecs.colorTextWithBack(xBar, yBar - 1, ecs.colors.gray, ecs.windowColors.background, lang.osInstallation)
  311.   ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, 0)
  312.   os.sleep(timing)
  313.  
  314.   for app = 1, #applications do
  315.     --ВСЕ ДЛЯ ГРАФОНА
  316.     drawInfo(xBar, yBar + 1, lang.downloading .. " " .. applications[app]["name"])
  317.     local percent = app / #applications * 100
  318.     ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
  319.  
  320.     ecs.getOSApplication(applications[app], downloadWallpapers)
  321.   end
  322.  
  323.   os.sleep(timing)
  324. end
  325.  
  326. --Создаем базовые обои рабочего стола
  327. ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath)
  328. if downloadWallpapers then ecs.createShortCut("MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Girl.pic") end
  329.  
  330. --Автозагрузка
  331. local file = io.open("autorun.lua", "w")
  332. file:write("local success, reason = pcall(loadfile(\"OS.lua\")); if not success then print(\"Ошибка: \" .. tostring(reason)) end")
  333. file:close()
  334.  
  335. --------------------------СТАДИЯ ПЕРЕЗАГРУЗКИ КОМПА-----------------------------------
  336.  
  337. ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  338.  
  339. image.draw(math.floor(xSize/2 - 16), math.floor(ySize/2 - 11), imageOK)
  340.  
  341. --Текстик по центру
  342. gpu.setBackground(ecs.windowColors.background)
  343. gpu.setForeground(ecs.colors.gray)
  344. ecs.centerText("x",yWindowEnd - 5, lang.needToRestart)
  345.  
  346. --Кнопа
  347. drawButton(lang.restart, false)
  348. waitForClickOnButton(lang.restart)
  349. ecs.prepareToExit()
  350.  
  351. computer.shutdown(true)
Add Comment
Please, Sign In to add comment