Advertisement
Guest User

ccYouTube/ComputerCraft YouTube

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