[+] IFileStream::GetHandle()
This commit is contained in:
parent
9f78555693
commit
9ce4e08d36
@ -64,5 +64,9 @@ namespace Aurora::IO::FS
|
||||
*/
|
||||
virtual void MakeTemporary() = 0;
|
||||
|
||||
/**
|
||||
* @brief Returns the IO handle backing the file stream, if available.
|
||||
*/
|
||||
virtual AuSPtr<IIOHandle> GetHandle() = 0;
|
||||
};
|
||||
}
|
@ -31,7 +31,7 @@ namespace Aurora::IO::FS
|
||||
LARGE_INTEGER distance {};
|
||||
LARGE_INTEGER pos {};
|
||||
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -56,7 +56,7 @@ namespace Aurora::IO::FS
|
||||
LARGE_INTEGER distance {};
|
||||
LARGE_INTEGER pos {};
|
||||
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -79,7 +79,7 @@ namespace Aurora::IO::FS
|
||||
{
|
||||
LARGE_INTEGER length;
|
||||
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -98,7 +98,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
bool WinFileStream::Read(const Memory::MemoryViewStreamWrite ¶meters)
|
||||
{
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
HANDLE hEventHandle { INVALID_HANDLE_VALUE };
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
@ -184,7 +184,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
bool WinFileStream::Write(const Memory::MemoryViewStreamRead ¶meters)
|
||||
{
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
HANDLE hEventHandle { INVALID_HANDLE_VALUE };
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
@ -275,7 +275,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
void WinFileStream::WriteEoS()
|
||||
{
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -288,7 +288,9 @@ namespace Aurora::IO::FS
|
||||
|
||||
void WinFileStream::Close()
|
||||
{
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
bool bDeleteFailed {};
|
||||
AuString path;
|
||||
|
||||
if ((hHandle != INVALID_HANDLE_VALUE) &&
|
||||
(this->bShouldDelete))
|
||||
@ -298,16 +300,29 @@ namespace Aurora::IO::FS
|
||||
if (!(pSetFileInformationByHandle &&
|
||||
pSetFileInformationByHandle(hHandle, _FILE_INFO_BY_HANDLE_CLASS::FileDispositionInfo, &rm, sizeof(rm))))
|
||||
{
|
||||
SysPushErrorIO("Couldn't delete temporary file {}", this->pHandle_ ? this->pHandle_->GetPath() : "");
|
||||
path = this->pHandle_ ? this->pHandle_->GetPath() : "";
|
||||
|
||||
SysPushErrorIO("Couldn't delete temporary file {}", path);
|
||||
|
||||
if (path.length())
|
||||
{
|
||||
bDeleteFailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AuResetMember(this->pHandle_);
|
||||
|
||||
// a bit of a hack for problematic NT-like platforms and Windows XP
|
||||
if (bDeleteFailed)
|
||||
{
|
||||
AuFS::Remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
void WinFileStream::Flush()
|
||||
{
|
||||
auto hHandle = this->GetHandle();
|
||||
auto hHandle = this->GetWin32Handle();
|
||||
|
||||
::FlushFileBuffers(hHandle);
|
||||
}
|
||||
@ -317,7 +332,12 @@ namespace Aurora::IO::FS
|
||||
this->bShouldDelete = true;
|
||||
}
|
||||
|
||||
HANDLE WinFileStream::GetHandle()
|
||||
AuSPtr<IIOHandle> WinFileStream::GetHandle()
|
||||
{
|
||||
return this->pHandle_;
|
||||
}
|
||||
|
||||
HANDLE WinFileStream::GetWin32Handle()
|
||||
{
|
||||
return this->pHandle_ ?
|
||||
(HANDLE)this->pHandle_->GetOSWriteHandleSafe().ValueOr(this->pHandle_->GetOSReadHandleSafe().ValueOr((AuUInt)INVALID_HANDLE_VALUE)) :
|
||||
|
@ -26,8 +26,9 @@ namespace Aurora::IO::FS
|
||||
void Flush() override;
|
||||
void WriteEoS() override;
|
||||
void MakeTemporary() override;
|
||||
AuSPtr<IIOHandle> GetHandle() override;
|
||||
|
||||
HANDLE GetHandle();
|
||||
HANDLE GetWin32Handle();
|
||||
|
||||
private:
|
||||
AuSPtr<IIOHandle> pHandle_;
|
||||
|
Loading…
Reference in New Issue
Block a user