[FarGroup/FarManager] master: Autorestart when appropriate (9b5a21d75)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 13, 2026, 4:46:12 PM (3 days ago) Apr 13
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/9b5a21d7525a816358f3aec20d675f20db3c757e

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

commit 9b5a21d7525a816358f3aec20d675f20db3c757e
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Mon Apr 13 21:38:51 2026 +0100

Autorestart when appropriate


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

9b5a21d7525a816358f3aec20d675f20db3c757e
far/imports.hpp | 1 +
far/main.cpp | 17 +++++++++++++++++
2 files changed, 18 insertions(+)

diff --git a/far/imports.hpp b/far/imports.hpp
index f5f7696b3..8ffd732e8 100644
--- a/far/imports.hpp
+++ b/far/imports.hpp
@@ -160,6 +160,7 @@ public: \
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); // Vista
+ DEFINE_IMPORT_FUNCTION(kernel32, nop, hr, WINAPI, HRESULT, RegisterApplicationRestart, PCWSTR Commandline, DWORD Flags); // 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
diff --git a/far/main.cpp b/far/main.cpp
index 6a5733976..ed88b5652 100644
--- a/far/main.cpp
+++ b/far/main.cpp
@@ -860,6 +860,19 @@ static void parse_command_line(std::span<const wchar_t* const> const Args, std::
}
}

+static void register_restart(bool const HasArgs)
+{
+ const auto Args = HasArgs? []
+ {
+ const auto CommandLine = GetCommandLine();
+ const auto ExecutableSize = enum_tokens_custom_t<with_quotes_keep>{ CommandLine, L" "sv }.begin()->size();
+ return CommandLine + ExecutableSize + 1;
+ }() : nullptr;
+
+ if (const auto Result = imports.RegisterApplicationRestart(Args, 0); FAILED(Result))
+ LOGWARNING(L"RegisterApplicationRestart(): {}"sv, os::format_error(Result));
+}
+
static int mainImpl(std::span<const wchar_t* const> const Args)
{
setlocale(LC_ALL, "");
@@ -905,6 +918,10 @@ static int mainImpl(std::span<const wchar_t* const> const Args)
if (const auto Result = ProcessServiceModes(RunMode, Args))
return *Result;

+ assert(RunMode == run_mode::interactive);
+
+ register_restart(!Args.empty());
+
SCOPED_ACTION(listener)(update_environment, [] { if (Global->Opt->UpdateEnvironment) ReloadEnvironment(); });
SCOPED_ACTION(listener)(update_intl, [] { locale.invalidate(); });
SCOPED_ACTION(listener)(update_devices, &UpdateSavedDrives);


Reply all
Reply to author
Forward
0 new messages