summaryrefslogtreecommitdiffhomepage
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
parent5f229ad1f0a16384627ea12e098970de47eda577 (diff)
downloadmullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.tar.xz
mullvadvpn-bb10571c465e81c8a4f2a8c4df3b122029fdadf0.zip
Add void target for log::Initialize
-rw-r--r--dist-assets/windows/installer.nsh26
-rw-r--r--windows/nsis-plugins/src/log/log.cpp61
-rw-r--r--windows/nsis-plugins/src/log/logger.h7
3 files changed, 72 insertions, 22 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index 7bf6caeb8e..4f92961f7f 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -50,6 +50,10 @@
!define PE_GENERAL_ERROR 0
!define PE_SUCCESS 1
+# Log targets
+!define LOG_FILE 0
+!define LOG_VOID 1
+
# Windows error codes
!define ERROR_SERVICE_DEPENDENCY_DELETED 1075
@@ -654,7 +658,7 @@
Push $R0
- log::Initialize
+ log::Initialize LOG_FILE
log::Log "Running installer for ${PRODUCT_NAME} ${VERSION}"
log::LogWindowsVersion
@@ -727,16 +731,26 @@
Sleep 1000
- log::Initialize
-
- ${RemoveCLIFromEnvironPath}
-
# Check command line arguments
+ Var /GLOBAL FullUninstall
+
${GetParameters} $0
${GetOptions} $0 "/S" $1
+ ${If} ${Errors}
+ Push 1
+ log::Initialize LOG_VOID
+ ${Else}
+ Push 0
+ log::Initialize LOG_FILE
+ ${EndIf}
+ Pop $FullUninstall
+
+ log::Log "Running uninstaller for ${PRODUCT_NAME} ${VERSION}"
+
+ ${RemoveCLIFromEnvironPath}
# If not ran silently
- ${If} ${Errors}
+ ${If} $FullUninstall == 1
# Remove the TAP adapter
${ExtractDriver}
${RemoveTap}
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: