summaryrefslogtreecommitdiffhomepage
path: root/windows
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2019-10-16 15:55:00 +0200
committerDavid Lönnhager <david.l@mullvad.net>2019-10-18 13:38:59 +0200
commitbb10571c465e81c8a4f2a8c4df3b122029fdadf0 (patch)
treea25cf75d27acb23ed64aee9886ff7a8299c58abb /windows
parent5f229ad1f0a16384627ea12e098970de47eda577 (diff)
downloadmullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.tar.xz
mullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.zip
Add void target for log::Initialize
Diffstat (limited to 'windows')
-rw-r--r--windows/nsis-plugins/src/log/log.cpp61
-rw-r--r--windows/nsis-plugins/src/log/logger.h7
2 files changed, 52 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)
{
diff --git a/windows/nsis-plugins/src/log/logger.h b/windows/nsis-plugins/src/log/logger.h
index 6f28e5c73a..fe06072581 100644
--- a/windows/nsis-plugins/src/log/logger.h
+++ b/windows/nsis-plugins/src/log/logger.h
@@ -14,6 +14,13 @@ struct ILogSink
virtual void log(const std::wstring &message) = 0;
};
+class VoidLogSink : public ILogSink
+{
+public:
+
+ void log(const std::wstring &message) override {}
+};
+
class AnsiFileLogSink : public ILogSink
{
public: