diff options
| author | Dan Engelbrecht <[email protected]> | 2025-01-10 15:52:34 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2025-01-10 15:52:34 +0100 |
| commit | 7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2 (patch) | |
| tree | b317ca99590a087724717e191ee3e2bc05801f75 /src | |
| parent | cleanups (diff) | |
| download | zen-7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2.tar.xz zen-7a73a49de6ddbc6712554c5c9b2863dd8e7de0f2.zip | |
displayname and description are windows-only properties
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/cmds/service_cmd.cpp | 62 | ||||
| -rw-r--r-- | src/zen/cmds/service_cmd.h | 2 | ||||
| -rw-r--r-- | src/zenutil/include/zenutil/service.h | 4 | ||||
| -rw-r--r-- | src/zenutil/service.cpp | 5 |
4 files changed, 41 insertions, 32 deletions
diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp index de3466eff..db60d9b54 100644 --- a/src/zen/cmds/service_cmd.cpp +++ b/src/zen/cmds/service_cmd.cpp @@ -160,6 +160,7 @@ ServiceCommand::ServiceCommand() fmt::format("Service name, defaults to \"{}\"", m_ServiceName), cxxopts::value(m_ServiceName), "<name>"); +#if ZEN_PLATFORM_WINDOWS m_InstallOptions.add_option("", "d", "display-name", @@ -172,9 +173,6 @@ ServiceCommand::ServiceCommand() fmt::format("Service description", m_ServiceDescription), cxxopts::value(m_ServiceDescription), "<description>"); - m_InstallOptions.parse_positional({"executable", "name", "display-name"}); - m_InstallOptions.positional_help("executable name display-name"); -#if ZEN_PLATFORM_WINDOWS m_InstallOptions.add_option("", "", "allow-elevation", @@ -182,6 +180,8 @@ ServiceCommand::ServiceCommand() cxxopts::value(m_AllowElevation), "<allow-elevation>"); #endif // ZEN_PLATFORM_WINDOWS + m_InstallOptions.parse_positional({"executable", "name", "display-name"}); + m_InstallOptions.positional_help("executable name display-name"); m_UninstallOptions.add_options()("h,help", "Print help"); m_UninstallOptions.add_option("", @@ -240,6 +240,27 @@ ServiceCommand::ServiceCommand() ServiceCommand::~ServiceCommand() = default; +std::string FmtServiceInfo(const ServiceInfo& Info, std::string_view Prefix) +{ + std::string Result = fmt::format( + "{}Status: {}\n" + "{}Executable: {}\n" + "{}CommandLineOptions: {}", + Prefix, ToString(Info.Status), + Prefix, Info.Spec.ExecutablePath, + Prefix, Info.Spec.CommandLineOptions); + +#if ZEN_PLATFORM_WINDOWS + Result += fmt::format("\n" + "{}Display Name: {}\n" + "{}Description: {}", + Prefix, Info.Spec.DisplayName, + Prefix, Info.Spec.Description); +#endif // ZEN_PLATFORM_WINDOWS + + return Result; +} + int ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { @@ -282,18 +303,9 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) else { ZEN_CONSOLE( - "Service '{}':\n" - " Status: {}\n" - " Executable: {}\n" - " CommandLineOptions: {}\n" - " Display Name: {}\n" - " Description: {}", + "Service '{}':\n{}", m_ServiceName, - ToString(Info.Status), - Info.Spec.ExecutablePath, - Info.Spec.CommandLineOptions, - Info.Spec.DisplayName, - Info.Spec.Description); + FmtServiceInfo(Info, " ")); } } @@ -304,18 +316,9 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) if (!Ec && Info.Status != ServiceStatus::NotInstalled) { ZEN_CONSOLE( - "Service '{}' already installed:\n" - " Status: {}\n" - " Executable: {}\n" - " CommandLineOptions: {}\n" - " Display Name: {}\n" - " Description: {}", + "Service '{}' already installed:\n{}", m_ServiceName, - ToString(Info.Status), - Info.Spec.ExecutablePath, - Info.Spec.CommandLineOptions, - Info.Spec.DisplayName, - Info.Spec.Description); + FmtServiceInfo(Info, " ")); return 1; } @@ -333,9 +336,12 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) m_ServerExecutable = std::filesystem::absolute(m_ServerExecutable); Ec = InstallService(m_ServiceName, ServiceSpec{.ExecutablePath = m_ServerExecutable, - .CommandLineOptions = GlobalOptions.PassthroughCommandLine, - .DisplayName = m_ServiceDisplayName, - .Description = m_ServiceDescription}); + .CommandLineOptions = GlobalOptions.PassthroughCommandLine + #if ZEN_PLATFORM_WINDOWS + ,.DisplayName = m_ServiceDisplayName + ,.Description = m_ServiceDescription + #endif // ZEN_PLATFORM_WINDOWS + }); if (Ec) { ZEN_CONSOLE("Failed to install service '{}' using '{}' . Reason: '{}'", m_ServiceName, m_ServerExecutable, Ec.message()); diff --git a/src/zen/cmds/service_cmd.h b/src/zen/cmds/service_cmd.h index b247a63ce..00a442048 100644 --- a/src/zen/cmds/service_cmd.h +++ b/src/zen/cmds/service_cmd.h @@ -35,8 +35,10 @@ private: "install", "Install zenserver as a service. Arguments following \" -- \" will be added as parameters to the installed service."}; std::filesystem::path m_ServerExecutable; +#if ZEN_PLATFORM_WINDOWS std::string m_ServiceDisplayName = "Unreal Zen Storage Service"; std::string m_ServiceDescription; +#endif // ZEN_PLATFORM_WINDOWS cxxopts::Options m_UninstallOptions{"uninstall", "Uninstall zenserver as a service"}; diff --git a/src/zenutil/include/zenutil/service.h b/src/zenutil/include/zenutil/service.h index 53c3483aa..1e96031f7 100644 --- a/src/zenutil/include/zenutil/service.h +++ b/src/zenutil/include/zenutil/service.h @@ -2,6 +2,8 @@ #pragma once +#include <zenbase/zenbase.h> + #include <filesystem> #include <optional> @@ -18,8 +20,10 @@ struct ServiceSpec { std::filesystem::path ExecutablePath; std::string CommandLineOptions; +#if ZEN_PLATFORM_WINDOWS std::string DisplayName; std::string Description; +#endif // ZEN_PLATFORM_WINDOWS }; enum class ServiceStatus diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp index 08ccac512..f85a8e7e3 100644 --- a/src/zenutil/service.cpp +++ b/src/zenutil/service.cpp @@ -188,11 +188,8 @@ namespace { const std::filesystem::path& ExecutablePath, std::string_view CommandLineOptions, std::string_view DaemonName, - std::string_view ServiceDisplayName, - std::string_view ServiceDescription, bool Debug) { - ZEN_UNUSED(ServiceDisplayName, ServiceDescription); std::vector<std::string_view> Arguments = SplitArguments(CommandLineOptions); ExtendableStringBuilder<256> ProgramArguments; for (const std::string_view Argument : Arguments) @@ -699,7 +696,7 @@ InstallService(std::string_view ServiceName, const ServiceSpec& Spec) { const std::string DaemonName = GetDaemonName(ServiceName); std::string PList = - BuildPlist(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, Spec.DisplayName, Spec.Description, true); + BuildPlist(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true); const std::filesystem::path PListPath = GetPListPath(DaemonName); ZEN_INFO("Writing launchd plist to {}", PListPath.string()); |