diff options
Diffstat (limited to 'windows/nsis-plugins/src/log/log.cpp')
| -rw-r--r-- | windows/nsis-plugins/src/log/log.cpp | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/windows/nsis-plugins/src/log/log.cpp b/windows/nsis-plugins/src/log/log.cpp index d9ab10f4ea..f0a050aadb 100644 --- a/windows/nsis-plugins/src/log/log.cpp +++ b/windows/nsis-plugins/src/log/log.cpp @@ -172,6 +172,12 @@ std::wstring GetWindowsVersion() // // Opens and maintains an open handle to the log file. // +enum class LogTarget +{ + LOG_FILE = 0, + LOG_VOID +}; + void __declspec(dllexport) NSISCALL Initialize ( HWND hwndParent, @@ -188,29 +194,52 @@ void __declspec(dllexport) NSISCALL Initialize { PinDll(); - auto logpath = std::experimental::filesystem::path(common::fs::GetKnownFolderPath( - FOLDERID_ProgramData, 0, nullptr)); - - logpath.append(L"Mullvad VPN"); - - if (FALSE == CreateDirectoryW(logpath.c_str(), nullptr)) + int target = popint(); + switch (target) { - if (ERROR_ALREADY_EXISTS != GetLastError()) + case static_cast<int>(LogTarget::LOG_FILE): { - std::wstringstream ss; + auto logpath = std::experimental::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 std::runtime_error(common::string::ToAnsi(ss.str())); + } + } + + const auto logfile = decltype(logpath)(logpath).append(L"install.log"); - ss << L"Cannot create folder: " - << L"\"" - << logpath - << L"\""; + g_logger = new Logger(std::make_unique<AnsiFileLogSink>(logfile)); + + break; - throw std::runtime_error(common::string::ToAnsi(ss.str())); } - } - const auto logfile = decltype(logpath)(logpath).append(L"install.log"); + case static_cast<int>(LogTarget::LOG_VOID): + { + g_logger = new Logger(std::make_unique<VoidLogSink>()); - g_logger = new Logger(std::make_unique<AnsiFileLogSink>(logfile)); + break; + + } + + default: + { + throw std::runtime_error("Invalid log target"); + } + } } catch (std::exception &err) { |
