,
Instead of writing a comment I decided to answer this question as a work around but it is something I didn’t want to do but maybe you guys can implement that might not just help me and others in the future.
I ran into problems with my attempted first work-around, and had to create my own customized FileHandle interface that goes off of IFileHandle. Then I had to create our own support of window calls.
There are a few things that I really needed that wasn’t provided that I think for pure customization of file systems. Right now I am working on using Binary Tree structure much like how a database works. But instead of using “SQL” which is something that I don’t want to do, it is more of an Index/Data Block Database that allows me to access data in real time between file/IO etc. We are using this for the purpose of real time caching and allowing the reduction of using so much ram for our game.
Windows based of course is SetEndOfFile which basically allows me to truncate the entire file and reset the position/length to be 0 byte size without having to close the handle. In C# this is called by the SetLength function which allows me to Set the Length to and then position offset the Seek to a new position in the file.
The other problem I had was with the FArchive was I could NOT seek beyond a position within a /write environment. I had to create a new handle therefore making it so that when a new file is created I extended it to be (adjusted above to show you what I had to do).
So this is what I had to do:
I added my own “OpenFile” method that is static part of my FileHandle that I overrided, I basically did something along the line below:
class IMyFileHandle : public IFileHandle {
public:
virtual bool SetLength(int64 offset = 0) = 0;
};
To extend for SetLength function
Then I added the OpenFile static function which looks like this:
FORCEINLINE static IUdbFileHandle* OpenFile(const TCHAR* Filename) {
uint32 Access = GENERIC_READ | GENERIC_WRITE;
uint32 WinFlags = FILE_SHARE_READ;
uint32 Create = OPEN_ALWAYS;
HANDLE H = CreateFileW(*NormalizeFilename(Filename), Access, WinFlags, NULL, Create, FILE_ATTRIBUTE_NORMAL, NULL);
if (H != INVALID_HANDLE_VALUE)
{
return new MyFileHandle(H);
}
return nullptr;
}
As you can see it looks exactly like the one within the IPlatformFile OpenWrite and OpenRead. Only difference is I used the OpenWrite directly , and made it so that it OPEN_ALWAYS. ALong with GENERIC_READ | GENERIC_WRITE which allows me to Write/ on the same Handle where as OpenRead only has GENERIC_READ and OpenWrite has only GENERIC_WRITE which caused me to have cannot or cannot write exceptions.
Doing this worked fine for me, but I would really prefer to be able to control this much better. If you have questions just please don’t hesitate to ask me I wouldn’t mind.