Advertisement
Guest User

Kizz's Easy Storage Solution

a guest
Aug 26th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.01 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.  
  12. disk=fs.exists("/disk")--checks if disk is in
  13. term.clear()--clears OS bs
  14.  
  15. print'Welcome to the Kizz Easy Storage Server'
  16. print''
  17. print'Please make a choice:'
  18. print'1: Write from Storage to Floppy'
  19. print'2: Write from Floppy to Storage'
  20. print'3: Delete a file from Storage'
  21. print'4: Delete a file from Floppy'
  22. print'5: View Storage'
  23. print'6: View Disk'
  24.  
  25. ch=io.read()--get choice
  26. ---------------------------------------------- Checks for valid options
  27. if ch~="1" and ch~="2" and ch~="3" and ch~="4" and ch~="5" and ch~="6" then --input check
  28.     print'Bad input idiot!'
  29.     sleep(.5)
  30. end
  31. if ch=="1" or ch=="2" or ch=="3" or ch=="4" or ch=="5" or ch=="6" then--double check
  32.     ch=ch+1-1--convert to numeric
  33. end
  34.  
  35. ----------------------------------------------
  36.  
  37. if ch==1 and disk==true then --from store to floppy
  38.     print'Listing files on Storage...'
  39.     sleep(.5)
  40.     flist("/Store")--lists storage
  41.     print'Please type the number you wish to add to floppy:'
  42.     sTf=io.read()--choose a file to copy
  43.     sTf=sTf+1-1
  44.     fdir=FileList[sTf]
  45.     --Function to check if disk exists
  46.     ow=fs.exists("/disk/"..fdir)--check if it exists on floppy
  47.    
  48.     if ow==false then --if doesnt exist, copy
  49.         fs.copy("/Store/"..fdir,"/disk/"..fdir)
  50.         print'Added file to floppy.'
  51.         sleep(1)
  52.     end
  53.    
  54.     if ow==true then --if does exist, prompt to overwrite
  55.         print
  56.         'You are about to overwrite a file. Press 1 to continue or 2 to exit.'
  57.         owp=io.read()
  58.         owp=owp+1-1
  59.        
  60.         if owp==1 then --yes overwrite
  61.             print'deleting'
  62.             fs.delete("/disk/"..fdir) --delete old
  63.             sleep(1)
  64.             print'copying'
  65.             fs.copy("/Store/"..fdir,"/disk/"..fdir) --replace new
  66.             print'Added file to floppy.'
  67.             sleep(1)
  68.         end
  69.        
  70.         if owp==2 then --no cancel
  71.             print'Cancelling'
  72.             sleep(1) --delay then break
  73.         end
  74.        
  75.         print'Press any key to continue.'
  76.         io.read()
  77.     end
  78. end
  79.  
  80. if ch==1 and disk==false then --if no disk then quit
  81.     print'Failed to find disk.'
  82.     print'Press any key to continue.'
  83.     io.read()
  84. end
  85.  
  86. --------------------------------------------
  87.  
  88. if ch==2 and disk==true then --copy from floppy to store
  89.     print'Listing files on floppy...'
  90.     sleep(.5)
  91.     flist("/disk") --list file on floppy
  92.     print'Please type the number you wish to choose:'
  93.     sTf=io.read() --choose file
  94.     sTf=sTf+1-1
  95.     fdir=FileList[sTf]
  96.     ow=fs.exists("/Store/"..fdir)--check if exists in store
  97.    
  98.     if ow==false then --doesnt exist
  99.         fs.copy("/disk/"..fdir,"/Store/"..fdir) --copy to store
  100.         print'Added file to storage.'
  101.         sleep(1)
  102.     end
  103.    
  104.     if ow==true then --does exist, prompt to overwrite
  105.         print
  106.         'You are about to overwrite a file. Press 1 to continue or 2 to exit.'
  107.         owp=io.read()
  108.         owp=owp+1-1
  109.     if owp==1 then --yea overwrite
  110.         print'deleting'
  111.         fs.delete("/Store/"..fdir) --delete old
  112.         sleep(1)
  113.         print'copying'
  114.         fs.copy("/disk/"..fdir,"/Store/"..fdir) --copy new
  115.         print'Added file to storage.'
  116.         sleep(1)
  117.     end
  118.    
  119.     if owp==2 then --cancel
  120.         print'Cancelling'
  121.         sleep(1)
  122.     end
  123.    
  124.     print'Press any key to continue.'
  125.     io.read()
  126.     end
  127. end
  128.  
  129. if ch==2 and disk==false then --no disk inserted
  130. print'Failed to find disk.'
  131. print'Press any key to continue.'
  132. io.read()
  133. end
  134.  
  135. --------------------------------------------
  136.  
  137.  
  138. if ch==3 then --delete in Store
  139.     print'Listing files in storage...'
  140.     sleep(.5)
  141.     flist("/Store")--list storage files
  142.     print'Please choose a file to delete or press ctrl+r to reboot.'
  143.     sTf=io.read() --choose file
  144.     sTf=sTf+1-1
  145.     fdir=FileList[sTf]
  146.     print'Deleting...'
  147.     fs.delete("/Store/"..fdir) --delete file
  148.     print'Deleted!'
  149.     print'Press any key to continue.'
  150.     io.read()
  151. end
  152.  
  153. --------------------------------------------
  154.  
  155. if ch==4 and disk==true then --delete on disk
  156.     print'Listing files in disk...'
  157.     sleep(.5)
  158.     flist("/disk") --list disk
  159.     print'Please choose a file to delete or press ctrl+r to reboot.'
  160.     sTf=io.read() --choose file
  161.     sTf=sTf+1-1
  162.     fdir=FileList[sTf]
  163.     print'Deleting...'
  164.     fs.delete("/disk/"..fdir) --delete file
  165.     print'Deleted!'
  166.     print'Press any key to continue.'
  167.     io.read()
  168. end
  169.  
  170. if ch==4 and disk==false then --no disk found
  171.     print'Failed to find a floppy.'
  172.     print'Press any key to continue.'
  173.     io.read()
  174. end
  175.  
  176. --------------------------------------------
  177.  
  178. if ch==5 then -- list storage
  179.     print'Listing files in storage...'
  180.     sleep(.5)
  181.     flist("/Store")
  182.     print'Press any key to continue.'
  183.     io.read()
  184. end
  185.  
  186. --------------------------------------------
  187.  
  188. if ch==6 and disk==true then --list disk
  189.     print'Listing files in disk...'
  190.     sleep(.5)
  191.     flist("/disk")
  192.     print'Press any key to continue.'
  193.     io.read()
  194. end
  195.  
  196. if ch==6 and disk==false then --no disk found
  197.     print'Cannot find a disk.'
  198.     print'Press any key to continue.'
  199.     io.read()
  200. end
  201.  
  202. --------------------------------------------
  203.  
  204. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement