diff options
Diffstat (limited to 'windows/nsis-plugins/src/log/log.cpp')
| -rw-r--r-- | windows/nsis-plugins/src/log/log.cpp | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/windows/nsis-plugins/src/log/log.cpp b/windows/nsis-plugins/src/log/log.cpp index 6c1fb9111a..4a7bf1bf49 100644 --- a/windows/nsis-plugins/src/log/log.cpp +++ b/windows/nsis-plugins/src/log/log.cpp @@ -184,17 +184,18 @@ std::wstring GetWindowsVersion() } // anonymous namespace // -// Initialize +// SetLogTarget // // Opens and maintains an open handle to the log file. // enum class LogTarget { - LOG_FILE = 0, - LOG_VOID + LOG_INSTALL = 0, + LOG_UNINSTALL = 1, + LOG_VOID = 2 }; -void __declspec(dllexport) NSISCALL Initialize +void __declspec(dllexport) NSISCALL SetLogTarget ( HWND hwndParent, int string_size, @@ -210,56 +211,66 @@ void __declspec(dllexport) NSISCALL Initialize { PinDll(); + const wchar_t *logfile = nullptr; + int target = popint(); switch (target) { - case static_cast<int>(LogTarget::LOG_FILE): + case static_cast<int>(LogTarget::LOG_INSTALL): { - auto logpath = std::filesystem::path(common::fs::GetKnownFolderPath( - FOLDERID_ProgramData, 0, nullptr)); - - logpath.append(L"Mullvad VPN"); - - if (FALSE == CreateDirectoryW(logpath.c_str(), nullptr)) - { - if (ERROR_ALREADY_EXISTS != GetLastError()) - { - std::wstringstream ss; - - ss << L"Cannot create folder: " - << L"\"" - << logpath - << L"\""; - - THROW_ERROR(common::string::ToAnsi(ss.str()).c_str()); - } - } - - const auto logfile = decltype(logpath)(logpath).append(L"install.log"); - - g_logger = new Logger(std::make_unique<Utf8FileLogSink>(logfile, false)); - + logfile = L"install.log"; break; - } - case static_cast<int>(LogTarget::LOG_VOID): + case static_cast<int>(LogTarget::LOG_UNINSTALL): { - g_logger = new Logger(std::make_unique<VoidLogSink>()); - + logfile = L"uninstall.log"; break; - + } + case static_cast<int>(LogTarget::LOG_VOID): + { + delete g_logger; + g_logger = nullptr; + return; } default: { THROW_ERROR("Invalid log target"); } } + + if (nullptr == logfile) + { + THROW_ERROR("Invalid log target"); + } + + auto logpath = std::filesystem::path(common::fs::GetKnownFolderPath( + FOLDERID_ProgramData, 0, nullptr)); + logpath.append(L"Mullvad VPN"); + + if (FALSE == CreateDirectoryW(logpath.c_str(), nullptr)) + { + if (ERROR_ALREADY_EXISTS != GetLastError()) + { + std::wstringstream ss; + + ss << L"Cannot create folder: " + << L"\"" + << logpath + << L"\""; + + THROW_ERROR(common::string::ToAnsi(ss.str()).c_str()); + } + } + + logpath.append(logfile); + + g_logger = new Logger(std::make_unique<Utf8FileLogSink>(logpath, false)); } catch (std::exception &err) { std::stringstream ss; - ss << "Failed to initialize logging plugin." + ss << "Failed to set logging plugin target." << std::endl << err.what(); |
