From e3018fed0429cf553d1b1e2d9d4715c528fe3539 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 7 Apr 2021 14:50:34 +0200 Subject: [PATCH] Add host info for LV2, and in general --- plugins/editor/src/editor/DlgAbout.cpp | 3 +++ plugins/editor/src/editor/NativeHelpers.cpp | 27 +++++++++++++++++++++ plugins/editor/src/editor/NativeHelpers.h | 1 + plugins/editor/src/editor/NativeHelpers.mm | 11 +++++++++ 4 files changed, 42 insertions(+) diff --git a/plugins/editor/src/editor/DlgAbout.cpp b/plugins/editor/src/editor/DlgAbout.cpp index fba4e275..ba79010e 100644 --- a/plugins/editor/src/editor/DlgAbout.cpp +++ b/plugins/editor/src/editor/DlgAbout.cpp @@ -161,9 +161,12 @@ SAboutDialog::SAboutDialog(const CRect& bounds) /// sysInfoTemplate_ = lblSysInfoValue_->getText(); + sysInfoVariables_["%Pluginformat%"] = {}; sysInfoVariables_["%HostOS%"] = getOperatingSystemName(); sysInfoVariables_["%HostCPU%"] = getProcessorName(); sysInfoVariables_["%HostBits%"] = std::to_string(8 * sizeof(void*)); + sysInfoVariables_["%HostProgram%"] = getCurrentProcessName(); + updateSysInfo(); } void SAboutDialog::setPluginFormat(const std::string& pluginFormat) diff --git a/plugins/editor/src/editor/NativeHelpers.cpp b/plugins/editor/src/editor/NativeHelpers.cpp index 311693e2..b720bc15 100644 --- a/plugins/editor/src/editor/NativeHelpers.cpp +++ b/plugins/editor/src/editor/NativeHelpers.cpp @@ -137,6 +137,24 @@ std::string getProcessorName() std::unique_ptr valueUTF8(stringToUTF8(valueW.get())); return valueUTF8.get(); } + +std::string getCurrentProcessName() +{ + DWORD size = 32768; + std::unique_ptr buffer(new WCHAR[size]()); + + if (!GetModuleFileNameW(nullptr, buffer.get(), size)) + return {}; + + buffer[size - 1] = L'\0'; + const WCHAR* name = buffer.get(); + + if (const WCHAR* pos = wcsrchr(name, L'\\')) + name = pos + 1; + + std::unique_ptr nameUTF8(stringToUTF8(name)); + return nameUTF8.get(); +} #elif defined(__APPLE__) // implemented in NativeHelpers.mm #else @@ -151,6 +169,7 @@ std::string getProcessorName() #include #include extern "C" { extern char **environ; } +extern "C" { extern char *__progname; } static bool openFileByMimeType(const char *filename, const char *mimetype) { @@ -296,4 +315,12 @@ std::string getProcessorName() return name; } + +std::string getCurrentProcessName() +{ + const char* name = __progname; + if (!name) + return std::string(); + return name; +} #endif diff --git a/plugins/editor/src/editor/NativeHelpers.h b/plugins/editor/src/editor/NativeHelpers.h index 41a88887..2741981e 100644 --- a/plugins/editor/src/editor/NativeHelpers.h +++ b/plugins/editor/src/editor/NativeHelpers.h @@ -13,6 +13,7 @@ bool openURLWithExternalProgram(const char *url); bool askQuestion(const char *text); std::string getOperatingSystemName(); std::string getProcessorName(); +std::string getCurrentProcessName(); #if !defined(_WIN32) && !defined(__APPLE__) bool isZenityAvailable(); diff --git a/plugins/editor/src/editor/NativeHelpers.mm b/plugins/editor/src/editor/NativeHelpers.mm index 831c3c52..da2eb1e4 100644 --- a/plugins/editor/src/editor/NativeHelpers.mm +++ b/plugins/editor/src/editor/NativeHelpers.mm @@ -12,6 +12,7 @@ #import #include #include +#include #include static bool openFileWithApplication(const char *fileName, NSString *application) @@ -78,4 +79,14 @@ std::string getProcessorName() return std::string(nameBuf, size); } + +std::string getCurrentProcessName() +{ + kinfo_proc proc {}; + size_t size = sizeof(kinfo_proc); + int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, int(getpid()) }; + if (sysctl(name, 4, &proc, &size, nullptr, 0) == -1) + return {}; + return proc.kp_proc.p_comm; +} #endif