Advertisement
tothe

MineOs by ECS

Oct 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 ) < 2048 then table.insert(govno, "Not enough RAM - MineOS requires at least 1536 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 .. "IgorTimofeev/OpenComputers/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. showHelpOnApplicationStart = showHelpTips,
  196. language = data[1],
  197. dockShortcuts = {
  198. {path = "/MineOS/Applications/AppMarket.app"},
  199. {path = "/MineOS/Applications/Finder.app"},
  200. {path = "/MineOS/Applications/Photoshop.app"},
  201. {path = "/MineOS/Applications/VK.app"},
  202. }
  203. }
  204.  
  205. ecs.saveOSSettings()
  206.  
  207. -- Загружаем локализацию инсталлера
  208. ecs.info("auto", "auto", " ", " Installing language packages...")
  209. local pathToLang = "/MineOS/System/OS/Installer/Language.lang"
  210. getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/Installer/" .. _G.OSSettings.language .. ".lang", pathToLang)
  211. getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/MineOS/License/" .. _G.OSSettings.language .. ".txt", "/MineOS/System/OS/License.txt")
  212.  
  213. local file = io.open(pathToLang, "r"); lang = serialization.unserialize(file:read("*a")); file:close()
  214. end
  215.  
  216.  
  217. ------------------------------------- Проверка, желаем ли мы вообще ставить ось -------------------------------------
  218.  
  219. do
  220. clear()
  221.  
  222. image.draw(math.ceil(xSize / 2 - 15), yWindow + 2, imageOS)
  223.  
  224. --Текстик по центру
  225. component.gpu.setBackground(ecs.windowColors.background)
  226. component.gpu.setForeground(ecs.colors.gray)
  227. ecs.centerText("x", yWindowEnd - 5 , lang.beginOsInstall)
  228.  
  229. --кнопа
  230. drawButton("->",false)
  231.  
  232. waitForClickOnButton("->")
  233.  
  234. end
  235.  
  236. ------------------------------ЛИЦ СОГЛАЩЕНЬКА------------------------------------------
  237.  
  238. do
  239. clear()
  240.  
  241. --Откуда рисовать условия согл
  242. local from = 1
  243. local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7
  244.  
  245. --Читаем файл с лиц соглл
  246. local lines = {}
  247. local file = io.open("/MineOS/System/OS/License.txt", "r")
  248. for line in file:lines() do
  249. table.insert(lines, line)
  250. end
  251. file:close()
  252.  
  253. --Штуку рисуем
  254. ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue)
  255. --кнопа
  256. drawButton(lang.acceptLicense, false)
  257.  
  258. while true do
  259. local e = { event.pull() }
  260. if e[1] == "touch" then
  261. 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
  262. drawButton(lang.acceptLicense, true)
  263. os.sleep(timing)
  264. break
  265. end
  266. elseif e[1] == "scroll" then
  267. if e[5] == -1 then
  268. if from < #lines then from = from + 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  269. else
  270. if from > 1 then from = from - 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  271. end
  272. end
  273. end
  274. end
  275.  
  276. -------------------------- Подготавливаем файловую систему ----------------------------------
  277.  
  278. --Создаем стартовые пути и прочие мелочи чисто для эстетики
  279. local desktopPath = "/MineOS/Desktop/"
  280. local dockPath = "/MineOS/System/OS/Dock/"
  281. local applicationsPath = "/MineOS/Applications/"
  282. local picturesPath = "/MineOS/Pictures/"
  283.  
  284. fs.remove(desktopPath)
  285. fs.remove(dockPath)
  286.  
  287. -- fs.makeDirectory(desktopPath .. "My files")
  288. -- fs.makeDirectory(picturesPath)
  289. fs.makeDirectory(dockPath)
  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, info)
  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. (applications[i].type == "Library" or applications[i].type == "Icon")
  316. or
  317. (
  318. (installOptions ~= "Install only libraries")
  319. and
  320. (
  321. (applications[i].forceDownload)
  322. or
  323. (applications[i].type == "Wallpaper" and downloadWallpapers)
  324. or
  325. (applications[i].type == "Application" and installOptions == "Full installation")
  326. )
  327. )
  328. then
  329. table.insert(thingsToDownload, applications[i])
  330. end
  331. --Подчищаем за собой, а то мусора нынче много
  332. applications[i] = nil
  333. end
  334.  
  335. -- Загружаем все из списка
  336. for app = 1, #thingsToDownload do
  337. drawInfo(xBar, yBar + 1, lang.downloading .. " " .. thingsToDownload[app]["name"])
  338. local percent = app / #thingsToDownload * 100
  339. ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
  340.  
  341. ecs.getOSApplication(thingsToDownload[app])
  342. end
  343.  
  344. os.sleep(timing)
  345. if installOptions == "Install only libraries" then flashEFI(); ecs.prepareToExit(); computer.shutdown(true) end
  346. end
  347.  
  348. -- Создаем базовые обои рабочего стола
  349. if downloadWallpapers then
  350. ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath)
  351. ecs.createShortCut("/MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Raspberry.pic")
  352. end
  353.  
  354. -- Создаем файл автозагрузки
  355. local file = io.open("autorun.lua", "w")
  356. file:write("local success, reason = pcall(loadfile(\"OS.lua\")); if not success then print(\"Ошибка: \" .. tostring(reason)) end")
  357. file:close()
  358.  
  359. -- Биосик
  360. flashEFI()
  361.  
  362. ------------------------------ Стадия перезагрузки ------------------------------------------
  363.  
  364. ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  365.  
  366. image.draw(math.floor(xSize/2 - 16), math.floor(ySize/2 - 11), imageOK)
  367.  
  368. --Текстик по центру
  369. component.gpu.setBackground(ecs.windowColors.background)
  370. component.gpu.setForeground(ecs.colors.gray)
  371. ecs.centerText("x",yWindowEnd - 5, lang.needToRestart)
  372.  
  373. --Кнопа
  374. drawButton(lang.restart, false)
  375. waitForClickOnButton(lang.restart)
  376.  
  377. --Перезагружаем компик
  378. ecs.prepareToExit()
  379. computer.shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement