Guest User

install

a guest
Feb 27th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. if not (string.sub(os.version(),1,8)=="TurtleOS") then
  2.   print("Diese API ist nur fuer Turtles gedacht!")
  3.   return
  4. end
  5.  
  6. local startupFile = "turtle.startup"
  7. local apiFolder = "customAPI"
  8. local apiFile = "turtle.advanced"
  9. local apiPath = fs.combine(apiFolder,apiFile)
  10.  
  11.  
  12. local function getFileContent( path )
  13.   local result
  14.   if fs.exists(path) then
  15.     local file = fs.open(path, "r")
  16.     result = file.readAll()
  17.     file.close()
  18.   end
  19.   return result
  20. end
  21.  
  22.  
  23. -- break if the api file is allready existing
  24. if fs.exists(apiPath) then
  25.   print("\""..apiPath.."\" existiert")
  26.   print("  schon auf dem System!")
  27.   return
  28. end
  29.  
  30. local oldStartup = getFileContent("startup")
  31. local newStartup = getFileContent("disk/"..startupFile)
  32.  
  33. -- break if defined startup file is not existant
  34. if not newStartup then
  35.   print("\"disk/"..startupFile.."\" konnte")
  36.   print("  nicht gelesen werden!")
  37.   return
  38. end
  39.  
  40. -- break if api file could not be found
  41. if not fs.exists("disk/"..apiFile) then
  42.   print("\"disk/"..apiFile.."\" existiert nicht!")
  43.   return
  44. end
  45.  
  46. -- try copying api file
  47. if not fs.exists(apiFolder) then
  48.   fs.makeDir(apiFolder)
  49. end
  50. fs.copy("disk/"..apiFile, apiPath)
  51.  
  52. -- check if startup exists on system
  53. if not oldStartup then
  54.   -- if not, simply copy the startup file
  55.   fs.copy("disk/"..startupFile, "startup")
  56. else
  57.   -- if it does, merge the new one in at the front
  58.   local file = fs.open("startup", "w")
  59.   file.writeLine("--- LOAD API ---")
  60.   file.writeLine(newStartup)
  61.   file.writeLine()
  62.   file.writeLine("--- BEGIN OF STARTUP ---")
  63.   file.writeLine(oldStartup)
  64.   file.close()
  65. end
  66.  
  67. -- print success message
  68. textutils.slowPrint("Installation vollstaendig!")
Advertisement
Add Comment
Please, Sign In to add comment