Repository :
https://github.com/FarGroup/FarManager
On branch : master
Link :
https://github.com/FarGroup/FarManager/commit/daaba5f82b26d15aad777a143f02ba60d55a50d1
>---------------------------------------------------------------
commit daaba5f82b26d15aad777a143f02ba60d55a50d1
Author: Alex Alabuzhev <
alab...@gmail.com>
Date: Sat Oct 4 00:01:37 2025 +0100
Refactoring
>---------------------------------------------------------------
daaba5f82b26d15aad777a143f02ba60d55a50d1
far/datetime.cpp | 2 +-
far/fileedit.cpp | 2 +-
far/imports.hpp | 10 +++++-----
far/platform.chrono.cpp | 29 +++++++++++++++++++++--------
far/platform.chrono.hpp | 2 ++
5 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/far/datetime.cpp b/far/datetime.cpp
index f4a456b6a..39427ff83 100644
--- a/far/datetime.cpp
+++ b/far/datetime.cpp
@@ -785,7 +785,7 @@ std::pair<string, string> format_datetime(os::chrono::time const Time)
Time.Hours,
Time.Minutes,
Time.Seconds,
- Time.Hectonanoseconds / (1ms / 1_hns)
+ Time.milliseconds()
)
};
}
diff --git a/far/fileedit.cpp b/far/fileedit.cpp
index bbafc1701..06fc5dfde 100644
--- a/far/fileedit.cpp
+++ b/far/fileedit.cpp
@@ -2129,7 +2129,7 @@ void FileEditor::SetFileName(const string_view NewFileName)
LocalTime.Hours,
LocalTime.Minutes,
LocalTime.Seconds,
- LocalTime.Hectonanoseconds / (1ms / 1_hns)
+ LocalTime.milliseconds()
)
);
}
diff --git a/far/imports.hpp b/far/imports.hpp
index 1c0cadd63..0f124d53f 100644
--- a/far/imports.hpp
+++ b/far/imports.hpp
@@ -108,8 +108,8 @@ public: \
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtQueryInformationFile, HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass); // NT4
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtSetInformationFile, HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass); // NT4
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtQueryObject, HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength); // NT4
- DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtOpenDirectoryObject, PHANDLE DirectoryHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes);
- DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtQueryDirectoryObject, HANDLE DirectoryHandle, PVOID Buffer, ULONG Length, BOOLEAN ReturnSingleEntry, BOOLEAN RestartScan, PULONG Context, PULONG ReturnLength);
+ DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtOpenDirectoryObject, PHANDLE DirectoryHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes); // NT4
+ DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtQueryDirectoryObject, HANDLE DirectoryHandle, PVOID Buffer, ULONG Length, BOOLEAN ReturnSingleEntry, BOOLEAN RestartScan, PULONG Context, PULONG ReturnLength); // NT4
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtOpenSymbolicLinkObject, PHANDLE LinkHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes); // NT4
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtQuerySymbolicLinkObject, HANDLE LinkHandle, PUNICODE_STRING LinkTarget, PULONG ReturnedLength); // NT4
DEFINE_IMPORT_FUNCTION(ntdll, nop, nt, NTAPI, NTSTATUS, NtClose, HANDLE Handle); // NT4
@@ -136,7 +136,7 @@ public: \
DEFINE_IMPORT_FUNCTION(kernel32, le, nullptr, WINAPI, PVOID, AddVectoredExceptionHandler, ULONG First, PVECTORED_EXCEPTION_HANDLER Handler); // XP
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, ULONG, RemoveVectoredExceptionHandler, PVOID Handle); // XP
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, TzSpecificLocalTimeToSystemTime, const TIME_ZONE_INFORMATION* TimeZoneInformation, const SYSTEMTIME* LocalTime, LPSYSTEMTIME UniversalTime); // XP
- DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetModuleHandleExW, DWORD Flags, LPCWSTR ModuleName, HMODULE* Module);
+ DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetModuleHandleExW, DWORD Flags, LPCWSTR ModuleName, HMODULE* Module); // XP
DEFINE_IMPORT_FUNCTION(kernel32, le, handle, WINAPI, HANDLE, FindFirstStreamW, LPCWSTR FileName, STREAM_INFO_LEVELS InfoLevel, LPVOID FindStreamData, DWORD Flags); // 2k3
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, FindNextStreamW, HANDLE FindStream, LPVOID FindStreamData); // 2k3
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetVolumePathNamesForVolumeNameW, LPCWSTR VolumeName, LPWSTR VolumePathNames, DWORD BufferLength, PDWORD ReturnLength); // 2k3
@@ -159,7 +159,7 @@ public: \
DEFINE_IMPORT_FUNCTION(kernel32, le, void, WINAPI, void, ReleaseSRWLockExclusive, PSRWLOCK SRWLock); // Vista
DEFINE_IMPORT_FUNCTION(kernel32, le, void, WINAPI, void, ReleaseSRWLockShared, PSRWLOCK SRWLock); // Vista
DEFINE_IMPORT_FUNCTION(kernel32, le, zero, WINAPI, int, CompareStringOrdinal, LPCWCH String1, int Count1, LPCWCH String2, int Count2, BOOL IgnoreCase); // Vista
- DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetProductInfo, DWORD OSMajorVersion, DWORD OSMinorVersion, DWORD SpMajorVersion, DWORD SpMinorVersion, PDWORD ReturnedProductType);
+ DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetProductInfo, DWORD OSMajorVersion, DWORD OSMinorVersion, DWORD SpMajorVersion, DWORD SpMinorVersion, PDWORD ReturnedProductType); // Vista
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOL, GetPhysicallyInstalledSystemMemory, PULONGLONG TotalMemoryInKilobytes); // Vista SP1
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOLEAN, TryAcquireSRWLockExclusive, PSRWLOCK SRWLock); // 7
DEFINE_IMPORT_FUNCTION(kernel32, le, false, WINAPI, BOOLEAN, TryAcquireSRWLockShared, PSRWLOCK SRWLock); // 7
@@ -184,7 +184,7 @@ public: \
DEFINE_IMPORT_FUNCTION(netapi32, nop, net, NET_API_FUNCTION, NET_API_STATUS, NetDfsGetInfo, LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName, DWORD Level, LPBYTE* Buffer); // 2k
DEFINE_IMPORT_FUNCTION(netapi32, nop, net, NET_API_FUNCTION, NET_API_STATUS, NetDfsGetClientInfo, LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName, DWORD Level, LPBYTE* Buffer); // 2k
- DEFINE_IMPORT_FUNCTION(dbgeng, nop, hr, STDAPICALLTYPE, HRESULT, DebugCreate, REFIID InterfaceId, PVOID* Interface);
+ DEFINE_IMPORT_FUNCTION(dbgeng, nop, hr, STDAPICALLTYPE, HRESULT, DebugCreate, REFIID InterfaceId, PVOID* Interface); // XP
DEFINE_IMPORT_FUNCTION(dbghelp, le, false, WINAPI, BOOL, SymInitialize, HANDLE Process, PCSTR UserSearchPath, BOOL InvadeProcess); // 2k
DEFINE_IMPORT_FUNCTION(dbghelp, le, false, WINAPI, BOOL, SymGetSearchPath, HANDLE Process, PSTR SearchPath, DWORD SearchPathLength); // 2k
diff --git a/far/platform.chrono.cpp b/far/platform.chrono.cpp
index d7c2df6e8..329f6af47 100644
--- a/far/platform.chrono.cpp
+++ b/far/platform.chrono.cpp
@@ -127,10 +127,15 @@ namespace os::chrono
.wHour = Time.Hours,
.wMinute = Time.Minutes,
.wSecond = Time.Seconds,
- .wMilliseconds = static_cast<WORD>(Time.Hectonanoseconds / (1ms / 1_hns)),
+ .wMilliseconds = Time.milliseconds(),
};
}
+ uint16_t time::milliseconds() const
+ {
+ return static_cast<uint16_t>(Hectonanoseconds / (1ms / 1_hns));
+ }
+
utc_time now_utc()
{
// hns precision
@@ -155,17 +160,27 @@ namespace os::chrono
return local_time{ make_time(LocalTime) };
}
- bool timepoint_to_utc_time(time_point const TimePoint, utc_time& UtcTime)
+ static bool timepoint_to_system_time(time_point const TimePoint, SYSTEMTIME& SystemTime)
{
const auto FileTime = nt_clock::to_filetime(TimePoint);
+ return FileTimeToSystemTime(&FileTime, &SystemTime);
+ }
+ static void transfer_hns(time_point const TimePoint, time& Time)
+ {
+ assert(!(Time.Hectonanoseconds % (1ms / 1_hns)));
+ Time.Hectonanoseconds += TimePoint.time_since_epoch() % 1ms / 1_hns;
+ }
+
+ bool timepoint_to_utc_time(time_point const TimePoint, utc_time& UtcTime)
+ {
SYSTEMTIME SystemTime;
- if (!FileTimeToSystemTime(&FileTime, &SystemTime))
+ if (!timepoint_to_system_time(TimePoint, SystemTime))
return false;
UtcTime = utc_time{ make_time(SystemTime) };
- UtcTime.Hectonanoseconds += TimePoint.time_since_epoch() % 1ms / 1_hns;
+ transfer_hns(TimePoint, UtcTime);
return true;
}
@@ -177,10 +192,8 @@ namespace os::chrono
bool utc_to_local(time_point UtcTime, local_time& LocalTime)
{
- const auto FileTime = nt_clock::to_filetime(UtcTime);
-
SYSTEMTIME SystemTime;
- if (!FileTimeToSystemTime(&FileTime, &SystemTime))
+ if (!timepoint_to_system_time(UtcTime, SystemTime))
return false;
SYSTEMTIME LocalSystemTime;
@@ -189,7 +202,7 @@ namespace os::chrono
LocalTime = local_time{ make_time(LocalSystemTime) };
- LocalTime.Hectonanoseconds += UtcTime.time_since_epoch() % 1ms / 1_hns;
+ transfer_hns(UtcTime, LocalTime);
return true;
}
diff --git a/far/platform.chrono.hpp b/far/platform.chrono.hpp
index 0586a47c7..4154e30b3 100644
--- a/far/platform.chrono.hpp
+++ b/far/platform.chrono.hpp
@@ -97,6 +97,8 @@ namespace os::chrono
uint32_t Hectonanoseconds; // 0 - 9999999
bool operator==(time const&) const = default;
+
+ uint16_t milliseconds() const;
};
namespace detail