SuicidalSTDz

EnderAPI v1.1.0

Mar 15th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. --# Files to grab when updating/installing
  2. local tFiles = {
  3. "/EnderAPI/master/apis/color",
  4. "/EnderAPI/master/apis/colour",
  5. "/EnderAPI/master/apis/number",
  6. "/EnderAPI/master/apis/pastebin",
  7. "/EnderAPI/master/apis/text",
  8. "/EnderAPI/master/apis/messageBox",
  9. "/EnderAPI/master/apis/file",
  10. "/EnderAPI/master/config"
  11. }
  12.  
  13. --# Create directories if they are not present
  14. if not fs.exists( "/.EnderAPI" ) then
  15. fs.makeDir( "/.EnderAPI" )
  16. end
  17. if not fs.exists( "/.EnderAPI/master" ) then
  18. fs.makeDir( "/.EnderAPI/master" )
  19. end
  20. if not fs.exists( "/.EnderAPI/master/apis" ) then
  21. fs.makeDir( "/.EnderAPI/master/apis" )
  22. end
  23. if not fs.exists( "/.EnderAPI/master/temp" ) then
  24. fs.makeDir( "/.EnderAPI/master/temp" )
  25. end
  26.  
  27. local function downloadFiles( bShow )
  28. for i = 1, #tFiles do
  29. local response = http.get( "https://raw.github.com/SuicidalSTDz" .. tFiles[ i ] )
  30. if response then
  31. local sResponse = response.readAll()
  32. response.close()
  33.  
  34. local sFile = tFiles[ i ]:sub( 1, 1 ) .. "." .. tFiles[ i ]:sub( 2, #tFiles[ i ] )
  35. local handle = fs.open( sFile, "w" )
  36. handle.write( sResponse )
  37. handle.close()
  38. --# Successfully downloaded file
  39. if bShow then
  40. print( "Downloaded " .. tFiles[ i ] )
  41. end
  42. else
  43. --# Error downloading file
  44. if bShow then
  45. print( "Failed to download " .. tFiles[ i ] )
  46. end
  47. end
  48. end
  49. end
  50.  
  51. local function loadAPIs( bShow, tAPIs )
  52. if bShow then
  53. print( "Loading APIs.." )
  54. end
  55.  
  56. local tAPIs = {
  57. TextAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/text" ) },
  58. NumberAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/number" ) },
  59. ColorAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/color" ) },
  60. ColourAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/colour" ) },
  61. PastebinAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/pastebin" ) },
  62. MessageBoxAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/messageBox" ) },
  63. FileAPI = { success = os.loadAPI( "/.EnderAPI/master/apis/file" ) },
  64. }
  65.  
  66. for k, v in pairs( tAPIs ) do
  67. if not v.success then
  68. if bShow then
  69. printError( "Failed to load " .. tostring( k ) )
  70. end
  71. else
  72. if bShow then
  73. term.setTextColour( colours.lime )
  74. print( "Loaded " .. tostring( k ) )
  75. end
  76. end
  77. end
  78. if bShow then
  79. term.setTextColour( colours.white )
  80. end
  81. end
  82.  
  83. --# Main Update Script
  84. if fs.exists( "/.EnderAPI/master/config" ) then
  85.  
  86. --# EnderAPI is installed (at least enough to download core files and load APIs)
  87. --# Load the EnderAPI config file
  88. os.loadAPI( "/.EnderAPI/master/config" )
  89. local bShow = config.returnVars().showUpdateStatus
  90. if config.returnVars().shouldAutoUpdate then
  91. if bShow then
  92. write( "Checking for updates\n" )
  93. end
  94. end
  95.  
  96. --# Check for any available updates, if showAutoUpdate is true
  97. if config.returnVars().shouldAutoUpdate then
  98. local response = http.get( "https://raw.github.com/SuicidalSTDz/EnderAPI/master/config" )
  99. if response then
  100. local sResponse = response.readAll()
  101. response.close()
  102.  
  103. local handle = io.open( "/.EnderAPI/master/temp/config", "w" )
  104. handle:write( sResponse )
  105. handle:close()
  106. local oldVersion = config.returnVars().version
  107. os.loadAPI( "/.EnderAPI/master/temp/config" )
  108. if config.returnVars().version ~= oldVersion then
  109. --# An update is available, ask user to update ( not yet implemented )
  110. write( "An update is available!\nDownload Update? Y/N?\n" )
  111. local sInput = read():lower()
  112. if sInput == ( "yes" or "y" ) then
  113. if bShow then
  114. print( "Updating.." )
  115. end
  116. downloadFiles( bShow )
  117. else
  118. if bShow then
  119. print( "Skipping update" )
  120. end
  121. end
  122. else
  123. --# No update is available
  124. if bShow then
  125. print( "No updates avavilable" )
  126. end
  127. end
  128. else
  129. --# Error updating
  130. if bShow then
  131. print( "Error updating" )
  132. end
  133. end
  134. end
  135. else
  136. --# EnderAPI is not installed, download necessary files
  137. downloadFiles( true )
  138. end
  139.  
  140. --# Load EnderAPI
  141. os.loadAPI( "/.EnderAPI/master/config" )
  142. loadAPIs( config.returnVars().showUpdateStatus, tbl )
Advertisement
Add Comment
Please, Sign In to add comment