Advertisement
MrRobar35

Fast OSinstaller

Apr 12th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.99 KB | None | 0 0
  1. ----------------------РЎРўРђР РгўРћР’ЫЕ ПРЕЛЕССССТР?-------------------------
  2.  
  3. local XSize, YSize = term.getSize()
  4. local Selector = 1
  5. local zaderzhka = 0.1
  6. local progressBarWidth = 20
  7. local ColorGray = colors.gray
  8. local ColorLightGray = colors.blue
  9. local ColorDownloadBack = colors.blue
  10. local ColorDownloadFront = colors.yellow
  11.  
  12. -----------СМЕНА ЦВЕТОВОЙ РџРђР›Р?РўР Р«, ЕСЛР? РњРћРќР?РўРћР  Р§Р•Р РќРћ-БЕЛЫЙ---------
  13.  
  14. if not term.isColor() then
  15.         ColorGray = colors.blue
  16.         ColorLightGray = colors.yellow
  17.         ColorDownloadBack = colors.green
  18.         ColorDownloadFront = colors.black
  19. end
  20.  
  21. -----------ЗАГРУЗКА ВСЯКОЙ ФИГНИ--------
  22.  
  23. local Data = {
  24.         --пнгшки
  25.         {["paste"]="KywaaXS4",["path"]="OS/.backgrounds/dt",["type"]="PNG",["category"]="pngs"},
  26.         --важные системные файлы
  27.         {["paste"]="729PYwzX",["path"]="/gui",["type"]="prog",["category"]="sysfiles"},
  28. }
  29.  
  30. ----------------------ОБЪЯВЛЕНР?Р• ФУНКЦР?Р™-----------------------
  31.  
  32. --ЗАГРУЗКА ФАЙЛОВ РЎ ПАСТЕБР?РќРђ
  33. local function pastebin(paste,path)
  34.         local file = http.get("http://pastebin.com/raw.php?i="..paste)
  35.         if file then
  36.                 file = file.readAll()
  37.                 h=fs.open(path,"w")
  38.                 h.write(file)
  39.                 h.close()
  40.         else
  41.                 error("Pastebin server is not aviable.")
  42.         end
  43. end
  44.  
  45. --ЗАГРУЗР?РўР¬ КОНКРЕТНОЕ РџР Р?ЛОЖЕНР?Р•
  46. local function downloadApp(pasteApp,pasteIcon,path)
  47.         fs.delete(path..".app")
  48.         pastebin(pasteApp,path..".app/main")
  49.         pastebin(pasteIcon,path..".app/Resources/icon.png")
  50. end
  51.  
  52. --РџР РћРЎРўРђРЇ Р—РђР›Р?Р’РљРђ Р­РљР РђРќРђ ЦВЕТОМ
  53. local function clearScreen(color)
  54.         term.setBackgroundColor(color)
  55.         term.clear()
  56. end
  57.  
  58. --ПЛАВНОЕ ВКЛЮЧЕНР?Р• Р­РљР РђРќРђ
  59. local function fadeIn(time)
  60.         clearScreen(ColorGray)
  61.         sleep(time)
  62.         clearScreen(ColorLightGray)
  63.         sleep(time)
  64.         clearScreen(colors.white)
  65.         sleep(time)
  66. end
  67.  
  68. --ПЛАВНОЕ Р—РђРўРЈРҐРђРќР?Р• Р­РљР РђРќРђ
  69. local function fadeOut(time)
  70.         clearScreen(ColorLightGray)
  71.         sleep(time)
  72.         clearScreen(ColorGray)
  73.         sleep(time)
  74.         clearScreen(colors.black)
  75.         sleep(time)
  76.         term.setCursorPos(1,1)
  77.         term.setTextColor(colors.white)
  78. end
  79.  
  80. --РЈРќР?ВЕРСАЛЬНАЯ ФУНКЦР?РЇ ДЛЯ ОТОБРАЖЕНР?РЇ ТЕКСТА РџРћ ЦЕНТРУ Р­РљР РђРќРђ
  81. local function centerText(how,coord,text,textColor,backColor)
  82.         term.setTextColor(textColor)
  83.         term.setBackgroundColor(backColor)
  84.         if how == "xy" then
  85.                 term.setCursorPos(math.floor(XSize/2-#text/2),math.floor(YSize/2))
  86.         elseif how == "x" then
  87.                 term.setCursorPos(math.floor(XSize/2-#text/2),coord)
  88.         elseif how == "y" then
  89.                 term.setCursorPos(coord,math.floor(YSize/2))
  90.         end
  91.         term.write(text)
  92. end
  93.  
  94. --РќРђР Р?РЎРћР’РђРўР¬ ГОРЗОНТАЛЬНУЮ Р›Р?РќР?Р® РЈРљРђР—РђРќРќРћР™ ДЛР?РќР« Р? ЦВЕТА
  95. local function horisontalBar(x,y,width,color)
  96.         for i=x,(x+width-1) do
  97.                 paintutils.drawPixel(i,y,color)
  98.         end
  99. end
  100.  
  101. --ОТОБРАЖЕНР?Р• ШКАЛЫ ЗАГРУЗКР? РЎ ПРОГРЕССОМ Р’ ПРОЦЕНТАХ
  102. local function progressBar(size,action,percent)
  103.         local doneSize = math.ceil(percent/100*size)
  104.         local startingY = math.floor(YSize/2-1)
  105.         local startingX = math.floor(XSize/2-size/2)
  106.         horisontalBar(1,startingY,XSize,colors.white)
  107.         centerText("x",startingY,"Installing "..action,ColorGray,colors.white)
  108.         horisontalBar(startingX,startingY+2,size,ColorDownloadBack)
  109.         horisontalBar(startingX,startingY+2,doneSize,ColorDownloadFront)
  110.         sleep(zaderzhka)
  111. end
  112.  
  113. --ЗАГРУЗР?РўР¬ Р’РЎР• ФАЙЛЫ РЎ ПАСТЕБР?РќРђ
  114. local function downloadAll()
  115.         clearScreen(colors.white)
  116.         progressBar(progressBarWidth,"started",0)
  117.  
  118.         fs.makeDir("Applications")
  119.         fs.makeDir("OS")
  120.         --fs.makeDir("Documents")
  121.         local oneFileIsHowMuchPercent = 1/#Data*100
  122.  
  123.         for i=1,#Data do
  124.                 if Data[i]["type"] == "Application" then
  125.                         downloadApp(Data[i]["paste"],Data[i]["icon"],Data[i]["path"])
  126.                 else
  127.                         pastebin(Data[i]["paste"],Data[i]["path"])
  128.                 end
  129.                 progressBar(progressBarWidth,Data[i]["category"],i*oneFileIsHowMuchPercent)
  130.         end
  131.  
  132.         clearScreen(colors.white)
  133.         centerText("x",math.floor(YSize/2),"Setup done.Press enter and print gui",ColorLightGray,colors.white)
  134.         os.pullEvent("key")
  135. end
  136.  
  137. --ЗАГРУЗР?РўР¬ Р’РЎР• РђРџР?
  138. local function downloadAPIs()
  139.         for i=1,#Data do
  140.                 if Data[i]["type"] == "API" then
  141.                         pastebin(Data[i]["paste"],Data[i]["path"])
  142.                 end
  143.         end
  144. end
  145.  
  146. --УДАЛР?РўР¬ Р’РЎР• РњРћР? ФАЙЛЫ
  147. local function deleteOld()
  148.         fs.delete("Applications")
  149.         fs.delete("Documents")
  150.         fs.delete("Images")
  151.         fs.delete("System")
  152.         fs.delete("OS")
  153.         fs.delete("MineCode")
  154.         fs.delete("startup")
  155.         fs.delete("Startup")
  156. end
  157.  
  158. --УДАЛР?РўР¬ ВООБЩЕ Р’РЎР• ФАЙЛЫ
  159. local function deleteAll()
  160.         local fileList = fs.list("")
  161.         for i=1,#fileList do
  162.                 if not fs.isReadOnly(fileList[i]) then
  163.                         fs.delete(fileList[i])
  164.                 end
  165.         end
  166. end
  167.  
  168. --РќРђР Р?РЎРћР’РђРўР¬ СЕЛЕКТОР Р”ЛЯ ВЫБОРА РџР Р? РЎРўРђР РўР• ПРОГРАММЫ
  169. local function drawSelection(y,text,id)
  170.         if id == Selector then
  171.                 horisontalBar(math.floor(XSize/2-8),y,16,ColorLightGray)
  172.                 centerText("x",y,text,colors.white,ColorLightGray)
  173.         else
  174.                 horisontalBar(math.floor(XSize/2-8),y,16,colors.white)
  175.                 centerText("x",y,text,ColorLightGray,colors.white)
  176.         end
  177. end
  178.  
  179. --ОТОБРАЖЕНР?Р• СТАРТОВОГО Р?НТЕРФЕЙСА
  180. local function gui()
  181.         local startingY = math.floor(YSize/2-2)
  182.         centerText("x",startingY,"Welcome to Fast OS installer! (C) Robar",ColorGray,colors.blue)
  183.  
  184.         drawSelection(startingY+2,"Install",1)
  185.         drawSelection(startingY+3,"Delet all files!",2)
  186.         drawSelection(startingY+5,"Exit",4)
  187. end
  188.  
  189. -----------------------СТАРТ ПРОГРАММЫ-----------------------
  190.  
  191. fadeIn(0)
  192. gui()
  193.  
  194. while true do
  195.         --ОТСЛЕЖР?Р’РђРќР?Р• КЛАВР?РЁ СТРЕЛОК Р? ENTER
  196.         local event, scancode = os.pullEvent("key")
  197.         --ПЕРЕМЕСТР?ТЬСЯ ВЫШЕ
  198.         if scancode == 200 then
  199.                 Selector = Selector-1
  200.                 if Selector<1 then Selector=1 end
  201.                 gui()
  202.         --ПЕРЕМЕСТР?ТЬСЯ РќР?Р–Р•
  203.         elseif scancode == 208 then
  204.                 Selector = Selector+1
  205.                 if Selector>4 then Selector=4 end
  206.                 gui()
  207.         --СКАЧАТЬ Р’РЎР• РЎ ПАСТЕБР?РќРђ
  208.         elseif scancode == 28 and Selector == 1 then
  209.                 --deleteOld()
  210.                 downloadAll()
  211.                 break
  212.         --РћР§Р?РЎРўР?РўР¬ РљРћРњРџ РћРў МОЕГО ГОВНА
  213.         elseif scancode == 28 and Selector == 2 then
  214.                 deleteAll()
  215.                 clearScreen(colors.white)
  216.                 centerText("x",math.floor(YSize/2),"disk has formated.",ColorLightGray,colors.white)
  217.                 local event, scancode = os.pullEvent("key")
  218.                 fadeOut(0)
  219.                 os.reboot()
  220.                 break
  221.         --СКАЧАТЬ ТОЛЬКО РђРџР? РЎ ПАСТЕБР?РќРђ
  222.         elseif scancode == 28 and Selector == 3 then
  223.                 fs.delete("System/API")
  224.                 clearScreen(colors.white)
  225.                 centerText("x",math.floor(YSize/2),"Downloading programs",ColorLightGray,colors.white)
  226.  
  227.                 --[[for i=1,11 do
  228.                         pastebin(Data[i]["paste"],Data[i]["path"])
  229.                 end]]
  230.                 downloadAPIs()
  231.  
  232.                 clearScreen(colors.white)
  233.                 centerText("x",math.floor(YSize/2),"Programs installed",ColorLightGray,colors.white)
  234.                 local event, scancode = os.pullEvent("key")
  235.                 break
  236.         --ВЫЙТР? Р?Р— ПРОГРАММЫ
  237.         elseif scancode == 28 and Selector == 4 then
  238.                 break
  239.         end
  240. end
  241.  
  242. fadeOut(0)
  243. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement