Advertisement
Pit_Anonim

MiOS Public Alpha

Mar 16th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 31.94 KB | None | 0 0
  1. OS = {
  2.   [ "MiOS/system/API/pastebin" ] = "--Thanks to standart pastebin program\
  3. function run(paste)\
  4.    local response = http.get(\
  5.        \"http://pastebin.com/raw/\"..textutils.urlEncode( paste )\
  6.     )\
  7. \
  8.    local sResponse = response.readAll()\
  9.    response.close()\
  10.    local func = loadstring(sResponse)\
  11.    return func()\
  12. end",
  13.   [ "MiOS/system/logo.pic" ] = "55   55   88888 88888\
  14. 5d5 5d5 5 87778 87777\
  15. 5 5 5 5 d 8   8 8\
  16. 5 d5d 5 5 8   8 88888\
  17. 5  5  5 5 8   8 77778\
  18. 5  d  5 5 8   8     8\
  19. 5     5 5 88888 88888\
  20. d     d d 77777 77777",
  21.   [ "MiOS/system/localization/english" ] = "{\
  22.  \"MiOS\",\
  23.  \"Press \",\
  24.  \" to open menu\",\
  25.  \">\",\
  26.  \"Menu\",\
  27.  \"Enter name!\",\
  28.  \"Press key\",\
  29.  \"Name\",\
  30.  \"Password\",\
  31.  \"Hello, \",\
  32.  \"Computer will restart\",\
  33.  menu2 = {\
  34.    \"Set background color\",\
  35.    \"Set text color\",\
  36.    \"Set input text color\",\
  37.    \"Set menu button\",\
  38.    \"Change language\",\
  39.    \"Edit user\",\
  40.    \"Other\",\
  41.  },\
  42.  menu2Colors = {\
  43.    \"White\",\
  44.    \"Orange\",\
  45.    \"Magenta\",\
  46.    \"Light Blue\",\
  47.    \"Yellow\",\
  48.    \"Lime\",\
  49.    \"Pink\",\
  50.    \"Gray\",\
  51.    \"Light Gray\",\
  52.    \"Cyan\",\
  53.    \"Purple\",\
  54.    \"Blue\",\
  55.    \"Brown\",\
  56.    \"Green\",\
  57.    \"Red\",\
  58.    \"Black\",\
  59.  },\
  60.  menu2Colors1 = {\
  61.    \"White\",\
  62.    \"Light Gray\",\
  63.    \"Gray\",\
  64.    \"Black\",\
  65.  },\
  66.  login = {\
  67.    \"Hello\",\
  68.    \"Step 1/Create User\",\
  69.    \"Name\",\
  70.    \"Enter name!\",\
  71.    \"Step 2/Create Password\",\
  72.    \"Password\",\
  73.    \"Thanks!\",\
  74.    \"Login\",\
  75.    \"Incorrect password!\",\
  76.    \"Change language\",\
  77.    table = {\
  78.      \"I need the password\",\
  79.      \"I don't need a password\",\
  80.    },\
  81.  },\
  82.  menu3 = {\
  83.    \"Draw logo\",\
  84.    \"Start from disk\"\
  85.  },\
  86.  menu4 = {\
  87.    \"New update\",\
  88.    \"Updating\",\
  89.    \"Update\",\
  90.    \"No updates\",\
  91.    \"We recommend you to install the updates\",\
  92.    table = {\
  93.      \"I need the update\",\
  94.      \"I don't need a update\",\
  95.    },\
  96.  },\
  97.  menu1 = {\
  98.    \"Edit system\",\
  99.    \"Update\",\
  100.    \"Reboot\",\
  101.    \"Shutdown\",\
  102.  },\
  103. }",
  104.   [ "MiOS/system/color" ] = "{ colored = {\
  105.        \"white\",\
  106.        \"orange\",\
  107.        \"magenta\",\
  108.        \"lightBlue\",\
  109.        \"yellow\",\
  110.        \"lime\",\
  111.        \"pink\",\
  112.        \"gray\",\
  113.        \"lightGray\",\
  114.        \"cyan\",\
  115.        \"purple\",\
  116.        \"blue\",\
  117.        \"brown\",\
  118.        \"green\",\
  119.        \"red\",\
  120.        \"black\",\
  121.    },\
  122.    notColored = {\
  123.        \"white\",\
  124.        \"lightGray\",\
  125.        \"gray\",\
  126.        \"black\",\
  127.    },\
  128.  }",
  129.   [ "MiOS/system/shell.lua" ] = "local contextMenu = mainGUI.loadFunction(\"contextMenu\")\
  130. local readString = mainGUI.loadFunction(\"readString\")\
  131. local tumbler = mainGUI.loadFunction(\"tumbler\")\
  132. local logo = paintutils.loadImage(\"MiOS/system/logo.pic\")\
  133. local settings = osSettings.loadSettings()\
  134. local localization = osSettings.loadLocalization()\
  135. local cHistory = {}\
  136. local currentVersion = \"Last Build\"\
  137. local dirs = osSettings.loadDirs()\
  138. local color = osSettings.loadColors()\
  139. if fs.exists(\"MiOS/system/localization/\" ..settings.language) then\
  140. \009settings.language = \"english\"\
  141. end\
  142. if term.isColor then\
  143. \009color = color.colored\
  144. else\
  145. \009localization.menu2Colors = localization.menu2Colors1\
  146. \009color = color.notColored\
  147. end\
  148. local function drawLogo()\
  149. \009if settings.setting[1] == true and term.isColor() then\
  150. \009\009paintutils.drawImage(logo, 27, 10)\
  151. \009\009term.setBackgroundColor(colors.white)\
  152. \009end\
  153. end\
  154. \
  155. local menu1Functions = {}\
  156. \009menu1Functions[1] = function()\
  157. \009\009local var1\
  158. \009\009local set, set2\
  159. \009\009local login, password, col\
  160. \009\009local x,y\
  161. \009\009local language = {}\
  162. \009\009local language2 = {}\
  163. \009\009local localiz = {}\
  164. \009\009term.clear()\
  165. \009\009mainGUI.nameBar(localization.menu1[1])\
  166. \009\009drawLogo()\
  167. \009\009var1 = contextMenu:new(3,3,localization.menu2)\
  168. \009\009set = mainGUI.findInTable(localization.menu2, var1:use())\
  169. \009\009if set >= 1 and set <= 3 then\
  170. \009\009\009term.clear()\
  171. \009\009\009mainGUI.nameBar(localization.menu2[set])\
  172. \009\009\009drawLogo()\
  173. \009\009\009var1 = contextMenu:new(3,3,localization.menu2Colors)\
  174. \009\009\009set2 = mainGUI.findInTable(localization.menu2Colors, var1:use())\
  175. \009\009\009settings.color[set] = colors[color[set2]]\
  176. \009\009\009osSettings.rewrite(settings)\
  177. \009\009elseif set == 4 then\
  178. \009\009\009term.clear()\
  179. \009\009\009mainGUI.nameBar(localization.menu2[set])\
  180. \009\009\009drawLogo()\
  181. \009\009\009mainGUI.writeOnCenter(localization[7])\
  182. \009\009\009event, settings.button = os.pullEvent(\"key\")\
  183. \009\009\009term.clear()\
  184. \009\009\009mainGUI.nameBar(localization.menu2[set])\
  185. \009\009\009drawLogo()\009\
  186. \009\009\009osSettings.rewrite(settings)\
  187. \009\009\009sleep(1)\
  188. \009\009elseif set == 5 then\
  189. \009\009\009term.clear()\
  190. \009\009\009mainGUI.nameBar(localization.menu2[set])\
  191. \009\009\009drawLogo()\
  192. \009\009\009language = fs.list(dirs[3])\
  193. \009\009\009for i = 1, #language do\
  194. \009\009\009\009language2[i] = string.upper(string.sub(language[i], 1, 1)) ..string.sub(language[i], 2)\
  195. \009\009\009end\
  196. \009\009\009var1 = contextMenu:new(3,3,language2)\
  197. \009\009\009settings.language = language[mainGUI.findInTable(language2,var1:use())]\
  198. \009\009\009mainGUI.winAnimation()\
  199. \009\009\009mainGUI.writeOnCenter(localization[11])\
  200. \009\009\009mainGUI.waitForUser()\
  201. \009\009\009osSettings.rewrite(settings)\
  202. \009\009\009os.reboot()\
  203. \009\009elseif set == 6 then\
  204. \009\009\009term.clear()\
  205. \009\009\009x,y = mainGUI.getCenter(20,1)\
  206. \009\009\009login, password = logSystem.login()\
  207. \009\009\009var1 = readString:new(x,y,nil,20,colors.black,localization[8])\
  208. \009\009\009var2 = readString:new(x,y+2,nil,20,colors.black,localization[9])\
  209. \009\009\009mainGUI.nameBar(localization.menu2[4])\
  210. \009\009\009while true do\
  211. \009\009\009\009drawLogo()\
  212. \009\009\009\009term.setTextColor(colors.black)\
  213. \009\009\009\009term.setCursorPos(x+22,y)\
  214. \009\009\009\009write(login)\
  215. \009\009\009\009term.setCursorPos(x+22,y+2)\
  216. \009\009\009\009write(password)\
  217. \009\009\009\009var1:draw()\
  218. \009\009\009\009var2:draw()\
  219. \009\009\009\009login = var1:use()\
  220. \009\009\009\009password = var2:use()\
  221. \009\009\009\009if login ~= \"\" then\
  222. \009\009\009\009\009local user = fs.open(dirs[4], \"w\")\
  223. \009\009\009\009\009user.writeLine(login)\
  224. \009\009\009\009\009user.writeLine(password)\
  225. \009\009\009\009\009user.close()\
  226. \009\009\009\009\009os.setComputerLabel(login)\
  227. \009\009\009\009\009break\
  228. \009\009\009\009end\
  229. \009\009\009\009mainGUI.winAnimation(\"w\")\
  230. \009\009\009\009mainGUI.nameBar(localization[6])\
  231. \009\009\009end\
  232. \009\009elseif set == 7 then\
  233. \009\009\009while true do\
  234. \009\009\009\009for i = 1, #localization.menu3 do\
  235. \009\009\009\009\009localiz[i] = localization.menu3[i] ..\"/\" ..tostring(settings.setting[i])\
  236. \009\009\009\009end\
  237. \009\009\009\009term.clear()\
  238. \009\009\009\009term.setBackgroundColor(colors.white)\
  239. \009\009\009\009mainGUI.nameBar(localization.menu2[set])\
  240. \009\009\009\009drawLogo()\
  241. \009\009\009\009var1 = contextMenu:new(3,3,localiz)\
  242. \009\009\009\009set  = mainGUI.findInTable(localiz, var1:use())\
  243. \009\009\009\009if settings.setting[set] == true then\
  244. \009\009\009\009\009settings.setting[set] = false\
  245. \009\009\009\009else\
  246. \009\009\009\009\009settings.setting[set] = true\
  247. \009\009\009\009end\
  248. \009\009\009\009osSettings.rewrite(settings)\
  249. \009\009\009end\
  250. \009\009end\
  251. \009end\
  252. \009menu1Functions[2] = function()\
  253. \009\009local ver = pastebin.run(\"0sEdXR0B\")\
  254. \009\009local x,y\
  255. \009\009local var1\
  256. \009\009term.clear()\
  257. \009\009mainGUI.winAnimation()\
  258. \009\009if ver ~= currentVersion then\
  259. \009\009\009mainGUI.writeOnCenter(localization.menu4[1] ..\" \" ..ver)\
  260. \009\009\009mainGUI.waitForUser()\
  261. \009\009\009mainGUI.nameBar(localization.menu4[3])\
  262. \009\009\009x,y = mainGUI.getCenter(string.len(localization.menu4.table[2]),2)\
  263. \009\009\009var1 = contextMenu:new(x,y, localization.menu4.table)\
  264. \009\009\009var1:draw()\
  265. \009\009\009if var1:use() == localization.menu4.table[1] then\
  266. \009\009\009\009mainGUI.winAnimation()\
  267. \009\009\009\009mainGUI.writeOnCenter(localization.menu4[2])\
  268. \009\009\009\009pastebin.run(\"q5VCDuKq\")\
  269. \009\009\009\009mainGUI.waitForUser()\
  270. \009\009\009\009os.reboot()\
  271. \009\009\009else\
  272. \009\009\009\009mainGUI.winAnimation()\
  273. \009\009\009\009mainGUI.writeOnCenter(localization.menu4[5])\
  274. \009\009\009\009mainGUI.waitForUser()\
  275. \009\009\009end\
  276. \009\009else\
  277. \009\009\009mainGUI.writeOnCenter(localization.menu4[4])\
  278. \009\009\009mainGUI.waitForUser()\
  279. \009\009end\
  280. \009end\
  281. \009menu1Functions[3] = function()\
  282. \009\009os.reboot()\
  283. \009end\
  284. \009menu1Functions[4] = function()\
  285. \009\009os.shutdown()\
  286. \009end\
  287. \
  288. local function checkForButton()\
  289. \009while true do\
  290. \009\009sleep(0)\
  291. \009\009local event, key = os.pullEvent(\"key\")\
  292. \009\009if key == settings.button then\
  293. \009\009\009break\
  294. \009\009end\
  295. \009end\
  296. end\
  297. \
  298. local function menu()\
  299. \009local var1\
  300. \009term.setCursorBlink(false)\
  301. \009term.setBackgroundColor(colors.white)\
  302. \009term.clear()\
  303. \009mainGUI.nameBar(localization[5])\
  304. \009drawLogo()\
  305. \009var1 = contextMenu:new(3,3,localization.menu1)\
  306. \009menu1Functions[mainGUI.findInTable(localization.menu1, var1:use())]()\
  307. end\
  308. \
  309. local function main()\
  310. \009local sLine\
  311. \009while true do\
  312. \009\009term.setBackgroundColor(settings.color[1])\
  313. \009\009term.clear()\
  314. \009\009mainGUI.nameBar(localization[1] ..\" \" ..currentVersion)\
  315. \009\009term.setTextColor(settings.color[2])\
  316. \009\009term.setCursorPos(1,2)\
  317. \009\009print(localization[2] ..keys.getName(settings.button) ..localization[3])\
  318. \009\009while true do\
  319. \009\009\009shell.setDir(dirs[5])\
  320. \009\009\009write(localization[4])\
  321. \009\009\009term.setTextColor(settings.color[3])\
  322. \009\009\009sLine = read(nil, cHistory, shell.complete)\
  323. \009\009\009shell.run(sLine)\
  324. \009\009\009if term.getBackgroundColor() ~= settings.color[1] then\
  325. \009\009\009\009break\
  326. \009\009\009end\
  327. \009\009\009term.setTextColor(settings.color[2])\
  328. \009\009end\
  329. \009end\
  330. end\
  331. \
  332. local login, password = logSystem.login()\
  333. term.clear()\
  334. mainGUI.writeOnCenter(localization[10] ..login)\
  335. mainGUI.waitForUser()\
  336. mainGUI.winAnimation(\"w\")\
  337. \
  338. \
  339. while true do\
  340. \009parallel.waitForAny(main,checkForButton)\
  341. \009parallel.waitForAny(menu,checkForButton)\
  342. end",
  343.   [ "MiOS/system/API/mainGUI" ] = "function colorPalette()\
  344. \009local oldColor, color\
  345. \009oldColor = term.getBackgroundColor()\
  346. \009if oldColor == colors.gray then\
  347. \009\009color = colors.lightGray\
  348. \009else\
  349. \009\009color = colors.gray\
  350. \009end\
  351. \
  352. \009local oldTextColor = term.getTextColor()\
  353. \009if term.getBackgroundColor() == colors.white then\
  354. \009\009term.setTextColor(colors.black)\
  355. \009else\
  356. \009\009term.setTextColor(colors.white)\
  357. \009end\
  358. \
  359. \009return oldColor, color, oldTextColor\
  360. end\
  361. function getCenter(xSize, ySize)\
  362. \009if not x or y then\
  363. \009\009x,y = term.getSize()\
  364. \009end\
  365. \009if not xSize then\
  366. \009\009xSize = 0\
  367. \009end\
  368. \009if not ySize then\
  369. \009\009ySize = 0\
  370. \009end\
  371. \009x = math.floor(x/2 - xSize/2)\
  372. \009y = math.floor(y/2 - ySize/2)\
  373. \009\
  374. \009return x,y\
  375. end\
  376. function readLine( _sReplaceChar, _size )\
  377.    term.setCursorBlink( true )\
  378. \
  379.    local sLine = \"\"\
  380.    local nHistoryPos\
  381.    local nPos = 0\
  382.    if _sReplaceChar then\
  383.        _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )\
  384.    end\
  385. \
  386.    if _size == nil then\
  387.    \009_size = 99\
  388.    end\
  389. \
  390.    local w = term.getSize()\
  391.    local sx = term.getCursorPos()\
  392. \
  393.    local function redraw( _bClear )\
  394.        local nScroll = 0\
  395.        if sx + nPos >= w then\
  396.            nScroll = (sx + nPos) - w\
  397.        end\
  398. \
  399.        local cx,cy = term.getCursorPos()\
  400.        term.setCursorPos( sx, cy )\
  401.        local sReplace = (_bClear and \" \") or _sReplaceChar\
  402.        if sReplace then\
  403.            write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )\
  404.        else\
  405.            write( string.sub( sLine, nScroll + 1 ) )\
  406.        end\
  407. \
  408.        term.setCursorPos( sx + nPos - nScroll, cy )\
  409.    end\
  410.    \
  411.    redraw()\
  412. \
  413.    while true do\
  414.        local sEvent, param = os.pullEvent()\
  415.        if sEvent == \"char\" and string.len(sLine) ~= _size then\
  416.            redraw( true )\
  417.            sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )\
  418.            nPos = nPos + 1\
  419.            redraw()\
  420.        elseif sEvent == \"key\" then\
  421.            if param == keys.enter then\
  422.                break\
  423.            elseif param == keys.left then\
  424.                if nPos > 0 then\
  425.                    redraw( true )\
  426.                    nPos = nPos - 1\
  427.                    redraw()\
  428.                end\
  429.            elseif param == keys.right then               \
  430.                if nPos < string.len(sLine) then\
  431.                    redraw( true )\
  432.                    nPos = nPos + 1\
  433.                    redraw()\
  434.                end\
  435.            elseif param == keys.backspace then\
  436.                if nPos > 0 then\
  437.                    redraw( true )\
  438.                    sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )\
  439.                    nPos = nPos - 1\
  440.                    redraw()\
  441.                end\
  442.            elseif param == keys.home then\
  443.                if nPos > 0 then\
  444.                    redraw( true )\
  445.                    nPos = 0\
  446.                    redraw()\
  447.                end\
  448.            elseif param == keys.delete then\
  449.                if nPos < string.len(sLine) then\
  450.                    redraw( true )\
  451.                    sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )                \
  452.                    redraw()\
  453.                end\
  454.            elseif param == keys[\"end\"] then\
  455.                if nPos < string.len(sLine ) then\
  456.                    redraw( true )\
  457.                    nPos = string.len(sLine)\
  458.                    redraw()\
  459.                end\
  460.            end\
  461.        elseif sEvent == \"term_resize\" then\
  462.            w = term.getSize()\
  463.            redraw()\
  464.        elseif sEvent == \"mouse_click\" then\
  465.        \009break\
  466.        end\
  467.    end\
  468. \
  469.    local cx, cy = term.getCursorPos()\
  470.    term.setCursorBlink( false )\
  471.    term.setCursorPos( w + 1, cy )\
  472.    print()\
  473.    \
  474.    return sLine\
  475. end\
  476. function drawPixelG(xPos, yPos, xSize, ySize, color)\
  477. \009local oldColor = term.getBackgroundColor()\
  478. \009term.setBackgroundColor(color)\
  479. \009for i = xPos, xSize+xPos-1, 1 do\
  480. \009\009for g = yPos, ySize+yPos-1, 1 do\
  481. \009\009\009term.setCursorPos(i,g)\
  482. \009\009\009write(\" \")\
  483. \009\009end\
  484. \009end\
  485. \009term.setBackgroundColor(oldColor)\
  486. end\
  487. function drawPixel(xPos, yPos, color)\
  488. \009local oldColor = term.getBackgroundColor()\
  489. \009term.setBackgroundColor(color)\
  490. \009term.setCursorPos(xPos,yPos)\
  491. \009write(\" \")\
  492. \009term.setBackgroundColor(oldColor)\
  493. end\
  494. \
  495. ---------------------------------------------\
  496. contextMenu = {}\
  497. function contextMenu:new(xPos,yPos,table)\
  498. \
  499. \009local lenght = string.len(table[1])\
  500. \009for i = 1, #table do\
  501. \009\009element = string.len(table[i])\
  502. \009\009if element > lenght then\
  503. \009\009\009lenght = element\
  504. \009\009end\
  505. \009end\
  506. \
  507. \009local oldColor, color = colorPalette()\
  508. \
  509. \009local arg = {}\
  510. \009\009arg.xPos = xPos\
  511. \009\009arg.yPos = yPos\
  512. \009\009arg.table = table\
  513. \009\009arg.oldColor = oldColor\
  514. \009\009arg.color = color\
  515. \009\009arg.oldTextColor = oldTextColor\
  516. \009\009arg.lenght = lenght\
  517. \
  518. \009function arg:draw(sel)\
  519. \009\009term.setCursorPos(self.xPos,self.yPos)\
  520. \009\009for i = 1, #table do\
  521. \009\009\009if i ~= sel then\
  522. \009\009\009\009term.setBackgroundColor(self.oldColor)\
  523. \009\009\009\009for g = 1, self.lenght+1 do\
  524. \009\009\009\009\009write(\" \")\
  525. \009\009\009\009end\
  526. \009\009\009\009term.setCursorPos(self.xPos,self.yPos+i-1)\
  527. \009\009\009\009write(\" \" ..self.table[i])\
  528. \009\009\009\009term.setCursorPos(self.xPos,self.yPos+i)\
  529. \009\009\009else\
  530. \009\009\009\009term.setCursorPos(self.xPos+1,self.yPos+i-1)\
  531. \009\009\009\009term.setBackgroundColor(self.color)\
  532. \009\009\009\009for g = 1, self.lenght do\
  533. \009\009\009\009\009write(\" \")\
  534. \009\009\009\009end\
  535. \009\009\009\009term.setCursorPos(self.xPos,self.yPos+i-1)\
  536. \009\009\009\009write(\">\" ..self.table[i])\
  537. \009\009\009\009term.setCursorPos(self.xPos,self.yPos+i)\
  538. \009\009\009end\
  539. \009\009end\
  540. \009end\
  541. \
  542. \009function arg:use()\
  543. \009\009self:draw(1)\
  544. \009\009self.oldColor = term.getBackgroundColor()\
  545. \009\009local ch\
  546. \009\009local function keyboard()\
  547. \009\009\009term.setCursorPos(self.xPos+1,self.yPos)\
  548. \009\009\009local cursorPos = 0\
  549. \009\009\009while true do\
  550. \
  551. \009\009\009\009local event, button, x, y = os.pullEvent()\
  552. \
  553. \009\009\009\009if event == \"key\" then \
  554. \009\009\009\009\009if button == 200 and cursorPos ~= 0 or event == \"mouse_scroll\" and button == -1 and cursorPos ~= 0 then\
  555. \009\009\009\009\009\009term.setCursorPos(self.xPos,self.yPos+cursorPos)\
  556. \
  557. \009\009\009\009\009\009cursorPos = cursorPos - 1\
  558. \009\009\009\009\009\009self:draw(cursorPos+1)\
  559. \
  560. \009\009\009\009\009elseif button == 208 and cursorPos ~= #table-1 then\
  561. \009\009\009\009\009\009term.setCursorPos(self.xPos,self.yPos+cursorPos)\
  562. \
  563. \009\009\009\009\009\009cursorPos = cursorPos + 1\
  564. \009\009\009\009\009\009self:draw(cursorPos+1)\
  565. \009\009\009\009\009elseif button == 28 then\
  566. \009\009\009\009\009\009ch = self.table[cursorPos+1]\
  567. \009\009\009\009\009\009break\
  568. \009\009\009\009\009end\
  569. \009\009\009\009elseif event == \"mouse_scroll\" then\
  570. \009\009\009\009\009if button == -1 and cursorPos ~= 0 then\
  571. \009\009\009\009\009\009term.setCursorPos(self.xPos,self.yPos+cursorPos)\
  572. \
  573. \009\009\009\009\009\009cursorPos = cursorPos - 1\
  574. \009\009\009\009\009\009self:draw(cursorPos+1)\
  575. \
  576. \009\009\009\009\009elseif button == 1 and cursorPos ~= #table-1 then\
  577. \009\009\009\009\009\009term.setCursorPos(self.xPos,self.yPos+cursorPos)\
  578. \
  579. \009\009\009\009\009\009cursorPos = cursorPos + 1\
  580. \009\009\009\009\009\009self:draw(cursorPos+1)\
  581. \009\009\009\009\009elseif button == 28 then\
  582. \009\009\009\009\009\009ch = self.table[cursorPos+1]\
  583. \009\009\009\009\009\009break\
  584. \009\009\009\009\009end\
  585. \009\009\009\009elseif event == \"mouse_click\" then\
  586. \009\009\009\009\009if y >= self.yPos and y <= self.yPos+#self.table-1 and x <= self.xPos+self.lenght and x >= self.xPos then\
  587. \009\009\009\009\009\009self:draw(y-self.yPos+1)\
  588. \009\009\009\009\009\009sleep(0.3)\
  589. \009\009\009\009\009\009ch = self.table[y-self.yPos+1]\
  590. \009\009\009\009\009\009break\
  591. \009\009\009\009\009end\
  592. \009\009\009\009end\
  593. \009\009\009\009term.setCursorPos(self.xPos,self.yPos+cursorPos)\
  594. \009\009\009end\
  595. \009\009end\
  596. \009\009keyboard()\
  597. \009\009term.setBackgroundColor(self.oldColor)\
  598. \009\009return ch\
  599. \009end\
  600.    setmetatable(arg, self)\
  601.    self.__index = self; return arg\
  602. end\
  603. ---------------------------------------------\
  604. tumbler = {}\
  605. function tumbler:new(xPos,yPos,table,table1)\
  606. \009local tHistory = {}\
  607. \009local oldColor, color, oldTextColor = colorPalette()\
  608. \009if table1 then\
  609. \009\009tHistory = table1\
  610. \009end\
  611. \
  612. \009local arg = {}\
  613. \009\009arg.xPos = xPos\
  614. \009\009arg.yPos = yPos\
  615. \009\009arg.table = table\
  616. \009\009arg.table1 = table1\
  617. \009\009arg.tHistory = tHistory\
  618. \009\009arg.oldColor = oldColor\
  619. \009\009arg.color = color\
  620. \009\009arg.oldTextColor = oldTextColor\
  621. \
  622. \009function arg:draw()\
  623. \009\009for i = 1, #self.table do\
  624. \009\009\009term.setCursorPos(self.xPos+2, self.yPos+i-1)\
  625. \009\009\009write(table[i])\
  626. \009\009end\
  627. \009\009term.setBackgroundColor(self.color)\
  628. \009\009for i = 1, #self.table do\
  629. \009\009\009term.setCursorPos(self.xPos, self.yPos+i-1)\
  630. \009\009\009if self.tHistory[i] == true then\
  631. \009\009\009\009write(\"O\")\
  632. \009\009\009else\
  633. \009\009\009\009write(\" \")\
  634. \009\009\009end\
  635. \009\009end\
  636. \009term.setBackgroundColor(self.oldColor)\
  637. \009term.setTextColor(self.oldTextColor)\
  638. \009end\
  639. \009function  tumbler:use()\
  640. \009\009self:draw()\
  641. \009\009while true do\
  642. \009\009\009local event, button, x, y = os.pullEvent(\"mouse_click\")\
  643. \009\009\009if y-self.yPos+1 <= #self.table and y-self.yPos+1 >= 1 and x == self.xPos then\
  644. \009\009\009\009if self.tHistory[y-yPos+1] == false or self.tHistory[y-yPos+1] == nil then\
  645. \009\009\009\009\009self.tHistory = {}\
  646. \009\009\009\009\009self.tHistory[y-self.yPos+1] = true\
  647. \009\009\009\009end\
  648. \009\009\009else\
  649. \009\009\009\009return self.tHistory\
  650. \009\009\009end\
  651. \009\009\009self:draw()\
  652. \009\009end\
  653. \009end\
  654. \009setmetatable(arg, self)\
  655. \009self.__index = self; return arg\
  656. end\
  657. ---------------------------------------------\
  658. local readString = {}\
  659. function readString:new( xPos, yPos, _sReplaceChar, _size, color, text)\
  660. \009local arg = {}\
  661. \009\009arg.xPos = xPos\
  662. \009\009arg.yPos = yPos\
  663. \009\009arg._sReplaceChar = _sReplaceChar\
  664. \009\009arg._size = _size\
  665. \009\009arg.color = color\
  666. \009\009arg.text = text\
  667. \009function arg:draw()\
  668. \009\009drawPixelG(self.xPos,self.yPos, self._size, 1, self.color)\
  669. \009end\
  670. \009function arg:use()\
  671. \009\009self:draw()\
  672. \009\009local function textDraw(color)\
  673. \009\009\009if arg.text then\
  674. \009\009\009\009if color ~= colors.gray then\
  675. \009\009\009\009\009term.setTextColor(colors.gray)\
  676. \009\009\009\009\009write(arg.text)\
  677. \009\009\009\009else\
  678. \009\009\009\009\009term.setTextColor(colors.black)\
  679. \009\009\009\009\009write(arg.text)\
  680. \009\009\009\009end\
  681. \009\009\009\009term.setCursorPos(self.xPos,self.yPos)\
  682. \009\009\009end\
  683. \009\009end\
  684. \009\009term.setCursorPos(self.xPos,self.yPos)\
  685. \009\009local oldColor = term.getBackgroundColor()\
  686. \009\009term.setBackgroundColor(self.color)\
  687. \009\009local oldTextColor = term.getTextColor()\
  688. \009\009if term.getBackgroundColor() == colors.white then\
  689. \009\009\009textDraw(colors.black)\
  690. \009\009\009term.setTextColor(colors.black)\
  691. \009\009else\
  692. \009\009\009textDraw(colors.white)\
  693. \009\009\009term.setTextColor(colors.white)\
  694. \009\009end\
  695. \009\009local result = readLine(self._sReplaceChar,self._size)\
  696. \009\009term.setTextColor(oldTextColor)\
  697. \009\009return result\
  698. \009end\
  699. \009setmetatable(arg, self)\
  700. \009self.__index = self; return arg\
  701. end\
  702. function loadFunction(var)\
  703. \009if var == \"contextMenu\" then\
  704. \009\009return contextMenu\
  705. \009elseif var == \"tumbler\" then\
  706. \009\009return tumbler\
  707. \009elseif var == \"readString\" then\
  708. \009\009return readString\
  709. \009end\
  710. end\
  711. -----------------------------------------------------\
  712. function winAnimation(black)\
  713. \009local xSize, ySize = term.getSize()\
  714. \009if black == \"b\" then\
  715. \009\009term.setBackgroundColor(colors.black)\
  716. \009\009term.clear()\
  717. \009\009sleep(0.03)\
  718. \009elseif black == \"w\" then\
  719. \009\009term.setBackgroundColor(colors.white)\
  720. \009\009term.clear()\
  721. \009\009sleep(0.03)\
  722. \009end\
  723. \009term.setBackgroundColor(colors.lightGray)\
  724. \009term.clear()\
  725. \009sleep(0.03)\
  726. \009term.setBackgroundColor(colors.gray)\
  727. \009term.clear()\
  728. \009sleep(0.03)\
  729. \009term.setBackgroundColor(colors.lightGray)\
  730. \009term.clear()\
  731. \009sleep(0.03)\
  732. \009term.setBackgroundColor(colors.white)\
  733. \009term.clear()\
  734. \009sleep(0.03)\
  735. end\
  736. \
  737. function nameBar(text)\
  738. \009local secondColor = colors.gray\
  739. \009local textColor = colors.white\
  740. \009local oldColor = term.getBackgroundColor()\
  741. \009local oldTextColor = term.getTextColor()\
  742. \009local xSize, ySize = term.getSize()\
  743. \
  744. \009term.clear()\
  745. \009drawPixelG(1, 1, xSize, 1, secondColor)\
  746. \009term.setCursorPos(2,1)\
  747. \009term.setBackgroundColor(secondColor)\
  748. \009term.setTextColor(textColor)\
  749. \009write(text)\
  750. \009term.setBackgroundColor(oldColor)\
  751. \009term.setTextColor(oldTextColor)\
  752. end\
  753. \
  754. function waitForUser()\
  755. \009sleep(0.1)\
  756. \009local event = os.pullEvent()\
  757. \009if event == \"key\" or event == \"mouse_click\" then\
  758. \009\009return\
  759. \009end\
  760. end\
  761. \
  762. function writeOnCenter(text)\
  763. \009local x,y = getCenter(string.len(text),1)\
  764. \009term.setCursorPos(x,y)\
  765. \009write(text)\
  766. end\
  767. \
  768. function findInTable(table, str)\
  769. \009for i = 1, #table do\
  770. \009\009if table[i] == str then\
  771. \009\009\009return i\
  772. \009\009end\
  773. \009end\
  774. \009return nil\
  775. end\
  776. \
  777. function getLongestElement(table)\
  778. \009local len = 0\
  779. \009for i = 1, #table do\
  780. \009\009if string.len(table[i]) > len then\
  781. \009\009\009len = string.len(table[i])\
  782. \009\009end\
  783. \009end\
  784. \009return len\
  785. end",
  786.   [ "MiOS/system/API/osSettings" ] = "function loadDirs()\
  787. \009file = fs.open(\"MiOS/system/dirs\",\"r\")\
  788. \009data = file.readAll()\
  789. \009file.close()\
  790. \009return textutils.unserialize(data)\
  791. end\
  792. \
  793. function loadSettings()\
  794. \009local dirs = loadDirs()\
  795. \009if fs.exists(dirs[6]) then\
  796. \009\009local file = fs.open(dirs[6], \"r\")\
  797. \009\009local table = file.readAll()\
  798. \009\009file.close()\
  799. \009\009settings = textutils.unserialize(table)\
  800. \009else\
  801. \009\009settings = {\
  802. \009\009\009\009color = {\009colors.white, \
  803. \009\009\009\009\009\009\009colors.black, \
  804. \009\009\009\009\009\009\009colors.black},\
  805. \009\009\009\009button = 56,\
  806. \009\009\009\009setting = {\
  807. \009\009\009\009\009true,\
  808. \009\009\009\009\009false,\
  809. \009\009\009\009},\
  810. \009\009\009\009language = \"english\"\
  811. \009\009\009\009}\
  812. \009end\
  813. \009return settings\
  814. end\
  815. \
  816. function loadLocalization()\
  817. \009local dirs = loadDirs()\
  818. \009local settings = loadSettings()\
  819. \009file = fs.open(dirs[3] ..settings.language,\"r\")\
  820. \009data = file.readAll()\
  821. \009file.close()\
  822. \009return textutils.unserialize(data)\
  823. end\
  824. \
  825. function loadColors()\
  826. \009local dirs = loadDirs()\
  827. \009local settings = loadSettings()\
  828. \009file = fs.open(dirs[2],\"r\")\
  829. \009data = file.readAll()\
  830. \009file.close()\
  831. \009return textutils.unserialize(data)\
  832. end\
  833. \
  834. function rewrite(settings)\
  835. \009local dirs = loadDirs()\
  836. \009local file = fs.open(dirs[6],\"w\")\
  837. \009file.write(textutils.serialize(settings))\
  838. \009file.close()\
  839. end",
  840.   [ "MiOS/system/localization/french" ] = "{\
  841. \"Pmi\",\
  842. \"La presse \",\
  843. \" pour ouvrir le menu\",\
  844. \">\",\
  845. \"Menu\",\
  846. \"Entrez le nom!\",\
  847. \"Appuyez sur la touche\",\
  848. \"Nom\",\
  849. \"Mot de passe\",\
  850. \"Bonjour, \",\
  851. \"L'ordinateur va redémarrer\",\
  852. menu2 = {\
  853. \"Définir la couleur d'arrière-plan\",\
  854. \"Définir la couleur du texte\",\
  855. \"D'entrée de jeu la couleur du texte\",\
  856. \"Définir le bouton de menu\",\
  857. \"Changer de langue\",\
  858. \"Modifier l'utilisateur\",\
  859. \"Les autres\",\
  860. },\
  861. menu2Colors = {\
  862. \"Blanc\",\
  863. \"Orange\",\
  864. \"Magenta\",\
  865. \"La Lumière Bleue\",\
  866. \"Jaune\",\
  867. \"La chaux\",\
  868. \"Rose\",\
  869. \"Gris\",\
  870. \"Gris Clair\",\
  871. \"Cyan\",\
  872. \"Violet\",\
  873. \"Bleu\",\
  874. \"Le brun\",\
  875. \"Vert\",\
  876. \"Rouge\",\
  877. \"Noir\",\
  878. },\
  879. menu2Colors1 = {\
  880. \"Blanc\",\
  881. \"Gris Clair\",\
  882. \"Gris\",\
  883. \"Noir\",\
  884. },\
  885. login = {\
  886. \"Bonjour\",\
  887. \"Étape 1/Créer Un Utilisateur\",\
  888. \"Nom\",\
  889. \"Entrez le nom!\",\
  890. \"Étape 2/Créer Un Mot De Passe\",\
  891. \"Mot de passe\",\
  892. \"Merci!\",\
  893. \"Login\",\
  894. \"Mot de passe Incorrect!\",\
  895. \"Changer de langue\",\
  896. table = {\
  897. \"J'ai besoin du mot de passe\",\
  898. \"Je n'ai pas besoin d'un mot de passe\",\
  899. },\
  900. },\
  901. menu3 = {\
  902. \"Dessiner logo\",\
  903. \"Démarrer à partir du disque\"\
  904. },\
  905. menu4 = {\
  906. \"Nouvelle mise à jour\",\
  907. \"Mise à jour\",\
  908. \"Mise à jour\",\
  909. \"Pas de mises à jour\",\
  910. \"Nous vous recommandons d'installer les mises à jour\",\
  911. table = {\
  912. \"J'ai besoin de la mise à jour\",\
  913. \"Je n'ai pas besoin d'une mise à jour\",\
  914. },\
  915. },\
  916. menu1 = {\
  917. \"Modifier le système\",\
  918. \"Mise à jour\",\
  919. \"Reboot\",\
  920. \"Shutdown\",\
  921. },\
  922. }",
  923.   [ "MiOS/system/dirs" ] = "{\
  924. \"MiOS/system/logo.pic\",\
  925. \"MiOS/system/color\",\
  926. \"MiOS/system/localization/\",\
  927. \"MiOS/user/user.txt\",\
  928. \"MiOS/user/files\",\
  929. \"MiOS/user/settings.txt\",\
  930. }",
  931.   startup = "os.loadAPI(\"MiOS/system/API/mainGUI\")\
  932. os.loadAPI(\"MiOS/system/API/logSystem\")\
  933. os.loadAPI(\"MiOS/system/API/osSettings\")\
  934. os.loadAPI(\"MiOS/system/API/pastebin\")\
  935. settings.set(\"bios.use_multishell\", false)\
  936. local setting = osSettings.loadSettings()\
  937. settings.set(\"shell.allow_disk_startup\", setting.setting[2])\
  938. settings.save(\".settings\")\
  939. shell.run(\"MiOS/system/shell.lua\")",
  940.   [ ".settings" ] = "{\
  941.  [ \"bios.use_multishell\" ] = false,\
  942.  [ \"shell.autocomplete\" ] = true,\
  943.  [ \"shell.allow_disk_startup\" ] = false,\
  944.  [ \"shell.allow_startup\" ] = true,\
  945.  [ \"lua.autocomplete\" ] = true,\
  946.  [ \"list.show_hidden\" ] = false,\
  947.  [ \"edit.autocomplete\" ] = true,\
  948. }",
  949.   [ "MiOS/system/API/logSystem" ] = "function login()\
  950. \009local var1, table\
  951. \009local x, y\
  952. \009local login, password\
  953. \009local readString = mainGUI.loadFunction(\"readString\")\
  954. \009local contextMenu = mainGUI.loadFunction(\"contextMenu\")\
  955. \009local localization = osSettings.loadLocalization()\
  956. \009local settings = osSettings.loadSettings()\
  957. \009local dirs = osSettings.loadDirs()\
  958. \009local language, language2 = {}, {}\
  959. \009term.setTextColor(colors.black)\
  960. \
  961. \009if not fs.exists(dirs[4]) then\
  962. \009\009mainGUI.winAnimation()\
  963. \009\009mainGUI.nameBar(localization.login[10])\
  964. \009\009language = fs.list(dirs[3])\
  965. \009\009for i = 1, #language do\
  966. \009\009\009language2[i] = string.upper(string.sub(language[i], 1, 1)) ..string.sub(language[i], 2)\
  967. \009\009end\
  968. \009\009x,y = mainGUI.getCenter(mainGUI.getLongestElement(language2),#language2)\
  969. \009\009var1 = contextMenu:new(x,y,language2)\
  970. \009\009settings.language = language[mainGUI.findInTable(language2,var1:use())]\
  971. \009\009osSettings.rewrite(settings)\
  972. \009\009localization = osSettings.loadLocalization()\
  973. \009\009\
  974. \009\009mainGUI.winAnimation()\
  975. \009\009mainGUI.writeOnCenter(localization.login[1])\
  976. \009\009mainGUI.waitForUser()\
  977. \009\009mainGUI.winAnimation()\
  978. \
  979. \009\009mainGUI.nameBar(localization.login[2])\
  980. \009\009while true do\
  981. \009\009\009x,y = mainGUI.getCenter(20,1)\
  982. \009\009\009var1 = readString:new(x,y,nil,20,colors.black,localization.login[3])\
  983. \009\009\009var1:draw()\
  984. \009\009\009login = var1:use()\
  985. \009\009\009mainGUI.winAnimation(\"w\")\
  986. \009\009\009if login == \"\" then\
  987. \009\009\009\009mainGUI.nameBar(localization.login[4])\
  988. \009\009\009else\
  989. \009\009\009\009break\
  990. \009\009\009end\
  991. \009\009end\
  992. \
  993. \009\009x,y = mainGUI.getCenter(string.len(localization.login.table[2]),2)\
  994. \009\009mainGUI.nameBar(localization.login[5])\
  995. \009\009var1 = contextMenu:new(x,y, localization.login.table)\
  996. \009\009var1:draw()\
  997. \009\009if var1:use() == localization.login.table[1] then\
  998. \009\009\009x,y = mainGUI.getCenter(20,1)\
  999. \009\009\009var1 = readString:new(x,y+2,\"*\",20,colors.black,localization.login[6])\
  1000. \009\009\009var1:draw()\
  1001. \009\009\009password = var1:use()\
  1002. \009\009end\
  1003. \
  1004. \009\009local file = fs.open(dirs[4], \"w\")\
  1005. \009\009file.writeLine(login)\
  1006. \009\009file.writeLine(password)\
  1007. \009\009file.close()\
  1008. \
  1009. \009\009mainGUI.winAnimation(\"w\")\
  1010. \009\009mainGUI.writeOnCenter(localization.login[7])\
  1011. \009\009mainGUI.waitForUser()\
  1012. \009\009os.reboot()\
  1013. \009end\
  1014. \009mainGUI.winAnimation(\"w\")\
  1015. \
  1016. \009local file = fs.open(dirs[4], \"r\")\
  1017. \009login = file.readLine()\
  1018. \009password = file.readLine()\
  1019. \009file.close()\
  1020. \
  1021. \009term.setTextColor(colors.black)\
  1022. \009mainGUI.nameBar(localization.login[8])\
  1023. \
  1024. \009if password ~= \"\" then\
  1025. \009\009while true do\
  1026. \009\009\009x,y = mainGUI.getCenter(20,1)\
  1027. \009\009\009var1 = readString:new(x,y+2,\"*\",20,colors.black,localization.login[6])\
  1028. \009\009\009mainGUI.writeOnCenter(login)\
  1029. \009\009\009var1:draw()\
  1030. \009\009\009if var1:use() ~= password then\
  1031. \009\009\009\009mainGUI.winAnimation(\"w\")\
  1032. \009\009\009\009mainGUI.nameBar(localization.login[9])\
  1033. \009\009\009else\
  1034. \009\009\009\009mainGUI.winAnimation(\"w\")\
  1035. \009\009\009\009break\
  1036. \009\009\009end\
  1037. \009\009end\
  1038. \009end\
  1039. \009return login, password\
  1040. end",
  1041. }
  1042. path = {
  1043.   "MiOS/system/logo.pic",
  1044.   "MiOS/system/shell.lua",
  1045.   "MiOS/system/color",
  1046.   "MiOS/system/API/osSettings",
  1047.   "MiOS/system/API/mainGUI",
  1048.   "MiOS/system/API/logSystem",
  1049.   "MiOS/system/API/pastebin",
  1050.   "MiOS/system/localization/english",
  1051.   "MiOS/system/localization/french",
  1052.   "MiOS/system/dirs",
  1053.   "startup",
  1054.   ".settings",
  1055. }
  1056. for i = 1, #path do
  1057.     file = fs.open(path[i],"w")
  1058.     file.writeLine(OS[path[i]])
  1059.     file.close()
  1060. end
  1061. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement