View difference between Paste ID: 8qa6hCVv and 34LemXCU
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 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
  { paste = "kreezxil/OpenComputers-1/master/lib/ECSAPI.lua", path = "lib/ECSAPI.lua" },
104
  { paste = "kreezxil/OpenComputers-1/master/lib/colorlib.lua", path = "lib/colorlib.lua" },
105
  { paste = "kreezxil/OpenComputers-1/master/lib/image.lua", path = "lib/image.lua" },
106
  { paste = "kreezxil/OpenComputers-1/master/lib/config.lua", path = "lib/config.lua" },
107
  { paste = "kreezxil/OpenComputers-1/master/MineOS/Icons/Languages.pic", path = "MineOS/System/OS/Icons/Languages.pic" },
108
  { paste = "kreezxil/OpenComputers-1/master/MineOS/Icons/OK.pic", path = "MineOS/System/OS/Icons/OK.pic" },
109
  { paste = "kreezxil/OpenComputers-1/master/MineOS/Icons/Downloading.pic", path = "MineOS/System/OS/Icons/Downloading.pic" },
110
  { paste = "kreezxil/OpenComputers-1/master/MineOS/Icons/OS_Logo.pic", path = "MineOS/System/OS/Icons/OS_Logo.pic" },
111
}
112
113
print("Downloading file list")
114
applications = seri.unserialize(getFromGitHubSafely(GitHubUserUrl .. "kreezxil/OpenComputers-1/master/Applications.txt", "MineOS/System/OS/Applications.txt"))
115
print(" ")
116
117
for i = 1, #preLoadApi do
118
  print("Downloading \"" .. fs.name(preLoadApi[i].path) .. "\"")
119
  getFromGitHubSafely(GitHubUserUrl .. preLoadApi[i].paste, preLoadApi[i].path)
120
end
121
122
print(" ")
123
print("Initialization stage is complete, loading installer")
124
print(" ")
125
126
package.loaded.ecs = nil
127
package.loaded.ECSAPI = nil
128
_G.ecs = require("ECSAPI")
129
_G.image = require("image")
130
_G.config = require("config")
131
132
local imageOS = image.load("MineOS/System/OS/Icons/OS_Logo.pic")
133
local imageLanguages = image.load("MineOS/System/OS/Icons/Languages.pic")
134
local imageDownloading = image.load("MineOS/System/OS/Icons/Downloading.pic")
135
local imageOK = image.load("MineOS/System/OS/Icons/OK.pic")
136
137
ecs.setScale(installerScale)
138
139
local xSize, ySize = gpu.getResolution()
140
local windowWidth = 80
141
local windowHeight = 2 + 16 + 2 + 3 + 2
142
local xWindow, yWindow = math.floor(xSize / 2 - windowWidth / 2), math.ceil(ySize / 2 - windowHeight / 2)
143
local xWindowEnd, yWindowEnd = xWindow + windowWidth - 1, yWindow + windowHeight - 1
144
145
146
-------------------------------------------------------------------------------------------
147
148
local function clear()
149
  ecs.blankWindow(xWindow, yWindow, windowWidth, windowHeight)
150
end
151
152
--ОБЪЕКТЫ
153
local obj = {}
154
local function newObj(class, name, ...)
155
  obj[class] = obj[class] or {}
156
  obj[class][name] = {...}
157
end
158
159
local function drawButton(name, isPressed)
160
  local buttonColor = 0x888888
161
  if isPressed then buttonColor = ecs.colors.blue end
162
  local d = { ecs.drawAdaptiveButton("auto", yWindowEnd - 3, 2, 1, name, buttonColor, 0xffffff) }
163
  newObj("buttons", name, d[1], d[2], d[3], d[4])
164
end
165
166
local function waitForClickOnButton(buttonName)
167
  while true do
168
    local e = { event.pull() }
169
    if e[1] == "touch" then
170
      if ecs.clickedAtArea(e[3], e[4], obj["buttons"][buttonName][1], obj["buttons"][buttonName][2], obj["buttons"][buttonName][3], obj["buttons"][buttonName][4]) then
171
        drawButton(buttonName, true)
172
        os.sleep(timing)
173
        break
174
      end
175
    end
176
  end
177
end
178
179
180
------------------------------ВЫБОР ЯЗЫКА------------------------------------
181
182
ecs.prepareToExit()
183
184
local downloadWallpapers, showHelpTips, downloadAllApps = false, false, false
185
186
do
187
188
  clear()
189
190
  image.draw(math.ceil(xSize / 2 - 30), yWindow + 2, imageLanguages)
191
192
  --кнопа
193
  drawButton("Select language",false)
194
195
  waitForClickOnButton("Select language")
196
197
  local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true,
198
    {"EmptyLine"},
199
    {"CenterText", ecs.colors.orange, "Select language"},
200
    {"EmptyLine"},
201
    {"Select", 0xFFFFFF, ecs.colors.green, "Russian", "English"},
202
    {"EmptyLine"},
203
    {"CenterText", ecs.colors.orange, "Change some OS properties"},
204
    {"EmptyLine"},
205
    {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Download all Apps", true},
206
    {"EmptyLine"},
207
    {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Download wallpapers", true},
208
    {"EmptyLine"},
209
    {"Switch", 0xF2B233, 0xffffff, 0xFFFFFF, "Show help tips in OS", true},
210
    {"EmptyLine"},
211
    {"Button", {ecs.colors.orange, 0x262626, "OK"}}
212
  )
213
  downloadAllApps, downloadWallpapers, showHelpTips = data[2], data[3], data[4]
214
215
  --УСТАНАВЛИВАЕМ НУЖНЫЙ ЯЗЫК
216
  _G.OSSettings = { showHelpOnApplicationStart = showHelpTips, language = data[1] }
217
  ecs.saveOSSettings()
218
219
  --Качаем язык
220
  ecs.info("auto", "auto", " ", " Installing language packages...")
221
  local pathToLang = "MineOS/System/OS/Installer/Language.lang"
222
  getFromGitHubSafely(GitHubUserUrl .. "kreezxil/OpenComputers-1/master/Installer/" .. _G.OSSettings.language .. ".lang", pathToLang)
223
  getFromGitHubSafely(GitHubUserUrl .. "kreezxil/OpenComputers-1/master/MineOS/License/" .. _G.OSSettings.language .. ".txt", "MineOS/System/OS/License.txt")
224
  
225
  --Ставим язык
226
  lang = config.readAll(pathToLang)
227
228
end
229
230
231
------------------------------СТАВИТЬ ЛИ ОСЬ------------------------------------
232
233
do
234
  clear()
235
236
  image.draw(math.ceil(xSize / 2 - 15), yWindow + 2, imageOS)
237
238
  --Текстик по центру
239
  gpu.setBackground(ecs.windowColors.background)
240
  gpu.setForeground(ecs.colors.gray)
241
  ecs.centerText("x", yWindowEnd - 5 , lang.beginOsInstall)
242
243
  --кнопа
244
  drawButton("->",false)
245
246
  waitForClickOnButton("->")
247
248
end
249
250
------------------------------ЛИЦ СОГЛАЩЕНЬКА------------------------------------------
251
252
do
253
  clear()
254
  
255
  --Откуда рисовать условия согл
256
  local from = 1
257
  local xText, yText, TextWidth, TextHeight = xWindow + 4, yWindow + 2, windowWidth - 8, windowHeight - 7
258
259
  --Читаем файл с лиц соглл
260
  local lines = {}
261
  local file = io.open("MineOS/System/OS/License.txt", "r")
262
  for line in file:lines() do
263
    table.insert(lines, line)
264
  end
265
  file:close()
266
267
  --Штуку рисуем
268
  ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue)
269
270
  --Инфо рисуем
271
  --ecs.centerText("x", yWindowEnd - 5 ,"Принимаете ли вы условия лицензионного соглашения?")
272
273
  --кнопа
274
  drawButton(lang.acceptLicense, false)
275
276
  while true do
277
    local e = { event.pull() }
278
    if e[1] == "touch" then
279
      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
280
        drawButton(lang.acceptLicense, true)
281
        os.sleep(timing)
282
        break
283
      end
284
    elseif e[1] == "scroll" then
285
      if e[5] == -1 then
286
        if from < #lines then from = from + 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
287
      else
288
        if from > 1 then from = from - 1; ecs.textField(xText, yText, TextWidth, TextHeight, lines, from, 0xffffff, 0x262626, 0x888888, ecs.colors.blue) end
289
      end
290
    end
291
  end
292
end
293
294
-------------------------- Подготавливаем файловую систему ----------------------------------
295
296
--Создаем стартовые пути и прочие мелочи чисто для эстетики
297
local desktopPath = "MineOS/Desktop/"
298
local dockPath = "MineOS/System/OS/Dock/"
299
local applicationsPath = "MineOS/Applications/"
300
local picturesPath = "MineOS/Pictures/"
301
302
fs.remove(desktopPath)
303
fs.remove(dockPath)
304
305
-- fs.makeDirectory(desktopPath .. "My files")
306
-- fs.makeDirectory(picturesPath)
307
fs.makeDirectory(dockPath)
308
309
--------------------------СТАДИЯ ЗАГРУЗКИ-----------------------------------
310
311
do
312
  local barWidth = math.floor(windowWidth * 2 / 3)
313
  local xBar = math.floor(xSize/2-barWidth/2)
314
  local yBar = yWindowEnd - 3
315
316
  local function drawInfo(x, y, info)
317
    ecs.square(x, y, barWidth, 1, ecs.windowColors.background)
318
    ecs.colorText(x, y, ecs.colors.gray, info)
319
  end
320
321
  ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
322
323
  image.draw(math.floor(xSize / 2 - 33), yWindow + 2, imageDownloading)
324
325
  ecs.colorTextWithBack(xBar, yBar - 1, ecs.colors.gray, ecs.windowColors.background, lang.osInstallation)
326
  ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, 0)
327
  os.sleep(timing)
328
329
  local thingsToDownload = {}
330
  for i = 1, #applications do
331
    if 
332
      (applications[i].type == "Wallpaper" and downloadWallpapers)
333
      or
334
      (applications[i].type == "Application" and (downloadAllApps or applications[i].forceDownload))
335
      or
336
      (applications[i].type == "Library" or applications[i].type == "Icon")
337
      or
338
      (applications[i].forceDownload)
339
    then
340
      table.insert(thingsToDownload, applications[i])
341
    end
342
    --Подчищаем за собой, а то мусора нынче много
343
    applications[i] = nil
344
  end
345
346
  for app = 1, #thingsToDownload do
347
    --ВСЕ ДЛЯ ГРАФОНА
348
    drawInfo(xBar, yBar + 1, lang.downloading .. " " .. thingsToDownload[app]["name"])
349
    local percent = app / #thingsToDownload * 100
350
    ecs.progressBar(xBar, yBar, barWidth, 1, 0xcccccc, ecs.colors.blue, percent)
351
352
    ecs.getOSApplication(thingsToDownload[app])
353
  end
354
355
  os.sleep(timing)
356
end
357
358
--Создаем базовые обои рабочего стола
359
if downloadWallpapers then
360
  ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath)
361
  ecs.createShortCut("MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Nettle.pic")
362
end
363
364
--Автозагрузка
365
local file = io.open("autorun.lua", "w")
366
file:write("local success, reason = pcall(loadfile(\"OS.lua\")); if not success then print(\"Ошибка: \" .. tostring(reason)) end")
367
file:close()
368
369
--------------------------СТАДИЯ ПЕРЕЗАГРУЗКИ КОМПА-----------------------------------
370
371
ecs.blankWindow(xWindow,yWindow,windowWidth,windowHeight)
372
373
image.draw(math.floor(xSize/2 - 16), math.floor(ySize/2 - 11), imageOK)
374
375
--Текстик по центру
376
gpu.setBackground(ecs.windowColors.background)
377
gpu.setForeground(ecs.colors.gray)
378
ecs.centerText("x",yWindowEnd - 5, lang.needToRestart)
379
380
--Кнопа
381
drawButton(lang.restart, false)
382
waitForClickOnButton(lang.restart)
383
ecs.prepareToExit()
384
385
computer.shutdown(true)