diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-09-12 10:14:18 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-09-12 10:14:18 +0200 |
| commit | 8df78d5faffc102860e80a225a60891c1330e026 (patch) | |
| tree | f8618688b744fb372a995204280f690f002fffec /windows/nsis-plugins/src/log/log.cpp | |
| parent | c53f622836e3265ccd438de49e3c9e775e5862b1 (diff) | |
| download | mullvadvpn-8df78d5faffc102860e80a225a60891c1330e026.tar.xz mullvadvpn-8df78d5faffc102860e80a225a60891c1330e026.zip | |
Properly create the destination folder
Diffstat (limited to 'windows/nsis-plugins/src/log/log.cpp')
| -rw-r--r-- | windows/nsis-plugins/src/log/log.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/windows/nsis-plugins/src/log/log.cpp b/windows/nsis-plugins/src/log/log.cpp index f4d255b190..af0b972179 100644 --- a/windows/nsis-plugins/src/log/log.cpp +++ b/windows/nsis-plugins/src/log/log.cpp @@ -7,6 +7,7 @@ #include <string> #include <vector> #include <memory> +#include <sstream> #include <experimental/filesystem> Logger *g_logger = nullptr; @@ -99,13 +100,40 @@ void __declspec(dllexport) NSISCALL Initialize { PinDll(); - auto logfile = std::experimental::filesystem::path(common::fs::GetKnownFolderPath( + auto logpath = std::experimental::filesystem::path(common::fs::GetKnownFolderPath( FOLDERID_ProgramData, 0, nullptr)); - logfile.append(L"Mullvad VPN").append(L"install.log"); + 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"); g_logger = new Logger(std::make_unique<AnsiFileLogSink>(logfile)); } + catch (std::exception &err) + { + std::stringstream ss; + + ss << "Failed to initialize logging plugin." + << std::endl + << err.what(); + + MessageBoxA(hwndParent, ss.str().c_str(), nullptr, MB_OK); + } catch (...) { } |
