Advertisement
Ewgeniy

Bios

Sep 9th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.92 KB | None | 0 0
  1.  
  2. -- Checking for required components
  3. local function getComponentAddress(name)
  4.     return component.list(name)() or error("Required " .. name .. " component is missing")
  5. end
  6.  
  7. local function getComponentProxy(name)
  8.     return component.proxy(getComponentAddress(name))
  9. end
  10.  
  11. local EEPROMProxy, internetProxy, GPUProxy =
  12.     getComponentProxy("eeprom"),
  13.     getComponentProxy("internet"),
  14.     getComponentProxy("gpu")
  15.  
  16. -- Binding GPU to screen in case it's not done yet
  17. GPUProxy.bind(getComponentAddress("screen"))
  18. local screenWidth, screenHeight = GPUProxy.getResolution()
  19.  
  20. local repositoryURL = "https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/"
  21. local installerURL = "Installer/"
  22. local EFIURL = "EFI/Minified.lua"
  23.  
  24. local installerPath = "/MineOS installer/"
  25. local installerPicturesPath = installerPath .. "Installer/Pictures/"
  26. local OSPath = "/"
  27.  
  28. local temporaryFilesystemProxy, selectedFilesystemProxy
  29.  
  30. --------------------------------------------------------------------------------
  31.  
  32. -- Working with components directly before system libraries are downloaded & initialized
  33. local function centrize(width)
  34.     return math.floor(screenWidth / 2 - width / 2)
  35. end
  36.  
  37. local function centrizedText(y, color, text)
  38.     GPUProxy.fill(1, y, screenWidth, 1, " ")
  39.     GPUProxy.setForeground(color)
  40.     GPUProxy.set(centrize(#text), y, text)
  41. end
  42.  
  43. local function title()
  44.     local y = math.floor(screenHeight / 2 - 1)
  45.     centrizedText(y, 0x2D2D2D, "MineOS")
  46.  
  47.     return y + 2
  48. end
  49.  
  50. local function status(text, needWait)
  51.     centrizedText(title(), 0x878787, text)
  52.  
  53.     if needWait then
  54.         repeat
  55.             needWait = computer.pullSignal()
  56.         until needWait == "key_down" or needWait == "touch"
  57.     end
  58. end
  59.  
  60. local function progress(value)
  61.     local width = 26
  62.     local x, y, part = centrize(width), title(), math.ceil(width * value)
  63.    
  64.     GPUProxy.setForeground(0x878787)
  65.     GPUProxy.set(x, y, string.rep("─", part))
  66.     GPUProxy.setForeground(0xC3C3C3)
  67.     GPUProxy.set(x + part, y, string.rep("─", width - part))
  68. end
  69.  
  70. local function filesystemPath(path)
  71.     return path:match("^(.+%/).") or ""
  72. end
  73.  
  74. local function filesystemName(path)
  75.     return path:match("%/?([^%/]+%/?)$")
  76. end
  77.  
  78. local function filesystemHideExtension(path)
  79.     return path:match("(.+)%..+") or path
  80. end
  81.  
  82. local function rawRequest(url, chunkHandler)
  83.     local internetHandle, reason = internetProxy.request(repositoryURL .. url:gsub("([^%w%-%_%.%~])", function(char)
  84.         return string.format("%%%02X", string.byte(char))
  85.     end))
  86.  
  87.     if internetHandle then
  88.         local chunk, reason
  89.         while true do
  90.             chunk, reason = internetHandle.read(math.huge) 
  91.            
  92.             if chunk then
  93.                 chunkHandler(chunk)
  94.             else
  95.                 if reason then
  96.                     error("Internet request failed: " .. tostring(reason))
  97.                 end
  98.  
  99.                 break
  100.             end
  101.         end
  102.  
  103.         internetHandle.close()
  104.     else
  105.         error("Connection failed: " .. url)
  106.     end
  107. end
  108.  
  109. local function request(url)
  110.     local data = ""
  111.    
  112.     rawRequest(url, function(chunk)
  113.         data = data .. chunk
  114.     end)
  115.  
  116.     return data
  117. end
  118.  
  119. local function download(url, path)
  120.     selectedFilesystemProxy.makeDirectory(filesystemPath(path))
  121.  
  122.     local fileHandle, reason = selectedFilesystemProxy.open(path, "wb")
  123.     if fileHandle then 
  124.         rawRequest(url, function(chunk)
  125.             selectedFilesystemProxy.write(fileHandle, chunk)
  126.         end)
  127.  
  128.         selectedFilesystemProxy.close(fileHandle)
  129.     else
  130.         error("File opening failed: " .. tostring(reason))
  131.     end
  132. end
  133.  
  134. local function deserialize(text)
  135.     local result, reason = load("return " .. text, "=string")
  136.     if result then
  137.         return result()
  138.     else
  139.         error(reason)
  140.     end
  141. end
  142.  
  143. -- Clearing screen
  144. GPUProxy.setBackground(0xE1E1E1)
  145. GPUProxy.fill(1, 1, screenWidth, screenHeight, " ")
  146.  
  147. -- Searching for appropriate temporary filesystem for storing libraries, images, etc
  148. for address in component.list("filesystem") do
  149.     local proxy = component.proxy(address)
  150.     if proxy.spaceTotal() >= 2 * 1024 * 1024 then
  151.         temporaryFilesystemProxy, selectedFilesystemProxy = proxy, proxy
  152.         break
  153.     end
  154. end
  155.  
  156. -- If there's no suitable HDDs found - then meow
  157. if not temporaryFilesystemProxy then
  158.     status("No appropriate filesystem found", true)
  159.     return
  160. end
  161.  
  162. -- First, we need a big ass file list with localizations, applications, wallpapers
  163. progress(0)
  164. local files = deserialize(request(installerURL .. "Files.cfg"))
  165.  
  166. -- After that we could download required libraries for installer from it
  167. for i = 1, #files.installerFiles do
  168.     progress(i / #files.installerFiles)
  169.     download(files.installerFiles[i], installerPath .. files.installerFiles[i])
  170. end
  171.  
  172. -- Initializing simple package system for loading system libraries
  173. package = {loading = {}, loaded = {}}
  174.  
  175. function require(module)
  176.     if package.loaded[module] then
  177.         return package.loaded[module]
  178.     elseif package.loading[module] then
  179.         error("already loading " .. module .. ": " .. debug.traceback())
  180.     else
  181.         package.loading[module] = true
  182.  
  183.         local handle, reason = temporaryFilesystemProxy.open(installerPath .. "Libraries/" .. module .. ".lua", "rb")
  184.         if handle then
  185.             local data, chunk = ""
  186.             repeat
  187.                 chunk = temporaryFilesystemProxy.read(handle, math.huge)
  188.                 data = data .. (chunk or "")
  189.             until not chunk
  190.  
  191.             temporaryFilesystemProxy.close(handle)
  192.            
  193.             local result, reason = load(data, "=" .. module)
  194.             if result then
  195.                 package.loaded[module] = result() or true
  196.             else
  197.                 error(reason)
  198.             end
  199.         else
  200.             error("File opening failed: " .. tostring(reason))
  201.         end
  202.  
  203.         package.loading[module] = nil
  204.  
  205.         return package.loaded[module]
  206.     end
  207. end
  208.  
  209. -- Initializing system libraries
  210. local filesystem = require("Filesystem")
  211. filesystem.setProxy(temporaryFilesystemProxy)
  212.  
  213. bit32 = bit32 or require("Bit32")
  214. local image = require("Image")
  215. local text = require("Text")
  216. local number = require("Number")
  217.  
  218. local screen = require("Screen")
  219. screen.setGPUProxy(GPUProxy)
  220.  
  221. local GUI = require("GUI")
  222. local system = require("System")
  223. local paths = require("Paths")
  224.  
  225. --------------------------------------------------------------------------------
  226.  
  227. -- Creating main UI workspace
  228. local workspace = GUI.workspace()
  229. workspace:addChild(GUI.panel(1, 1, workspace.width, workspace.height, 0x1E1E1E))
  230.  
  231. -- Main installer window
  232. local window = workspace:addChild(GUI.window(1, 1, 80, 24))
  233. window.localX, window.localY = math.ceil(workspace.width / 2 - window.width / 2), math.ceil(workspace.height / 2 - window.height / 2)
  234. window:addChild(GUI.panel(1, 1, window.width, window.height, 0xE1E1E1))
  235.  
  236. -- Top menu
  237. local menu = workspace:addChild(GUI.menu(1, 1, workspace.width, 0xF0F0F0, 0x787878, 0x3366CC, 0xE1E1E1))
  238. local installerMenu = menu:addContextMenuItem("MineOS", 0x2D2D2D)
  239. installerMenu:addItem("Shutdown").onTouch = function()
  240.     computer.shutdown()
  241. end
  242. installerMenu:addItem("Reboot").onTouch = function()
  243.     computer.shutdown(true)
  244. end
  245. installerMenu:addSeparator()
  246. installerMenu:addItem("Exit").onTouch = function()
  247.     workspace:stop()
  248. end
  249.  
  250. -- Main vertical layout
  251. local layout = window:addChild(GUI.layout(1, 1, window.width, window.height - 2, 1, 1))
  252.  
  253. local stageButtonsLayout = window:addChild(GUI.layout(1, window.height - 1, window.width, 1, 1, 1))
  254. stageButtonsLayout:setDirection(1, 1, GUI.DIRECTION_HORIZONTAL)
  255. stageButtonsLayout:setSpacing(1, 1, 3)
  256.  
  257. local function loadImage(name)
  258.     return image.load(installerPicturesPath .. name .. ".pic")
  259. end
  260.  
  261. local function newInput(...)
  262.     return GUI.input(1, 1, 26, 1, 0xF0F0F0, 0x787878, 0xC3C3C3, 0xF0F0F0, 0x878787, "", ...)
  263. end
  264.  
  265. local function newSwitchAndLabel(width, color, text, state)
  266.     return GUI.switchAndLabel(1, 1, width, 6, color, 0xD2D2D2, 0xF0F0F0, 0xA5A5A5, text .. ":", state)
  267. end
  268.  
  269. local function addTitle(color, text)
  270.     return layout:addChild(GUI.text(1, 1, color, text))
  271. end
  272.  
  273. local function addImage(before, after, name)
  274.     if before > 0 then
  275.         layout:addChild(GUI.object(1, 1, 1, before))
  276.     end
  277.  
  278.     local picture = layout:addChild(GUI.image(1, 1, loadImage(name)))
  279.     picture.height = picture.height + after
  280.  
  281.     return picture
  282. end
  283.  
  284. local function addStageButton(text)
  285.     local button = stageButtonsLayout:addChild(GUI.adaptiveRoundedButton(1, 1, 2, 0, 0xC3C3C3, 0x878787, 0xA5A5A5, 0x696969, text))
  286.     button.colors.disabled.background = 0xD2D2D2
  287.     button.colors.disabled.text = 0xB4B4B4
  288.  
  289.     return button
  290. end
  291.  
  292. local prevButton = addStageButton("<")
  293. local nextButton = addStageButton(">")
  294.  
  295. local localization
  296. local stage = 1
  297. local stages = {}
  298.  
  299. local usernameInput = newInput("")
  300. local passwordInput = newInput("", false, "•")
  301. local passwordSubmitInput = newInput("", false, "•")
  302. local usernamePasswordText = GUI.text(1, 1, 0xCC0040, "")
  303. local passwordSwitchAndLabel = newSwitchAndLabel(26, 0x66DB80, "", false)
  304.  
  305. local wallpapersSwitchAndLabel = newSwitchAndLabel(30, 0xFF4980, "", true)
  306. local screensaversSwitchAndLabel = newSwitchAndLabel(30, 0xFFB600, "", true)
  307. local applicationsSwitchAndLabel = newSwitchAndLabel(30, 0x33DB80, "", true)
  308. local localizationsSwitchAndLabel = newSwitchAndLabel(30, 0x33B6FF, "", true)
  309.  
  310. local acceptSwitchAndLabel = newSwitchAndLabel(30, 0x9949FF, "", false)
  311.  
  312. local localizationComboBox = GUI.comboBox(1, 1, 22, 1, 0xF0F0F0, 0x969696, 0xD2D2D2, 0xB4B4B4)
  313. for i = 1, #files.localizations do
  314.     localizationComboBox:addItem(filesystemHideExtension(filesystemName(files.localizations[i]))).onTouch = function()
  315.         -- Obtaining localization table
  316.         localization = deserialize(request(installerURL .. files.localizations[i]))
  317.  
  318.         -- Filling widgets with selected localization data
  319.         usernameInput.placeholderText = localization.username
  320.         passwordInput.placeholderText = localization.password
  321.         passwordSubmitInput.placeholderText = localization.submitPassword
  322.         passwordSwitchAndLabel.label.text = localization.withoutPassword
  323.         wallpapersSwitchAndLabel.label.text = localization.wallpapers
  324.         screensaversSwitchAndLabel.label.text = localization.screensavers
  325.         applicationsSwitchAndLabel.label.text = localization.applications
  326.         localizationsSwitchAndLabel.label.text = localization.languages
  327.         acceptSwitchAndLabel.label.text = localization.accept
  328.     end
  329. end
  330.  
  331. local function addStage(onTouch)
  332.     table.insert(stages, function()
  333.         layout:removeChildren()
  334.         onTouch()
  335.         workspace:draw()
  336.     end)
  337. end
  338.  
  339. local function loadStage()
  340.     if stage < 1 then
  341.         stage = 1
  342.     elseif stage > #stages then
  343.         stage = #stages
  344.     end
  345.  
  346.     stages[stage]()
  347. end
  348.  
  349. local function checkUserInputs()
  350.     local nameEmpty = #usernameInput.text == 0
  351.     local nameVaild = usernameInput.text:match("^%w[%w%s_]+$")
  352.     local passValid = passwordSwitchAndLabel.switch.state or #passwordInput.text == 0 or #passwordSubmitInput.text == 0 or passwordInput.text == passwordSubmitInput.text
  353.  
  354.     if (nameEmpty or nameVaild) and passValid then
  355.         usernamePasswordText.hidden = true
  356.         nextButton.disabled = nameEmpty or not nameVaild or not passValid
  357.     else
  358.         usernamePasswordText.hidden = false
  359.         nextButton.disabled = true
  360.  
  361.         if nameVaild then
  362.             usernamePasswordText.text = localization.passwordsArentEqual
  363.         else
  364.             usernamePasswordText.text = localization.usernameInvalid
  365.         end
  366.     end
  367. end
  368.  
  369. local function checkLicense()
  370.     nextButton.disabled = not acceptSwitchAndLabel.switch.state
  371. end
  372.  
  373. prevButton.onTouch = function()
  374.     stage = stage - 1
  375.     loadStage()
  376. end
  377.  
  378. nextButton.onTouch = function()
  379.     stage = stage + 1
  380.     loadStage()
  381. end
  382.  
  383. acceptSwitchAndLabel.switch.onStateChanged = function()
  384.     checkLicense()
  385.     workspace:draw()
  386. end
  387.  
  388. passwordSwitchAndLabel.switch.onStateChanged = function()
  389.     passwordInput.hidden = passwordSwitchAndLabel.switch.state
  390.     passwordSubmitInput.hidden = passwordSwitchAndLabel.switch.state
  391.     checkUserInputs()
  392.  
  393.     workspace:draw()
  394. end
  395.  
  396. usernameInput.onInputFinished = function()
  397.     checkUserInputs()
  398.     workspace:draw()
  399. end
  400.  
  401. passwordInput.onInputFinished = usernameInput.onInputFinished
  402. passwordSubmitInput.onInputFinished = usernameInput.onInputFinished
  403.  
  404. -- Localization selection stage
  405. addStage(function()
  406.     prevButton.disabled = true
  407.  
  408.     addImage(0, 1, "Languages")
  409.     layout:addChild(localizationComboBox)
  410.  
  411.     workspace:draw()
  412.     localizationComboBox:getItem(1).onTouch()
  413. end)
  414.  
  415. -- Filesystem selection stage
  416. addStage(function()
  417.     prevButton.disabled = false
  418.     nextButton.disabled = false
  419.  
  420.     layout:addChild(GUI.object(1, 1, 1, 1))
  421.     addTitle(0x696969, localization.select)
  422.    
  423.     local diskLayout = layout:addChild(GUI.layout(1, 1, layout.width, 11, 1, 1))
  424.     diskLayout:setDirection(1, 1, GUI.DIRECTION_HORIZONTAL)
  425.     diskLayout:setSpacing(1, 1, 0)
  426.  
  427.     local HDDImage = loadImage("HDD")
  428.  
  429.     local function select(proxy)
  430.         selectedFilesystemProxy = proxy
  431.  
  432.         for i = 1, #diskLayout.children do
  433.             diskLayout.children[i].children[1].hidden = diskLayout.children[i].proxy ~= selectedFilesystemProxy
  434.         end
  435.     end
  436.  
  437.     local function updateDisks()
  438.         local function diskEventHandler(workspace, disk, e1)
  439.             if e1 == "touch" then
  440.                 select(disk.proxy)
  441.                 workspace:draw()
  442.             end
  443.         end
  444.  
  445.         local function addDisk(proxy, picture, disabled)
  446.             local disk = diskLayout:addChild(GUI.container(1, 1, 14, diskLayout.height))
  447.  
  448.             local formatContainer = disk:addChild(GUI.container(1, 1, disk.width, disk.height))
  449.             formatContainer:addChild(GUI.panel(1, 1, formatContainer.width, formatContainer.height, 0xD2D2D2))
  450.             formatContainer:addChild(GUI.button(1, formatContainer.height, formatContainer.width, 1, 0xCC4940, 0xE1E1E1, 0x990000, 0xE1E1E1, localization.erase)).onTouch = function()
  451.                 local list, path = proxy.list("/")
  452.                 for i = 1, #list do
  453.                     path = "/" .. list[i]
  454.  
  455.                     if proxy.address ~= temporaryFilesystemProxy.address or path ~= installerPath then
  456.                         proxy.remove(path)
  457.                     end
  458.                 end
  459.  
  460.                 updateDisks()
  461.             end
  462.  
  463.             if disabled then
  464.                 picture = image.blend(picture, 0xFFFFFF, 0.4)
  465.                 disk.disabled = true
  466.             end
  467.  
  468.             disk:addChild(GUI.image(4, 2, picture))
  469.             disk:addChild(GUI.label(2, 7, disk.width - 2, 1, disabled and 0x969696 or 0x696969, text.limit(proxy.getLabel() or proxy.address, disk.width - 2))):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
  470.             disk:addChild(GUI.progressBar(2, 8, disk.width - 2, disabled and 0xCCDBFF or 0x66B6FF, disabled and 0xD2D2D2 or 0xC3C3C3, disabled and 0xC3C3C3 or 0xA5A5A5, math.floor(proxy.spaceUsed() / proxy.spaceTotal() * 100), true, true, "", "% " .. localization.used))
  471.  
  472.             disk.eventHandler = diskEventHandler
  473.             disk.proxy = proxy
  474.         end
  475.  
  476.         diskLayout:removeChildren()
  477.        
  478.         for address in component.list("filesystem") do
  479.             local proxy = component.proxy(address)
  480.             if proxy.spaceTotal() >= 1 * 1024 * 1024 then
  481.                 addDisk(
  482.                     proxy,
  483.                     proxy.spaceTotal() < 1 * 1024 * 1024 and floppyImage or HDDImage,
  484.                     proxy.isReadOnly() or proxy.spaceTotal() < 2 * 1024 * 1024
  485.                 )
  486.             end
  487.         end
  488.  
  489.         select(selectedFilesystemProxy)
  490.     end
  491.    
  492.     updateDisks()
  493. end)
  494.  
  495. -- User profile setup stage
  496. addStage(function()
  497.     checkUserInputs()
  498.  
  499.     addImage(0, 0, "User")
  500.     addTitle(0x696969, localization.setup)
  501.  
  502.     layout:addChild(usernameInput)
  503.     layout:addChild(passwordInput)
  504.     layout:addChild(passwordSubmitInput)
  505.     layout:addChild(usernamePasswordText)
  506.     layout:addChild(passwordSwitchAndLabel)
  507. end)
  508.  
  509. -- Downloads customization stage
  510. addStage(function()
  511.     nextButton.disabled = false
  512.  
  513.     addImage(0, 0, "Settings")
  514.     addTitle(0x696969, localization.customize)
  515.  
  516.     layout:addChild(wallpapersSwitchAndLabel)
  517.     layout:addChild(screensaversSwitchAndLabel)
  518.     layout:addChild(applicationsSwitchAndLabel)
  519.     layout:addChild(localizationsSwitchAndLabel)
  520. end)
  521.  
  522. -- License acception stage
  523. addStage(function()
  524.     checkLicense()
  525.  
  526.     local lines = text.wrap({request("LICENSE")}, layout.width - 2)
  527.     local textBox = layout:addChild(GUI.textBox(1, 1, layout.width, layout.height - 3, 0xF0F0F0, 0x696969, lines, 1, 1, 1))
  528.  
  529.     layout:addChild(acceptSwitchAndLabel)
  530. end)
  531.  
  532. -- Downloading stage
  533. addStage(function()
  534.     stageButtonsLayout:removeChildren()
  535.    
  536.     -- Creating user profile
  537.     layout:removeChildren()
  538.     addImage(1, 1, "User")
  539.     addTitle(0x969696, localization.creating)
  540.     workspace:draw()
  541.  
  542.     -- Renaming if possible
  543.     if not selectedFilesystemProxy.getLabel() then
  544.         selectedFilesystemProxy.setLabel("MineOS HDD")
  545.     end
  546.  
  547.     local function switchProxy(runnable)
  548.         filesystem.setProxy(selectedFilesystemProxy)
  549.         runnable()
  550.         filesystem.setProxy(temporaryFilesystemProxy)
  551.     end
  552.  
  553.     -- Creating system paths
  554.     local userSettings, userPaths
  555.     switchProxy(function()
  556.         paths.create(paths.system)
  557.         userSettings, userPaths = system.createUser(
  558.             usernameInput.text,
  559.             localizationComboBox:getItem(localizationComboBox.selectedItem).text,
  560.             not passwordSwitchAndLabel.switch.state and passwordInput.text,
  561.             wallpapersSwitchAndLabel.switch.state,
  562.             screensaversSwitchAndLabel.switch.state
  563.         )
  564.     end)
  565.  
  566.     -- Flashing EEPROM
  567.     layout:removeChildren()
  568.     addImage(1, 1, "EEPROM")
  569.     addTitle(0x969696, localization.flashing)
  570.     workspace:draw()
  571.    
  572.     EEPROMProxy.set(request(EFIURL))
  573.     EEPROMProxy.setLabel("MineOS EFI")
  574.     EEPROMProxy.setData(selectedFilesystemProxy.address)
  575.  
  576.     -- Downloading files
  577.     layout:removeChildren()
  578.     addImage(3, 2, "Downloading")
  579.  
  580.     local container = layout:addChild(GUI.container(1, 1, layout.width - 20, 2))
  581.     local progressBar = container:addChild(GUI.progressBar(1, 1, container.width, 0x66B6FF, 0xD2D2D2, 0xA5A5A5, 0, true, false))
  582.     local cyka = container:addChild(GUI.label(1, 2, container.width, 1, 0x969696, "")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP)
  583.  
  584.     -- Creating final filelist of things to download
  585.     local downloadList = {}
  586.  
  587.     local function getData(item)
  588.         if type(item) == "table" then
  589.             return item.path, item.id, item.version, item.shortcut
  590.         else
  591.             return item
  592.         end
  593.     end
  594.  
  595.     local function addToList(state, key)
  596.         if state then
  597.             local selectedLocalization, path, localizationName = localizationComboBox:getItem(localizationComboBox.selectedItem).text
  598.            
  599.             for i = 1, #files[key] do
  600.                 path = getData(files[key][i])
  601.  
  602.                 if filesystem.extension(path) == ".lang" then
  603.                     localizationName = filesystem.hideExtension(filesystem.name(path))
  604.  
  605.                     if
  606.                         -- If ALL loacalizations need to be downloaded
  607.                         localizationsSwitchAndLabel.switch.state or
  608.                         -- If it's required localization file
  609.                         localizationName == selectedLocalization or
  610.                         -- Downloading English "just in case" for non-english localizations
  611.                         selectedLocalization ~= "English" and localizationName == "English"
  612.                     then
  613.                         table.insert(downloadList, files[key][i])
  614.                     end
  615.                 else
  616.                     table.insert(downloadList, files[key][i])
  617.                 end
  618.             end
  619.         end
  620.     end
  621.  
  622.     addToList(true, "required")
  623.     addToList(true, "localizations")
  624.     addToList(applicationsSwitchAndLabel.switch.state, "optional")
  625.     addToList(wallpapersSwitchAndLabel.switch.state, "wallpapers")
  626.     addToList(screensaversSwitchAndLabel.switch.state, "screensavers")
  627.  
  628.     -- Downloading files from created list
  629.     local versions, path, id, version, shortcut = {}
  630.     for i = 1, #downloadList do
  631.         path, id, version, shortcut = getData(downloadList[i])
  632.  
  633.         cyka.text = text.limit(localization.installing .. " \"" .. path .. "\"", container.width, "center")
  634.         workspace:draw()
  635.  
  636.         -- Download file
  637.         download(path, OSPath .. path)
  638.  
  639.         -- Adding system versions data
  640.         if id then
  641.             versions[id] = {
  642.                 path = OSPath .. path,
  643.                 version = version or 1,
  644.             }
  645.         end
  646.  
  647.         -- Create shortcut if possible
  648.         if shortcut then
  649.             switchProxy(function()
  650.                 system.createShortcut(
  651.                     userPaths.desktop .. filesystem.hideExtension(filesystem.name(filesystem.path(path))),
  652.                     OSPath .. filesystem.path(path)
  653.                 )
  654.             end)
  655.         end
  656.  
  657.         progressBar.value = math.floor(i / #downloadList * 100)
  658.         workspace:draw()
  659.     end
  660.  
  661.     -- Saving system versions
  662.     switchProxy(function()
  663.         filesystem.writeTable(paths.system.versions, versions, true)
  664.     end)
  665.  
  666.     -- Done info
  667.     layout:removeChildren()
  668.     addImage(1, 1, "Done")
  669.     addTitle(0x969696, localization.installed)
  670.     addStageButton(localization.reboot).onTouch = function()
  671.         computer.shutdown(true)
  672.     end
  673.     workspace:draw()
  674.  
  675.     -- Removing temporary installer directory
  676.     temporaryFilesystemProxy.remove(installerPath)
  677. end)
  678.  
  679. --------------------------------------------------------------------------------
  680.  
  681. loadStage()
  682. workspace:start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement