[FarGroup/FarManager] master: Refactoring (84f3c607c)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
May 26, 2024, 7:45:44 PMMay 26
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/84f3c607cc388f00e6f51e06f1616695b977bdee

>---------------------------------------------------------------

commit 84f3c607cc388f00e6f51e06f1616695b977bdee
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Mon May 27 00:36:17 2024 +0100

Refactoring


>---------------------------------------------------------------

84f3c607cc388f00e6f51e06f1616695b977bdee
_build/vc/.vsconfig | 1 -
_build/vc/config/common.props | 2 +-
far/components.cpp | 3 +--
far/diskmenu.cpp | 27 +++++++------------
far/fileowner.cpp | 2 +-
far/findfile.cpp | 21 +++++++--------
far/locale.cpp | 48 +++++++++++++++++++++++-----------
far/locale.hpp | 7 +++--
far/main.cpp | 14 ++++++++++
far/pathmix.cpp | 55 +++++++++++++++++++++++---------------
far/pathmix.hpp | 13 ++-------
far/platform.fs.cpp | 61 +++++++++++++++++--------------------------
far/platform.fs.hpp | 12 ---------
far/plugapi.cpp | 2 +-
far/plugins.cpp | 2 +-
far/setattr.cpp | 1 -
far/strmix.cpp | 36 ++++++++++++++++---------
far/strmix.hpp | 2 ++
far/testing.cpp | 2 +-
far/vmenu.cpp | 19 +++++++++-----
20 files changed, 175 insertions(+), 155 deletions(-)

diff --git a/_build/vc/.vsconfig b/_build/vc/.vsconfig
index 96228012a..32f96014c 100644
--- a/_build/vc/.vsconfig
+++ b/_build/vc/.vsconfig
@@ -8,6 +8,5 @@
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
- "Microsoft.VisualStudio.Component.Windows10SDK.18362"
]
}
diff --git a/_build/vc/config/common.props b/_build/vc/config/common.props
index 340c4aeb4..5dcc79fc9 100644
--- a/_build/vc/config/common.props
+++ b/_build/vc/config/common.props
@@ -73,7 +73,7 @@
</ItemGroup>

<PropertyGroup Label="Globals">
- <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformMinVersion>10.0</WindowsTargetPlatformMinVersion>
</PropertyGroup>

<PropertyGroup Label="UserMacros">
diff --git a/far/components.cpp b/far/components.cpp
index 03618cc08..2bb686b68 100644
--- a/far/components.cpp
+++ b/far/components.cpp
@@ -93,8 +93,7 @@ namespace components
static const auto sList = []
{
FN_RETURN_TYPE(GetComponentsInfo) Result;
- const auto& ComponentsList = components_list::instance();
- std::ranges::transform(ComponentsList, std::inserter(Result, Result.end()), [](const auto& i)
+ std::ranges::transform(components_list::instance(), std::inserter(Result, Result.end()), [](const auto& i)
{
return i();
});
diff --git a/far/diskmenu.cpp b/far/diskmenu.cpp
index 8c7d0d394..d180ce48c 100644
--- a/far/diskmenu.cpp
+++ b/far/diskmenu.cpp
@@ -117,23 +117,14 @@ using disk_menu_item = std::variant<disk_item, plugin_item>;
[[nodiscard]]
static bool is_disk(string_view const RootDirectory)
{
- return RootDirectory.size() == L"\\\\?\\C:\\"sv.size();
+ return RootDirectory.size() == L"C:\\"sv.size();
}

[[nodiscard]]
static string_view dos_drive_name(string_view const RootDirectory)
{
if (is_disk(RootDirectory))
- return RootDirectory.substr(L"\\\\?\\"sv.size(), L"C:"sv.size());
-
- return RootDirectory;
-}
-
-[[nodiscard]]
-static string_view dos_drive_root_directory(string_view const RootDirectory)
-{
- if (is_disk(RootDirectory))
- return RootDirectory.substr(L"\\\\?\\"sv.size(), L"C:\\"sv.size());
+ return RootDirectory.substr(0, L"C:"sv.size());

return RootDirectory;
}
@@ -661,7 +652,7 @@ static void RemoveHotplugDevice(panel_ptr Owner, const disk_item& item, VMenu2 &
static string GetShellName(string_view const RootDirectory)
{
return is_disk(RootDirectory)?
- os::com::get_shell_name(dos_drive_root_directory(RootDirectory)) :
+ os::com::get_shell_name(RootDirectory):
L""s;
}

@@ -846,7 +837,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)

for (const auto& i: os::fs::enum_drives(AllDrives))
{
- process_location(os::fs::drive::get_win32nt_root_directory(i));
+ process_location(os::fs::drive::get_root_directory(i));
}

if (DriveMode & DRIVE_SHOW_UNMOUNTED_VOLUMES)
@@ -880,7 +871,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)
{
if (IsDisk)
{
- const auto DiskNumber = os::fs::drive::get_number(i.RootDirectory[L"\\\\?\\"sv.size()]);
+ const auto DiskNumber = os::fs::drive::get_number(i.RootDirectory[0]);

ChDiskItem.SetSelect(static_cast<int>(DiskNumber) == Pos);

@@ -981,7 +972,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)

std::visit(overload{[&](disk_item const& item)
{
- OpenFolderInShell(dos_drive_root_directory(item.Path));
+ OpenFolderInShell(item.Path);
},
[](plugin_item const&){}}, *MenuItem);
break;
@@ -1094,7 +1085,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)
return;

//вызовем EMenu если он есть
- null_terminated const RootDirectory(dos_drive_root_directory(item.Path));
+ null_terminated const RootDirectory(item.Path);
struct DiskMenuParam
{
const wchar_t* CmdLine; BOOL Apps; COORD MousePos;
@@ -1335,7 +1326,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)

const auto IsDisk = is_disk(item.Path);

- while (!(FarChDir(dos_drive_name(item.Path)) || (IsDisk && FarChDir(dos_drive_root_directory(item.Path)))))
+ while (!(FarChDir(dos_drive_name(item.Path)) || (IsDisk && FarChDir(item.Path))))
{
error_state_ex const ErrorState = os::last_error();

@@ -1369,7 +1360,7 @@ static int ChangeDiskMenu(panel_ptr Owner, int Pos, bool FirstCall)
if (Builder.ShowDialog())
{
if (IsDisk)
- item.Path = os::fs::drive::get_win32nt_root_directory(upper(DriveLetter[0]));
+ item.Path = os::fs::drive::get_root_directory(upper(DriveLetter[0]));
}
else
{
diff --git a/far/fileowner.cpp b/far/fileowner.cpp
index d85097616..c83d8903a 100644
--- a/far/fileowner.cpp
+++ b/far/fileowner.cpp
@@ -276,7 +276,7 @@ bool SetOwnerInternal(const string& Object, const string& Owner)

bool SetFileOwner(string_view const Object, const string& Owner)
{
- const NTPath NtObject(Object);
+ const auto NtObject = NTPath(Object);

if (SetOwnerInternal(NtObject, Owner))
return true;
diff --git a/far/findfile.cpp b/far/findfile.cpp
index cd302e7be..672a2533b 100644
--- a/far/findfile.cpp
+++ b/far/findfile.cpp
@@ -2915,13 +2915,16 @@ bool FindFiles::FindFilesProcess()
}
else
{
- size_t Length=strFileName.size();
-
- if (!Length)
+ if (strFileName.empty())
break;

- if (Length>1 && path::is_separator(strFileName[Length-1]) && strFileName[Length-2] != L':')
- strFileName.pop_back();
+ const auto remove_trailing_slash_if_not_root = [](string& Path)
+ {
+ if (Path.size() > 1 && path::is_separator(Path.back()) && Path[Path.size() - 2] != L':')
+ Path.pop_back();
+ };
+
+ remove_trailing_slash_if_not_root(strFileName);

if (!os::fs::exists(strFileName) && (GetLastError() != ERROR_ACCESS_DENIED))
break;
@@ -2938,10 +2941,8 @@ bool FindFiles::FindFilesProcess()
}

strFileName.resize(strFileName.size() - NamePtr.size());
- Length=strFileName.size();

- if (Length>1 && path::is_separator(strFileName[Length-1]) && strFileName[Length-2] != L':')
- strFileName.pop_back();
+ remove_trailing_slash_if_not_root(strFileName);

if (strFileName.empty())
break;
@@ -2960,10 +2961,8 @@ bool FindFiles::FindFilesProcess()
// ! Не меняем каталог, если мы уже в нем находимся.
// Тем самым добиваемся того, что выделение с элементов панели не сбрасывается.
string strDirTmp = FindPanel->GetCurDir();
- Length=strDirTmp.size();

- if (Length>1 && path::is_separator(strDirTmp[Length-1]) && strDirTmp[Length-2] != L':')
- strDirTmp.pop_back();
+ remove_trailing_slash_if_not_root(strDirTmp);

if (!equal_icase(strFileName, strDirTmp))
FindPanel->SetCurDir(strFileName,true);
diff --git a/far/locale.cpp b/far/locale.cpp
index fc97e433c..9f6914ac2 100644
--- a/far/locale.cpp
+++ b/far/locale.cpp
@@ -286,6 +286,30 @@ static auto get_month_day_names(int const Language)

namespace detail
{
+ locale::locale(bool const Invariant):
+ m_IsInvariant(Invariant)
+ {
+ if (m_IsInvariant)
+ {
+ m_IsCJK = false;
+ m_DateFormat = date_type::mdy;
+ m_DigitsGrouping = 3;
+ m_DateSeparator = L'/';
+ m_TimeSeparator = L':';
+ m_DecimalSeparator = L'.';
+ m_ThousandSeparator = L',';
+
+ m_LocalNames = m_EnglishNames = get_month_day_names(LANG_ENGLISH);
+
+ m_Valid = true;
+ }
+ }
+
+ bool locale::is_invariant() const
+ {
+ return m_IsInvariant;
+ }
+
bool locale::is_cjk() const
{
refresh();
@@ -348,6 +372,9 @@ namespace detail

void locale::invalidate()
{
+ if (m_IsInvariant)
+ return;
+
m_Valid = false;

if (Global)
@@ -358,7 +385,7 @@ namespace detail

void locale::refresh() const
{
- if (m_Valid)
+ if (m_Valid || m_IsInvariant)
return;

m_IsCJK = get_is_cjk();
@@ -374,19 +401,10 @@ namespace detail

m_Valid = true;
}
+}

- void locale::invariant()
- {
- m_IsCJK = false;
- m_DateFormat = date_type::mdy;
- m_DigitsGrouping = 3;
- m_DateSeparator = L'/';
- m_TimeSeparator = L':';
- m_DecimalSeparator = L'.';
- m_ThousandSeparator = L',';
-
- m_LocalNames = m_EnglishNames = get_month_day_names(LANG_ENGLISH);
-
- m_Valid = true;
- }
+detail::locale const& invariant_locale()
+{
+ static const detail::locale s_InvariantLocale(true);
+ return s_InvariantLocale;
}
diff --git a/far/locale.hpp b/far/locale.hpp
index 3d2550b1f..9a78c96e2 100644
--- a/far/locale.hpp
+++ b/far/locale.hpp
@@ -68,8 +68,9 @@ namespace detail
class locale
{
public:
- locale() = default;
+ explicit locale(bool Invariant = false);

+ bool is_invariant() const;
bool is_cjk() const;
date_type date_format() const;
unsigned digits_grouping() const;
@@ -81,11 +82,11 @@ namespace detail
const locale_names& EnglishNames() const;
const locale_names& Names(bool Local) const;
void invalidate();
- void invariant();

private:
void refresh() const;

+ bool m_IsInvariant;
mutable bool m_IsCJK{};
mutable date_type m_DateFormat{ date_type::mdy };
mutable unsigned m_DigitsGrouping{};
@@ -102,4 +103,6 @@ namespace detail

NIFTY_DECLARE(detail::locale, locale);

+detail::locale const& invariant_locale();
+
#endif // LOCALE_HPP_C358EF79_F894_425E_B689_C4F4131DBE76
diff --git a/far/main.cpp b/far/main.cpp
index db118faa5..936faab40 100644
--- a/far/main.cpp
+++ b/far/main.cpp
@@ -964,6 +964,10 @@ static void handle_exception_final(function_ref<bool()> const Handler)
throw;
}

+#ifdef _DEBUG
+static void premain();
+#endif
+
static int wmain_seh()
{
os::set_error_mode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX);
@@ -988,6 +992,10 @@ static int wmain_seh()
}
#endif

+#ifdef _DEBUG
+ premain();
+#endif
+
#ifdef __SANITIZE_ADDRESS__
os::env::set(L"ASAN_VCASAN_DEBUGGING"sv, L"1"sv);
#endif
@@ -1166,3 +1174,9 @@ TEST_CASE("Args")
}
}
#endif
+
+#ifdef _DEBUG
+static void premain()
+{
+}
+#endif
diff --git a/far/pathmix.cpp b/far/pathmix.cpp
index 17e284c8c..243dfbc25 100644
--- a/far/pathmix.cpp
+++ b/far/pathmix.cpp
@@ -57,31 +57,44 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------------

-void NTPath::Transform()
+string NTPath(string Path)
{
- string& Data = *this;
- if (!Data.empty())
+ if (Path.empty())
+ return Path;
+
+ if(!HasPathPrefix(Path))
{
- if(!HasPathPrefix(Data))
- {
- Data = ConvertNameToFull(Data);
-
- if (!HasPathPrefix(Data))
- {
- ReplaceSlashToBackslash(Data);
- const auto Prefix = ParsePath(Data) == root_type::drive_letter? L"\\\\?\\"sv : L"\\\\?\\UNC"sv;
- remove_duplicates(Data, path::separator);
- Data.insert(0, Prefix);
- }
- }
- static const bool is_win2k = !IsWindowsXPOrGreater();
- if(is_win2k && Data.size() > 5 && Data[5] == L':')
+ Path = ConvertNameToFull(Path);
+
+ if (!HasPathPrefix(Path))
{
- // "\\?\C:" -> "\\?\c:"
- // Some file operations fail on Win2k if a drive letter is in upper case
- inplace::lower(Data, 4, 1);
+ ReplaceSlashToBackslash(Path);
+
+ const auto RootType = ParsePath(Path);
+ if (RootType == root_type::unknown)
+ return Path;
+
+ const auto Prefix = ParsePath(Path) == root_type::drive_letter? L"\\\\?\\"sv : L"\\\\?\\UNC"sv;
+ remove_duplicates(Path, path::separator);
+ Path.insert(0, Prefix);
}
}
+
+ static const bool is_win2k = !IsWindowsXPOrGreater();
+
+ if(is_win2k && Path.size() > 5 && Path[5] == L':')
+ {
+ // "\\?\C:" -> "\\?\c:"
+ // Some file operations fail on Win2k if a drive letter is in upper case
+ inplace::lower(Path, 4, 1);
+ }
+
+ return Path;
+}
+
+string NTPath(string_view const Path)
+{
+ return NTPath(string(Path));
}

string KernelPath(string_view const NtPath)
@@ -102,7 +115,7 @@ string KernelPath(string NtPath)
root_type ParsePath(const string_view Path, size_t* const RootSize, bool* const RootOnly)
{
// Do not use regex::icase here.
- // The case-insensitive data is minimal here ("unc" / "volume{hex}" / "pipe") and ASCII by definition.
+ // The case-insensitive data is minimal here ("unc" / "volume{hex}") and ASCII by definition.
// Doing it manually should be way faster than letting wregex delegate it to OS locale facilities.
const auto re = [](const wchar_t* const Str) { return std::wregex(Str, std::regex::optimize); };

diff --git a/far/pathmix.hpp b/far/pathmix.hpp
index 374feb396..6600413b2 100644
--- a/far/pathmix.hpp
+++ b/far/pathmix.hpp
@@ -130,17 +130,8 @@ namespace path
}
}

-class NTPath:public string
-{
- void Transform();
-public:
- explicit(false) NTPath(const string_view Src):
- string(Src)
- {
- Transform();
- }
-};
-
+string NTPath(string_view Path);
+string NTPath(string Path);

string KernelPath(string_view NtPath);
string KernelPath(string NtPath);
diff --git a/far/platform.fs.cpp b/far/platform.fs.cpp
index 197d9e40b..0bd29dbf6 100644
--- a/far/platform.fs.cpp
+++ b/far/platform.fs.cpp
@@ -150,12 +150,6 @@ namespace os::fs
LOGWARNING(L"FindVolumeClose(): {}"sv, last_error());
}

- void find_notification_handle_closer::operator()(HANDLE Handle) const noexcept
- {
- if (!FindCloseChangeNotification(Handle))
- LOGWARNING(L"FindCloseChangeNotification(): {}"sv, last_error());
- }
-
void find_nt_handle_closer::operator()(HANDLE const Handle) const noexcept
{
if (const auto Status = imports.NtClose(Handle); !NT_SUCCESS(Status))
@@ -244,7 +238,7 @@ namespace os::fs
return GetDriveType(get_root_directory(PathType == root_type::drive_letter? Path[0] : Path[4]).c_str());
}

- NTPath NtPath(Path.empty()? os::fs::get_current_directory() : Path);
+ auto NtPath = NTPath(Path.empty()? os::fs::get_current_directory() : Path);
AddEndSlash(NtPath);

return GetDriveType(NtPath.c_str());
@@ -548,7 +542,7 @@ namespace os::fs
if (!imports.FindFirstFileNameW)
return {};

- const NTPath NtFileName(FileName);
+ const auto NtFileName = NTPath(FileName);
find_handle Handle;
// BUGBUG check result
(void)os::detail::ApiDynamicStringReceiver(LinkName, [&](std::span<wchar_t> Buffer)
@@ -1847,7 +1841,7 @@ namespace os::fs

bool create_directory(const string_view TemplateDirectory, const string_view NewDirectory, SECURITY_ATTRIBUTES* SecurityAttributes)
{
- const NTPath NtNewDirectory(NewDirectory);
+ const auto NtNewDirectory = NTPath(NewDirectory);

const auto Create = [&](const string& Template)
{
@@ -1879,7 +1873,7 @@ namespace os::fs

bool remove_directory(const string_view DirName)
{
- const NTPath strNtName(DirName);
+ const auto strNtName = NTPath(DirName);
if (low::remove_directory(strNtName.c_str()))
return true;

@@ -1900,7 +1894,7 @@ namespace os::fs

handle create_file(const string_view Object, const DWORD DesiredAccess, const DWORD ShareMode, SECURITY_ATTRIBUTES* SecurityAttributes, const DWORD CreationDistribution, DWORD FlagsAndAttributes, HANDLE TemplateFile, const bool ForceElevation)
{
- const NTPath strObject(Object);
+ const auto strObject = NTPath(Object);
FlagsAndAttributes |= FILE_FLAG_BACKUP_SEMANTICS;
if (CreationDistribution == OPEN_EXISTING || CreationDistribution == TRUNCATE_EXISTING)
{
@@ -1941,7 +1935,7 @@ namespace os::fs

bool delete_file(const string_view FileName)
{
- const NTPath strNtName(FileName);
+ const auto strNtName = NTPath(FileName);

if (low::delete_file(strNtName.c_str()))
return true;
@@ -1987,8 +1981,8 @@ namespace os::fs

bool copy_file(const string_view ExistingFileName, const string_view NewFileName, progress_routine ProgressRoutine, BOOL* const Cancel, const DWORD CopyFlags)
{
- const NTPath strFrom(ExistingFileName);
- NTPath strTo(NewFileName);
+ const auto strFrom = NTPath(ExistingFileName);
+ auto strTo = NTPath(NewFileName);

if (path::is_separator(strTo.back()))
{
@@ -2023,8 +2017,8 @@ namespace os::fs

bool move_file(const string_view ExistingFileName, const string_view NewFileName, const DWORD Flags)
{
- const NTPath strFrom(ExistingFileName);
- NTPath strTo(NewFileName);
+ const auto strFrom = NTPath(ExistingFileName);
+ auto strTo = NTPath(NewFileName);

if (path::is_separator(strTo.back()))
{
@@ -2061,7 +2055,10 @@ namespace os::fs

bool replace_file(string_view ReplacedFileName, string_view ReplacementFileName, string_view BackupFileName, DWORD Flags)
{
- const NTPath To(ReplacedFileName), From(ReplacementFileName), Backup(BackupFileName);
+ const auto
+ To = NTPath(ReplacedFileName),
+ From = NTPath(ReplacementFileName),
+ Backup = NTPath(BackupFileName);

if (low::replace_file(To.c_str(), From.c_str(), Backup.c_str(), Flags))
return true;
@@ -2075,7 +2072,7 @@ namespace os::fs

attributes get_file_attributes(const string_view FileName)
{
- const NTPath NtName(FileName);
+ const auto NtName = NTPath(FileName);

const auto Result = low::get_file_attributes(NtName.c_str());
if (Result != INVALID_FILE_ATTRIBUTES)
@@ -2089,7 +2086,7 @@ namespace os::fs

bool set_file_attributes(string_view const FileName, attributes const Attributes)
{
- const NTPath NtName(FileName);
+ const auto NtName = NTPath(FileName);

if (low::set_file_attributes(NtName.c_str(), Attributes))
return true;
@@ -2144,7 +2141,7 @@ namespace os::fs
bool GetVolumeNameForVolumeMountPoint(string_view const VolumeMountPoint, string& VolumeName)
{
wchar_t VolumeNameBuffer[50];
- NTPath strVolumeMountPoint(VolumeMountPoint);
+ auto strVolumeMountPoint = NTPath(VolumeMountPoint);
AddEndSlash(strVolumeMountPoint);
if (!::GetVolumeNameForVolumeMountPoint(strVolumeMountPoint.c_str(), VolumeNameBuffer, static_cast<DWORD>(std::size(VolumeNameBuffer))))
return false;
@@ -2238,7 +2235,7 @@ namespace os::fs

security::descriptor get_file_security(const string_view Object, const SECURITY_INFORMATION RequestedInformation)
{
- NTPath const NtObject(Object);
+ const auto NtObject = NTPath(Object);

if (auto Result = low::get_file_security(NtObject.c_str(), RequestedInformation))
return Result;
@@ -2251,7 +2248,7 @@ namespace os::fs

bool set_file_security(const string_view Object, const SECURITY_INFORMATION RequestedInformation, const security::descriptor& SecurityDescriptor)
{
- NTPath const NtObject(Object);
+ const auto NtObject = NTPath(Object);

if (low::set_file_security(NtObject.c_str(), RequestedInformation, SecurityDescriptor.data()))
return true;
@@ -2264,7 +2261,7 @@ namespace os::fs

bool reset_file_security(string_view const Object)
{
- NTPath const NtObject(Object);
+ const auto NtObject = NTPath(Object);
if (low::reset_file_security(NtObject.c_str()))
return true;

@@ -2287,7 +2284,7 @@ namespace os::fs

bool get_disk_size(const string_view Path, unsigned long long* const UserTotal, unsigned long long* const TotalFree, unsigned long long* const UserFree)
{
- NTPath strPath(Path);
+ auto strPath = NTPath(Path);
AddEndSlash(strPath);

if (low::get_disk_free_space(strPath.c_str(), UserFree, UserTotal, TotalFree))
@@ -2349,16 +2346,6 @@ namespace os::fs
return true;
}

- find_notification_handle find_first_change_notification(const string_view PathName, bool WatchSubtree, DWORD NotifyFilter)
- {
- return find_notification_handle(::FindFirstChangeNotification(NTPath(PathName).c_str(), WatchSubtree, NotifyFilter));
- }
-
- bool find_next_change_notification(find_notification_handle const& Handle)
- {
- return FindNextChangeNotification(Handle.native_handle()) != FALSE;
- }
-
bool IsDiskInDrive(string_view const Root)
{
string strDrive(Root);
@@ -2391,7 +2378,7 @@ namespace os::fs

bool CreateSymbolicLink(string_view const SymlinkFileName, string_view const TargetFileName, DWORD Flags)
{
- const NTPath NtSymlinkFileName(SymlinkFileName);
+ const auto NtSymlinkFileName = NTPath(SymlinkFileName);

if (CreateSymbolicLinkInternal(NtSymlinkFileName, TargetFileName, Flags))
return true;
@@ -2404,7 +2391,7 @@ namespace os::fs

bool set_file_encryption(const string_view FileName, const bool Encrypt)
{
- const NTPath NtName(FileName);
+ const auto NtName = NTPath(FileName);

if (low::set_file_encryption(NtName.c_str(), Encrypt))
return true;
@@ -2417,7 +2404,7 @@ namespace os::fs

bool detach_virtual_disk(const string_view Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType)
{
- const NTPath NtObject(Object);
+ const auto NtObject = NTPath(Object);

if (low::detach_virtual_disk(NtObject.c_str(), VirtualStorageType))
return true;
diff --git a/far/platform.fs.hpp b/far/platform.fs.hpp
index 8bb923645..4867602e5 100644
--- a/far/platform.fs.hpp
+++ b/far/platform.fs.hpp
@@ -67,11 +67,6 @@ namespace os::fs
void operator()(HANDLE Handle) const noexcept;
};

- struct find_notification_handle_closer
- {
- void operator()(HANDLE Handle) const noexcept;
- };
-
struct find_nt_handle_closer
{
void operator()(HANDLE Handle) const noexcept;
@@ -86,7 +81,6 @@ namespace os::fs
using find_handle = os::detail::handle_t<detail::find_handle_closer>;
using find_file_handle = os::detail::handle_t<detail::find_file_handle_closer>;
using find_volume_handle = os::detail::handle_t<detail::find_volume_handle_closer>;
- using find_notification_handle = os::detail::handle_t<detail::find_notification_handle_closer>;
using find_nt_handle = os::detail::handle_t<detail::find_nt_handle_closer>;

using drives_set = std::bitset<26>;
@@ -620,12 +614,6 @@ namespace os::fs
[[nodiscard]]
bool get_find_data(string_view FileName, find_data& FindData, bool ScanSymLink = true);

- [[nodiscard]]
- find_notification_handle find_first_change_notification(string_view PathName, bool WatchSubtree, DWORD NotifyFilter);
-
- [[nodiscard]]
- bool find_next_change_notification(find_notification_handle const& Handle);
-
[[nodiscard]]
bool IsDiskInDrive(string_view Root);

diff --git a/far/plugapi.cpp b/far/plugapi.cpp
index ae2e56361..d7d20935b 100644
--- a/far/plugapi.cpp
+++ b/far/plugapi.cpp
@@ -2127,7 +2127,7 @@ static size_t WINAPI apiConvertPath(CONVERTPATHMODES Mode, const wchar_t *Src, w
switch (Mode)
{
case CPM_NATIVE:
- strDest=NTPath(Src);
+ strDest = NTPath(string_view{ Src });
break;

case CPM_REAL:
diff --git a/far/plugins.cpp b/far/plugins.cpp
index ecee2f818..b271616a5 100644
--- a/far/plugins.cpp
+++ b/far/plugins.cpp
@@ -2415,7 +2415,7 @@ void PluginManager::GetContentData(
unordered_string_map<string>& ContentData
) const
{
- const NTPath Path(FilePath);
+ const auto Path = NTPath(FilePath);
const auto Count = ColNames.size();

for (const auto& i: Plugins)
diff --git a/far/setattr.cpp b/far/setattr.cpp
index 4ff627684..8a1790ff7 100644
--- a/far/setattr.cpp
+++ b/far/setattr.cpp
@@ -1126,7 +1126,6 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object)
SrcPanel->GetCurDir() :
ConvertNameToFull(SingleSelFileName));

- // BANANA
GetFileOwner(ComputerName, SingleSelFileName, DlgParam.Owner.InitialValue);
}
else
diff --git a/far/strmix.cpp b/far/strmix.cpp
index b3ed77a57..5781173c0 100644
--- a/far/strmix.cpp
+++ b/far/strmix.cpp
@@ -62,10 +62,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------------

-string GroupDigits(unsigned long long Value)
+static auto GroupDigitsImpl(unsigned long long Value, detail::locale const& Locale)
{
- wchar_t DecimalSeparator[]{ locale.decimal_separator(), L'\0' };
- wchar_t ThousandSeparator[]{ locale.thousand_separator(), L'\0' };
+ wchar_t DecimalSeparator[]{ Locale.decimal_separator(), L'\0' };
+ wchar_t ThousandSeparator[]{ Locale.thousand_separator(), L'\0' };

NUMBERFMT const Fmt
{
@@ -73,7 +73,7 @@ string GroupDigits(unsigned long long Value)
.NumDigits = 0,
// Don't care - can't be decimal
.LeadingZero = 1,
- .Grouping = locale.digits_grouping(),
+ .Grouping = Locale.digits_grouping(),
.lpDecimalSep = DecimalSeparator,
.lpThousandSep = ThousandSeparator,
// Don't care - can't be negative
@@ -93,6 +93,16 @@ string GroupDigits(unsigned long long Value)
return Src;
}

+string GroupDigits(unsigned long long Value)
+{
+ return GroupDigitsImpl(Value, locale);
+}
+
+string GroupDigitsInvariant(unsigned long long Value)
+{
+ return GroupDigitsImpl(Value, invariant_locale());
+}
+
static wchar_t* legacy_InsertQuotes(wchar_t *Str)
{
const auto QuoteChar = L'"';
@@ -371,12 +381,14 @@ void PrepareUnitStr()
}
}

-static string FileSizeToStrImpl(unsigned long long const FileSize, int const WidthWithSign, unsigned long long const ViewFlags, bool const Localized)
+static string FileSizeToStrImpl(unsigned long long const FileSize, int const WidthWithSign, unsigned long long const ViewFlags, detail::locale const& Locale)
{
- if (Localized && !UnitSymbol[id::localized][0][0])
+ const auto IsInvariantLocale = Locale.is_invariant();
+
+ if (!IsInvariantLocale && !UnitSymbol[id::localized][0][0])
PrepareUnitStr();

- const auto& Symbol = UnitSymbol[Localized? id::localized : id::invariant];
+ const auto& Symbol = UnitSymbol[IsInvariantLocale? id::invariant : id::localized];
const size_t Width = std::abs(WidthWithSign);
const bool LeftAlign = WidthWithSign < 0;
const bool UseGroupDigits = (ViewFlags & COLFLAGS_GROUPDIGITS) != 0;
@@ -454,7 +466,7 @@ static string FileSizeToStrImpl(unsigned long long const FileSize, int const Wid
return RoundedFractionalDigits == Multiplier? std::pair(RawIntegral + 1, 0u) : std::pair(RawIntegral, RoundedFractionalDigits);
}();

- Str = concat(str(IntegralPart), locale.decimal_separator(), pad_left(str(FractionalPart), NumDigits, L'0'));
+ Str = concat(str(IntegralPart), Locale.decimal_separator(), pad_left(str(FractionalPart), NumDigits, L'0'));
}
else
{
@@ -465,9 +477,9 @@ static string FileSizeToStrImpl(unsigned long long const FileSize, int const Wid
return FormatSize(std::move(Str), UnitIndex);
}

- const auto ToStr = [UseGroupDigits](auto Size)
+ const auto ToStr = [&](auto Size)
{
- return UseGroupDigits? GroupDigits(Size) : str(Size);
+ return UseGroupDigits? GroupDigitsImpl(Size, Locale) : str(Size);
};

size_t UnitIndex = 0;
@@ -497,12 +509,12 @@ static string FileSizeToStrImpl(unsigned long long const FileSize, int const Wid

string FileSizeToStr(unsigned long long FileSize, int WidthWithSign, unsigned long long ViewFlags)
{
- return FileSizeToStrImpl(FileSize, WidthWithSign, ViewFlags, true);
+ return FileSizeToStrImpl(FileSize, WidthWithSign, ViewFlags, locale);
}

string FileSizeToStrInvariant(unsigned long long FileSize, int WidthWithSign, unsigned long long ViewFlags)
{
- return FileSizeToStrImpl(FileSize, WidthWithSign, ViewFlags, false);
+ return FileSizeToStrImpl(FileSize, WidthWithSign, ViewFlags, invariant_locale());
}

// Заменить в строке Str Count вхождений подстроки FindStr на подстроку ReplStr
diff --git a/far/strmix.hpp b/far/strmix.hpp
index 513dc6db1..c07ebc9e7 100644
--- a/far/strmix.hpp
+++ b/far/strmix.hpp
@@ -148,6 +148,8 @@ string ReplaceBrackets(string_view SearchStr, string_view ReplaceStr, std::span<

[[nodiscard]]
string GroupDigits(unsigned long long Value);
+[[nodiscard]]
+string GroupDigitsInvariant(unsigned long long Value);

[[nodiscard]]
inline bool IsWordDiv(string_view const WordDiv, wchar_t const Chr)
diff --git a/far/testing.cpp b/far/testing.cpp
index 206b1b914..5e0dd7454 100644
--- a/far/testing.cpp
+++ b/far/testing.cpp
@@ -136,7 +136,7 @@ std::optional<int> testing_main(std::span<wchar_t const* const> const Args)
NewArgs.emplace_back(L"--warn");
NewArgs.emplace_back(L"NoAssertions");

- locale.invariant();
+ locale = invariant_locale();

return Catch::Session().run(static_cast<int>(NewArgs.size()), NewArgs.data());
}
diff --git a/far/vmenu.cpp b/far/vmenu.cpp
index 681411a6b..73094572e 100644
--- a/far/vmenu.cpp
+++ b/far/vmenu.cpp
@@ -2726,13 +2726,20 @@ void VMenu::AssignHighlights(bool Reverse)

const auto Delta = Reverse? -1 : 1;

- const auto RegisterHotkey = [&Used](wchar_t Hotkey)
+ const auto RegisterHotkey = [&](wchar_t const Hotkey)
{
+ const auto Upper = upper(Hotkey);
+ if (Used[Upper])
+ return false;
+
+ Used[Upper] = true;
+ Used[lower(Hotkey)] = true;
+
const auto OtherHotkey = KeyToKeyLayout(Hotkey);
Used[upper(OtherHotkey)] = true;
Used[lower(OtherHotkey)] = true;
- Used[upper(Hotkey)] = true;
- Used[lower(Hotkey)] = true;
+
+ return true;
};

const auto ShowAmpersand = CheckFlags(VMENU_SHOWAMPERSAND);
@@ -2742,9 +2749,8 @@ void VMenu::AssignHighlights(bool Reverse)
wchar_t Hotkey{};
size_t HotkeyVisualPos{};
// TODO: проверка на LIF_HIDDEN
- if (!ShowAmpersand && HiTextHotkey(Items[I].Name, Hotkey, &HotkeyVisualPos) && !Used[upper(Hotkey)] && !Used[lower(Hotkey)])
+ if (!ShowAmpersand && HiTextHotkey(Items[I].Name, Hotkey, &HotkeyVisualPos) && RegisterHotkey(Hotkey))
{
- RegisterHotkey(Hotkey);
Items[I].AutoHotkey = Hotkey;
Items[I].AutoHotkeyPos = HotkeyVisualPos;
}
@@ -2763,9 +2769,8 @@ void VMenu::AssignHighlights(bool Reverse)
// TODO: проверка на LIF_HIDDEN
for (const auto& Ch: MenuItemForDisplay)
{
- if ((Ch == L'&' || is_alpha(Ch) || std::iswdigit(Ch)) && !Used[upper(Ch)] && !Used[lower(Ch)])
+ if ((Ch == L'&' || is_alpha(Ch) || std::iswdigit(Ch)) && RegisterHotkey(Ch))
{
- RegisterHotkey(Ch);
Items[I].AutoHotkey = Ch;
Items[I].AutoHotkeyPos = &Ch - MenuItemForDisplay.data();
break;


Reply all
Reply to author
Forward
0 new messages