This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cdel's profile picture

Directory Faking

Started by cdel, 03 November 2014 - 07:19 AM
cdel #1
Posted 03 November 2014 - 08:19 AM
I want to store some files or at least make it appear as if files are stored in the rom. Therefore, I want t make it so when you something such as "cd rom" it will actually do "cd .rom" and show you you're in the rom directory within the shell.
DannySMc #2
Posted 03 November 2014 - 09:09 AM
You would need to create a folder called .rom but "." files are hidden so it's quite hard. What are you doing it for?
cdel #3
Posted 03 November 2014 - 09:17 AM
You would need to create a folder called .rom but "." files are hidden so it's quite hard. What are you doing it for?

I want the files for my desktop environment within the rom, rather than having them in another location.
oeed #4
Posted 03 November 2014 - 09:56 AM
When you want to do tricky stuff with the FS API you generally have to sandbox it. It's not that difficult to do. You basically want to do something like this:

local _fs = fs
fs.list = function(path)
-- if the path starts with rom then redirect to the .rom folder
end
-- add fs.open, fs.copy, usw.

I did something a bit like this not too long ago. Basically this program squished a multi-file program in to one file and runs without needing to be extracted, although it can if you want to. Here's an example from Quest, go to line 6300 for the sandboxing stuff
cdel #5
Posted 03 November 2014 - 09:57 AM
When you want to do tricky stuff with the FS API you generally have to sandbox it. It's not that difficult to do. You basically want to do something like this:

local _fs = fs
fs.list = function(path)
-- if the path starts with rom then redirect to the .rom folder
end
-- add fs.open, fs.copy, usw.

I did something a bit like this not too long ago. Basically this program squished a multi-file program in to one file and runs without needing to be extracted, although it can if you want to. Here's an example from Quest, go to line 6300 for the sandboxing stuff

thanks :)/>
subzero22 #6
Posted 03 November 2014 - 10:00 AM
I'd like to know this also as right now my os is hiding files and to top it off the start file makes it so they can't edit those files. But as for actually faking a rom folder location I'd like to know that myself. I was thinking of x = . but not sure if that would work and too bad lua has to read the code from top to bottom or I'd put it like 10-20 lines below the code. Actually that makes me think. Make the startup file load a hidden file with x = .rom and since x isn't local it should work with any file loaded after it.

connard does _ before fs add a .?
cdel #7
Posted 03 November 2014 - 10:33 AM
When you want to do tricky stuff with the FS API you generally have to sandbox it. It's not that difficult to do. You basically want to do something like this:

local _fs = fs
fs.list = function(path)
-- if the path starts with rom then redirect to the .rom folder
end
-- add fs.open, fs.copy, usw.

I did something a bit like this not too long ago. Basically this program squished a multi-file program in to one file and runs without needing to be extracted, although it can if you want to. Here's an example from Quest, go to line 6300 for the sandboxing stuff

Could you possibly refine that pseudo code hybrid please? after reading through both quest and the pseudo hybrid I still don't fully understand it. :)/>
oeed #8
Posted 03 November 2014 - 10:38 AM
When you want to do tricky stuff with the FS API you generally have to sandbox it. It's not that difficult to do. You basically want to do something like this:

local _fs = fs
fs.list = function(path)
-- if the path starts with rom then redirect to the .rom folder
end
-- add fs.open, fs.copy, usw.

I did something a bit like this not too long ago. Basically this program squished a multi-file program in to one file and runs without needing to be extracted, although it can if you want to. Here's an example from Quest, go to line 6300 for the sandboxing stuff

Could you possibly refine that pseudo code hybrid please? after reading through both quest and the pseudo hybrid I still don't fully understand it. :)/>

Yea sorry, it's not the best pseudo code.


fs.list = function(path)
  if path starts with rom then --obviously change this to something that will work
	 if _fs.exists(path) then -- use the existing file/folder if it exists
	   _fs.list(path)
	 else
	   local realPath = path:replace...--replace /rom with .rom or whatever
	   fs.list(realPath)
	 end
end
You then basically copy that for each different function, maybe may a resolve path function to use first.
cdel #9
Posted 03 November 2014 - 10:45 AM
When you want to do tricky stuff with the FS API you generally have to sandbox it. It's not that difficult to do. You basically want to do something like this:

local _fs = fs
fs.list = function(path)
-- if the path starts with rom then redirect to the .rom folder
end
-- add fs.open, fs.copy, usw.

I did something a bit like this not too long ago. Basically this program squished a multi-file program in to one file and runs without needing to be extracted, although it can if you want to. Here's an example from Quest, go to line 6300 for the sandboxing stuff

Could you possibly refine that pseudo code hybrid please? after reading through both quest and the pseudo hybrid I still don't fully understand it. :)/>

Yea sorry, it's not the best pseudo code.


fs.list = function(path)
  if path starts with rom then --obviously change this to something that will work
	 if _fs.exists(path) then -- use the existing file/folder if it exists
	   _fs.list(path)
	 else
	   local realPath = path:replace...--replace /rom with .rom or whatever
	   fs.list(realPath)
	 end
end
You then basically copy that for each different function, maybe may a resolve path function to use first.

thanks again :D/>