COOLGAMETUBEorginal

**[ComputerCraft] CCInstall

Aug 13th, 2015
355
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local vers = 1.201 --Command line support!
  2.  
  3. if not http then error("Sorry! you need Internet") end
  4.  
  5. shell.run("clear")
  6.  
  7. --fastRun = true --Only for Debug
  8. --noUpdate = true --Only for Debug
  9. local params = {...}
  10. if #params > 0 then
  11.     usep= true
  12. end
  13. local rP = 0
  14. local tread = function(a)
  15.     if usep then
  16.         return read(a)
  17.     else
  18.         rP = rP +1
  19.         return params[rP]
  20.     end
  21. end
  22.  
  23.  
  24. function CanWait(time)
  25.     if fastRun then
  26.         return false
  27.     else
  28.         sleep(time)
  29.         return true
  30.     end
  31. end
  32.  
  33. function HiddenPastebinGET(pstbinID, savLocFile)
  34.     if not noUpdate then
  35.         local sCode = pstbinID
  36.         local sFile = savLocFile
  37.         local sPath = shell.resolve( sFile )
  38.         if fs.exists( sPath ) then
  39.             fs.delete(sPath)
  40.         end
  41.        
  42.         local response = http.get(
  43.             "http://pastebin.com/raw.php?i="..textutils.urlEncode( pstbinID )
  44.         )
  45.            
  46.         if response then
  47.             local sResponse = response.readAll()
  48.             response.close()
  49.             res = sResponse
  50.         end
  51.  
  52.         if res then        
  53.             local file = fs.open( sPath, "w" )
  54.             file.write( res )
  55.             file.close()
  56.         end
  57.     end
  58. end
  59.  
  60. function printBanner()
  61.     shell.run("clear")
  62.     if not pocket then
  63.         print(",-------------------------------,\n|--------- CCInstaller ---------|\n`-------------------------------'\n")
  64.     else
  65.         print(",-------------,\n| CCInstaller |\n`-------------'\n")
  66.     end
  67. end
  68.  
  69. printBanner()
  70. CanWait(0.2)
  71. print("Downloading Assets")
  72. write("|#         |")
  73. local AssetSaveLocation = "/CCInstaller.assets/"
  74. if not fs.exists(AssetSaveLocation) then
  75.     fs.makeDir(AssetSaveLocation)
  76. else
  77.     if not fs.isDir(AssetSaveLocation) then
  78.         fs.makeDir(AssetSaveLocation)
  79.     end
  80. end
  81. term.setCursorPos(2, 6)
  82. HiddenPastebinGET("REaZXV7W", AssetSaveLocation.."WicowsTools")
  83. print("#####")
  84.  
  85. term.setCursorPos(2, 6)
  86. HiddenPastebinGET("7c1zEuXF", AssetSaveLocation.."InstallBase")
  87. print("##########")
  88.  
  89.  
  90. printBanner()
  91. print("Adding required External Functions...")
  92. os.unloadAPI(AssetSaveLocation.."WicowsTools")
  93. os.loadAPI(AssetSaveLocation.."WicowsTools")
  94. --CanWait(0.2)
  95. print("Done!\nInitalizing LanguagePack...")
  96. langPack = {
  97.         en = {
  98.                 "Please coppy all Installation Files into the \"CCInstallFiles\" Folder\n\nPress any key to contiune",
  99.                 "Found Folder: ",
  100.                 "Found File:" ,
  101.                 "ERROR: No Files found",
  102.                 "Done! ",
  103.                 " Objects found!",
  104.                 "Building InstallationFile...",
  105.                 "Scan Folders and Files...",
  106.                 "Please Enter ",
  107.                 "ProjectName: ",
  108.                 "Saved as:",
  109.         },
  110.         de = {
  111.                 "Bitte kopiere alle Installationsdateien in den \"CCInstallFiles\" Ordner\n\nZum fortfahren beliebige Taste druecken",
  112.                 "Ordner gefunden: ",
  113.                 "Datei gefunden: ",
  114.                 "FEHLER: Keine Dateien gefunden!",
  115.                 "Fertig! ",
  116.                 " Objekte gefunden!",
  117.                 "Baue Installationsdateien...",
  118.                 "Scanne Ordner und Dateien:",
  119.                 "Bitte gebe den ",
  120.                 "Projektnamen ein: ",
  121.                 "Gespeichert unter:",
  122.         },
  123.     }
  124. --CanWait(0.1)
  125. print("Done")
  126. --CanWait(0.3)
  127. ----------------------------------------------------------------------------------------------------------------------------------------
  128. ----------------------------------------------------------------------------------------------------------------------------------------
  129. ----------------------------------------------------------------------------------------------------------------------------------------
  130.  
  131. shell.run("clear")
  132. lang = "en"
  133. local n=1
  134. if not usep then
  135.     while true do
  136.         local x, y=term.getCursorPos()
  137.         shell.run("clear")
  138.         if n==1 then print("Select Language:\n,------------,\n|[x] English |\n|[ ] Deutsch |\n`------------'")
  139.         else print("Select Language:\n,------------,\n|[ ] English |\n|[x] Deutsch |\n`------------'")end
  140.         term.setCursorPos(x, y)
  141.         a, b=os.pullEvent()
  142.         while a~="key" do a, b=os.pullEvent() end
  143.         if b==200 then n=n-1 end
  144.         if b==208 then n=n+1 end
  145.         if b==28 then break end
  146.         if n==0 then n=2 end
  147.         if n==3 then n=1 end
  148.     end
  149.         if n==1 then lang = "en"
  150.     elseif n==2 then lang = "de"
  151.      
  152.       else error("Code Crash!!!") end
  153. end
  154.  
  155. WicowsTools.MagicClear(0.05)
  156. print(langPack[lang][1])
  157. if not fs.exists("CCInstallFiles") then fs.makeDir("CCInstallFiles") end
  158. if not usep then os.pullEvent("key") end
  159. WicowsTools.CreateBorder()
  160. x, y = term.getSize()
  161. DebugLog = window.create(term.current(), 2, 2, x -2, y-2)
  162. ----------------------------------------------------------------------------------------------------------------------------------------
  163. ----------------------------------------------------------------------------------------------------------------------------------------
  164. ----------------------------------------------------------------------------------------------------------------------------------------
  165. scrolled = 0
  166. function Log(str, add)
  167.  
  168. x, y = DebugLog.getCursorPos()
  169. w, h = DebugLog.getSize()
  170. if y > h then
  171.     term.setBackgroundColor(colors.black)
  172.     term.clear()DebugLog.clear()
  173.     WicowsTools.CreateBorder()
  174.     DebugLog.setCursorPos(1, 1)
  175. end
  176. x, y = DebugLog.getCursorPos()
  177. DebugLog.write(str)
  178. if not add then
  179. DebugLog.setCursorPos(1, y+1)
  180. end end
  181.  
  182. fc = 0
  183. fileList = {
  184.     Folders = {},
  185.     Files = {},
  186. }
  187. if pocket then Log(langPack[lang][9]) Log(langPack[lang][10]) else Log(langPack[lang][9]..langPack[lang][10]) end Log("> ",true) t = tread() if t == "" then t = "Installer" end fileList["Title"] = t Log(fileList["Title"])
  188. function fScan(folder)
  189.     fol = "CCInstallFiles/"
  190.     if folder == "CCInstallFiles" then
  191.         folder = ""
  192.         fol = "CCInstallFiles"
  193.     end
  194.     local FileList = fs.list(fol..folder)
  195.     for _, file in ipairs(FileList) do
  196.       fc = fc + 1
  197.       CanWait(0.001)
  198.       if fs.isDir(fol..folder.."/"..file) then
  199.         Log(langPack[lang][2]..folder.."/"..file)
  200.         table.insert(fileList["Folders"], folder.."/"..file)
  201.         fScan(folder.."/"..file)
  202.       else
  203.         Log(langPack[lang][3]..folder.."/"..file)
  204.         table.insert(fileList["Files"], { Path = folder.."/"..file, Content = WicowsTools.ReadFile(fol..folder.."/"..file) })
  205.       end
  206.     end
  207. end
  208. Log(langPack[lang][8])
  209. --CanWait(0.5)
  210. fScan("CCInstallFiles")
  211. print("1")
  212. if fc == 0 then
  213.     Log(langPack[lang][4])else
  214.     Log(langPack[lang][5]..tostring(fc)..langPack[lang][6])
  215. end
  216. Log(langPack[lang][7]) --[[CanWait(0.2)]]
  217. Log("Define")
  218. BuildingString = "Content = " --[[CanWait(0.2)]]
  219. Log("Adding Content")
  220. BuildingString = BuildingString..textutils.serialize(fileList) --[[CanWait(0.5)]]
  221. Log("Adding BaseScript")
  222. BuildingString = BuildingString.."\n"..WicowsTools.ReadFile("/CCInstaller.assets/InstallBase") --[[CanWait(0.5)]]
  223. Log("Saving...") --[[CanWait(1.2)]]
  224. WicowsTools.WriteFile(fileList["Title"], BuildingString)
  225. Log(langPack[lang][5])
  226. Log(langPack[lang][11])
  227. Log("/"..fileList["Title"])
  228. if not usep then os.pullEvent("key") end
  229. shell.run("clear")
  230. fs.delete(AssetSaveLocation.."/")
RAW Paste Data