AuroraRuntime/Source/IO/FS/FSTimes.NT.cpp
Reece Wilson f43251c8fc [+] AuNet::ISocketChannelEventListener
[+] AuFS::UpdateTimes
[+] AuFS::UpdateFileTimes
[+] AuFS::CompressEx
[*] AuFS::Compress now rejects files that look to be already compressed
[+] AuFS::DecompressEx
[+] AuFS::Create
[+] AuFS::WriteNewFile
[+] AuFS::WriteNewString
[+] AuFs::FileAttrsList
[+] AuFs::FileAttrsGet
[+] AuFs::FileAttrsSet
[+] DirectoryLogger::uMaxLogsOrZeroBeforeCompress
[+] ISocketChannel.AddEventListener
[+] ISocketChannel.AddEventListener
[+] DirectoryLogger.uMaxLogsOrZeroBeforeCompress
[*] Fix UNIX regression
[*] Fix up stream socket channel realloc IPC
[*] Fix shutdown regression in pretty much everything thanks to 8ff81df1's dumbass fix
    (fixes fence regression on shutdown)
[*] Fix DirDeleterEx formatting of reported failed paths
[*] Fix up file not truncated if already exists bugs. Extended and alternative apis added.
[*] Fix ICompressionStream::ReadEx returning the wrong read value
[+] Legacy compression API can now self-correct once newer stream processor objects are added
2023-02-04 19:43:01 +00:00

80 lines
2.1 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FSTimes.NT.cpp
Date: 2023-2-4
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
#include "FSTimes.NT.hpp"
#include <Source/Time/Time.hpp>
namespace Aurora::IO::FS
{
const FILETIME *ConvertFileTime(FILETIME *temp, AuOptionalEx<AuInt64> time)
{
if (!time)
{
return nullptr;
}
auto word = AuTime::ConvertTimestampNs(time.value());
temp->dwLowDateTime = AuBitsToLower(word);
temp->dwHighDateTime = AuBitsToHigher(word);
return temp;
}
AUKN_SYM bool UpdateFileTimes(const AuString &path, const UpdateTimes &times)
{
HANDLE hFile;
FILETIME created;
FILETIME modified;
FILETIME access;
auto pathex = NormalizePathRet(path);
if (pathex.empty())
{
return false;
}
auto win32Path = Locale::ConvertFromUTF8(pathex);
if (win32Path.empty())
{
return false;
}
hFile = ::CreateFileW(win32Path.c_str(),
GENERIC_WRITE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
if (!AuFS::FileExists(pathex))
{
SysPushErrorIO("Missing file: {}", path);
return false;
}
SysPushErrorIO("Couoldn't open a handle for: {}", path);
return false;
}
bool bRet = ::SetFileTime(hFile,
ConvertFileTime(&created, times.createdNs),
ConvertFileTime(&access, times.accessedNs),
ConvertFileTime(&modified, times.modifiedNs));
if (!bRet)
{
SysPushErrorIO();
}
AuWin32CloseHandle(hFile);
return bRet;
}
}