Advertisement
Dimach

MineX 2.0 installer

Jan 1st, 2013
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.90 KB | None | 0 0
  1. function writeCenter(msg,y,sLen)
  2.         if sLang==1 or sLang==0 then len = sLen else len = #msg end
  3.         term.setCursorPos((52-len)/2,y)
  4.         term.write(msg)
  5. end
  6.  
  7. function findfromback(arg,w)
  8. for n = 1,#arg do
  9. local a=#arg-n
  10. if string.sub (arg, a,a+#w-1)==w then
  11. return a;
  12. end
  13. end
  14. end
  15.  
  16. function writeAsNSymbol(text,n,y)
  17.  
  18.     if n >= 0 and n <= 50 then
  19.    
  20.         for i=1,#text do
  21.             term.setCursorPos(n,y-1+i)
  22.             write(text[i])
  23.         end
  24.        
  25.     end
  26.    
  27. end
  28.  
  29. function progresBar(pos,x,y,len)
  30.     local i, procentAsSymbol, progress
  31.     local progres = ""
  32.     procentAsSymbol = math.modf (100/(len-2))
  33.     progress = math.modf (pos/procentAsSymbol)
  34.    
  35.     for i=1,len-2 do
  36.         if i <= progress then progres = progres.."|" else progres = progres.." " end
  37.     end
  38.    
  39.     term.setCursorPos(x,y)
  40.     write("["..progres.."]")
  41. end
  42.  
  43. function buttonAllPos(bts,x,y,btsn,sel)
  44.     local i,event,key,xx,yy
  45.     local len=#bts*2
  46.     xx,yy=term.getSize()
  47.    
  48.     if sLang == 1 then
  49.     len=len+1
  50.     for i=1,#bts do len=len+(#bts[i])/2 end
  51.     else
  52.     for i=1,#bts do len=len+#bts[i] end
  53.     end
  54.    
  55.     if type(x)=="string" then
  56.         if x=="left" then x=1
  57.         elseif x=="center" then x=(xx-len+2)/2
  58.         elseif x=="right" then x=xx-len+1
  59.         else x=1 end
  60.     end
  61.    
  62.     if type(y)=="string" then
  63.         if y=="top" then y=1
  64.         elseif y=="center" then y=yy/2
  65.         elseif y=="bottom" then y=yy
  66.         else y=1 end
  67.     end
  68.    
  69.     if sel==nil then sel=1 end
  70.    
  71.     while true do
  72.         term.setCursorPos(x,y)
  73.         term.clearLine()
  74.        
  75.         for i=1,#bts do
  76.             if i==sel then term.write("["..bts[i].."]") else term.write(" "..bts[i].." ") end
  77.         end
  78.        
  79.         if sel=="break" then break end
  80.        
  81.         event,key=os.pullEvent("key")
  82.        
  83.         if key==203 and sel>1 then sel=sel-1
  84.         elseif key==205 and sel<#bts then sel=sel+1
  85.         elseif key==28 then break end
  86.        
  87.     end
  88.    
  89.     if btsn==nil then return bts[sel] else return btsn[sel] end
  90.    
  91. end
  92.  
  93. function TextGet(pos)
  94. lang={}
  95. lang[1]={
  96. {"Данная программа установит на ваш","компьютер ос MineX","MineX - полуграфическая ОС для ComputerCraft"},
  97. "Вас приветствует мастер установки ос MineX",
  98. {"<Назад","Выйти","Дальше>"},
  99. {"Внимание! Все существовавшие ранее","файлы будут недоступны"},
  100. {"<Назад","Выйти","Установить!"},
  101. "Вы уверены что хотите прервать процесс установки?",
  102. {"Да","Нет"},
  103. "Подождите пока мастер установки MineX OS выполнит",
  104. "необходимые операции..."
  105. }
  106.  
  107. lang[2]={
  108. {"Dannaya programma ustanovit na vash","kompyuter os MineX","MineX - polugraficheskaya OS dlya","ComputerCraft"},
  109. "Vas privetstvuet master ustanovki os MineX",
  110. {"<Nazad","Vyiti","Dalshe>"},
  111. {"Vnimanie! Vse sushchestvovavshie ranyee","faily budut nedostupny"},
  112. {"<Nazad","Vyiti","Ustanovit!"},
  113. "Vy uvereny chto khotite vyiti iz protsessa ustanovki?",
  114. {"Da","Net"},
  115. "Podozhdite poka master ustanovki OS MineX vypolnit",
  116. "nyeobkhodimye operatsii..."
  117. }
  118.  
  119. lang[3]={
  120. {"This program install on your","computer OS MineX","MineX - halfgraphical OS for ComputerCraft"},
  121. "Welcome to MineX OS Setup",
  122. {"<Back","Exit","Next>"},
  123. {"Attention! All pre-existing files","will are not available"},
  124. {"<Back","Exit","Install!"},
  125. "Do you really want to cancel the installation?",
  126. {"Yes","No"},
  127. "Wait until the installation wizard MineX OS",
  128. "will perform the necessary operations ..."
  129. }
  130.  
  131. return lang[sLang][pos]
  132. end
  133.  
  134. function FormInstallDisabet (func)
  135. writeCenter("--------------------------------------------------",7,50)
  136. writeCenter(TextGet(6),8,49)
  137. writeCenter("--------------------------------------------------",10,50)
  138. local select = buttonAllPos(TextGet(7),"center",9,{1,2})
  139. if select == 2 then
  140. func()
  141. else
  142. term.clear()
  143. term.setCursorPos(1,1)
  144. end
  145. end
  146.  
  147. function FormHello()
  148. term.clear()
  149. writeCenter("Выберите язык/vuberite yazuk/select a language",8,46)
  150. sLang = buttonAllPos({"Русский","Russkiy","English"},13,9,{1,2,3})
  151. FormInfo()
  152. end
  153.  
  154. function FormInfo()
  155. term.clear()
  156. writeCenter(TextGet(2),1,42)
  157. writeAsNSymbol(TextGet(1),5,3)
  158. local select = buttonAllPos(TextGet(3),"right","bottom",{1,2,3})
  159. if select==1 then
  160. FormHello()
  161. elseif select == 2 then
  162. FormInstallDisabet(FormInfo)
  163. else
  164. FormWarning()
  165. end
  166. end
  167.  
  168. function FormWarning()
  169. term.clear()
  170. writeCenter(TextGet(2),1,42)
  171. writeAsNSymbol(TextGet(4),5,3)
  172. local select = buttonAllPos(TextGet(5),"right","bottom",{1,2,3})
  173. if select==1 then
  174. FormInfo()
  175. elseif select==2 then
  176. FormInstallDisabet(FormWarning)
  177. else
  178. FormProgres()
  179. end
  180. end
  181.  
  182. function FormProgres()
  183. term.clear()
  184. writeCenter(TextGet(2),1,42)
  185. writeCenter("--------------------------------------------------",2,50)
  186. writeCenter(TextGet(8),3,50)
  187. writeCenter(TextGet(9),4,23)
  188. writeCenter("--------------------------------------------------",5,50)
  189.  
  190.     local response = http.get(
  191.         "https://raw.github.com/Dimach/MineXDownload/master/MineX/version.txt"
  192.         )
  193.     build = response.readAll()
  194.  
  195.         response.close()
  196.  
  197.        
  198.         local response = http.get(
  199.         "https://raw.github.com/Dimach/MineXDownload/master/MineX/stable/"..build.."/fl"
  200.         )
  201.     fl = response.readAll()
  202.  
  203.         response.close()
  204.        
  205.  
  206.  f=io.open("fl","w")
  207.  f:write(fl)
  208.  f:close()
  209.  dofile("fl")
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219. for i=1,#fileslist do
  220.  
  221. if fileslist[i][1]=="dir" then
  222.  
  223. fs.makeDir(fileslist[i][2])
  224.  
  225. progresBar(i*100/#fileslist,1,9,49)
  226. else
  227.  
  228.     local response = http.get(
  229.         "https://raw.github.com/Dimach/MineXDownload/master/MineX/stable/"..build.."/"..fileslist[i][1]
  230.         )
  231.             fils = response.readAll()
  232.  
  233.         response.close()
  234.        
  235.         progresBar(i*100/#fileslist,1,9,49)
  236.         file=io.open(fileslist[i][2],"w")
  237.         file:write(fils)
  238.         file:close()
  239.         end
  240.        
  241.         sleep(1)
  242.  
  243.  
  244. end
  245.  
  246. end
  247.  
  248.  
  249. sLang = 0
  250. FormHello()
  251. term.clear()
  252. term.setCursorPos(1,1)
  253. textutils.slowPrint("MineX installation compleated...")
  254. textutils.slowPrint("CraftBIOS will be rebooted...")
  255.  
  256. sleep(1)
  257. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement