Advertisement
RadioNurshat

Untitled

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