Advertisement
Guest User

x3edit_up

a guest
Nov 25th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. ----------------------
  2. -- x3edit installer --
  3. -- Created by Pilix --
  4. --     McFine.ru    --
  5. ----------------------
  6.  
  7. local Error = false
  8.  
  9. -------------
  10.  
  11. local function InjectInEdit()
  12.   local From = io.open("rom/programs/edit",'r')
  13.   local To   = io.open("x3edit/x3edit",'w')
  14.   local key  = true
  15.  
  16.   if From ~= nil and To ~= nil then
  17.     local cnt = 0
  18.     for line in From:lines() do
  19.       To:write(line.."\n")
  20.       cnt = cnt + 1
  21.       if cnt == 594 then
  22.         To:write("   x3edit_api.detect(tLines,param,param3 + scrollY)\n")
  23.         To:write("   redrawText()\n")
  24.       end
  25.     end
  26.   else
  27.     key = false
  28.   end
  29.   From:close()
  30.   To:close()
  31.   return key
  32. end
  33.  
  34. -------------
  35.  
  36. local function InjectInStartup()
  37.   local From = io.open("/startup",'r')
  38.   local To   = io.open("/new_startup",'w')
  39.  
  40.   if From ~= nil and To ~= nil then
  41.     To:write("os.loadAPI(\"/x3edit/x3edit_api\")\n")
  42.     To:write("shell.setAlias(\"x3edit\",\"/x3edit/x3edit\")\n")
  43.     for line in From:lines() do
  44.       To:write(line.."\n")
  45.     end
  46.     From:close()
  47.     To:close()
  48.     fs.delete("/startup")
  49.     fs.move("/new_startup","startup")
  50.     return true
  51.   end
  52.   From:close()
  53.   To:close()
  54.   return false
  55. end
  56.  
  57. -------------
  58.  
  59. local function CreateStartup()
  60.   local To = io.open("/startup",'w')
  61.  
  62.   if To ~= nil then
  63.     To:write("os.loadAPI(\"/x3edit/x3edit_api\")\n")
  64.     To:write("shell.setAlias(\"x3edit\",\"/x3edit/x3edit\")\n")
  65.     To:close()
  66.     return true
  67.   end
  68.   return false
  69. end
  70.  
  71. -------------
  72.  
  73. local function CreateAPI()
  74.   local From = io.open(shell.getRunningProgram(),'r')
  75.   local To   = io.open("/x3edit/x3edit_api",'w')
  76.   local key  = true
  77.  
  78.   if From ~= nil and To ~= nil then
  79.     CopyKey = false
  80.     for line in From:lines() do
  81.       if line == "--[ Block #1 ]--" then
  82.         if CopyKey then
  83.           break
  84.         else
  85.           CopyKey = true
  86.         end
  87.       elseif CopyKey then
  88.         To:write(line.."\n")
  89.       end
  90.     end
  91.   else
  92.     key = false
  93.   end
  94.   From:close()
  95.   To:close()
  96.   return key
  97. end
  98.  
  99. --[ Block #1 ]--
  100. bPath = "/x3edit/x3buff"
  101.  
  102. function detect (iTab,button,pos_y)
  103.   if     button == 1 then
  104.     iTab.pos = pos_y
  105.   elseif button == 2 then
  106.     local pos1 = iTab.pos
  107.     local cnt = pos_y - pos1 + 1
  108.     if cnt > 0 then
  109.       Fp = io.open(bPath,"w")
  110.       if Fp ~= nil then
  111.         local pos_i = 0
  112.         while cnt > 0 do
  113.           Fp:write(iTab[pos1 + pos_i].."\n")
  114.           pos_i = pos_i + 1
  115.           cnt = cnt - 1
  116.         end
  117.         Fp:close()
  118.       end
  119.     end
  120.   elseif button == 3 then
  121.     if fs.getSize(bPath) > 0 then
  122.       Fp = io.open(bPath,"r")
  123.       if Fp ~= nil then
  124.         local pos_i = 0
  125.         for line in Fp:lines() do
  126.           table.insert(iTab,pos_y + pos_i,line)
  127.           pos_i = pos_i + 1
  128.         end
  129.         Fp:close()
  130.       end
  131.     end
  132.   end
  133. end
  134. --[ Block #1 ]--
  135.  
  136. ----------------------------------
  137.  
  138. shell.setDir("")
  139.  
  140. if not fs.exists("/x3edit") then
  141.   fs.makeDir("/x3edit")
  142. end
  143.  
  144. if fs.exists("/x3edit/x3edit") then
  145.   fs.delete("/x3edit/x3edit")
  146. end
  147.  
  148. if InjectInEdit() then
  149.   print("Inject <edit> : Ok")
  150. else
  151.   print("Inject <edit> : Error -> Break...")
  152.   Error = true
  153. end
  154.  
  155. if not Error then
  156.   if fs.exists("/startup") then
  157.     if InjectInStartup() then
  158.       print("Inject <startup> : Ok")
  159.     else
  160.       print("Inject <startup> : Error -> Break...")
  161.       Error = true
  162.     end
  163.   else
  164.     if CreateStartup() then
  165.       print("Create <startup> : Ok")
  166.     else
  167.       print("Create <startup> : Error -> Break...")
  168.       Error = true
  169.     end
  170.   end
  171. end
  172.  
  173. if not Error then
  174.   if CreateAPI() then
  175.     print("Create <API> : Ok")
  176.   else
  177.     print("Create <API> : Error -> Break...")
  178.     Error = true
  179.   end
  180. end
  181.  
  182. if Error then
  183.   print("x3edit install failed...")
  184. else
  185.   print("x3edit install successful!")
  186. end
  187.  
  188. term.write("Reboot system... ")
  189. local x,y = term.getCursorPos()
  190. local cnt = 5
  191.  
  192. while cnt>0 do
  193.   term.write(tostring(cnt))
  194.   term.setCursorPos(x,y)
  195.   cnt = cnt - 1
  196.   sleep(1)
  197. end
  198. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement