100xdonaldx001

TurtleShell

Sep 10th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. --[[
  2. File: install - TurtleSHELL
  3. Purpose: Installs TurtleSHELL and it's components!
  4. Author: da404lewzer
  5. Project: http://turtlescripts.com/project/gjdgyz
  6. License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
  7. http://creativecommons.org/licenses/by-sa/3.0/
  8. ]]
  9.  
  10. local betaKey = "" --used for dev
  11. local running = true
  12.  
  13. --Initial setup routines.. reverted to single monitor.. to emulate old windows installs
  14. local function drawModalMessage(monitor, monID, messageArr, bgText, bgColor, bgTextColor)
  15. local w,h = monitor.getSize()
  16. local xOffset,yOffset = 2,2
  17. local setupBG,setupBGText = colors.black, colors.white
  18. if monitor.isColor() then
  19. setupBG,setupBGText = bgColor, bgTextColor
  20. end
  21. monitor.setBackgroundColor(setupBG)
  22. monitor.setTextColor(setupBGText)
  23. monitor.clear()
  24. monitor.setCursorPos(xOffset,yOffset)
  25. monitor.write("TurtleSHELL Setup")
  26. monitor.setCursorPos(xOffset,yOffset+1)
  27. monitor.write(string.rep("-",w-((xOffset -1)*2)))
  28. local extraLineFeed = 2
  29. for i=1, #messageArr do
  30. monitor.setCursorPos(xOffset,yOffset+i+extraLineFeed)
  31. local wl = 0
  32. for word in string.gmatch(messageArr[i], "[^%s]+") do
  33. if wl+string.len(word) > w - ((xOffset -1)*2) then
  34. wl = 0
  35. extraLineFeed=extraLineFeed+1
  36. end
  37. monitor.setCursorPos(xOffset+wl,yOffset+i+extraLineFeed)
  38. wl=wl+string.len(word)+1
  39. monitor.write(word)
  40. end
  41. end
  42. monitor.setCursorPos(xOffset,h - yOffset+1)
  43. monitor.write(bgText)
  44. end
  45. local showingMessage = false
  46. function setupMessage(msgArr, bgText, bgColor, bgTextColor)
  47. local timer = os.startTimer(0)
  48. showingMessage = true
  49. drawModalMessage(term, 0, msgArr, bgText, bgColor, bgTextColor)
  50. sleep(0.5)
  51. while running and showingMessage do
  52. local event, p1, p2 = os.pullEvent()
  53. if event == "key" then
  54. lastKeypress = os.clock()
  55. showingMessage = false
  56. else
  57. drawModalMessage(term, 0, msgArr, bgText, bgColor, bgTextColor)
  58. end
  59. end
  60. showingMessage = false
  61. end
  62. function updateAllTheThings()
  63. fs.makeDir("turtleshell")
  64. --shell.run("market get gjdgz7 market y")
  65. shell.run("market get gjdh20 turtleshell/update "..betaKey.." y")
  66. if fs.exists("turtleshell/update") then
  67. shell.run("turtleshell/update")
  68. end
  69. end
  70. function getDefaultSettingsFiles()
  71. shell.run("market get gjdh05 turtleshell/os.settings "..betaKey) --DO NOT OVERRIDE IF FILE EXISTS
  72. shell.run("market get gjdh21 turtleshell/texty.settings "..betaKey) --DO NOT OVERRIDE IF FILE EXISTS
  73. end
  74. function setToStartup()
  75. if fs.exists("startup") and not fs.exists("startup.bak") then
  76. fs.move("startup", "startup.bak")
  77. end
  78. h = fs.open("startup", "w")
  79. h.write('shell.run("turtleshell/os")')
  80. h.close()
  81. end
  82. function cleanUp()
  83. term.clear()
  84. term.setCursorPos(1,1)
  85. end
  86. local logo = {
  87. " cccc ";
  88. " c0cc0c ";
  89. " cccccc 111111 1 11 111 1 111";
  90. " cc cccc cc 1 1 1 1 1 1 1 1 ";
  91. "cccc55d55d55cccc 1 1 1 11 1 1 11 ";
  92. " cd5dd5dd5dd5dc 1 1 1 1 1 1 1 1 ";
  93. " d5dd5dd5dd5d 1 111 1 1 1 111 111";
  94. " 5d55d55d55d5 ";
  95. " d5dd5dd5dd5d 3333 3 3 3333 3 3 ";
  96. " d5dd5dd5dd5d 3 3 3 3 3 3 ";
  97. " 5d55d55d55d5 333 3333 333 3 3 ";
  98. " d5dd5dd5dd5d 3 3 3 3 3 3 ";
  99. " cc5dd5dd5dd5cc 3333 3 3 3333 333 333";
  100. "cccc55d55d55cccc ";
  101. " cc cc cc ";
  102. }
  103. --[[Stolen Shamelessly from nPaintPro - http://pastebin.com/4QmTuJGU]]
  104. local function getColourOf(hex)
  105. local value = tonumber(hex, 16)
  106. if not value then return nil end
  107. value = math.pow(2,value)
  108. return value
  109. end
  110. local function drawPictureTable(mon, image, xinit, yinit, alpha)
  111. if not alpha then alpha = 1 end
  112. for y=1,#image do
  113. for x=1,#image[y] do
  114. mon.setCursorPos(xinit + x-1, yinit + y-1)
  115. local col = getColourOf(string.sub(image[y], x, x))
  116. if not col then col = alpha end
  117. if term.isColor() then
  118. mon.setBackgroundColour(col)
  119. else
  120. if string.sub(image[y], x, x) ~= " " then
  121. mon.setBackgroundColour(colors.black)
  122. else
  123. mon.setBackgroundColour(colors.white)
  124. end
  125. end
  126. mon.write(" ")
  127. end
  128. end
  129. end
  130. --[[End Theft]]
  131. function performOSSetup()
  132. cleanUp()
  133. setupMessage({
  134. "Welcome to TurtleSHELL BETA Setup",
  135. "",
  136. "Current Features:",
  137. " * Screen Savers [4D, Texty, and Matrix]",
  138. " * Customizable Menus / Footer Text",
  139. " * Multi-monitor support (screensavers too!)",
  140. " * Color Support",
  141. "",
  142. "To configure see 'os.settings' file after install."
  143. }, "[Next]", colors.blue, colors.white)
  144. setupMessage({
  145. "We will now download the remainder of the system including a couple screensavers and settings files.",
  146. "",
  147. "Settings files are isolated so you don't have to worry about losing settings when we make updates!",
  148. "",
  149. "This will also override your startup and make a backup if it exists :)",
  150. }, "[Install]", colors.blue, colors.white)
  151. cleanUp()
  152. updateAllTheThings()
  153. getDefaultSettingsFiles()
  154. setToStartup()
  155. fs.delete("install") --remove the installer
  156. drawModalMessage(term, 0, {"Everything seems normal..","","The system will now reboot :)"}, "Please wait...", colors.blue, colors.white)
  157. sleep(2)
  158. os.reboot()
  159. end
  160. --End of Initial setup routines
  161.  
  162.  
  163. term.setBackgroundColor(colors.white)
  164. term.clear()
  165. local w, h = term.getSize()
  166. drawPictureTable(term, logo, w/2 - #logo[1]/2, h/2 - #logo/2, colours.white)
  167. sleep(2)
  168. performOSSetup() --reboots if completes, can return errors or when cancelled
Add Comment
Please, Sign In to add comment