Advertisement
manaphoenix

Ficsit Networks [Simple Filesystem Loader]

Sep 23rd, 2020 (edited)
2,732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. --[[
  2.   For "MyFile" put inside the quotes the name of the file you want to run, including the extension
  3.   example: "myFile.ficlua"
  4.   You can also leave the field blank "" and it will run the first file it finds.
  5.  
  6.   For "MyDrive" put inside the quote the ID of the drive you files are stored in
  7.   The drive ID is the same as the folder id in the SaveGames/Computer/<ID>
  8.   Leave it blank and it will find a workable drive by itself
  9.   NOTE: this can cause it find the wrong drive if you have a drive and a floppy
  10. ]]
  11.  
  12. local myFile = ""
  13. local myDrive = ""
  14.  
  15.  
  16. -- [[ CODE DO NOT TOUCH ]] --
  17.  
  18. -- init filesystem
  19. local _G = _G
  20. local fs = _G.filesystem
  21. local computer = _G.computer
  22. if fs.initFileSystem("/dev") == false then
  23.     computer.panic("Cannot initialize /dev!")
  24. end
  25. -- find drive if one isn't stated
  26. if (myDrive:len() == 0) then
  27.   for _,f in pairs(fs.childs("/dev")) do
  28.    if f ~= "serial" then
  29.     myDrive = f
  30.     break
  31.    end
  32.   end
  33. end
  34. -- mount drive
  35. if (myDrive:len() > 0) then
  36.   local ch = fs.mount("/dev/"..myDrive, "/")
  37.   if (not ch) then
  38.     computer.panic(myDrive .. " could not be found!")
  39.   end
  40. else
  41.   computer.panic("No HardDrive Found!")
  42. end
  43.  
  44. -- find a file if one isn't stated
  45. if (myFile:len() == 0) then
  46.   for _,f in pairs(fs.childs("/")) do
  47.     if fs.isFile(f) then
  48.       myFile = f
  49.       break
  50.     end
  51.   end
  52. end
  53. -- run the file
  54. if (myFile:len() > 0) then
  55.   if (fs.exists(myFile)) then
  56.     fs.doFile(myFile)
  57.   else
  58.     computer.panic(myFile .. " could not be found!")
  59.   end
  60. else
  61.   computer.panic("No file found!")
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement