SHOW:
|
|
- or go back to the newest paste.
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 | ----------------- Computer Checking for compliance with the SIS. requirements -------------------------- | |
12 | ||
13 | - | --Sozdaem Array of poop |
13 | + | --Sozdaem Array of shit |
14 | local govno = {} | |
15 | ||
16 | print ( "") | |
17 | print ( "Analyzing computer for matching system requirements ...") | |
18 | ||
19 | --Proveryaem GPU | |
20 | if gpu.maxResolution () <150 then table.insert (govno, "Bad GPU - this OS requires Tier 1 GPU.") end | |
21 | ||
22 | --Proveryaem screen | |
23 | if gpu.getDepth (1) <8 and gpu.maxResolution (1) <1 then table.insert (govno, "Bad Screen - this OS requires Tier 1 screen.") end | |
24 | ||
25 | --Proveryaem operativku | |
26 | - | if math.floor (computer.totalMemory (1) / 1024) <2048 then table.insert (govno, "Not enough RAM - this OS requires at least 2048 KB RAM.") end |
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 not 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 | --If Found some discrepancy ICU. requirements, then write that it is not so | |
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 | ----------------------------- ------------------- Preparation stage ------------------------ | |
55 | ||
56 | ||
57 | With --ZAGRUZOCHKA GITHABA | |
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 | --Safety ZAGRUZOCHKA | |
80 | local function getFromGitHubSafely (url, path) | |
81 | local success, sRepos = pcall (getFromGitHub, url, path) | |
82 | if not success then | |
83 | io.stderr: write ( "Can not download \" ".. url .." \ "\ n"!) | |
84 | return -1 | |
85 | end | |
86 | return sRepos | |
87 | end | |
88 | ||
89 | With --ZAGRUZOCHKA PASTEBINA | |
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 | --------------------------------- Stage Homepage download all necessary ------------ --------------------- | |
124 | ||
125 | ||
126 | local preLoadApi = { | |
127 | {Paste = "IgorTimofeev / OpenComputers / master / lib / ECSAPI.lua", path = "lib / ECSAPI.lua"}, | |
128 | {Paste = "IgorTimofeev / OpenComputers / master / lib / colorlib.lua", path = "lib / colorlib.lua"}, | |
129 | {Paste = "IgorTimofeev / OpenComputers / master / lib / image.lua", path = "lib / image.lua"}, | |
130 | {Paste = "IgorTimofeev / OpenComputers / master / lib / config.lua", path = "lib / config.lua"}, | |
131 | {Paste = "IgorTimofeev / OpenComputers / master / MineOS / Icons / Languages.pic", path = "MineOS / System / OS / Icons / Languages.pic"}, | |
132 | {Paste = "IgorTimofeev / OpenComputers / master / MineOS / Icons / OK.pic", path = "MineOS / System / OS / Icons / OK.pic"}, | |
133 | {Paste = "IgorTimofeev / OpenComputers / master / MineOS / Icons / Downloading.pic", path = "MineOS / System / OS / Icons / Downloading.pic"}, | |
134 | {Paste = "IgorTimofeev / OpenComputers / 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 / OpenComputers / 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 | --OBEKTY | |
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 | ------------------------------ ------------------ LANGUAGE ------------------ | |
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 | --knopa | |
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 | --USTANAVLIVAEM Desired language | |
221 | _G.OSSettings = {ShowHelpOnApplicationStart = showHelpTips, language = data [1]} | |
222 | ecs.saveOSSettings () | |
223 | ||
224 | --Kachaem language | |
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 | --Stavim language | |
231 | lang = config.readAll (pathToLang) | |
232 | ||
233 | end | |
234 | ||
235 | ||
236 | ------------------------------ ----------------- AXIS IS PUT ------------------- | |
237 | ||
238 | do | |
239 | clear () | |
240 | ||
241 | image.draw (math.ceil (xSize / 2 - 15), yWindow + 2, imageOS) | |
242 | ||
243 | --Tekstik Centered | |
244 | gpu.setBackground (ecs.windowColors.background) | |
245 | gpu.setForeground (ecs.colors.gray) | |
246 | ecs.centerText ( "x", yWindowEnd - 5, lang.beginOsInstall) | |
247 | ||
248 | --knopa | |
249 | drawButton ( "->", false) | |
250 | ||
251 | waitForClickOnButton ( "->") | |
252 | ||
253 | end | |
254 | ||
255 | ------------------------------ ------------------ PERSONS SOGLASCHENKA ------------------------ | |
256 | ||
257 | do | |
258 | clear () | |
259 | ||
260 | --Otkuda Draw acc conditions | |
261 | local from = 1 | |
262 | local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7 | |
263 | ||
264 | --Chitaem File sogll persons | |
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 | --Shtuku draw | |
273 | ecs.textField (xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) | |
274 | ||
275 | --Info draw | |
276 | --ecs.centerText ( "x", yWindowEnd - 5, "Do you accept the license agreement?") | |
277 | ||
278 | --knopa | |
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 | -------------------------- Prepare filesystem --------------------- ------------- | |
300 | ||
301 | --Sozdaem Starting way and other little things purely for aesthetics | |
302 | local desktopPath = "MineOS / Desktop /" | |
303 | local dockPath = "MineOS / System / OS / Dock /" | |
304 | local applicationsPath = "MineOS / Applications /" | |
305 | local picturesPath = "MineOS / Pictures /" | |
306 | ||
307 | fs.remove (desktopPath) | |
308 | fs.remove (dockPath) | |
309 | ||
310 | fs.makeDirectory (desktopPath .. "My files") | |
311 | fs.makeDirectory (picturesPath) | |
312 | fs.makeDirectory (dockPath) | |
313 | ||
314 | -------------------------- ---------------------- STAGE LOADING ------------- | |
315 | ||
316 | do | |
317 | ||
318 | local barWidth = math.floor (windowWidth * 2/3) | |
319 | local xBar = math.floor (xSize / 2-barWidth / 2) | |
320 | local yBar = yWindowEnd - 3 | |
321 | ||
322 | local function drawInfo (x, y, info) | |
323 | ecs.square (x, y, barWidth, 1, ecs.windowColors.background) | |
324 | ecs.colorText (x, y, ecs.colors.gray, info) | |
325 | end | |
326 | ||
327 | ecs.blankWindow (xWindow, yWindow, windowWidth, windowHeight) | |
328 | ||
329 | image.draw (math.floor (xSize / 2 - 33), yWindow + 2, imageDownloading) | |
330 | ||
331 | ecs.colorTextWithBack (xBar, yBar - 1, ecs.colors.gray, ecs.windowColors.background, lang.osInstallation) | |
332 | ecs.progressBar (xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, 0) | |
333 | os.sleep (timing) | |
334 | ||
335 | for app = 1, #applications do | |
336 | --All FOR GRAFONA | |
337 | drawInfo (xBar, yBar + 1, lang.downloading .. "" .. applications [app] [ "name"]) | |
338 | local percent = app / #applications * 100 | |
339 | ecs.progressBar (xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent) | |
340 | ||
341 | --All DOWNLOAD | |
342 | local path = applications [app] [ "name"] | |
343 | fs.remove (path .. ".app") | |
344 | ||
345 | --If Type = application | |
346 | if applications [app] [ "type"] == "Application" then | |
347 | fs.makeDirectory (path .. ". app / Resources") | |
348 | getFromGitHubSafely (GitHubUserUrl .. applications [app] [ "url"], path .. ".app /" .. fs.name (applications [app] [ "name"] .. ".lua")) | |
349 | getFromGitHubSafely (GitHubUserUrl .. applications [app] [ "icon"], path .. ".app / Resources / Icon.pic") | |
350 | ||
351 | --If There are resources, then downloaded resources | |
352 | if applications [app] [ "resources"] then | |
353 | for i = 1, #applications [app] [ "resources"] do | |
354 | getFromGitHubSafely (GitHubUserUrl .. applications [app] [ "resources"] [i] [ "url"], path .. ". app / Resources /" .. applications [app] [ "resources"] [i] [ "name "]) | |
355 | end | |
356 | end | |
357 | ||
358 | --If There is a file "on the program", the ship and its | |
359 | if applications [app] .about then | |
360 | getFromGitHubSafely (GitHubUserUrl .. applications [app] .about, path .. ".app / Resources / About.txt") | |
361 | end | |
362 | ||
363 | --If There is a label creation mode, you create it | |
364 | if applications [app] .createShortcut then | |
365 | if applications [app] .createShortcut == "dock" then | |
366 | ecs.createShortCut (dockPath .. fs.name (applications [app] .name) .. ".lnk", applications [app] .name .. ".app") | |
367 | else | |
368 | ecs.createShortCut (desktopPath .. fs.name (applications [app] .name) .. ".lnk", applications [app] .name .. ".app") | |
369 | end | |
370 | end | |
371 | ||
372 | --If Type = other, stranger, and MB and their pastebin | |
373 | elseif applications [app] [ "type"] == "Pastebin" then | |
374 | fs.remove (applications [app] [ "name"]) | |
375 | fs.makeDirectory (fs.path (applications [app] [ "name"])) | |
376 | getFromPastebin (applications [app] [ "url"], applications [app] [ "name"]) | |
377 | ||
378 | --If wallpaper | |
379 | elseif applications [app] [ "type"] == "Wallpaper" then | |
380 | if downloadWallpapers then | |
381 | getFromGitHubSafely (GitHubUserUrl .. applications [app] [ "url"], path) | |
382 | end | |
383 | --A If something else Th | |
384 | else | |
385 | getFromGitHubSafely (GitHubUserUrl .. applications [app] [ "url"], path) | |
386 | end | |
387 | end | |
388 | ||
389 | os.sleep (timing) | |
390 | end | |
391 | ||
392 | --Sozdaem Basic wallpaper | |
393 | ecs.createShortCut (desktopPath .. "Pictures.lnk", picturesPath) | |
394 | if downloadWallpapers then ecs.createShortCut ( "MineOS / System / OS / Wallpaper.lnk", picturesPath .. "ChristmasTree.pic") end | |
395 | ||
396 | --Avtozagruzka | |
397 | local file = io.open ( "autorun.lua", "w") | |
398 | file: write ( "local success, reason = pcall (loadfile (\" OS.lua \ ")); if not success then print (\" Error: \ ".. tostring (reason)) end") | |
399 | file: close () | |
400 | ||
401 | -------------------------- PHASE RESET COMP --------------------- -------------- | |
402 | ||
403 | ecs.blankWindow (xWindow, yWindow, windowWidth, windowHeight) | |
404 | ||
405 | image.draw (math.floor (xSize / 2 - 16), math.floor (ySize / 2 - 11), imageOK) | |
406 | ||
407 | --Tekstik Centered | |
408 | gpu.setBackground (ecs.windowColors.background) | |
409 | gpu.setForeground (ecs.colors.gray) | |
410 | ecs.centerText ( "x", yWindowEnd - 5, lang.needToRestart) | |
411 | ||
412 | --Knopa | |
413 | drawButton (lang.restart, false) | |
414 | waitForClickOnButton (lang.restart) | |
415 | ecs.prepareToExit () | |
416 | ||
417 | computer.shutdown (true) |