OpenFileForWrite question.
by Stefan Lundmark · in Torque Game Engine · 09/23/2005 (5:35 am) · 6 replies
I'm stuck and there are not much information about this on the forums so I figured I'd ask.
I'm trying to open a file and then append data to it, rather than overwriting the file each time a new stream is saved.
In previous versions of TGE, there was a openForAppend function, but it does not seem to exist anymore.
So I went in and found that you could use ResourceManager->openFileForWrite(writeFile, file, append).
So I came up with this:
The only important part here really, is the second line. I put 1 as an argument, there to show the function that I want to append, not overwrite.
But it doesn't work, it behaves the same way as if I left it out.
There's really nothing about this at all in the forums :) The only hint I found was in the documentation. So I would appreaciate tons if anyone had an answer.
Any ideas?
/Stefan
I'm trying to open a file and then append data to it, rather than overwriting the file each time a new stream is saved.
In previous versions of TGE, there was a openForAppend function, but it does not seem to exist anymore.
So I went in and found that you could use ResourceManager->openFileForWrite(writeFile, file, append).
So I came up with this:
FileStream writeFile;
[b]if (!ResourceManager->openFileForWrite(writeFile, file, 1))[/b]
return false;
for(U32 i =0; i<mBufferSize;i++){
writeFile.write(mBuffer[i]);
}
dFree(mBuffer);
mBuffer = 0;
mBufferSize = 0;The only important part here really, is the second line. I put 1 as an argument, there to show the function that I want to append, not overwrite.
But it doesn't work, it behaves the same way as if I left it out.
There's really nothing about this at all in the forums :) The only hint I found was in the documentation. So I would appreaciate tons if anyone had an answer.
Any ideas?
/Stefan
About the author
#2
09/23/2005 (9:18 pm)
Hmm... Checking, it seems that the flag SHOULD be working properly. What platform are you running on?
#3
I'll try OpenForAppend again then Billy, I didn't see it last time I checked.
I also checked the functions (going from memory here) Stream::Open and OpenFileForWrite and they both look like they should be working correctly with the append flag, still.. results show that it overwrites.
But I'll check again! Thanks both of you :)
I'll do some more testing and report again.
09/24/2005 (2:07 pm)
Windows XP Pro, and Windows XP Home.I'll try OpenForAppend again then Billy, I didn't see it last time I checked.
I also checked the functions (going from memory here) Stream::Open and OpenFileForWrite and they both look like they should be working correctly with the append flag, still.. results show that it overwrites.
But I'll check again! Thanks both of you :)
I'll do some more testing and report again.
#4
09/25/2005 (6:09 pm)
Could be a wrong or changed API usage. I'd appreciate hearing anything you find out!
#5
It still doesn't work. Not even with the script called openForAppend, which should be calling it correctly. I replicated the syntax into my function too, but with the same results.
Have any changes been made here recently Ben? Would appreciate some help.
10/24/2005 (12:46 pm)
I'm on this again.It still doesn't work. Not even with the script called openForAppend, which should be calling it correctly. I replicated the syntax into my function too, but with the same results.
Have any changes been made here recently Ben? Would appreciate some help.
#6
This is how it works:
A bit different from how I did it above. It doesn't use ResourceManager directly as far as I can see, but instead uses FileObject to create the file. I'll check that out, thanks for the previous help.
11/03/2005 (11:25 am)
Just wanted you guys to know that this is infact working. I used the consoleCommand instead, and it does write in portions as you would expect from an appendwrite.This is how it works:
return object->openForWrite(argv[2], true);
A bit different from how I did it above. It doesn't use ResourceManager directly as far as I can see, but instead uses FileObject to create the file. I'll check that out, thanks for the previous help.
Torque 3D Owner Billy L
The openForAppend is still working in ver 1.3 and 1.4 but if you use TSE i have no answer.