Advertisement
seriy-coder

MineOS 7.6.6.6 release

Jan 18th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.14 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local unicode = require("unicode")
  4. local event = require("event")
  5. local fs = require("filesystem")
  6. local serialization = require("serialization")
  7. local shell = require("shell")
  8. local args, options = shell.parse( ... )
  9.  
  10. ------------------------------------- Проверка компа на соответствие сис. требованиям -------------------------------------
  11.  
  12. shell.execute("cd ..")
  13. shell.setWorkingDirectory("")
  14.  
  15. -- Создаем массив говна
  16. local govno = {}
  17.  
  18. print(" ")
  19. print("Analyzing computer for matching system requirements...")
  20.  
  21. -- Проверяем, не планшет ли это
  22. if component.isAvailable("tablet") then table.insert(govno, "Tablet PC detected - You can't install MineOS on tablet because of primitive GPU and Screen.") end
  23. -- Проверяем GPU
  24. if component.gpu.maxResolution() < 150 then table.insert(govno, "Bad GPU or Screen - MineOS requires Tier 3 GPU and Tier 3 Screen.") end
  25. -- Проверяем оперативку
  26. if math.floor(computer.totalMemory() / 1024 ) < 1024 then table.insert(govno, "Not enough RAM - MineOS requires at least 1024 KB RAM.") end
  27. -- Проверяем, не флоппи-диск ли это
  28. if fs.get("/bin/edit.lua") == nil or fs.get("/bin/edit.lua").isReadOnly() then table.insert(govno, "You can't install MineOS on floppy disk. Run \"install\" in command line and install OpenOS from floppy to HDD first. After that you're be able to install MineOS from Pastebin.") end
  29.  
  30. --Если нашло какое-то несоответствие сис. требованиям, то написать, что именно не так
  31. if #govno > 0 and not options.skipcheck then
  32.   print(" ")
  33.   for i = 1, #govno do print(govno[i]) end
  34.   print(" ")
  35.   return
  36. else
  37.   print("Done, everything's good. Proceed to downloading.")
  38.   print(" ")
  39. end
  40.  
  41. ------------------------------------- Создание базового дерьмища -------------------------------------
  42.  
  43. local lang
  44. local applications
  45. local padColor = 0x262626
  46. local installerScale = 1
  47. local timing = 0.2
  48. local GitHubUserUrl = "https://raw.githubusercontent.com/"
  49.  
  50. local function internetRequest(url)
  51.   local success, response = pcall(component.internet.request, url)
  52.   if success then
  53.     local responseData = ""
  54.     while true do
  55.       local data, responseChunk = response.read()
  56.       if data then
  57.         responseData = responseData .. data
  58.       else
  59.         if responseChunk then
  60.           return false, responseChunk
  61.         else
  62.           return true, responseData
  63.         end
  64.       end
  65.     end
  66.   else
  67.     return false, reason
  68.   end
  69. end
  70.  
  71. --БЕЗОПАСНАЯ ЗАГРУЗОЧКА
  72. local function getFromGitHubSafely(url, path)
  73.   local success, reason = internetRequest(url)
  74.   if success then
  75.     fs.makeDirectory(fs.path(path) or "")
  76.     fs.remove(path)
  77.     local file = io.open(path, "w")
  78.     file:write(reason)
  79.     file:close()
  80.     return reason
  81.   else
  82.     error("Can't download \"" .. url .. "\"!\n")
  83.   end
  84. end
  85.  
  86. -- Прошивочка биоса
  87. local function flashEFI()
  88.   local oldBootAddress = component.eeprom.getData()
  89.   local data; local file = io.open("/MineOS/System/OS/EFI.lua", "r"); data = file:read("*a"); file:close()
  90.   component.eeprom.set(data)
  91.   component.eeprom.setLabel("EEPROM (MineOS EFI)")
  92.   component.eeprom.setData(oldBootAddress)
  93.   pcall(component.proxy(oldBootAddress).setLabel, "MineOS")
  94. end
  95.  
  96. ------------------------------------- Стадия стартовой загрузки всего необходимого -------------------------------------
  97.  
  98. print("Downloading file list")
  99. applications = serialization.unserialize(getFromGitHubSafely(GitHubUserUrl .. "seriy-coder/MineOS_7.6.6.6/master/Applications.txt", "/MineOS/System/OS/Applications.txt"))
  100. print(" ")
  101.  
  102. for i = 1, #applications do
  103.   if applications[i].preLoadFile then
  104.     print("Downloading \"" .. fs.name(applications[i].name) .. "\"")
  105.     getFromGitHubSafely(GitHubUserUrl .. applications[i].url, applications[i].name)
  106.   end
  107. end
  108.  
  109. print(" ")
  110.  
  111. ------------------------------------- Стадия инициализации загруженных библиотек -------------------------------------
  112.  
  113. package.loaded.ecs = nil
  114. package.loaded.ECSAPI = nil
  115. _G.ecs = require("ECSAPI")
  116. _G.image = require("image")
  117.  
  118. local imageOS = image.load("/MineOS/System/OS/Icons/OS_Logo.pic")
  119. local imageLanguages = image.load("/MineOS/System/OS/Icons/Languages.pic")
  120. local imageDownloading = image.load("/MineOS/System/OS/Icons/Downloading.pic")
  121. local imageOK = image.load("/MineOS/System/OS/Icons/OK.pic")
  122.  
  123. ecs.setScale(installerScale)
  124.  
  125. local xSize, ySize = component.gpu.getResolution()
  126. local windowWidth, windowHeight = 80, 25
  127. local xWindow, yWindow = math.floor(xSize / 2 - windowWidth / 2), math.ceil(ySize / 2 - windowHeight / 2)
  128. local xWindowEnd, yWindowEnd = xWindow + windowWidth - 1, yWindow + windowHeight - 1
  129.  
  130. ------------------------------------- Базовые функции для работы с будущим окном -------------------------------------
  131.  
  132. local function clear()
  133.   ecs.blankWindow(xWindow, yWindow, windowWidth, windowHeight)
  134. end
  135.  
  136. local obj = {}
  137. local function newObj(class, name, ...)
  138.   obj[class] = obj[class] or {}
  139.   obj[class][name] = {...}
  140. end
  141.  
  142. local function drawButton(name, isPressed)
  143.   local buttonColor = 0x888888
  144.   if isPressed then buttonColor = ecs.colors.blue end
  145.   local d = { ecs.drawAdaptiveButton("auto", yWindowEnd - 3, 2, 1, name, buttonColor, 0xffffff) }
  146.   newObj("buttons", name, d[1], d[2], d[3], d[4])
  147. end
  148.  
  149. local function waitForClickOnButton(buttonName)
  150.   while true do
  151.     local e = { event.pull() }
  152.     if e[1] == "touch" then
  153.       if ecs.clickedAtArea(e[3], e[4], obj["buttons"][buttonName][1], obj["buttons"][buttonName][2], obj["buttons"][buttonName][3], obj["buttons"][buttonName][4]) then
  154.         drawButton(buttonName, true)
  155.         os.sleep(timing)
  156.         break
  157.       end
  158.     end
  159.   end
  160. end
  161.  
  162. ------------------------------------- Стадия выбора языка и настройки системы -------------------------------------
  163.  
  164. ecs.prepareToExit()
  165.  
  166. local installOption, downloadWallpapers, showHelpTips
  167.  
  168. do
  169.   clear()
  170.   image.draw(math.ceil(xSize / 2 - 30), yWindow + 2, imageLanguages)
  171.  
  172.   drawButton("Select language",false)
  173.   waitForClickOnButton("Select language")
  174.  
  175.   local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true,
  176.     {"EmptyLine"},
  177.     {"CenterText", ecs.colors.orange, "Select language"},
  178.     {"EmptyLine"},
  179.     {"Select", 0xFFFFFF, ecs.colors.green, "Russian", "English"},
  180.     {"EmptyLine"},
  181.     {"CenterText", ecs.colors.orange, "Change some OS properties"},
  182.     {"EmptyLine"},
  183.     {"Selector", 0xFFFFFF, 0xF2B233, "Full installation", "Install only must-have apps", "Install only libraries"},
  184.     {"EmptyLine"},
  185.     {"Switch", 0xF2B233, 0xFFFFFF, 0xFFFFFF, "Download wallpapers", true},
  186.     {"EmptyLine"},
  187.     {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Show help tips in OS", true},
  188.     {"EmptyLine"},
  189.     {"Button", {ecs.colors.orange, 0x262626, "OK"}}
  190.   )
  191.   installOptions, downloadWallpapers, showHelpTips = data[2], data[3], data[4]
  192.  
  193.   -- Устанавливаем базовую конфигурацию системы
  194.   _G.OSSettings = {
  195.     screensaver = "Matrix",
  196.     screensaverDelay = 20,
  197.     showHelpOnApplicationStart = showHelpTips,
  198.     language = data[1],
  199.     dockShortcuts = {
  200.       {path = "/MineOS/Applications/AppMarket.app"},
  201.       {path = "/MineOS/Applications/MineCode IDE.app"},
  202.       {path = "/MineOS/Applications/Photoshop.app"},
  203.       {path = "/MineOS/Applications/VK.app"},
  204.     }
  205.   }
  206.  
  207.   ecs.saveOSSettings()
  208.  
  209.   -- Загружаем локализацию инсталлера
  210.   ecs.info("auto", "auto", " ", " Installing language packages...")
  211.   local pathToLang = "/MineOS/System/OS/Installer/Language.lang"
  212.   getFromGitHubSafely(GitHubUserUrl .. "seriy-coder/MineOS_7.6.6.6/master/Installer/" .. _G.OSSettings.language .. ".lang", pathToLang)
  213.   getFromGitHubSafely(GitHubUserUrl .. "seriy-coder/MineOS_7.6.6.6/master/MineOS/License/" .. _G.OSSettings.language .. ".txt", "/MineOS/System/OS/License.txt")
  214.  
  215.   local file = io.open(pathToLang, "r"); lang = serialization.unserialize(file:read("*a")); file:close()
  216. end
  217.  
  218.  
  219. ------------------------------------- Проверка, желаем ли мы вообще ставить ось -------------------------------------
  220.  
  221. do
  222.   clear()
  223.  
  224.   image.draw(math.ceil(xSize / 2 - 15), yWindow + 2, imageOS)
  225.  
  226.   --Текстик по центру
  227.   component.gpu.setBackground(ecs.windowColors.background)
  228.   component.gpu.setForeground(ecs.colors.gray)
  229.   ecs.centerText("x", yWindowEnd - 5 , lang.beginOsInstall)
  230.  
  231.   --кнопа
  232.   drawButton("->",false)
  233.  
  234.   waitForClickOnButton("->")
  235.  
  236. end
  237.  
  238. ------------------------------ЛИЦ СОГЛАЩЕНЬКА------------------------------------------
  239.  
  240. do
  241.   clear()
  242.  
  243.   --Откуда рисовать условия согл
  244.   local from = 1
  245.   local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7
  246.  
  247.   --Читаем файл с лиц соглл
  248.   local lines = {}
  249.   local file = io.open("/MineOS/System/OS/License.txt", "r")
  250.   for line in file:lines() do
  251.     table.insert(lines, line)
  252.   end
  253.   file:close()
  254.  
  255.   --Штуку рисуем
  256.   ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue)
  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 applicationsPath = "/MineOS/Applications/"
  283. local picturesPath = "/MineOS/Pictures/"
  284.  
  285. fs.remove(desktopPath)
  286.  
  287. -- fs.makeDirectory(desktopPath .. "My files")
  288. -- fs.makeDirectory(picturesPath)
  289. fs.makeDirectory("/MineOS/Trash/")
  290.  
  291. ------------------------------ Загрузка всего ------------------------------------------
  292.  
  293. do
  294.   local barWidth = math.floor(windowWidth * 2 / 3)
  295.   local xBar = math.floor(xSize/2-barWidth/2)
  296.   local yBar = yWindowEnd - 3
  297.  
  298.   local function drawInfo(x, y, info)
  299.     ecs.square(x, y, barWidth, 1, ecs.windowColors.background)
  300.     ecs.colorText(x, y, ecs.colors.gray, ecs.stringLimit("end", info, barWidth))
  301.   end
  302.  
  303.   ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  304.  
  305.   image.draw(math.floor(xSize / 2 - 33), yWindow + 2, imageDownloading)
  306.  
  307.   ecs.colorTextWithBack(xBar, yBar - 1, ecs.colors.gray, ecs.windowColors.background, lang.osInstallation)
  308.   ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, 0)
  309.   os.sleep(timing)
  310.  
  311.   -- Создаем список того, что будем загружать, в зависимости от выбранных ранее опций
  312.   local thingsToDownload = {}
  313.   for i = 1, #applications do
  314.     if
  315.       not applications[i].preLoadFile and
  316.       (
  317.         (applications[i].type == "Library" or applications[i].type == "Icon")
  318.         or
  319.         (
  320.           (installOptions ~= "Install only libraries")
  321.           and
  322.           (
  323.             (applications[i].forceDownload)
  324.             or
  325.             (applications[i].type == "Wallpaper" and downloadWallpapers)
  326.             or
  327.             (applications[i].type == "Application" and installOptions == "Full installation")
  328.           )
  329.         )
  330.       )
  331.     then
  332.       table.insert(thingsToDownload, applications[i])
  333.     end
  334.     --Подчищаем за собой, а то мусора нынче много
  335.     applications[i] = nil
  336.   end
  337.  
  338.   -- Загружаем все из списка
  339.   for app = 1, #thingsToDownload do
  340.     drawInfo(xBar, yBar + 1, lang.downloading .. " " .. thingsToDownload[app]["name"])
  341.     local percent = app / #thingsToDownload * 100
  342.     ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
  343.  
  344.     ecs.getOSApplication(thingsToDownload[app])
  345.   end
  346.  
  347.   os.sleep(timing)
  348.   if installOptions == "Install only libraries" then flashEFI(); ecs.prepareToExit(); computer.shutdown(true) end
  349. end
  350.  
  351. -- Создаем базовые обои рабочего стола
  352. if downloadWallpapers then
  353.   ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath)
  354.   ecs.createShortCut("/MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Ciri.pic")
  355. end
  356.  
  357. -- Создаем файл автозагрузки
  358. local file = io.open("autorun.lua", "w")
  359. file:write("local success, reason = pcall(loadfile(\"OS.lua\")); if not success then print(\"Ошибка: \" .. tostring(reason)) end")
  360. file:close()
  361.  
  362. -- Биосик
  363. flashEFI()
  364.  
  365. ------------------------------ Стадия перезагрузки ------------------------------------------
  366.  
  367. ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  368.  
  369. image.draw(math.floor(xSize/2 - 16), math.floor(ySize/2 - 11), imageOK)
  370.  
  371. --Текстик по центру
  372. component.gpu.setBackground(ecs.windowColors.background)
  373. component.gpu.setForeground(ecs.colors.gray)
  374. ecs.centerText("x",yWindowEnd - 5, lang.needToRestart)
  375.  
  376. --Кнопа
  377. drawButton(lang.restart, false)
  378. waitForClickOnButton(lang.restart)
  379.  
  380. --Перезагружаем компик
  381. ecs.prepareToExit()
  382. computer.shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement