76 posts
Location
Death City
Posted 22 September 2012 - 02:23 PM
Hello all, I was wondering if there was any way to make a ROF (Read Only File) in a program for instance here is my code:
Spoiler
term.clear()
term.setCursorPos(1,1)
print("What would you like your display name to be?")
local dispName = read()
print("Okay, "..dispName.." what is your real name?")
local realName = read()
if not fs.isDir("saves") then
fs.makeDir("saves")
end
local file = fs.open("saves/"..dispName,"a")
file.writeLine(realName)
file.close()
Now let's just say that after 'fs.close()' I want to make it a read-only file, how would I do that?
1111 posts
Location
Portland OR
Posted 22 September 2012 - 02:34 PM
I don't think you can do that through a Lua script in CC. You would have to set it on the file on your real computer/the server you play on.
76 posts
Location
Death City
Posted 22 September 2012 - 03:49 PM
D:<
23 posts
Location
Poland
Posted 22 September 2012 - 06:36 PM
In fact it is kind of possible. Save this as startup:
deleteOrig=fs.delete
readOnly = {"foo/bar",
"bar/foo"}
function fs.delete(plik)
for i=1,#readOnly do
if plik==readOnly[i] then
error(plik.." is read only!")
end
end
deleteOrig(plik)
end
This way you can't remove files listed in readOnly table. Of course you should add your startup file there :P/>/>
1604 posts
Posted 22 September 2012 - 06:39 PM
In fact it is kind of possible. Save this as startup:
deleteOrig=fs.delete
readOnly = {"foo/bar",
"bar/foo"}
function fs.delete(plik)
for i=1,#readOnly do
if plik==readOnly[i] then
error(plik.." is read only!")
end
end
deleteOrig(plik)
end
This way you can't remove files listed in readOnly table. Of course you should add your startup file there ;)/>/>
You would also need to change the fs.open function so it can't be edited. And some kind of path resolving, so people can't do something like:
fs.delete("/./foo/bar")
And then is the problem of disk startups, but I'll leave that to you :P/>/>
79 posts
Posted 24 September 2012 - 02:00 PM
Yeh, basically, you can't really make anything read only… but you can try.
105 posts
Posted 24 September 2012 - 02:15 PM
Yeah, pretty hard to make a robust read-only system without modifying the BIOS and api to prevent insecure startups from floppy.
1111 posts
Location
Portland OR
Posted 24 September 2012 - 09:57 PM
The only way to do it is to write the program outside of Minecraft and save it in the rom folder. Then all computers will have access to it, but wont be able to write to it or delete it.