[FarGroup/FarManager] master: Refactoring (2b82b574f)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
May 12, 2026, 4:30:55 PMMay 12
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/2b82b574fd0ab6b1f3a327565dd8b933c79ae665

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

commit 2b82b574fd0ab6b1f3a327565dd8b933c79ae665
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Tue May 12 21:19:25 2026 +0100

Refactoring


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

2b82b574fd0ab6b1f3a327565dd8b933c79ae665
far/elevation.cpp | 10 ++--------
far/main.cpp | 3 +++
far/platform.concurrency.cpp | 4 +---
far/platform.fs.hpp | 2 +-
far/platform.security.cpp | 13 +++++++++----
far/platform.security.hpp | 3 +++
far/print.cpp | 7 +++++--
far/vc_crt_fix_impl.cpp | 15 ++++++++++++---
plugins/common/vc_crt_fix_impl.cpp | 15 ++++++++++++---
9 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/far/elevation.cpp b/far/elevation.cpp
index 89282cf80..7d98247f6 100644
--- a/far/elevation.cpp
+++ b/far/elevation.cpp
@@ -316,12 +316,6 @@ auto elevation::execute(lng Why, string_view const Object, auto Fallback, const
}
}

-static auto make_admin_sid()
-{
- SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
- return os::security::make_sid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS);
-}
-
static auto make_explicit_admin_access(os::security::sid_ptr const& AdminSid)
{
EXPLICIT_ACCESS Access{};
@@ -349,7 +343,7 @@ static os::handle create_named_pipe(string_view const Name)
if (!InitializeSecurityDescriptor(&SD, SECURITY_DESCRIPTOR_REVISION))
return nullptr;

- const auto AdminSid = make_admin_sid();
+ const auto AdminSid = os::security::make_admin_sid();
if (!AdminSid)
return nullptr;

@@ -378,7 +372,7 @@ static bool grant_duplicate_handle()
return false;
}

- const auto AdminSid = make_admin_sid();
+ const auto AdminSid = os::security::make_admin_sid();
if (!AdminSid)
return false;

diff --git a/far/main.cpp b/far/main.cpp
index 9e44dccc5..f8ba93367 100644
--- a/far/main.cpp
+++ b/far/main.cpp
@@ -862,6 +862,9 @@ static void parse_command_line(std::span<const wchar_t* const> const Args, std::

static void register_restart(bool const HasArgs)
{
+ if (!imports.RegisterApplicationRestart)
+ return;
+
const auto Args = HasArgs? []
{
const auto CommandLine = GetCommandLine();
diff --git a/far/platform.concurrency.cpp b/far/platform.concurrency.cpp
index 68692eba7..0e8110841 100644
--- a/far/platform.concurrency.cpp
+++ b/far/platform.concurrency.cpp
@@ -102,9 +102,7 @@ namespace os::concurrency
finalise();

handle::operator=(std::move(rhs));
-
- m_ThreadId = rhs.m_ThreadId;
- rhs.m_ThreadId = {};
+ m_ThreadId = std::exchange(rhs.m_ThreadId, 0);

return *this;
}
diff --git a/far/platform.fs.hpp b/far/platform.fs.hpp
index 871315689..b18ceb7e3 100644
--- a/far/platform.fs.hpp
+++ b/far/platform.fs.hpp
@@ -78,7 +78,7 @@ namespace os::fs
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 drives_set = std::bitset<26>;
+ using drives_set = std::bitset<'Z' - 'A' + 1>;

using security_descriptor = block_ptr<SECURITY_DESCRIPTOR, default_buffer_size>;

diff --git a/far/platform.security.cpp b/far/platform.security.cpp
index d2ebc6541..e7ab02237 100644
--- a/far/platform.security.cpp
+++ b/far/platform.security.cpp
@@ -93,6 +93,12 @@ namespace os::security
return sid_ptr(AllocateAndInitializeSid(IdentifierAuthority, SubAuthorityCount, SubAuthority0, SubAuthority1, SubAuthority2, SubAuthority3, SubAuthority4, SubAuthority5, SubAuthority6, SubAuthority7, &Sid)? Sid : nullptr);
}

+ sid_ptr make_admin_sid()
+ {
+ SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
+ return make_sid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS);
+ }
+
bool is_admin()
{
static const auto Result = []
@@ -104,13 +110,12 @@ namespace os::security
return Elevation.TokenIsElevated != 0;

// Old method
- SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
- const auto AdministratorsGroup = make_sid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS);
- if (!AdministratorsGroup)
+ const auto AdminSid = make_admin_sid();
+ if (!AdminSid)
return false;

BOOL IsMember;
- return CheckTokenMembership(nullptr, AdministratorsGroup.get(), &IsMember) && IsMember;
+ return CheckTokenMembership(nullptr, AdminSid.get(), &IsMember) && IsMember;
}();

return Result;
diff --git a/far/platform.security.hpp b/far/platform.security.hpp
index 2bb8e69b1..e79df4c59 100644
--- a/far/platform.security.hpp
+++ b/far/platform.security.hpp
@@ -62,6 +62,9 @@ namespace os::security
[[nodiscard]]
sid_ptr make_sid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, BYTE SubAuthorityCount, DWORD SubAuthority0 = 0, DWORD SubAuthority1 = 0, DWORD SubAuthority2 = 0, DWORD SubAuthority3 = 0, DWORD SubAuthority4 = 0, DWORD SubAuthority5 = 0, DWORD SubAuthority6 = 0, DWORD SubAuthority7 = 0);

+ [[nodiscard]]
+ sid_ptr make_admin_sid();
+
[[nodiscard]]
bool is_admin();

diff --git a/far/print.cpp b/far/print.cpp
index e2ff1505b..c3155e3c3 100644
--- a/far/print.cpp
+++ b/far/print.cpp
@@ -116,14 +116,17 @@ void PrintFiles(FileList* SrcPanel)
if (DirsCount == SelCount)
return;

- block_ptr<PRINTER_INFO_4, os::default_buffer_size> pi(os::default_buffer_size);
+#define PRINTER_INFO_LEVEL 4
+#define PRINTER_INFO(n) CONCATENATE(PRINTER_INFO_, n)
+
+ block_ptr<PRINTER_INFO(PRINTER_INFO_LEVEL), os::default_buffer_size> pi(os::default_buffer_size);

DWORD Needed = 0, PrintersCount = 0;

while (!EnumPrinters(
PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
nullptr,
- 4,
+ PRINTER_INFO_LEVEL,
std::bit_cast<BYTE*>(pi.data()),
static_cast<DWORD>(pi.size()),
&Needed,
diff --git a/far/vc_crt_fix_impl.cpp b/far/vc_crt_fix_impl.cpp
index 6b6a55d83..43a7e21d7 100644
--- a/far/vc_crt_fix_impl.cpp
+++ b/far/vc_crt_fix_impl.cpp
@@ -257,10 +257,19 @@ extern "C" BOOL WINAPI WRAPPER(GetLogicalProcessorInformation)(PSYSTEM_LOGICAL_P
{
struct implementation
{
- static BOOL WINAPI impl(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD)
+ static BOOL WINAPI impl(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Info, PDWORD Size)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ if (*Size < sizeof(*Info))
+ {
+ *Size = sizeof(*Info);
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
+ *Info = {};
+ Info->ProcessorMask = 1;
+ Info->Relationship = RelationProcessorCore;
+ return TRUE;
}
};

diff --git a/plugins/common/vc_crt_fix_impl.cpp b/plugins/common/vc_crt_fix_impl.cpp
index 6b6a55d83..43a7e21d7 100644
--- a/plugins/common/vc_crt_fix_impl.cpp
+++ b/plugins/common/vc_crt_fix_impl.cpp
@@ -257,10 +257,19 @@ extern "C" BOOL WINAPI WRAPPER(GetLogicalProcessorInformation)(PSYSTEM_LOGICAL_P
{
struct implementation
{
- static BOOL WINAPI impl(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD)
+ static BOOL WINAPI impl(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Info, PDWORD Size)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ if (*Size < sizeof(*Info))
+ {
+ *Size = sizeof(*Info);
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return FALSE;
+ }
+
+ *Info = {};
+ Info->ProcessorMask = 1;
+ Info->Relationship = RelationProcessorCore;
+ return TRUE;
}
};



Reply all
Reply to author
Forward
0 new messages