diff options
| author | David Lönnhager <david.l@mullvad.net> | 2019-10-16 15:55:00 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2019-10-18 13:38:59 +0200 |
| commit | bb10571c465e81c8a4f2a8c4df3b122029fdadf0 (patch) | |
| tree | a25cf75d27acb23ed64aee9886ff7a8299c58abb /windows/nsis-plugins/src/log/log.cpp | |
| parent | 5f229ad1f0a16384627ea12e098970de47eda577 (diff) | |
| download | mullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.tar.xz mullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.zip | |
Add void target for log::Initialize
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) { |
