Advertisement
Guest User

KESS 1.25

a guest
Aug 27th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.34 KB | None | 0 0
  1.  
  2. function flist(n) --lists files cleanly for n path
  3.     FileList = fs.list(n) --Table with all the files and directories available
  4.     trk=1
  5.     for _, file in ipairs(FileList) do --Loop. Underscore because we don't use the key, ipairs so it's in order
  6.         print(trk..":"..file) --Print the file name
  7.         trk=trk+1
  8.     end --End the loop
  9. end
  10.  
  11. function addslash()
  12.     strlen=string.len(strdir) --get length
  13.     if strdir[strlen]~='/' then --add / to prevent creation of new files
  14.         strdir=strdir.."/"
  15.     end
  16. end
  17.  
  18.  
  19. diske=fs.exists("/disk")--checks if disk is in
  20. term.clear()--clears OS bs
  21.  
  22. print'Welcome to the Kizz Easy Storage Server'
  23. print''
  24. print'Default settings store to /Store.'
  25. print'Please make a choice:'
  26. print'1: Write from Storage to Floppy'
  27. print'2: Write from Floppy to Storage'
  28. print'3: Delete a file from Storage'
  29. print'4: Delete a file from Floppy'
  30. print'5: View Storage'
  31. print'6: View Disk'
  32. print'7: Change Storage Directory'
  33. print'8: Set Label on Disk'
  34. ch=io.read()--get choice
  35. ---------------------------------------------- Checks for valid options
  36. if ch~="1" and ch~="2" and ch~="3" and ch~="4" and ch~="5" and ch~="6" and ch~="7" and ch~="8" then --input check
  37.     print'Bad input idiot!'
  38.     sleep(.5)
  39. end
  40. if ch=="1" or ch=="2" or ch=="3" or ch=="4" or ch=="5" or ch=="6" or ch=="7" or ch=="8" then--double check
  41.     ch=ch+1-1--convert to numeric
  42. end
  43.  
  44. if fs.exists("/Store/")==false then
  45.     fs.makeDir("/Store/")
  46. end
  47.  
  48.  
  49. strdir="/Store/" --sets default directory
  50. if fs.exists("/kessconfig") then
  51.     cfg=fs.open("kessconfig","r")
  52.     strdir=cfg.readLine() --read config
  53.     addslash()
  54.     cfg.close()
  55. end
  56.  
  57. -- This has to go before the rest of the choices to prevent using wrong dir
  58. if ch==7 then --allows user to change default directory
  59.     print'Please enter the new directory, being sure to include pre and post slashes.'
  60.     print'Ex: /Deep/Storage/Example/'
  61.    
  62.     strdir=io.read()
  63.     chkdirstr=fs.exists(strdir)
  64.     if chkdirstr==true then --if suggested dir exists, create config, write new default dir, close
  65.         cfg=fs.open("kessconfig","w")
  66.         addslash()
  67.         cfg.write(strdir)
  68.         cfg.close()
  69.         print'Directory exists. Storage directory altered.'
  70.     end
  71.     if chkdirstr==false then --if dir missing, create dir, write new config, close
  72.         print'Directory missing. Would you like to create it?'
  73.         print'Press 1 to continue or 2 to cancel.'
  74.         dirch=io.read()
  75.         dirch=dirch+1-1
  76.         if dirch==1 then
  77.             fs.makeDir(strdir)
  78.             print'Directory created.'
  79.             cfg=fs.open("kessconfig","w")
  80.             addslash()
  81.             cfg.write(strdir)
  82.             cfg.close()
  83.             print'Default directory altered.'
  84.         end
  85.         if dirch==2 then --cancel and revert
  86.             print'Reverting to default directory.'
  87.             strdir="/Store/"
  88.         end
  89.     end
  90. end
  91.  
  92. ----------------------------------------------
  93.  
  94. if ch==1 and diske==true then --from store to floppy
  95.     print'Listing files on Storage...'
  96.     sleep(.2)
  97.     flist(strdir)--lists storage
  98.     print'Please type the number you wish to add to floppy:'
  99.     sTf=io.read()--choose a file to copy
  100.     sTf=sTf+1-1
  101.     fdir=FileList[sTf]
  102.     --Function to check if disk exists
  103.     ow=fs.exists("/disk/"..fdir)--check if it exists on floppy
  104.    
  105.     if ow==false then --if doesnt exist, copy
  106.         fs.copy(strdir..""..fdir,"/disk/"..fdir)
  107.         print'Added file to floppy.'
  108.         sleep(.2)
  109.     end
  110.    
  111.     if ow==true then --if does exist, prompt to overwrite
  112.         print
  113.         'You are about to overwrite a file. Press 1 to continue or 2 to exit.'
  114.         owp=io.read()
  115.         owp=owp+1-1
  116.        
  117.         if owp==1 then --yes overwrite
  118.             print'deleting'
  119.             fs.delete("/disk/"..fdir) --delete old
  120.             sleep(.2)
  121.             print'copying'
  122.             fs.copy(strdir..""..fdir,"/disk/"..fdir) --replace new
  123.             print'Added file to floppy.'
  124.             sleep(.2)
  125.         end
  126.        
  127.         if owp==2 then --no cancel
  128.             print'Cancelling'
  129.             sleep(.2) --delay then break
  130.         end
  131.        
  132.         print'Press enter to continue.'
  133.         io.read()
  134.     end
  135. end
  136.  
  137. if ch==1 and diske==false then --if no disk then quit
  138.     print'Failed to find disk.'
  139.     print'Press enter to continue.'
  140.     io.read()
  141. end
  142.  
  143. --------------------------------------------
  144.  
  145. if ch==2 and diske==true then --copy from floppy to store
  146.     print'Listing files on floppy...'
  147.     sleep(.2)
  148.     flist("/disk") --list file on floppy
  149.     print'Please type the number you wish to choose:'
  150.     sTf=io.read() --choose file
  151.     sTf=sTf+1-1
  152.     fdir=FileList[sTf]
  153.     ow=fs.exists(strdir..""..fdir)--check if exists in store
  154.    
  155.     if ow==false then --doesnt exist
  156.         fs.copy("/disk/"..fdir,strdir..""..fdir) --copy to store
  157.         print'Added file to storage.'
  158.         sleep(.2)
  159.     end
  160.    
  161.     if ow==true then --does exist, prompt to overwrite
  162.         print
  163.         'You are about to overwrite a file. Press 1 to continue or 2 to exit.'
  164.         owp=io.read()
  165.         owp=owp+1-1
  166.     if owp==1 then --yea overwrite
  167.         print'deleting'
  168.         fs.delete(strdir..""..fdir) --delete old
  169.         sleep(.2)
  170.         print'copying'
  171.         fs.copy("/disk/"..fdir,strdir..""..fdir) --copy new
  172.         print'Added file to storage.'
  173.         sleep(.2)
  174.     end
  175.    
  176.     if owp==2 then --cancel
  177.         print'Cancelling'
  178.         sleep(.2)
  179.     end
  180.    
  181.     print'Press enter to continue.'
  182.     io.read()
  183.     end
  184. end
  185.  
  186. if ch==2 and diske==false then --no disk inserted
  187. print'Failed to find disk.'
  188. print'Press enter to continue.'
  189. io.read()
  190. end
  191.  
  192. --------------------------------------------
  193.  
  194.  
  195. if ch==3 then --delete in Store
  196.     print'Listing files in storage...'
  197.     sleep(.2)
  198.     flist(strdir)--list storage files
  199.     print'Please choose a file to delete or press ctrl+r to reboot.'
  200.     sTf=io.read() --choose file
  201.     sTf=sTf+1-1
  202.     fdir=FileList[sTf]
  203.     print'Deleting...'
  204.     fs.delete(strdir..""..fdir) --delete file
  205.     print'Deleted!'
  206.     print'Press enter to continue.'
  207.     io.read()
  208. end
  209.  
  210. --------------------------------------------
  211.  
  212. if ch==4 and diske==true then --delete on disk
  213.     print'Listing files in disk...'
  214.     sleep(.2)
  215.     flist("/disk/") --list disk
  216.     print'Please choose a file to delete or press ctrl+r to reboot.'
  217.     sTf=io.read() --choose file
  218.     sTf=sTf+1-1
  219.     fdir=FileList[sTf]
  220.     print'Deleting...'
  221.     fs.delete("/disk/"..fdir) --delete file
  222.     print'Deleted!'
  223.     print'Press enter to continue.'
  224.     io.read()
  225. end
  226.  
  227. if ch==4 and diske==false then --no disk found
  228.     print'Failed to find a floppy.'
  229.     print'Press enter to continue.'
  230.     io.read()
  231. end
  232.  
  233. --------------------------------------------
  234.  
  235. if ch==5 then -- list storage
  236.     print'Listing files in storage...'
  237.     sleep(.2)
  238.     flist(strdir)
  239.     print'Press enter to continue.'
  240.     io.read()
  241. end
  242.  
  243. --------------------------------------------
  244.  
  245. if ch==6 and diske==true then --list disk
  246.     print'Listing files in disk...'
  247.     sleep(.2)
  248.     flist("/disk")
  249.     print'Press enter to continue.'
  250.     io.read()
  251. end
  252.  
  253. if ch==6 and diske==false then --no disk found
  254.     print'Cannot find a disk.'
  255.     print'Press enter to continue.'
  256.     io.read()
  257. end
  258.  
  259. if ch==8 and diske==true then --list disk
  260.     print'Please choose the disk drive side:'
  261.     print'1:Bottom, 2:Top, 3:Left, 4:Right, 5:Back'
  262.     side=io.read()
  263.     side=side+1-1
  264.     if side==1 then
  265.     side="bottom"
  266.     end
  267.     if side==2 then
  268.     side="top"
  269.     end
  270.     if side==3 then
  271.     side="left"
  272.     end
  273.     if side==4 then
  274.     side="right"
  275.     end
  276.     if side==5 then
  277.     side="back"
  278.     end
  279.    
  280.     print'Please enter the name you wish to assign to the floppy.'
  281.     fname=io.read()
  282.     disk.setLabel(side,fname)
  283.     sleep(.2)
  284.     print("Floppy renamed to "..fname..".")
  285.     print'Press enter to continue.'
  286.     io.read()
  287. end
  288.  
  289. if ch==8 and diske==false then --no disk found
  290.     print'Cannot find a disk.'
  291.     print'Press enter to continue.'
  292.     io.read()
  293. end
  294.  
  295. --------------------------------------------
  296.  
  297. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement