Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.65 KB | None | 0 0
  1. Skip to content
  2. Personal Open source Business Explore
  3. Sign upSign inPricingBlogSupport
  4. This repository
  5. Search
  6. Watch 2 Star 0 Fork 0 remiX-/ccYouTube
  7. Code Issues 0 Pull requests 0 Pulse Graphs
  8. Branch: master Find file Copy pathccYouTube/ComputerCraft YouTube
  9. efc54da on Mar 25, 2013
  10. @remiX- remiX- fixed gsub error
  11. 1 contributor
  12. RawBlameHistory 1539 lines (1412 sloc) 57.7 KB
  13. local version = "3.21"
  14. --[[
  15.  
  16. ComputerCraft YouTube is a program designed to keep everyone up-to-date with
  17. the latest Lightshot videos. It utilizes the use of HTTP api and the use of
  18. a few string functions to get all the required text off the website.
  19.  
  20. This code was made by and ONLY by remiX, aka Nicholas. I, hereby allow users
  21. to use, redistribute and edit the program to their liking IF they keep this comment within
  22. the program and add credits if applied into an OS.
  23.  
  24. Enjoy!
  25.  
  26. --]]
  27.  
  28. --[[ Variables ]]--
  29. local screenX, screenY = term.getSize()
  30. local running = true
  31.  
  32. -- Credentials
  33. local logged = false
  34. local userInfo = {
  35. name = "",
  36. username = "",
  37. email = "",
  38. password = "",
  39. }
  40. local inbox = {}
  41. local menus = { { text = logged and "Prefrences" or "Login", x = 4 }, { text = logged and "Messages" or "", x = logged and 16 or 11 }, { text = logged and "Logout" or "Register", x = logged and 26 or 11 } }
  42.  
  43. -- Files paths
  44. local sourceFolder = ".ccYouTube"
  45. local errorLocation = sourceFolder .. "/errorLog.txt"
  46. local ccYouTubeLocation = shell.getRunningProgram()
  47.  
  48. -- Load Loading Screen API
  49. os.loadAPI(sourceFolder .. "/apis/loadingScreen")
  50.  
  51. -- Other
  52. local selectedMenu = "Home"
  53.  
  54. -- URLs
  55. local serverURL = "http://www.cc-youtube.hostei.com"
  56.  
  57. -- Tables
  58. local t_Programs = {}
  59.  
  60. local t_Folders = {
  61. { sFolderName = "downloads", sPath = sourceFolder .. "/downloads" },
  62. { sFolderName = "apis", sPath = sourceFolder .. "/apis" },
  63. { sFolderName = "recycleBin", sPath = sourceFolder .. "/recycleBin" },
  64. { sFolderName = "logos", sPath = sourceFolder .. "/logos" },
  65. }
  66.  
  67. local t_NeededFiles = {
  68. { sFileName = "Extended String Library", sUrl = "zeG34tu6", sPath = sourceFolder .. "/apis/extStrLib", sType = "api"},
  69. { sFileName = "Box Function", sUrl = "R84v3P9G", sPath = sourceFolder .. "/apis/box", sType = "api"},
  70. }
  71.  
  72. local t_logos = {
  73. ["home"] = paintutils.loadImage( sourceFolder .. "/logos/home" ),
  74. ["logo"] = paintutils.loadImage( sourceFolder .. "/logos/ccytLogo" ),
  75. ["loadLogo"] = {
  76. " f f eeeee e ",
  77. " f f e e ",
  78. " 9999 9999 ffff fff f f e e e eee eee",
  79. "9 9 f f f f f e e e e e e e",
  80. "9 9 ffff f f f f f e e e e e eee",
  81. "9 9 f f f f f e e e e e e ",
  82. " 9999 9999 ffff fff fff e eee eee eee",
  83. }
  84. }
  85.  
  86. local t_Menus = {
  87. ["MainScreen"] = {
  88. -- top bar
  89. { text = "Account", xPos = 2, yPos = 2 },
  90. { text = "Home", xPos = 14, yPos = 2 },
  91. -- middle bar
  92. { text = "Local Gallery", xPos = 2, yPos = 3 },
  93. { text = "Website Gallery", xPos = 20, yPos = 3 },
  94. { text = "Upload", xPos = screenX - 6, yPos = 3 },
  95. -- Bottom bar
  96. { text = "Help", xPos = 2, yPos = 4 },
  97. { text = "Credits", xPos = 16, yPos = 4 },
  98. { text = "Update", xPos = 30, yPos = 4 },
  99. { text = "Exit", xPos = screenX - 4, yPos = 4 },
  100. }
  101. }
  102.  
  103. local t_Credits = {
  104. { text = "Developer:", col = colours.cyan },
  105. { text = "remiX", col = colours.cyan },
  106. { text = "", col = colours.white },
  107. { text = "APIS:", col = colours.red },
  108. { text = "TheOriginalBIT", col = colours.blue },
  109. { text = "- Loading Screen", col = colours.black },
  110. { text = "- Extended String Library", col = colours.black },
  111. { text = "", col = colours.white },
  112. { text = "HTTP", col = colours.orange },
  113. { text = "Orwell", col = colours.blue },
  114. { text = "- string.gmatch and http.post help", col = colours.black },
  115. { text = "Bubba", col = colours.blue },
  116. { text = "- string.gmatch help", col = colours.black },
  117. { text = "GravityScore", col = colours.blue },
  118. { text = "- PHP Help / Mailing system", col = colours.black },
  119. }
  120.  
  121. local helpText = {
  122. { head = "Logging in", text = {
  123. "How to login", "",
  124. " Click the 'Account' menu and",
  125. "enter your personal credentials.",
  126. '',
  127. ' Remember: You may login using',
  128. 'your username or email address',
  129. 'if you had registered your account',
  130. 'with one.'
  131. } },
  132. { head = "Registering", text = {
  133. "How to register an account", "",
  134. " Click the 'Account' menu and",
  135. "then select 'Register' from the",
  136. "smaller screen.",
  137. " Here you enter your name,",
  138. "email address, username and",
  139. "password. Name and email boxes",
  140. 'are optional.',
  141. ' Passwords are heavily secured.'
  142. } },
  143. { head = "Uploading", text = {
  144. "How to upload a video", "",
  145. "Select 'Upload' from the menu", "",
  146. " In order to successfully upload",
  147. "a video, you must enter a valid",
  148. "video title, username and pastebin",
  149. "code.",
  150. " Then you are able to supply a",
  151. "description about the video.",
  152. " A dialogue box will appear to show",
  153. "if the upload was successful or not."
  154. } },
  155. { head = "Downloading",
  156. text = {
  157. "How to download a video", "",
  158. " Select 'Website Gallery' from the",
  159. "menu.", "",
  160. " Use arrow keys or mouse to scroll",
  161. "up and down to change your selection",
  162. "and then hit enter to view details",
  163. "on the video.",
  164. " You can click the 'download' button",
  165. "to download the video and it will be",
  166. "added to your local gallery."
  167. } },
  168. { head = "Changelog",
  169. text = {
  170. "What's new", "",
  171. " - v3.0",
  172. " - Complete re-write of the GUI",
  173. " - New and better menu",
  174. " - New display of the website and",
  175. " local gallery which is now in",
  176. " the form of a table",
  177. " - Added help screen",
  178. " - Removed control panel menu",
  179. " - Login system soon to come"
  180. } },
  181. { head = "About",
  182. text = {
  183. "About CC-YouTube", "",
  184. " ComputerCraft YouTube is a program",
  185. "designed to handle videos that have",
  186. "been recorded by Lightshot (by",
  187. "GravityScore).",
  188. " You can download, upload and play",
  189. "videos from your minecraft computer.", "",
  190. "Last update: v3.21, 03/17/2013"
  191. } }
  192. }
  193. --[[ End of Variables ]]--
  194.  
  195. term.setTextColour(colours.red)
  196. if not term.isColor() or turtle then
  197. print("Error; Advanced Computer Required.")
  198. return
  199. elseif not http then
  200. print("Error; HTTP needs to be enabled.")
  201. return
  202. elseif not loadingScreen.getVersion then
  203. print("Error; Loading screen API cannot be found")
  204. return
  205. end
  206.  
  207. --[[ Functions ]]--
  208. local function getCenter( l, x1, x2 )
  209. return math.floor( ( ( x2 + x1 ) - ( type(l) == 'string' and #l or l ) ) / 2 ) + 1
  210. end
  211.  
  212. local function centerWrite( text, yPos, txtCol, bgCol )
  213. term.setCursorPos( ( screenX - #text ) / 2, yPos )
  214. term.setTextColour( txtCol )
  215. if bgCol then term.setBackgroundColour( bgCol ) end
  216. write( text )
  217. end
  218.  
  219. local function leftWrite( text, yPos, txtCol, bgCol )
  220. term.setCursorPos( 1, yPos )
  221. term.setTextColour( txtCol )
  222. term.setBackgroundColour( bgCol )
  223. write( text )
  224. end
  225.  
  226. local function rightWrite( text, yPos, txtCol, bgCol )
  227. term.setCursorPos( screenX - #text, yPos )
  228. term.setTextColour( txtCol )
  229. term.setBackgroundColour( bgCol )
  230. write( text )
  231. end
  232.  
  233. local function sWrite( text, xPos, yPos, txtCol, bgCol )
  234. term.setCursorPos( xPos, yPos )
  235. if txtCol then term.setTextColour( txtCol ) end
  236. if bgCol then term.setBackgroundColour( bgCol ) end
  237. write( text )
  238. end
  239.  
  240. local function isValidClick(_table, mx, my)
  241. for i, v in pairs(_table) do
  242. if mx >= v.xPos and mx < v.xPos + #v.text
  243. and my == v.yPos and selectedMenu ~= v.text then
  244. selectedMenu = v.text
  245. return true, v.text
  246. end
  247. end
  248. return false, nil
  249. end
  250.  
  251. local function limitRead( nLimit, replaceChar, tmpString, dispInvalid, startX, oldCol, useTmpBut, tmpBtnSX, tmpBtnEX, tmpBtnY, btnOpt )
  252. term.setCursorBlink(true)
  253. local cX, cY = term.getCursorPos()
  254. local rString = tmpString or ''
  255. write( rString:sub( #rString >= nLimit and #rString - nLimit or 1 ) )
  256. replaceChar = replaceChar and replaceChar:sub( 1, 1 ) or nil
  257. if replaceChar == "" then replaceChar = nil end
  258. while true do
  259. local event, p1, x, y = os.pullEvent()
  260. if event == "char" then
  261. -- Character event
  262. if #rString + 1 <= nLimit then
  263. rString = rString .. p1
  264. write(replaceChar or p1)
  265. else
  266. term.setCursorPos( startX, cY )
  267. rString = rString .. p1
  268. write( replaceChar and string.rep( replaceChar, nLimit ) or rString:sub( #rString - nLimit ) )
  269. end
  270. elseif event == "key" then
  271. if p1 == keys.backspace and #rString >= 1 then
  272. -- Backspace
  273. rString = rString:sub( 1, #rString - 1 )
  274. xPos, yPos = term.getCursorPos()
  275. term.setCursorPos(xPos-1, yPos)
  276. write(" ")
  277. term.setCursorPos(xPos-1, yPos)
  278. if #rString > nLimit then
  279. term.setCursorPos( startX, cY )
  280. write( replaceChar and string.rep( replaceChar, nLimit ) or rString:sub( #rString - nLimit ) )
  281. end
  282. elseif p1 == keys.enter then
  283. if #rString <= 3 and dispInvalid then
  284. term.setCursorBlink(false)
  285. mx, my = term.getCursorPos()
  286. sWrite( "invalid", screenX - 3 - string.len("invalid"), cY, colours.red, nil )
  287. pcall(sleep, 1)
  288. sWrite( " ", screenX - 3 - string.len("invalid"), cY )
  289. if oldCol then term.setTextColour( oldCol ) end
  290. term.setCursorPos(mx,my)
  291. term.setCursorBlink(true)
  292. else
  293. term.setCursorBlink(false)
  294. return rString
  295. end
  296. end
  297. elseif event == "mouse_click" and p1 == 1 then
  298. if isValidClick( t_Menus["MainScreen"], x, y ) then
  299. break
  300. elseif useTmpBut and x >= tmpBtnSX and x < tmpBtnEX and y == tmpBtnY then
  301. term.setCursorBlink(false)
  302. if btnOpt == 'kill' then
  303. return nil
  304. else return rString end
  305. end
  306. end
  307. end
  308. end
  309.  
  310. local function colorW(...)
  311. local curColor
  312. for i=1, #arg do -- arg is ...
  313. if type(arg[i]) == 'number' then
  314. curColor = arg[i]
  315. else
  316. if curColor then
  317. term.setTextColor(curColor)
  318. end
  319. write(arg[i])
  320. end
  321. end
  322. end
  323.  
  324. local function drawScreen( opt )
  325. term.clear()
  326. paintutils.drawImage( t_logos[opt], 1, 1 )
  327.  
  328. leftWrite( " ComputerCraft YouTube", 1, colours.white, colours.blue )
  329. rightWrite( "version " .. version, 1, colours.white, colours.blue )
  330. for i, v in pairs( t_Menus["MainScreen"] ) do
  331. sWrite( v.text, v.xPos, v.yPos, colours.black, v.text == selectedMenu and colours.red or colours.lightGrey )
  332. end
  333. end
  334.  
  335. local function credits()
  336. yPos = 1
  337. drawScreen( "home" ) term.setBackgroundColour( colours.white )
  338. while true do
  339. for i = 6, screenY - 1 do
  340. term.setCursorPos( 1, i )
  341. if t_Credits[yPos + i - 6] then
  342. term.clearLine()
  343. centerWrite(t_Credits[yPos + i - 6].text, i, t_Credits[yPos + i - 6].col )
  344. else
  345. break
  346. end
  347. end
  348.  
  349. local event, but, x, y = os.pullEvent()
  350. if event == "mouse_scroll" or event == "key" then
  351. if ( but == -1 or but == keys.up ) and yPos > 1 then
  352. yPos = yPos - 1
  353. elseif ( but == 1 or but == keys.down ) and yPos < #t_Credits - 12 then
  354. yPos = yPos + 1
  355. end
  356. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  357. break
  358. end
  359. end
  360. end
  361.  
  362. local function websiteGallery()
  363. -- Get the list of programs
  364. local function getList()
  365. sWrite( "Retrieving List...", 5, 6, colours.red, colours.white )
  366.  
  367. t_Programs = {}
  368. local response = http.get("http://cc-youtube.hostei.com/print-info.php")
  369. local sourceText = response.readAll()
  370. response.close()
  371.  
  372. index = 1
  373. for id in sourceText:gmatch('<ID>(.-)</ID>') do
  374. t_Programs[index] = {}
  375. t_Programs[index].id = id
  376. index = index + 1
  377. end
  378.  
  379. index = 1
  380. for user in sourceText:gmatch('<USER>(.-)</USER>') do
  381. t_Programs[index].user = user
  382. index = index + 1
  383. end
  384.  
  385. index = 1
  386. for title in sourceText:gmatch('<TITLE>(.-)</TITLE>') do
  387. t_Programs[index].title = title
  388. index = index + 1
  389. end
  390.  
  391. index = 1
  392. for code in sourceText:gmatch('<URL>(.-)</URL>') do
  393. t_Programs[index].code = code
  394. index = index + 1
  395. end
  396.  
  397. index = 1
  398. for desc in sourceText:gmatch('<DESC>(.-)</DESC>') do
  399. t_Programs[index].desc = desc
  400. index = index + 1
  401. end
  402.  
  403. index = 1
  404. for pDate in sourceText:gmatch('<POSTDATE>(.-)</POSTDATE>') do
  405. t_Programs[index].postDate = pDate
  406. index = index + 1
  407. end
  408. end
  409.  
  410. local function download(t)
  411. drawScreen( "home" )
  412. sWrite( "Downloading video ...", 5, 6, colours.red, colours.white )
  413. sWrite( t.title, 5, 7, colours.blue, colours.white )
  414. local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( t.code ))
  415. sWrite( response and "Successfully downloaded video!" or "Failed to download file", 5, 6, response and colours.lime or colours.red, colours.white )
  416. if response then
  417. fHandle = fs.open(sourceFolder .. "/downloads/" .. extStrLib.replace(t.title, " ", "_"), "w")
  418. fHandle.write([[
  419. -- File downloaded by ComputerCraft YouTube
  420. --
  421. -- Title: ]] .. t.title .. [[
  422. -- User: ]] .. t.user .. [[
  423. -- Pastebin URL: www.pastebin.com/]] .. t.code .. [[
  424. -- Timestamp: ]] .. t.postDate .. '\n\n' .. response.readAll() )
  425. fHandle.close()
  426. response.close()
  427. end
  428. centerWrite( "[back]", screenY, colours.black, colours.white )
  429. while true do
  430. local e, butt, x, y = os.pullEvent()
  431. if e == "mouse_click" and butt == 1 then
  432. if x >= math.floor( ( screenX - string.len( "[back]" ) ) / 2 ) and x < math.floor( ( screenX - string.len( "[back]" ) ) / 2 ) + string.len( "[back]" )
  433. and y == screenY then
  434. -- Back
  435. break
  436. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  437. -- Change of selected menu
  438. break
  439. end
  440. end
  441. end
  442. end
  443.  
  444. local function info(t)
  445. term.setBackgroundColour( colours.white )
  446. term.clear()
  447. local isInstalled = fs.exists( sourceFolder .. "/downloads/" .. extStrLib.replace(t.title, " ", "_") )
  448.  
  449. term.setBackgroundColour( colours.blue )
  450. term.setCursorPos(1,1)
  451. term.setTextColour( colours.white )
  452. local tmp = " " .. t.title .. " - " .. t.code
  453. write( tmp .. string.rep(" ", screenX - #tmp) )
  454.  
  455. term.setBackgroundColour( colours.white )
  456. term.setCursorPos( math.floor( ( screenX*0.5 - string.len("[back]") ) / 2 ), screenY ) colorW( colours.black, "[back]" )
  457. term.setCursorPos( math.floor( ( screenX*1.5 - string.len( isInstalled and "[installed]" or "[download]" ) ) / 2 ), screenY ) colorW( colours.black, isInstalled and "[installed]" or "[download]" )
  458. term.setCursorPos(2, 3) colorW(colours.grey, " File Name: ", colours.red, t.title)
  459. term.setCursorPos(2, 4) colorW(colours.grey, " User: ", colours.red, t.user)
  460. term.setCursorPos(2, 5) colorW(colours.grey, "Pastebin Code: ", colours.red, t.code)
  461. term.setCursorPos(2, 6) colorW(colours.grey, " Timestamp: ", colours.blue, t.postDate)
  462. term.setCursorPos(2, 8) colorW(colours.grey, " Description: ")
  463. parallel.waitForAny(
  464. function() box.textBox(colours.red, colours.orange, 1, screenX, 9, screenY - 1, t.desc) end,
  465. function()
  466. while true do
  467. local eve, butt, x, y = os.pullEvent()
  468. if eve == "mouse_click" and butt == 1 then
  469. if x >= math.floor( ( screenX*0.5 - string.len("[back]") ) / 2 ) and x < math.floor( ( screenX*0.5 - string.len("[back]") ) / 2 ) + string.len("[back]")
  470. and y == screenY then
  471. -- Back
  472. break
  473. elseif x >= math.floor( ( screenX*1.5 - string.len("[download]") ) / 2 ) and x < math.floor( ( screenX*1.5 - string.len("[download]") ) / 2 ) + string.len("[download]")
  474. and y == screenY and not isInstalled then
  475. -- Download
  476. download(t)
  477. break
  478. end
  479. end
  480. end
  481. end
  482. )
  483. end
  484.  
  485. local function drawTableArea()
  486. box.fillArea( 5, 50, 6, 6, colours.blue )
  487. -- File name area
  488. -- Heading
  489. sWrite( 'Name', getCenter( 4, 5, 30 ), 6, colours.white, colours.blue )
  490. -- Contents
  491. --box.fillArea( 5, 30, 7, screenY - 2, colours.grey )
  492. -- File code area
  493. -- Heading
  494. sWrite( 'Code', getCenter( 4, 31, 40 ), 6, colours.white, colours.blue )
  495. -- Contents
  496. --box.fillArea( 31, 40, 7, screenY - 2, colours.lightGrey )
  497. -- File timestamp area
  498. -- Heading
  499. sWrite( 'Time', getCenter( 4, 41, 50 ), 6, colours.white, colours.blue )
  500. -- Contents
  501. --box.fillArea( 41, 50, 7, screenY - 2, colours.grey )
  502.  
  503. -- Other
  504. -- Refresh button
  505. centerWrite( "[refresh]", screenY, colours.black, colours.white )
  506. end
  507.  
  508. drawScreen( "home" )
  509. getList()
  510. drawTableArea()
  511. local yPos = 1
  512. local sel = 1
  513. while true do
  514. for i = 7, 17 do
  515. if t_Programs[i + yPos - 7] then
  516. local t = t_Programs[i + yPos - 7].title
  517. local c = t_Programs[i + yPos - 7].code
  518. local p = t_Programs[i + yPos - 7].postDate
  519.  
  520. sWrite( sel == i + yPos - 7 and ">> " or ( fs.exists( sourceFolder .. '/downloads/' .. extStrLib.replace( t, " ", "_" ) ) and " + " or " " ), 2, i, sel == i + yPos - 7 and colours.red or ( fs.exists( sourceFolder .. '/downloads/' .. extStrLib.replace( t, " ", "_" ) ) and colours.lime or colours.black ), colours.white )
  521. sWrite( ' ' .. ( t:len() > 24 and t:sub( 1, 20 ) .. " ... " or t .. string.rep(' ', 25 - t:len() ) ), 5, i, ( i + yPos - 7 ) % 2 == 0 and colours.lightBlue or colours.black, ( i + yPos - 7 ) % 2 == 0 and colours.black or colours.orange )
  522. sWrite( ' ' .. ( c:len() > 9 and c:sub( 1, 4 ) .. " ... " or c .. string.rep(' ', 9 - c:len() ) ), 31, i, ( i + yPos - 7 ) % 2 == 0 and colours.lightBlue or colours.black, ( i + yPos - 7 ) % 2 == 0 and colours.black or colours.orange )
  523. sWrite( ' ' .. p:sub( 1, 6 ) .. '.. ', 41, i, ( i + yPos - 7 ) % 2 == 0 and colours.lightBlue or colours.black, ( i + yPos - 7 ) % 2 == 0 and colours.black or colours.orange )
  524. else
  525. break
  526. end
  527. end
  528. local e, butt, x, y = os.pullEvent()
  529. if e == "mouse_click" and butt == 1 then
  530. if x >= math.floor( ( screenX - string.len("[refresh]") ) / 2 ) and x <= math.floor( ( screenX - string.len("[refresh]") ) / 2 ) + string.len("[refresh]")
  531. and y == screenY then
  532. break
  533. else
  534. local bValid, sOption = isValidClick( t_Menus["MainScreen"], x, y )
  535. if bValid then selectedMenu = sOption return end
  536. end
  537. elseif ( e == "mouse_scroll" ) or ( e == "key" ) then
  538. if butt == 1 or butt == keys.down then -- down
  539. if sel < #t_Programs then
  540. sel = sel + 1
  541. end
  542. if yPos < #t_Programs - 10 and sel >= 12 then
  543. yPos = yPos + 1
  544. end
  545. elseif butt == -1 or butt == keys.up then -- up
  546. if yPos > 1 then
  547. yPos = yPos - 1
  548. end
  549. if sel > 1 then
  550. sel = sel - 1
  551. end
  552. elseif butt == keys.enter then
  553. info({
  554. title = t_Programs[ sel ].title,
  555. code = t_Programs[ sel ].code,
  556. user = t_Programs[ sel ].user,
  557. postDate = t_Programs[ sel ].postDate,
  558. desc = t_Programs[sel].desc
  559. })
  560. sel = 1
  561. yPos = 1
  562. drawScreen( "home" )
  563. drawTableArea()
  564. end
  565. end
  566. end
  567. end
  568.  
  569. local function checkForUpdate()
  570. drawScreen( "home" )
  571. sWrite( "Checking for updates ...", 4, 6, colours.red, colours.white )
  572. sWrite( "Checking for updates ...", 4, 6, colours.red, colours.white )
  573. local response = http.get( "https://raw.github.com/remiX-/ccYouTube/master/ComputerCraft%20YouTube" )
  574. local v = string.sub(response.readLine(), 18, -2)
  575. response.close()
  576.  
  577. if version ~= v then
  578. sWrite( "Update found!", 4, 6, colours.red, colours.white )
  579. local opt = box.confirmBox(colours.grey, colours.lightGrey, colours.red, colours.white, 5, screenX - 5, 6, "Update Now", "Would you like to update?", "Your version: " .. version, "Update version: " .. v)
  580. drawScreen( "home" )
  581. if opt == "YES" then
  582. sWrite( "Updating ...", 4, 6, colours.black, colours.white )
  583. local response = http.get( "https://raw.github.com/remiX-/ccYouTube/master/ComputerCraft%20YouTube" )
  584. local content = response.readAll()
  585. response.close()
  586. local f = fs.open( ccYouTubeLocation, "w")
  587. f.write( content )
  588. f.close()
  589. sWrite( "Done! ", 4, 6, colours.lightGrey, colours.white )
  590. sWrite( "Changes will be applied after", 4, 8, colours.lightGrey, colours.white )
  591. sWrite( "a program restart.", 4, 9, colours.lightGrey, colours.white )
  592. else
  593. sWrite( "Update cancelled.", 4, 6, colours.lightGrey, colours.white )
  594. end
  595. else
  596. sWrite( "Your client is up-to-date.", 4, 6, colours.lightGrey, colours.white )
  597. end
  598.  
  599. while true do
  600. e, butt, x, y = os.pullEvent()
  601. if e == "mouse_click" and butt == 1 then
  602. if isValidClick( t_Menus["MainScreen"], x, y) then break end
  603. end
  604. end
  605. end
  606.  
  607. local function localGallery()
  608. local fileList = fs.list(sourceFolder .. "/downloads/")
  609. local files = {}
  610.  
  611. local function updateList()
  612. fileList = fs.list( sourceFolder .. "/downloads/" )
  613. files = {}
  614. for i = 1, #fileList do
  615. local f = fs.open( sourceFolder .. "/downloads/" .. fileList[i], "r" )
  616. local tmp = {}
  617. for p = 1, 6 do
  618. tmp[p] = f.readLine()
  619. end
  620. f.close()
  621. table.remove( tmp, 1 ) table.remove( tmp, 1 )
  622. table.insert( files, {
  623. title = extStrLib.replace( tmp[1]:sub( 18, -2 ), "_", " " ),
  624. user = tmp[2]:sub( 18, -2 ),
  625. code = extStrLib.replace( tmp[3]:sub( 18, -2 ), "www.pastebin.com/", "" ),
  626. postDate = tmp[4]:sub( 18, -2 ),
  627. } )
  628. end
  629. end
  630.  
  631. local function drawTableArea()
  632. box.fillArea( 5, 50, 6, 6, colours.blue )
  633. -- File name area
  634. -- Heading
  635. sWrite( 'Name', getCenter( 4, 5, 30 ), 6, colours.white, colours.blue )
  636. -- Contents
  637. box.fillArea( 5, 30, 7, screenY - 2, colours.grey )
  638. -- File code area
  639. -- Heading
  640. sWrite( 'User', getCenter( 4, 31, 50 ), 6, colours.white, colours.blue )
  641. -- Contents
  642. box.fillArea( 31, 50, 7, screenY - 2, colours.lightGrey )
  643. end
  644.  
  645. local function info(t)
  646. drawScreen( "home" )
  647.  
  648. term.setBackgroundColour( colours.white )
  649.  
  650. term.setCursorPos(2, 6) colorW( colours.blue, "Viewing video" )
  651. term.setCursorPos(2, 8) colorW(colours.grey, " Title: ", colours.red, t.title)
  652. term.setCursorPos(2, 9) colorW(colours.grey, " Uploader: ", colours.red, t.user)
  653. term.setCursorPos(2, 10) colorW(colours.grey, "Pastebin Code: ", colours.red, t.code)
  654. term.setCursorPos(2, 11) colorW(colours.grey, " Timestamp: ", colours.blue, t.postDate)
  655.  
  656. term.setCursorPos( math.floor( ( screenX*0.5 - string.len("[play]") ) / 2 ), screenY ) colorW( colours.black, "[play]" )
  657. term.setCursorPos( math.floor( ( screenX - string.len("[back]") ) / 2 ), screenY ) colorW( colours.black, "[back]" )
  658. term.setCursorPos( math.floor( ( screenX*1.5 - string.len("[delete]") ) / 2 ), screenY ) colorW( colours.black, "[delete]" )
  659.  
  660. while true do
  661. local e, but, x, y = os.pullEvent()
  662. if e == "mouse_click" and but == 1 then
  663. if x >= math.floor( ( screenX*0.5 - string.len("[play]") ) / 2 ) and x < math.floor( ( screenX*0.5 - string.len("[play]") ) / 2 ) + string.len("[play]") and y == screenY then
  664. drawScreen( "home" )
  665. term.setCursorPos(4, 8)
  666. colorW(colours.red, "Press ", colours.black, "F1", colours.red, " to stop the playback.")
  667. for i = 3, 1, -1 do
  668. term.setCursorPos(4, 6)
  669. colorW(colours.black, "Starting video in ", 2^math.random(1,15), tostring(i), colours.black, "...")
  670. pcall(sleep, 1)
  671. end
  672. parallel.waitForAny( function() shell.run(sourceFolder .. "/downloads/" .. extStrLib.replace( t.title, " ", "_" ) ) end, function() repeat _, k = os.pullEvent("key") until k == 59 end)
  673. term.setCursorBlink(false)
  674. return info( t )
  675. elseif x >= math.floor( ( screenX - string.len("[back]") ) / 2 ) and x < math.floor( ( screenX - string.len("[back]") ) / 2 ) + string.len("[back]") and y == screenY then
  676. break
  677. elseif x >= math.floor( ( screenX*1.5 - string.len("[delete]") ) / 2 ) and x < math.floor( ( screenX*1.5 - string.len("[delete]") ) / 2 ) + string.len("[delete]") and y == screenY then
  678. opt = box.confirmBox(colours.grey, colours.lightGrey, colours.red, colours.white, 5, screenX - 5, 6, "Confirm", "Are you sure you want to", "delete the file?", t.title )
  679. if opt == "YES" then
  680. if fs.exists(sourceFolder .. "/recycleBin/" .. extStrLib.replace( t.title, " ", "_" ) ) then
  681. fs.delete(sourceFolder .. "/recycleBin/" .. extStrLib.replace( t.title, " ", "_" ) )
  682. end
  683. fs.move(sourceFolder .. "/downloads/" .. extStrLib.replace( t.title, " ", "_" ), sourceFolder .. "/recycleBin/" .. extStrLib.replace( t.title, " ", "_" ) )
  684. updateList()
  685. break
  686. end
  687. return info( t )
  688. else
  689. local bValid, sOption = isValidClick( t_Menus["MainScreen"], x, y )
  690. if bValid then
  691. selectedMenu = sOption
  692. return false
  693. end
  694. end
  695. end
  696. end
  697. end
  698.  
  699. drawScreen( "home" )
  700. drawTableArea()
  701. updateList()
  702.  
  703. local yPos = 1
  704. local sel = 1
  705. while true do
  706. for i = 7, 17 do
  707. if files[i + yPos - 7] then
  708. local t = files[i + yPos - 7].title
  709. local u = files[i + yPos - 7].user
  710. local p = files[i + yPos - 7].postDate
  711. term.setCursorPos(2, i)
  712. term.setBackgroundColour( colours.white )
  713. colorW( colours.red, sel == i + yPos - 7 and ">> " or " " )
  714. term.setCursorPos(6, i)
  715. term.setBackgroundColour( colours.grey )
  716. colorW( ( i + yPos - 7 ) % 2 == 0 and colours.lightBlue or colours.blue, t:len() > 24 and t:sub( 1, 19 ) .. " ..." or t .. string.rep(' ', 24 - t:len() ) )
  717. term.setCursorPos(32, i)
  718. term.setBackgroundColour( colours.lightGrey )
  719. colorW( ( i + yPos - 7 ) % 2 == 0 and colours.lightBlue or colours.blue, u:len() > 19 and u:sub( 1, 14 ) .. " ..." or u .. string.rep(' ', 19 - u:len() ) )
  720. else
  721. break
  722. end
  723. end
  724. if #files == 0 then term.setCursorPos( 8, 8 ) term.setBackgroundColour( colours.grey ) colorW( colours.red, "No local videos :(" ) end
  725. local e, butt, x, y = os.pullEvent()
  726. if e == "mouse_click" and butt == 1 then
  727. bValid, sOption = isValidClick( t_Menus["MainScreen"], x, y )
  728. if bValid then selectedMenu = sOption return end
  729. elseif ( e == "mouse_scroll" ) or ( e == "key" ) then
  730. if butt == 1 or butt == keys.down then -- down
  731. if sel < #files then
  732. sel = sel + 1
  733. end
  734. if yPos < #files - 10 and sel >= 12 then
  735. yPos = yPos + 1
  736. end
  737. elseif butt == -1 or butt == keys.up then -- up
  738. if yPos > 1 then
  739. yPos = yPos - 1
  740. end
  741. if sel > 1 then
  742. sel = sel - 1
  743. end
  744. elseif butt == keys.enter then
  745. if not info( files[ sel ] ) then break end
  746. drawScreen( "home" )
  747. drawTableArea()
  748. end
  749. end
  750. end
  751. end
  752.  
  753. local function postVideo( tmp )
  754. local info = tmp or { ["title"] = "", ["name"] = logged and userInfo.username or "", ["code"] = "", ["desc"] = {""} }
  755.  
  756. drawScreen( "home" )
  757.  
  758. term.setBackgroundColour(colours.white)
  759. term.setCursorPos( 3, 6 )
  760. colorW(colours.blue, "Upload your video!")
  761. term.setCursorPos( 3, 14 )
  762. colorW(colours.red, "* ", colours.black, "'code' box needs only pastebin code")
  763.  
  764. box.fillArea( 3, screenX - 2, 7, 13, colours.lightGrey )
  765. box.fillArea( 12, screenX - 4, 8, 8, colours.grey )
  766. box.fillArea( 12, screenX - 4, 10, 10, colours.grey )
  767. box.fillArea( 12, screenX - 4, 12, 12, colours.grey )
  768.  
  769. -- "Video Title"
  770. sWrite( "Title:", 5, 8, colours.red, colours.lightGrey )
  771. sWrite( info.title:sub( info.title:len() > 33 and info.title:len() - 33 or 1 ), 13, 8, colours.orange, colours.grey )
  772.  
  773. -- "Name"
  774. sWrite( "Name:", 6, 10, colours.red, colours.lightGrey )
  775. sWrite( info.name:sub( info.name:len() > 33 and info.name:len() - 33 or 1 ), 13, 10, colours.orange, colours.grey )
  776.  
  777. -- "Code"
  778. sWrite( "Code:", 6, 12, colours.red, colours.lightGrey )
  779. sWrite( info.code:sub( info.code:len() > 33 and info.code:len() - 33 or 1 ), 13, 12, colours.orange, colours.grey )
  780. term.setTextColour( colours.orange )
  781. term.setBackgroundColour( colours.grey )
  782. -- Get title
  783. term.setCursorPos(13, 8)
  784. local title = limitRead( 33, nil, info.title, true, 13, colours.orange )
  785. info["title"] = title
  786. if not info["title"] then return end
  787.  
  788. -- Get Name
  789. if not logged then
  790. term.setCursorPos(13, 10)
  791. local name = limitRead( 33, nil, info.name, true, 13, colours.orange )
  792. info["name"] = name
  793. if not info["name"] then return end
  794. end
  795.  
  796. -- Get code
  797. term.setCursorPos(13, 12)
  798. local code = limitRead( 33, nil, info.code, true, 13, colours.orange )
  799. info["code"] = code
  800. if not info["code"] then return end
  801.  
  802. drawScreen( "home" )
  803. sWrite( "Description", 2, 7, colours.black, colours.white )
  804. centerWrite( "[upload]", screenY, colours.black, colours.white )
  805. local restart = false
  806. parallel.waitForAny(
  807. function()
  808. box.textField( colours.blue, colours.white, 1, screenX, 8, screenY - 2, info.desc )
  809. end,
  810. function()
  811. while true do
  812. local ev, but, x, y = os.pullEvent("mouse_click")
  813. if x >= math.floor( ( screenX - string.len("[upload]") ) / 2 ) and x <= math.floor( ( screenX - string.len("[upload]") ) / 2 ) + 8
  814. and y == screenY and but == 1 then
  815. -- "Apply"
  816. info.desc = box.getTable()
  817. if info.desc[1]:len() > 0 then
  818. term.setCursorBlink(false)
  819. local description = ""
  820. for i = 1, #info.desc do
  821. description = description .. info.desc[i] .. (i ~= #info.desc and "\n" or "")
  822. end
  823.  
  824. local params = string.format("username=%s&video_title=%s&pastebin_code=%s&description=%s&submit_post=send", info.name, info.title, info.code, description)
  825. local res = http.post( serverURL .. "/upload.php/", params)
  826. local isValidCode
  827. if res then
  828. local content = res.readAll()
  829. res.close()
  830. infoMessage = content:match( '<INFO>(.-)</INFO>' )
  831. isValidCode = infoMessage == "Your video has been added!"
  832. box.dialogBox(colours.lightGrey, colours.grey, colours[isValidCode and "lime" or "red"], colours.white, 5, screenX - 5, 6, isValidCode and "Success!" or "Error", isValidCode and "Your video has been uploaded" or "An error has occured:", isValidCode and "" or infoMessage )
  833. else
  834. box.dialogBox(colours.lightGrey, colours.grey, colours.red, colours.white, 10, screenX - 10, 6, "Error", "An error has occured:", "Server is not responding.", "Please try again later.")
  835. end
  836. restart = not isValidCode
  837. break
  838. end
  839. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  840. -- Change menu
  841. break
  842. end
  843. end
  844. end
  845. )
  846. if restart then return postVideo( info ) end
  847. end
  848.  
  849. local function home()
  850. local barOut = false
  851. local text = {
  852. 'ComputerCraft YouTube Homepage',
  853. '',
  854. ' version ' .. version .. ' is now out with',
  855. 'a newly implemented menu tab',
  856. 'for registering and logging in',
  857. 'into your own personal account.',
  858. ' Test it out and send remiX some',
  859. 'feedback for fast new releases!'
  860. }
  861.  
  862. local function transEffect( s )
  863. if s == "out" then
  864. term.setBackgroundColour( colours.orange )
  865. for x = 1, 35 do
  866. for y = screenY - 10, screenY - 1 do
  867. term.setCursorPos( x, y )
  868. write( ' ' )
  869. end
  870. if x > 2 then
  871. for i = 1, #text do
  872. leftWrite( ' ' .. text[i]:sub( math.abs( x - 36 ) ), i + 9, i == 1 and colours.blue or colours.black, colours.orange )
  873. end
  874. end
  875. sleep( 0.05 )
  876. end
  877. elseif s == "in" then
  878. for x = 36, 2, -1 do
  879. for i = 1, #text do
  880. if text[i] ~= "" then sWrite( text[i]:sub( 37 - x ) .. string.rep( ' ', 33 - #text[i] ), 2, i + 9, i == 1 and colours.blue or colours.black, colours.orange ) end
  881. end
  882. for y = screenY - 10, screenY - 1 do
  883. sWrite( ' ', x, y, colours.red, colours.white )
  884. end
  885. sleep( 0.05 )
  886. end
  887. paintutils.drawImage( t_logos["logo"] , 5, 8 )
  888. end
  889.  
  890. for y = screenY - 10, screenY - 1 do
  891. sWrite( y == math.floor( ( ( screenY - 10 ) + ( screenY - 1 ) ) / 2 ) and (s == "out" and '<' or '>') or ' ', s == "out" and 36 or 1, y, colours.white, colours.blue )
  892. end
  893. end
  894.  
  895. drawScreen( "home" )
  896. paintutils.drawImage( t_logos["logo"] , 5, 8 )
  897.  
  898. for y = screenY - 10, screenY - 1 do
  899. leftWrite( y == math.floor( ( ( screenY - 10 ) + ( screenY - 1 ) ) / 2 ) and '>' or ' ', y, colours.white, colours.blue )
  900. end
  901.  
  902. while true do
  903. local _, but, x, y = os.pullEvent("mouse_click")
  904. if isValidClick( t_Menus["MainScreen"], x, y) then break
  905. elseif but == 1 and y >= screenY - 7 and y <= screenY - 1 then
  906. if x == 1 and not barOut then
  907. transEffect( 'out' )
  908. barOut = true
  909. elseif x == 36 and barOut then
  910. transEffect( 'in' )
  911. barOut = false
  912. end
  913. end
  914. end
  915. end
  916.  
  917. local function help()
  918. local function checkClick( x, y )
  919. for i, v in pairs( helpText ) do
  920. if x >= screenX - 14 and x < screenX - 1 + #v.head and y == i + 9 then
  921. return true, v.text
  922. end
  923. end
  924. return false, nil
  925. end
  926. drawScreen( "home" )
  927. box.fillArea( screenX - 14, screenX - 1, 9, 10 + #helpText, colours.blue )
  928. term.setTextColour( colours.white )
  929.  
  930. for i, v in pairs( helpText ) do
  931. rightWrite( v.head .. ' ', i + 9, colours.white, colours.blue )
  932. end
  933. box.fillArea( screenX, screenX, 9, 10 + #helpText, colours.white )
  934.  
  935. centerWrite( "ComputerCraft YouTube help section", 6, colours.black, colours.white )
  936.  
  937. term.setCursorPos( 1, 9 )
  938. write([[
  939. This section will provide
  940. you with the help you need
  941. to use ComputerCraft
  942. YouTube in the best way.
  943.  
  944. Click on a sub-heading on
  945. the right and text will be
  946. displayed here.]])
  947.  
  948. while true do
  949. local e, but, x, y = os.pullEvent()
  950. if e == "mouse_click" and but == 1 then
  951. local bValid, tText = checkClick( x, y )
  952. if bValid then
  953. box.fillArea( 1, screenX - 15, 8, screenY, colours.white )
  954. for i, v in pairs( tText ) do
  955. term.setCursorPos( i == 1 and math.floor( (screenX*0.5+5 - #v ) /2 ) or 1, i + 7 )
  956. term.setTextColour( i == 1 and colours.cyan or colours.grey )
  957. write( v )
  958. end
  959. else
  960. local bValid, sOption = isValidClick( t_Menus["MainScreen"], x, y )
  961. if bValid then
  962. selectedMenu = sOption
  963. break
  964. end
  965. end
  966. end
  967. end
  968. end
  969.  
  970. local function account()
  971. local screen = logged and "Prefrences" or "Login"
  972. local tmpInfo = { ['name'] = "", ['email'] = "", ['username'] = "" }
  973. local run = true
  974.  
  975. local function updateMenu() menus = { { text = logged and "Prefrences" or "Login", x = 4 }, { text = logged and "Messages" or "", x = logged and 16 or 11 }, { text = logged and "Logout" or "Register", x = logged and 26 or 11 } } end
  976.  
  977. local function validateCredentials( _type, _user, _pass )
  978. local res = http.post( serverURL .. "/verify.php",
  979. "type=" .. textutils.urlEncode( _type ) .. "&" ..
  980. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  981. "password=" .. textutils.urlEncode( _pass ) .. "&" ..
  982. "new=" .. textutils.urlEncode( 'banana' ) )
  983. if res then
  984. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  985. res.close()
  986. if a:find("true!") then
  987. return true, textutils.unserialize( a:gsub("true!", "") )
  988. else
  989. return false, a
  990. end
  991. else
  992. return false, "Failed to Connect to server"
  993. end
  994. end
  995.  
  996. local function registerCredentials( _name, _email, _user, _pass )
  997. local res = http.post( serverURL .. "/register.php",
  998. "name=" .. textutils.urlEncode( _name ) .. "&" ..
  999. "email=" .. textutils.urlEncode( _email ) .. "&" ..
  1000. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  1001. "password=" .. textutils.urlEncode( _pass ) .. "&" ..
  1002. "new=" .. textutils.urlEncode( 'banana' ) )
  1003.  
  1004. if res then
  1005. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  1006. res.close()
  1007. if a:find( "Registered " ) then
  1008. return true, a:gsub("Registered ", '')
  1009. else
  1010. return false, textutils.unserialize( a )
  1011. end
  1012. else
  1013. return false, "Failed to Connect to server"
  1014. end
  1015. end
  1016.  
  1017. local function deleteAccount( _user, _pass )
  1018. local res = http.post( serverURL .. "/deleteaccount.php",
  1019. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  1020. "password=" .. textutils.urlEncode( _pass ) )
  1021.  
  1022. if res then
  1023. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  1024. res.close()
  1025. return a == "Your account has been deleted.", a
  1026. else
  1027. return false, "Failed to Connect to server"
  1028. end
  1029. end
  1030.  
  1031. local function deleteMsg( _user, _pass, msg )
  1032. local res = http.post( serverURL .. "/deletemsg.php",
  1033. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  1034. "password=" .. textutils.urlEncode( _pass ) .. "&" ..
  1035. "id=" .. textutils.urlEncode( msg.msgid ) )
  1036.  
  1037. if res then
  1038. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  1039. res.close()
  1040. return a == "Message has been deleted.", a
  1041. else
  1042. return false, "Failed to Connect to server"
  1043. end
  1044. end
  1045.  
  1046. local function retrieveInbox( _user, _pass )
  1047. local res = http.post(serverURL .. "/get.php",
  1048. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  1049. "password=" .. textutils.urlEncode( _pass ) )
  1050. if res then
  1051. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  1052. res.close()
  1053. if a:find("true!") then
  1054. return textutils.unserialize(a:gsub("true!", ""))
  1055. else
  1056. return a
  1057. end
  1058. else
  1059. return {}
  1060. end
  1061. end
  1062.  
  1063. local function sendMessage( _user, _pass, msg )
  1064. local res = http.post(serverURL .. "/send.php",
  1065. "username=" .. textutils.urlEncode( _user ) .. "&" ..
  1066. "password=" .. textutils.urlEncode( _pass ) .. "&" ..
  1067. "to=" .. textutils.urlEncode( msg.to ) .. "&" ..
  1068. "subject=" .. textutils.urlEncode( msg.subject ) .. "&" ..
  1069. "message=" .. textutils.urlEncode( textutils.serialize( msg.content ) ) )
  1070. if res then
  1071. local a = res.readAll():gsub( '\n', '' ):gsub( '<%!%-%- Hosting24 Analytics Code %-%-><script type="text/javascript" src="http://stats.hosting24.com/count.php"></script><%!%-%- End Of Analytics Code %-%->', '' )
  1072. res.close()
  1073. return a == "Your message has been sent.", a
  1074. else
  1075. return false, "Failed to Connect to server"
  1076. end
  1077. return "true"
  1078. end
  1079.  
  1080. local function waitForScreenChange( )
  1081. while true do
  1082. local _, but, x, y = os.pullEvent( "mouse_click" )
  1083. if but == 1 then
  1084. for i, v in pairs( menus ) do
  1085. if x >= v.x and x < v.x + #v.text + 2 and y == 6 and screen ~= v.text and screen ~= "" then
  1086. screen = v.text
  1087. return
  1088. end
  1089. end
  1090. end
  1091. end
  1092. end
  1093.  
  1094. local function drawMain( sel, opt, drawMainText )
  1095. drawScreen( "home" )
  1096. box.fillArea( 4, screenX - 3, 6, 6, colours.blue )
  1097. box.fillArea( 4, screenX - 3, 7, 18, colours.lightGrey )
  1098.  
  1099. if drawMainText then
  1100. if sel == "Login" then
  1101. box.fillArea( 21, screenX - 10, 10, 10, colours.grey )
  1102. box.fillArea( 21, screenX - 10, 13, 13, colours.grey )
  1103. sWrite( "*Username can be your username or email", 8, 8, colours.black, colours.lightGrey )
  1104. sWrite( "Username:", 11, 10, colours.black, colours.lightGrey )
  1105. sWrite( "Password:", 11, 13, colours.black, colours.lightGrey )
  1106. sWrite( " Login ", ( screenX - string.len( " login " ) ) /2, 16, colours.white, colours.black )
  1107. elseif sel == "Logout" then
  1108. sWrite( "You have been successfully logged out.", 8, 8, colours.lightBlue, colours.lightGrey )
  1109. logged = false
  1110. userInfo.name = ""
  1111. userInfo.username = ""
  1112. userInfo.email = ""
  1113. userInfo.password = ""
  1114. updateMenu()
  1115. elseif sel == "Register" then
  1116. box.fillArea( 21, screenX - 10, 9, 9, colours.grey )
  1117. box.fillArea( 21, screenX - 10, 11, 11, colours.grey )
  1118. box.fillArea( 21, screenX - 10, 13, 13, colours.grey )
  1119. box.fillArea( 21, screenX - 10, 15, 15, colours.grey )
  1120. sWrite( "*Required", 8, 8, colours.red, colours.lightGrey )
  1121. sWrite( " Name:", 11, 9, colours.black, colours.lightGrey ) sWrite( tmpInfo['name']:sub( #tmpInfo['name'] >= ( screenX - 33 ) and #tmpInfo['name'] - ( screenX - 33 ) or 1 ), 22, 9, colours.white, colours.grey )
  1122. sWrite( " Email:", 11, 11, colours.black, colours.lightGrey ) sWrite( tmpInfo['email']:sub( #tmpInfo['email'] >= ( screenX - 33 ) and #tmpInfo['email'] - ( screenX - 33 ) or 1 ), 22, 11, colours.white, colours.grey )
  1123. sWrite( "*", 10, 13, colours.red, colours.lightGrey ) sWrite( "Username:", 11, 13, colours.black, colours.lightGrey ) sWrite( tmpInfo['username']:sub( #tmpInfo['username'] >= ( screenX - 33 ) and #tmpInfo['username'] - ( screenX - 33 ) or 1 ), 22, 13, colours.white, colours.grey )
  1124. sWrite( "*", 10, 15, colours.red, colours.lightGrey ) sWrite( "Password:", 11, 15, colours.black, colours.lightGrey )
  1125. sWrite( " Register ", ( screenX - string.len( " Register " ) ) /2, 17, colours.white, colours.black )
  1126. elseif sel == "Prefrences" then
  1127. -- Account details
  1128. sWrite( userInfo.username .. " -> Account details", 10, 8, colours.white, colours.lightGrey )
  1129. sWrite( " Name:", 9, 10, colours.grey, colours.lightGrey )
  1130. sWrite( userInfo.name, 19, 10, colours.blue, colours.lightGrey )
  1131. sWrite( " Email:", 9, 11, colours.grey, colours.lightGrey )
  1132. sWrite( userInfo.email, 19, 11, colours.blue, colours.lightGrey )
  1133. sWrite( "Username:", 9, 12, colours.grey, colours.lightGrey )
  1134. sWrite( userInfo.username, 19, 12, colours.blue, colours.lightGrey )
  1135. -- Other
  1136. sWrite( "[Del]", 43, 8, colours.red, colours.lightGrey )
  1137. elseif sel == "Messages" then
  1138. sWrite( userInfo.username .. ' -> Messages', 10, 8, colours.red, colours.lightGrey )
  1139. sWrite( "[ Inbox ]", 7, 10, colours.blue, colours.lightGrey )
  1140. sWrite( "[ Compose a message ]", 7, 11, colours.blue, colours.lightGrey )
  1141. end
  1142. end
  1143.  
  1144. if opt == "compose" then
  1145. sWrite( userInfo.username .. " -> Compose a message", 10, 8, colours.red, colours.lightGrey )
  1146. sWrite( "Subject:", 7, 10, colours.white, colours.lightGrey )
  1147. sWrite( " From:", 7, 11, colours.white, colours.lightGrey )
  1148. sWrite( " To:", 7, 12, colours.white, colours.lightGrey )
  1149. sWrite( '[cancel]', getCenter( 8, 4, screenX - 3 ), screenY - 2, colours.black, colours.lightGrey )
  1150. elseif opt == 'inbox' then
  1151. sWrite( userInfo.username .. " -> Retrieving Inbox ... ", 10, 8, colours.red, colours.lightGrey )
  1152. elseif opt == 'showmsg' then
  1153. sWrite( 'Subject:', 7, 7, colours.white, colours.lightGrey )
  1154. sWrite( ' From:', 7, 8, colours.white, colours.lightGrey )
  1155. sWrite( '[reply]', math.floor( ( screenX*0.55 - string.len("[reply]") ) / 2 ), screenY - 1, colours.black, colours.lightGrey )
  1156. sWrite( '[delete]', math.floor( getCenter( 8, 4, screenX - 3 ) ), screenY - 1, colours.black, colours.lightGrey )
  1157. sWrite( '[back]', math.floor( ( screenX*1.65 - string.len("[back]") ) / 2 ), screenY - 1, colours.black, colours.lightGrey )
  1158. end
  1159.  
  1160. for i, v in pairs( menus ) do
  1161. sWrite( ' ' .. v.text .. ' ', v.x, 6, sel == v.text and colours.black or colours.white, sel == v.text and colours.lightGrey or colours.blue )
  1162. end
  1163. end
  1164.  
  1165. local function compose( msg )
  1166. drawMain( screen, 'compose', false )
  1167. local msg = msg or {subject = "", to = "", from = userInfo.username, content = {""}}
  1168. sWrite( msg.subject, 16, 10, colours.blue, colours.lightGrey )
  1169. sWrite( msg.from, 16, 11, colours.blue, colours.lightGrey )
  1170. sWrite( msg.to, 16, 12, colours.blue, colours.lightGrey )
  1171.  
  1172. term.setCursorPos( 16, 10 )
  1173. local msgSubject = limitRead( 30, nil, msg.subject, false, 16, nil, true, getCenter( 8, 4, screenX - 3 ), getCenter( 8, 4, screenX - 3 ) + 8, screenY - 2, 'kill' )
  1174. if not msgSubject then return end
  1175. msg.subject = msgSubject
  1176.  
  1177. term.setCursorPos( 16, 12 )
  1178. local toUser = limitRead( 30, nil, msg.to, false, 16, nil, true, getCenter( 8, 4, screenX - 3 ), getCenter( 8, 4, screenX - 3 ) + 8, screenY - 2, 'kill' )
  1179. if not toUser then return end
  1180. msg.to = toUser
  1181.  
  1182. sWrite( userInfo.username .. " -> Content", 10, 8, colours.red, colours.lightGrey )
  1183. sWrite( '[send]', math.floor( ( screenX*0.5 - string.len("[send]") ) / 2 ), screenY - 1, colours.black, colours.lightGrey )
  1184. sWrite( '[cancel]', math.floor( ( screenX*1.5 - string.len("[cancel]") ) / 2 ), screenY - 1, colours.black, colours.lightGrey )
  1185.  
  1186. local ok = true
  1187. parallel.waitForAny(
  1188. function() box.textField( colours.grey, colours.lightBlue, 4, screenX - 3, 10, screenY - 2, msg.content ) end,
  1189. function()
  1190. while true do
  1191. local e, but, x, y = os.pullEvent()
  1192. if e == "mouse_click" and but == 1 then
  1193. if x >= math.floor( ( screenX*0.5 - string.len("[send]") ) / 2 ) and x < math.floor( ( screenX*0.5 - string.len("[send]") ) / 2 ) + string.len('[send]') and y == screenY - 1 then
  1194. -- send
  1195. term.setCursorBlink( false )
  1196. msg.content = box.getTable()
  1197. local success, info = sendMessage( userInfo.username, userInfo.password, msg )
  1198. box.dialogBox(colours.orange, colours.blue, success and colours.lime or colours.red, colours.white, 5, screenX - 4, 7, success and "Success" or "Error", info )
  1199. ok = success
  1200. break
  1201. elseif x >= math.floor( ( screenX*1.5 - string.len("[cancel]") ) / 2 ) and x < math.floor( ( screenX*1.5 - string.len("[cancel]") ) / 2 ) + string.len('[cancel]') and y == screenY - 1 then
  1202. -- cancel
  1203. break
  1204. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  1205. -- Change menu
  1206. break
  1207. end
  1208. end
  1209. end
  1210. end
  1211. )
  1212. if not ok then return compose( msg ) end
  1213. term.setCursorBlink( false )
  1214. end
  1215.  
  1216. local function showMsg( msg )
  1217. drawMain( screen, 'showmsg', false )
  1218.  
  1219. sWrite( msg.subject, 16, 7, colours.white, colours.lightGrey )
  1220. sWrite( msg.from, 16, 8, colours.white, colours.lightGrey )
  1221.  
  1222. parallel.waitForAny(
  1223. function() box.textBox(colours.grey, colours.lightBlue, 4, screenX - 3, 9, screenY - 2, msg.content) end,
  1224. function()
  1225. while true do
  1226. local e, but, x, y = os.pullEvent()
  1227. if e == "mouse_click" and but == 1 then
  1228. if x >= math.floor( ( screenX*0.55 - string.len("[reply]") ) / 2 ) and x < math.floor( ( screenX*0.55 - string.len("[reply]") ) / 2 ) + string.len('[reply]') and y == screenY - 1 then
  1229. -- reply
  1230. box.fillArea( 4, screenX - 3, 7, 18, colours.lightGrey )
  1231. compose( { subject = "RE: " .. msg.subject, from = userInfo.username, content = {""}, to = msg.from } )
  1232. break
  1233. elseif x >= math.floor( getCenter( 8, 4, screenX - 3 ) ) and x < math.floor( getCenter( 8, 4, screenX - 3 ) ) + string.len('[delete]') and y == screenY - 1 then
  1234. -- delete
  1235. local success, info = deleteMsg( userInfo.username, userInfo.password, msg )
  1236. break
  1237. elseif x >= math.floor( ( screenX*1.65 - string.len("[back]") ) / 2 ) and x < math.floor( ( screenX*1.65 - string.len("[back]") ) / 2 ) + string.len('[back]') and y == screenY - 1 then
  1238. -- back
  1239. break
  1240. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  1241. -- Change menu
  1242. run = false
  1243. break
  1244. end
  1245. end
  1246. end
  1247. end
  1248. )
  1249. end
  1250.  
  1251. local function displayInbox()
  1252. drawMain( screen, 'inbox', false )
  1253. inbox = retrieveInbox( userInfo.username, userInfo.password )
  1254. sWrite( userInfo.username .. ' -> Inbox ', 10, 8, colours.red, colours.lightGrey )
  1255. sWrite( '[back]', getCenter( 6, 4, screenX - 3 ), screenY - 2, colours.black, colours.lightGrey )
  1256. local yPos = 1
  1257. while true do
  1258. for i = 9, 17 do
  1259. if inbox[i + yPos - 9] then
  1260. term.setCursorPos( 6, i ) term.setBackgroundColour( colours.lightGrey )
  1261. colorW( colours.black, '[ ', colours.cyan, tostring( i + yPos - 9 ), colours.black, ": ", colours.yellow, inbox[i + yPos - 9].from, colours.black, ' : ', colours.purple, inbox[i + yPos - 9].subject,
  1262. string.rep( ' ', 40 - ( 7 + tostring( i + yPos - 9 ):len() + inbox[i + yPos - 9].from:len() + inbox[i + yPos - 9].subject:len() ) ), colours.black, ']' )
  1263. else
  1264. break
  1265. end
  1266. end
  1267. if type( inbox ) and #inbox == 0 then sWrite( 'Your inbox is empty.', 13, 10, colours.blue, colours.lightGrey )
  1268. elseif inbox == 'Incorrect username/password!' then
  1269. sWrite( 'Invalid user credentials.', 13, 10, colours.blue, colours.lightGrey )
  1270. sWrite( 'Please relog.', 13, 11, colours.blue, colours.lightGrey )
  1271. end
  1272. local e, butt, x, y = os.pullEvent()
  1273. if e == "mouse_click" and butt == 1 then
  1274. if isValidClick( t_Menus["MainScreen"], x, y ) then
  1275. run = false
  1276. break
  1277. elseif x >= 6 and x <= 46 and y >= 9 and y <= 17 and inbox[yPos + y - 9] then
  1278. showMsg( inbox[yPos + y - 9] )
  1279. box.fillArea( 4, screenX - 3, 7, 18, colours.lightGrey )
  1280. return displayInbox()
  1281. elseif x >= getCenter( 6, 4, screenX - 3 ) and x < getCenter( 6, 4, screenX - 3 ) + string.len('[back]') and y == 17 then
  1282. break
  1283. end
  1284. elseif ( e == "mouse_scroll" ) or ( e == "key" ) then
  1285. if ( butt == 1 or butt == keys.down ) and yPos < #inbox - 8 then -- down
  1286. yPos = yPos + 1
  1287. elseif ( butt == -1 or butt == keys.up ) and yPos > 1 then -- up
  1288. yPos = yPos - 1
  1289. end
  1290. end
  1291. end
  1292. end
  1293.  
  1294. local tFuncs = {
  1295. ["Login"] = function()
  1296. while true do
  1297. -- Get user's login username and password credentials
  1298. term.setBackgroundColour( colours.grey )
  1299. term.setCursorPos( 22, 10 ) local user = limitRead( screenX - 33, nil, nil, false, 22, nil, true, ( screenX - string.len( " login " ) ) /2, ( screenX - string.len( " login " ) ) /2 + string.len( " login " ), 16 )
  1300. if not user then run = false return end
  1301. local loginType = user:find( '@' ) and 'email' or 'user'
  1302.  
  1303. term.setCursorPos( 22, 13 ) local password = limitRead( screenX - 32, "*", nil, false, 22, nil, true, ( screenX - string.len( " login " ) ) /2, ( screenX - string.len( " login " ) ) /2 + string.len( " login " ), 16 )
  1304. if not password then run = false return end
  1305.  
  1306. local success, info = validateCredentials( loginType, user, password )
  1307. if success then
  1308. logged = true
  1309. userInfo = info
  1310. updateMenu()
  1311. screen = "Prefrences"
  1312. break
  1313. else
  1314. centerWrite( info == 'out-dated' and 'Your client is out-dated' or 'Invalid login', 15, colours.red, colours.lightGrey )
  1315. term.setTextColour( colours.white )
  1316. term.setBackgroundColour( colours.grey )
  1317. sWrite( string.rep( ' ', 20 ), 22, 10 )
  1318. sWrite( string.rep( ' ', 20 ), 22, 13 )
  1319. end
  1320. end
  1321. end,
  1322. ["Logout"] = function()
  1323. while true do
  1324. local e, but, x, y = os.pullEvent()
  1325. if isValidClick( t_Menus["MainScreen"], x, y ) then
  1326. run = false
  1327. break
  1328. end
  1329. end
  1330. end,
  1331. ["Register"] = function()
  1332. local tmpInfo = { success = false, err = { text = '', x = 1, y = 1 }, name = '', email = '', username = '', password = '' }
  1333. while true do
  1334. -- Get user's credentials for registration
  1335. term.setTextColour( colours.white )
  1336. term.setBackgroundColour( colours.grey )
  1337.  
  1338. sWrite( tmpInfo.name, 22, 9, nil, colours.grey )
  1339. sWrite( tmpInfo.email, 22, 11, nil, colours.grey )
  1340. sWrite( tmpInfo.username, 22, 13, nil, colours.grey )
  1341.  
  1342. term.setCursorPos( 22, 9 )
  1343. local name = limitRead( screenX - 33, nil, tmpInfo['name'], false, 22, nil, true, ( screenX - string.len( " Register " ) ) /2, ( screenX - string.len( " Register " ) ) /2 + string.len( " Register " ), 17 )
  1344. if not name then run = false return end
  1345. tmpInfo.name = name
  1346.  
  1347. term.setCursorPos( 22, 11 )
  1348. local email = limitRead( screenX - 33, nil, tmpInfo['email'], false, 22, nil, true, ( screenX - string.len( " Register " ) ) /2, ( screenX - string.len( " Register " ) ) /2 + string.len( " Register " ), 17 )
  1349. if not email then run = false return end
  1350. tmpInfo.email = email
  1351.  
  1352. term.setCursorPos( 22, 13 )
  1353. local username = limitRead( screenX - 33, nil, tmpInfo['username'], false, 22, nil, true, ( screenX - string.len( " Register " ) ) /2, ( screenX - string.len( " Register " ) ) /2 + string.len( " Register " ), 17 )
  1354. if not username then run = false return end
  1355. tmpInfo.username = username
  1356.  
  1357. term.setCursorPos( 22, 15 )
  1358. local password = limitRead( screenX - 33, "*", nil, false, 22, nil, true, ( screenX - string.len( " Register " ) ) /2, ( screenX - string.len( " Register " ) ) /2 + string.len( " Register " ), 17 )
  1359. if not password then run = false return end
  1360. tmpInfo.password = password
  1361.  
  1362. sWrite( string.rep(' ', tmpInfo.err.text:len() ), tmpInfo.err.x, tmpInfo.err.y, colours.red, colours.lightGrey )
  1363. tmpInfo.success, tmpInfo.err = registerCredentials( tmpInfo.name, tmpInfo.email, tmpInfo.username, tmpInfo.password )
  1364.  
  1365. if tmpInfo.success then
  1366. logged = true
  1367. userInfo.name = tmpInfo.name == "" and "not set" or tmpInfo.name
  1368. userInfo.email = tmpInfo.email == "" and "not set" or tmpInfo.email
  1369. userInfo.username = tmpInfo.username
  1370. userInfo.password = tmpInfo.err
  1371. updateMenu()
  1372. screen = "Prefrences"
  1373. break
  1374. else
  1375. sWrite( tmpInfo.err.text, tmpInfo.err.x, tmpInfo.err.y, colours.red, colours.lightGrey )
  1376. sWrite( string.rep(' ', 19 ), 22, 9, nil, colours.grey )
  1377. sWrite( string.rep(' ', 19 ), 22, 11, nil, colours.grey )
  1378. sWrite( string.rep(' ', 19 ), 22, 13, nil, colours.grey )
  1379. sWrite( string.rep(' ', 19 ), 22, 15, nil, colours.grey )
  1380. end
  1381. end
  1382. end,
  1383. ["Prefrences"] = function()
  1384. while true do
  1385. local e, but, x, y = os.pullEvent()
  1386. if e == "mouse_click" and but == 1 then
  1387. if x >= 43 and x < 48 and y == 8 then
  1388. -- Delete account
  1389. box.fillArea( 9, screenX - 8, 6, 6, colours.blue )
  1390. box.fillArea( 9, screenX - 8, 11, 11, colours.blue )
  1391. box.fillArea( 9, 9, 6, 11, colours.blue )
  1392. box.fillArea( screenX - 8, screenX - 8, 6, 11, colours.blue )
  1393. box.fillArea( 10, screenX - 9, 7, 10, colours.lightGrey )
  1394. sWrite( "Are you sure?", 20, 6, colours.red, colours.blue )
  1395. sWrite( "Confirm password:", 17, 7, colours.red, colours.lightGrey )
  1396. sWrite( "[Apply]", 22, 10, colours.white, colours.green )
  1397. box.fillArea( 11, screenX - 10, 8, 8, colours.grey )
  1398. term.setTextColour( colours.white )
  1399. term.setCursorPos( 12, 8 )
  1400. local p = limitRead( 25, "*", nil, false, nil, nil, true, 22, 29, 10 )
  1401. if not p then return end
  1402. local success, info = deleteAccount( userInfo.username, p )
  1403. box.dialogBox(colours.orange, colours.blue, success and colours.lime or colours.red, colours.white, 5, screenX - 5, 6, success and "Account deleted" or "Error", info )
  1404. if success then
  1405. logged = false
  1406. userInfo.name = ""
  1407. userInfo.email = ""
  1408. userInfo.username = ""
  1409. updateMenu()
  1410. screen = "Login"
  1411. end
  1412. break
  1413. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  1414. run = false
  1415. break
  1416. end
  1417. end
  1418. end
  1419. end,
  1420. ["Messages"] = function()
  1421. while true do
  1422. local e, but, x, y = os.pullEvent()
  1423. if e == "mouse_click" and but == 1 then
  1424. if x >= 7 and x < 7 + string.len( '[ Inbox ]' ) and y == 10 then
  1425. -- Inbox
  1426. displayInbox()
  1427. break
  1428. elseif x >= 7 and x < 7 + string.len( '[ Compose a message ]' ) and y == 11 then
  1429. -- Compose
  1430. compose()
  1431. break
  1432. elseif isValidClick( t_Menus["MainScreen"], x, y ) then
  1433. run = false
  1434. break
  1435. end
  1436. end
  1437. end
  1438. end
  1439. }
  1440.  
  1441. while run do
  1442. drawMain( screen, '', true )
  1443. parallel.waitForAny( waitForScreenChange, tFuncs[screen] )
  1444. end
  1445. end
  1446.  
  1447. local function initiate()
  1448. -- Checking the required files and folders
  1449. bar:setMessage("")
  1450. bar:triggerUpdate( "Checking source folder... (" .. ( bar:getCurrentProgress() + 1 ) .. "/4)..." )
  1451. sleep(0.5)
  1452. if not fs.isDir(sourceFolder) then
  1453. error("Source folder does not exist! Please re-install using the installer.")
  1454. end
  1455. bar:triggerUpdate( "Checking folders... (" .. ( bar:getCurrentProgress() + 1 ) .. "/4)..." )
  1456. sleep(0.5)
  1457. for i = 1, #t_Folders do
  1458. if not fs.exists(t_Folders[i].sPath) then
  1459. error(t_Folders[i].sPath .. " does not exist! Please re-install using the installer.")
  1460. end
  1461. end
  1462. bar:triggerUpdate( "Checking files... (" .. ( bar:getCurrentProgress() + 1 ) .. "/4)..." )
  1463. sleep(0.5)
  1464. for i = 1, #t_NeededFiles do
  1465. for k = 1, #t_NeededFiles[i] do
  1466. if not fs.exists(t_NeededFiles[i][k].sPath) then
  1467. error(t_NeededFiles[i][k].sPath .. " does not exist!\nPlease redownload it at 'http://pastebin.com/" .. t_NeededFiles[i][k].sUrl .. "' and save it as '.ccYouTube/apis/" .. fs.getName(t_NeededFiles[i][k].sPath) .. "' or redownload ComputerCraft YouTube using the installer.")
  1468. end
  1469. end
  1470. end
  1471.  
  1472. -- Loading APIS
  1473. bar:triggerUpdate( "Loading APIS... (" .. ( bar:getCurrentProgress() + 1 ) .. "/4)..." )
  1474. sleep(0.5)
  1475. for i = 1, #t_NeededFiles do
  1476. if t_NeededFiles[i].sType == "api" then
  1477. os.loadAPI(t_NeededFiles[i].sPath)
  1478. end
  1479. end
  1480. sleep(1)
  1481. end
  1482.  
  1483. local function safeRun( func, errDir )
  1484. local ok, err = pcall( func )
  1485. if not ok then
  1486. term.setCursorBlink( false )
  1487. term.setBackgroundColour( colours.red )
  1488. term.setTextColour( colours.white )
  1489. term.clear()
  1490. centerWrite( "Oh noes!", 2, colours.white, colours.red )
  1491. centerWrite( "It looks like ComputerCraft YouTube", 3, colours.white, colours.red )
  1492. centerWrite( "has crashed!", 4, colours.white, colours.red )
  1493. centerWrite( "Error:", 6, colours.white, colours.red )
  1494. centerWrite( err, 7, colours.blue, colours.red )
  1495. centerWrite( "A crash log has been saved to", 9, colours.white, colours.red )
  1496. centerWrite( errDir, 10, colours.lightBlue, colours.red )
  1497. centerWrite( "Please report this to remiX on the", 11, colours.white, colours.red )
  1498. centerWrite( "ComputerCraft forums as soon as possible.", 12, colours.white, colours.red )
  1499. centerWrite( "State any changes you have made if any.", 13, colours.white, colours.red )
  1500. local f = fs.open( errDir, "w" )
  1501. f.writeLine( "ComputerCraft YouTube Crash Log" )
  1502. f.writeLine( "" )
  1503. f.writeLine( "Error" )
  1504. f.writeLine( "===============================" )
  1505. f.writeLine( err )
  1506. f.writeLine( "===============================" )
  1507. f.writeLine( "" )
  1508. f.writeLine( "Report this error to remiX on the ComputerCraft Forums! asap!" )
  1509. f.writeLine( "" )
  1510. f.writeLine( "Please Note: This error log only saves the last logged error." )
  1511. f.close()
  1512.  
  1513. term.setCursorPos( ( screenX - string.len("[Home]") ) / 2, 15 )
  1514. colorW( colours.black, "[Home]" )
  1515. repeat local _, b, x, y = os.pullEvent() until b == 1 and x >= ( screenX - string.len("[Home]") ) / 2 and x <= ( screenX - string.len("[Home]") ) / 2 + string.len("[Home]") and y == 15
  1516. selectedMenu = "Home"
  1517. end
  1518. end
  1519.  
  1520. --[[ End of functions ]] ---
  1521.  
  1522. --[[ Main part of the program ]]--
  1523. -- Loading screen
  1524. bar = loadingScreen.init( loadingScreen.STANDARD, t_logos["loadLogo"], 4, 30, 14, colors.red, "Starting up...", "version " .. version, "By remiX" )
  1525. parallel.waitForAll( function() bar:run( true ) end, initiate )
  1526.  
  1527. local t = {
  1528. ["Account"] = function() safeRun( account, errorLocation ) end,
  1529. ["Home"] = function() safeRun( home, errorLocation ) end,
  1530. ["Local Gallery"] = function() safeRun( localGallery, errorLocation ) end,
  1531. ["Website Gallery"] = function() safeRun( websiteGallery, errorLocation ) end,
  1532. ["Upload"] = function() safeRun( postVideo, errorLocation ) end,
  1533. ["Credits"] = function() safeRun( credits, errorLocation ) end,
  1534. ["Update"] = function() safeRun( checkForUpdate, errorLocation ) end,
  1535. ["Help"] = function() safeRun( help, errorLocation ) end,
  1536. ["Exit"] = function()
  1537. term.setBackgroundColour(colours.black)
  1538. term.setCursorPos(1, 1)
  1539. term.clear()
  1540. colorW(colours.cyan, "Thank you for using cc", colours.grey, "-You", colours.red, "Tube", colours.cyan, ".\n", colours.white, "Made by remiX\n\n")
  1541. running = false
  1542. end,
  1543. }
  1544.  
  1545. drawScreen( "home" )
  1546.  
  1547. -- Infinite loop
  1548. while running do
  1549. term.setCursorBlink(false)
  1550. t[selectedMenu]()
  1551. end
  1552. Status API Training Shop Blog About
  1553. © 2016 GitHub, Inc. Terms Privacy Security Contact Help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement