Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.46 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. --Проверяем GPU
  20. if gpu.maxResolution() < 150 then table.insert(govno, "Bad GPU - this OS requires Tier 3 GPU.") end
  21.  
  22. --Проверяем экран
  23. if gpu.getDepth() < 8 and gpu.maxResolution() < 150 then table.insert(govno, "Bad Screen - this OS requires Tier 3 screen.") end
  24.  
  25. --Проверяем оперативку
  26. if math.floor(computer.totalMemory() / 1024 ) < 2048 then table.insert(govno, "Not enough RAM - this OS requires at least 2048 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 then
  32. print(" ")
  33. for i = 1, #govno do
  34. print(govno[i])
  35. end
  36. print(" ")
  37. return
  38. else
  39. print("Done, everything's good. Proceed to downloading.")
  40. print(" ")
  41. end
  42.  
  43. ------------------------------------------------------------------------------------------
  44.  
  45. local lang
  46.  
  47. local applications
  48.  
  49. local padColor = 0x262626
  50. local installerScale = 1
  51.  
  52. local timing = 0.2
  53.  
  54. -----------------------------СТАДИЯ ПОДГОТОВКИ-------------------------------------------
  55.  
  56.  
  57. --ЗАГРУЗОЧКА С ГИТХАБА
  58. local function getFromGitHub(url, path)
  59. local sContent = ""
  60. local result, response = pcall(internet.request, url)
  61. if not result then
  62. return nil
  63. end
  64.  
  65. if fs.exists(path) then fs.remove(path) end
  66. fs.makeDirectory(fs.path(path))
  67. local file = io.open(path, "w")
  68.  
  69. for chunk in response do
  70. file:write(chunk)
  71. sContent = sContent .. chunk
  72. end
  73.  
  74. file:close()
  75.  
  76. return sContent
  77. end
  78.  
  79. --БЕЗОПАСНАЯ ЗАГРУЗОЧКА
  80. local function getFromGitHubSafely(url, path)
  81. local success, sRepos = pcall(getFromGitHub, url, path)
  82. if not success then
  83. io.stderr:write("Can't download \"" .. url .. "\"!\n")
  84. return -1
  85. end
  86. return sRepos
  87. end
  88.  
  89. --ЗАГРУЗОЧКА С ПАСТЕБИНА
  90. local function getFromPastebin(paste, filename)
  91. local cyka = ""
  92. local f, reason = io.open(filename, "w")
  93. if not f then
  94. io.stderr:write("Failed opening file for writing: " .. reason)
  95. return
  96. end
  97. --io.write("Downloading from pastebin.com... ")
  98. local url = "http://pastebin.com/raw.php?i=" .. paste
  99. local result, response = pcall(internet.request, url)
  100. if result then
  101. --io.write("success.\n")
  102. for chunk in response do
  103. --if not options.k then
  104. --string.gsub(chunk, "\r\n", "\n")
  105. --end
  106. f:write(chunk)
  107. cyka = cyka .. chunk
  108. end
  109. f:close()
  110. --io.write("Saved data to " .. filename .. "\n")
  111. else
  112. f:close()
  113. fs.remove(filename)
  114. io.stderr:write("HTTP request failed: " .. response .. "\n")
  115. end
  116.  
  117. return cyka
  118. end
  119.  
  120. local GitHubUserUrl = "https://raw.githubusercontent.com/"
  121.  
  122.  
  123. --------------------------------- Стадия стартовой загрузки всего необходимого ---------------------------------
  124.  
  125.  
  126. local preLoadApi = {
  127. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/lib/ECSAPI.lua", path = "lib/ECSAPI.lua" },
  128. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/lib/colorlib.lua", path = "lib/colorlib.lua" },
  129. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/lib/image.lua", path = "lib/image.lua" },
  130. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/lib/config.lua", path = "lib/config.lua" },
  131. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/MineOS/Icons/Languages.pic", path = "MineOS/System/OS/Icons/Languages.pic" },
  132. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/MineOS/Icons/OK.pic", path = "MineOS/System/OS/Icons/OK.pic" },
  133. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/MineOS/Icons/Downloading.pic", path = "MineOS/System/OS/Icons/Downloading.pic" },
  134. { paste = "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/MineOS/Icons/OS_Logo.pic", path = "MineOS/System/OS/Icons/OS_Logo.pic" },
  135. }
  136.  
  137. print("Downloading file list")
  138. applications = seri.unserialize(getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/MineOS/27e044539cc3c5c887957a1bb181fb3718b41ae3/master/Applications.txt", "MineOS/System/OS/Applications.txt"))
  139. print(" ")
  140.  
  141. for i = 1, #preLoadApi do
  142. print("Downloading must-have files (" .. fs.name(preLoadApi[i].path) .. ")")
  143. getFromGitHubSafely(GitHubUserUrl .. preLoadApi[i].paste, preLoadApi[i].path)
  144. end
  145.  
  146. print(" ")
  147.  
  148. _G.ecs = require("ECSAPI")
  149. _G.image = require("image")
  150. _G.config = require("config")
  151.  
  152. local imageOS = image.load("MineOS/System/OS/Icons/OS_Logo.pic")
  153. local imageLanguages = image.load("MineOS/System/OS/Icons/Languages.pic")
  154. local imageDownloading = image.load("MineOS/System/OS/Icons/Downloading.pic")
  155. local imageOK = image.load("MineOS/System/OS/Icons/OK.pic")
  156.  
  157. ecs.setScale(installerScale)
  158.  
  159. local xSize, ySize = gpu.getResolution()
  160. local windowWidth = 80
  161. local windowHeight = 2 + 16 + 2 + 3 + 2
  162. local xWindow, yWindow = math.floor(xSize / 2 - windowWidth / 2), math.ceil(ySize / 2 - windowHeight / 2)
  163. local xWindowEnd, yWindowEnd = xWindow + windowWidth - 1, yWindow + windowHeight - 1
  164.  
  165.  
  166. -------------------------------------------------------------------------------------------
  167.  
  168. local function clear()
  169. ecs.blankWindow(xWindow, yWindow, windowWidth, windowHeight)
  170. end
  171.  
  172. --ОБЪЕКТЫ
  173. local obj = {}
  174. local function newObj(class, name, ...)
  175. obj[class] = obj[class] or {}
  176. obj[class][name] = {...}
  177. end
  178.  
  179. local function drawButton(name, isPressed)
  180. local buttonColor = 0x888888
  181. if isPressed then buttonColor = ecs.colors.blue end
  182. local d = { ecs.drawAdaptiveButton("auto", yWindowEnd - 3, 2, 1, name, buttonColor, 0xffffff) }
  183. newObj("buttons", name, d[1], d[2], d[3], d[4])
  184. end
  185.  
  186. local function waitForClickOnButton(buttonName)
  187. while true do
  188. local e = { event.pull() }
  189. if e[1] == "touch" then
  190. if ecs.clickedAtArea(e[3], e[4], obj["buttons"][buttonName][1], obj["buttons"][buttonName][2], obj["buttons"][buttonName][3], obj["buttons"][buttonName][4]) then
  191. drawButton(buttonName, true)
  192. os.sleep(timing)
  193. break
  194. end
  195. end
  196. end
  197. end
  198.  
  199.  
  200. ------------------------------ВЫБОР ЯЗЫКА------------------------------------
  201.  
  202. ecs.prepareToExit()
  203.  
  204. local downloadWallpapers, showHelpTips = false, false
  205.  
  206. do
  207.  
  208. clear()
  209.  
  210. image.draw(math.ceil(xSize / 2 - 30), yWindow + 2, imageLanguages)
  211.  
  212. --кнопа
  213. drawButton("Select language",false)
  214.  
  215. waitForClickOnButton("Select language")
  216.  
  217. 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.green, 0xffffff, "OK"}})
  218. downloadWallpapers, showHelpTips = data[2], data[3]
  219.  
  220. --УСТАНАВЛИВАЕМ НУЖНЫЙ ЯЗЫК
  221. _G.OSSettings = { showHelpOnApplicationStart = showHelpTips, language = data[1] }
  222. ecs.saveOSSettings()
  223.  
  224. --Качаем язык
  225. ecs.info("auto", "auto", " ", " Installing language packages...")
  226. local pathToLang = "MineOS/System/OS/Installer/Language.lang"
  227. getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/Installer/" .. _G.OSSettings.language .. ".lang", pathToLang)
  228. getFromGitHubSafely(GitHubUserUrl .. "IgorTimofeev/OpenComputers/master/MineOS/License/" .. _G.OSSettings.language .. ".txt", "MineOS/System/OS/License.txt")
  229.  
  230. --Ставим язык
  231. lang = config.readAll(pathToLang)
  232.  
  233. end
  234.  
  235.  
  236. ------------------------------СТАВИТЬ ЛИ ОСЬ------------------------------------
  237.  
  238. do
  239. clear()
  240.  
  241. image.draw(math.ceil(xSize / 2 - 15), yWindow + 2, imageOS)
  242.  
  243. --Текстик по центру
  244. gpu.setBackground(ecs.windowColors.background)
  245. gpu.setForeground(ecs.colors.gray)
  246. ecs.centerText("x", yWindowEnd - 5 , lang.beginOsInstall)
  247.  
  248. --кнопа
  249. drawButton("->",false)
  250.  
  251. waitForClickOnButton("->")
  252.  
  253. end
  254.  
  255. ------------------------------ЛИЦ СОГЛАЩЕНЬКА------------------------------------------
  256.  
  257. do
  258. clear()
  259.  
  260. --Откуда рисовать условия согл
  261. local from = 1
  262. local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7
  263.  
  264. --Читаем файл с лиц соглл
  265. local lines = {}
  266. local file = io.open("MineOS/System/OS/License.txt", "r")
  267. for line in file:lines() do
  268. table.insert(lines, line)
  269. end
  270. file:close()
  271.  
  272. --Штуку рисуем
  273. ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue)
  274.  
  275. --Инфо рисуем
  276. --ecs.centerText("x", yWindowEnd - 5 ,"Принимаете ли вы условия лицензионного соглашения?")
  277.  
  278. --кнопа
  279. drawButton(lang.acceptLicense, false)
  280.  
  281. while true do
  282. local e = { event.pull() }
  283. if e[1] == "touch" then
  284. 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
  285. drawButton(lang.acceptLicense, true)
  286. os.sleep(timing)
  287. break
  288. end
  289. elseif e[1] == "scroll" then
  290. if e[5] == -1 then
  291. if from < #lines then from = from + 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  292. else
  293. if from > 1 then from = from - 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
  294. end
  295. end
  296. end
  297. end
  298.  
  299. --------------------------СТАДИЯ ЗАГРУЗКИ-----------------------------------
  300.  
  301. do
  302.  
  303. local barWidth = math.floor(windowWidth * 2 / 3)
  304. local xBar = math.floor(xSize/2-barWidth/2)
  305. local yBar = yWindowEnd - 3
  306.  
  307. local function drawInfo(x, y, info)
  308. ecs.square(x, y, barWidth, 1, ecs.windowColors.background)
  309. ecs.colorText(x, y, ecs.colors.gray, info)
  310. end
  311.  
  312. ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
  313.  
  314. image.draw(math.floor(xSize/2 - 33), yWindow + 2, imageDownloading)
  315.  
  316. ecs.colorTextWithBack(xBar, yBar - 1, ecs.colors.gray, ecs.windowColors.background, lang.osInstallation)
  317. ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, 0)
  318. os.sleep(timing)
  319.  
  320. for app = 1, #applications do
  321. --ВСЕ ДЛЯ ГРАФОНА
  322. drawInfo(xBar, yBar + 1, lang.downloading .. " " .. applications[app]["name"])
  323. local percent = app / #applications * 100
  324. ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
  325.  
  326. --ВСЕ ДЛЯ ЗАГРУЗКИ
  327. local path = applications[app]["name"]
  328. if fs.exists(path) then fs.remove(path) end
  329.  
  330. --Если тип = приложение
  331. if applications[app]["type"] == "Application" then
  332. fs.makeDirectory(path..".app/Resources")
  333. getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path..".app/"..fs.name(applications[app]["name"]..".lua"))
  334. getFromGitHubSafely(GitHubUserUrl .. applications[app]["icon"], path..".app/Resources/Icon.pic")
  335. if applications[app]["resources"] then
  336. for i = 1, #applications[app]["resources"] do
  337. getFromGitHubSafely(GitHubUserUrl .. applications[app]["resources"][i]["url"], path..".app/Resources/"..applications[app]["resources"][i]["name"])
  338. end
  339. end
  340.  
  341. if applications[app].about then
  342. getFromGitHubSafely(GitHubUserUrl .. applications[app].about, path .. ".app/Resources/About.txt")
  343. end
  344.  
  345. --Если тип = другой, чужой, а мб и свой пастебин
  346. elseif applications[app]["type"] == "Pastebin" then
  347. fs.remove(applications[app]["name"])
  348. fs.makeDirectory(fs.path(applications[app]["name"]))
  349. getFromPastebin(applications[app]["url"], applications[app]["name"])
  350.  
  351. --Если обои
  352. elseif applications[app]["type"] == "Wallpaper" then
  353. if downloadWallpapers then
  354. getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path)
  355. end
  356. --А если че-то другое
  357. else
  358. getFromGitHubSafely(GitHubUserUrl .. applications[app]["url"], path)
  359. end
  360. end
  361.  
  362. os.sleep(timing)
  363. end
  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. gpu.setBackground(ecs.windowColors.background)
  373. gpu.setForeground(ecs.colors.gray)
  374. ecs.centerText("x",yWindowEnd - 5, lang.needToRestart)
  375.  
  376. --Кнопа
  377. drawButton(lang.restart, false)
  378.  
  379. waitForClickOnButton(lang.restart)
  380.  
  381. ecs.prepareToExit()
  382.  
  383. --Постподготовка
  384. fs.remove("MineOS/Desktop")
  385. fs.remove("MineOS/System/OS/Dock")
  386.  
  387. local apps = {
  388. "Calc.app",
  389. "Crossword.app",
  390. "Geoscan.app",
  391. "Highlight.app",
  392. "HoloClock.app",
  393. "HoloEdit.app",
  394. "MineCode.app",
  395. "Pastebin.app",
  396. "Piano.app",
  397. "Shooting.app",
  398. "Shop.app",
  399. "CodeDoor.app",
  400. "Snake.app",
  401. "Keyboard.app",
  402. "Nano.app",
  403. "Camera.app",
  404. "Autorun.app",
  405. "BufferDemo.app",
  406. "Matrix.app",
  407. "InfoPanel.app",
  408. }
  409.  
  410. local dockApps = {
  411. "Finder.app",
  412. "Calendar.app",
  413. "Control.app",
  414. "Photoshop.app",
  415. "HEX.app"
  416. }
  417.  
  418. local desktopPath = "MineOS/Desktop/"
  419. local dockPath = "MineOS/System/OS/Dock/"
  420. local applicationsPath = "MineOS/Applications/"
  421. local picturesPath = "MineOS/Pictures/"
  422.  
  423. fs.makeDirectory(desktopPath .. "My files")
  424. fs.makeDirectory(picturesPath)
  425.  
  426. for i = 1, #apps do
  427. ecs.createShortCut(desktopPath .. ecs.hideFileFormat(apps[i]) .. ".lnk", applicationsPath .. apps[i])
  428. end
  429.  
  430. fs.makeDirectory(dockPath)
  431.  
  432. for i = 1, #dockApps do
  433. ecs.createShortCut(dockPath .. ecs.hideFileFormat(dockApps[i]) .. ".lnk", applicationsPath .. dockApps[i])
  434. end
  435.  
  436. ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath)
  437.  
  438. if downloadWallpapers then ecs.createShortCut("MineOS/System/OS/Wallpaper.lnk", picturesPath .. "AhsokaTano.pic") end
  439.  
  440. --Автозагрузка
  441. local file = io.open("autorun.lua", "w")
  442. file:write("local success, reason = pcall(loadfile(\"OS.lua\")); if not success then print(\"Ошибка: \" .. tostring(reason)) end")
  443. file:close()
  444.  
  445. computer.shutdown(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement