FileObject problem still there.
by Stefan Lundmark · in Torque Game Engine · 11/20/2004 (8:05 am) · 4 replies
Ah, the glory of FileObject again.
I've come across an issue that I think is not how it was meant to be.
I know Pat Wilson did fix something like this when he was working with T2D but I'm not sure this was the one.
He also suggested a fix here which is not really what the thread was about and I was confused.
Let me start with a script.
This writes a file "file.ext" containing "yadda" in the folder "folder".
Everything is okay, so far!
Then I want to read it.
This code does not open the file, however.
I did put in breakpoints and for all I know, it doesn't get to the openStream part.
Has someone worked with this before and made it so that you can read from folders outside your mod folder, or in the root?
Would be great to see.
I've come across an issue that I think is not how it was meant to be.
I know Pat Wilson did fix something like this when he was working with T2D but I'm not sure this was the one.
He also suggested a fix here which is not really what the thread was about and I was confused.
Let me start with a script.
%file = new FileObject();
%file.openForWrite("folder/file.ext");
%file.writeLine("Yadda");
%file.close();
%file.delete();This writes a file "file.ext" containing "yadda" in the folder "folder".
Everything is okay, so far!
Then I want to read it.
%file = new FileObject();
%file.openForRead("folder/file.ext");
%text = %file.readLine();
%file.close();
%file.delete();This code does not open the file, however.
I did put in breakpoints and for all I know, it doesn't get to the openStream part.
Has someone worked with this before and made it so that you can read from folders outside your mod folder, or in the root?
Would be great to see.
About the author
#2
It was to make it look cleaner, sorry for that. I changed it in the post.
11/20/2004 (10:31 am)
Aho, sorry for the confusion Melv.. I forgot to change that part back before posting the code. I removed the internal openForRead, which is empty in stock Torque and doesn't do anything.. and renamed the ConsoleFunction to reflect the internal ReadMemory.It was to make it look cleaner, sorry for that. I changed it in the post.
#3
Also, my fix was not for objects outside the root, it was to allow you to do something like '%file.openForRead( "~/blah.txt" );' where as before you could not use '~' to indicate the home directory of the mod.
11/20/2004 (10:34 am)
Stefan, we have not changed it so you can read folders outside the active mod folders or in the root because this is a game-security issue. You can do this in C++ code using FileStream if you want, however for script-exposed objects I highly recomend against against allowing this functionality because it is a security hole. We will not be adding this functionality to FileObject.Also, my fix was not for objects outside the root, it was to allow you to do something like '%file.openForRead( "~/blah.txt" );' where as before you could not use '~' to indicate the home directory of the mod.
#4
Why are you able to write outside the root then? Just curious.
Oh the ~/ stuff is a great additional!! :D Like how you set files in the GUI's, like bitmaps. Great, thanks.
Edit: Oh and if that's the case, then this line doesn't work:
Line 1098 Resmanager.cc.
Because I can write into the root.
11/20/2004 (1:06 pm)
I know you won't be adding it to TGE, I just wondered if it was trivial to fix.Why are you able to write outside the root then? Just curious.
Oh the ~/ stuff is a great additional!! :D Like how you set files in the GUI's, like bitmaps. Great, thanks.
Edit: Oh and if that's the case, then this line doesn't work:
Line 1098 Resmanager.cc.
if (!file)
return false; // don't allow storing files in rootBecause I can write into the root.
Associate Melv May
Forgive my ignorance of any recent changes but as far as I know, "readMemory" is not an exposed console function. If you use "openForRead", it internally calls "readMemory" (rather than the internal openForRead) but in either case, shouldn't you be using "openForRead"?
As an addition, it's always safer to use something like "%file.openForRead(ExpandFilename(%myFile))" just to ensure that the correct directory is being used.
- Melv.