2023-02-04 19:43:01 +00:00
|
|
|
/***
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-04-19 03:33:57 +00:00
|
|
|
AUKN_SYM bool UpdateFileTimes(const AuROString &path, const UpdateTimes ×)
|
2023-02-04 19:43:01 +00:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
FILETIME created;
|
|
|
|
FILETIME modified;
|
|
|
|
FILETIME access;
|
|
|
|
|
2023-07-29 08:58:02 +00:00
|
|
|
if (path.empty())
|
|
|
|
{
|
|
|
|
SysPushErrorArg("Empty path provided");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-04 19:43:01 +00:00
|
|
|
auto pathex = NormalizePathRet(path);
|
|
|
|
if (pathex.empty())
|
|
|
|
{
|
2023-09-12 19:48:35 +00:00
|
|
|
SysPushErrorMemory();
|
2023-02-04 19:43:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto win32Path = Locale::ConvertFromUTF8(pathex);
|
|
|
|
if (win32Path.empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-13 01:27:18 +00:00
|
|
|
hFile = Win32Open(win32Path.c_str(),
|
|
|
|
GENERIC_WRITE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
false,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
0,
|
|
|
|
0);
|
2023-02-04 19:43:01 +00:00
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (!AuFS::FileExists(pathex))
|
|
|
|
{
|
2023-07-29 08:58:02 +00:00
|
|
|
SysPushErrorResourceMissing("Missing file: {}", path);
|
2023-02-04 19:43:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-01-09 05:08:54 +00:00
|
|
|
if (GetLastError() == ERROR_SHARING_VIOLATION)
|
|
|
|
{
|
|
|
|
RuntimeWaitForSecondaryTick();
|
|
|
|
hFile = Win32Open(win32Path.c_str(),
|
|
|
|
GENERIC_WRITE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
false,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2023-07-29 08:58:02 +00:00
|
|
|
SysPushErrorIO("Couldn't open a handle for: {}", path);
|
2023-02-04 19:43:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|