diff --git a/src/libcommon/filesystem.cpp b/src/libcommon/filesystem.cpp index 66873c6..c985129 100644 --- a/src/libcommon/filesystem.cpp +++ b/src/libcommon/filesystem.cpp @@ -2,10 +2,24 @@ #include "filesystem.h" #include "string.h" #include "error.h" +#include namespace common::fs { +// Calls into rust to recursively create directories with total access for admins and read-only access for authenticated users. +// If any or all directories already exists will attempt to set the correct permissions on them and if successful will not error. +void CreatePrivilegedDirectory(std::filesystem::path path) +{ + const wchar_t* w_path = path.wstring().c_str(); + auto result = create_privileged_directory(reinterpret_cast(w_path)); + + if (Status::Ok != result) + { + THROW_ERROR("Failed to create privileged directory"); + } +} + void Mkdir(const std::wstring &path) { if (path.empty()) @@ -51,7 +65,6 @@ void Mkdir(const std::wstring &path) lastError = (CreateDirectoryW(target.c_str(), nullptr) ? ERROR_SUCCESS : GetLastError()); } while (it != dirs.end()); - if (ERROR_SUCCESS != lastError && ERROR_ALREADY_EXISTS != lastError) { auto msg = std::string("Failed to create directory: ").append(common::string::ToAnsi(target)); diff --git a/src/libcommon/filesystem.h b/src/libcommon/filesystem.h index 79d4965..09ccb80 100644 --- a/src/libcommon/filesystem.h +++ b/src/libcommon/filesystem.h @@ -3,12 +3,15 @@ #include #include #include +#include namespace common::fs { void Mkdir(const std::wstring &path); +void CreatePrivilegedDirectory(std::filesystem::path path); + std::wstring GetKnownFolderPath(REFKNOWNFOLDERID folderId, DWORD flags = KF_FLAG_DEFAULT, HANDLE userToken = nullptr); class ScopedNativeFileSystem diff --git a/src/libcommon/libcommon.vcxproj b/src/libcommon/libcommon.vcxproj index b18dd91..6844b3b 100644 --- a/src/libcommon/libcommon.vcxproj +++ b/src/libcommon/libcommon.vcxproj @@ -151,7 +151,7 @@ WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug stdcpp20 - $(ProjectDir)../ + $(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include; Windows @@ -160,6 +160,12 @@ ntdll.lib + + cargo build --target i686-pc-windows-msvc --release -p mullvad-nsis + + + Build mullvad-nsis library + @@ -170,7 +176,7 @@ _DEBUG;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug stdcpp20 - $(ProjectDir)../ + $(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include; Windows @@ -179,6 +185,10 @@ ntdll.lib + + cargo build --target x86_64-pc-windows-msvc --release -p mullvad-nsis + Build mullvad-nsis library + @@ -191,7 +201,7 @@ WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) MultiThreaded stdcpp20 - $(ProjectDir)../ + $(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include; Windows @@ -202,6 +212,10 @@ ntdll.lib + + cargo build --target i686-pc-windows-msvc --release -p mullvad-nsis + Build mullvad-nsis library + @@ -214,7 +228,7 @@ NDEBUG;_LIB;%(PreprocessorDefinitions) MultiThreaded stdcpp20 - $(ProjectDir)../ + $(ProjectDir)../;$(ProjectDir)../../../../mullvad-nsis/include; Windows @@ -225,6 +239,10 @@ ntdll.lib + + cargo build --target x86_64-pc-windows-msvc --release -p mullvad-nsis + Build mullvad-nsis library + diff --git a/windows-libraries.sln b/windows-libraries.sln index a2e97e1..2b2058a 100644 --- a/windows-libraries.sln +++ b/windows-libraries.sln @@ -5,11 +5,6 @@ VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcommon", "src\libcommon\libcommon.vcxproj", "{B52E2D10-A94A-4605-914A-2DCEF6A757EF}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-libcommon", "src\test-libcommon\test-libcommon.vcxproj", "{326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}" - ProjectSection(ProjectDependencies) = postProject - {B52E2D10-A94A-4605-914A-2DCEF6A757EF} = {B52E2D10-A94A-4605-914A-2DCEF6A757EF} - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -26,14 +21,6 @@ Global {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x64.Build.0 = Release|x64 {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x86.ActiveCfg = Release|Win32 {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x86.Build.0 = Release|Win32 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x64.ActiveCfg = Debug|x64 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x64.Build.0 = Debug|x64 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x86.ActiveCfg = Debug|Win32 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Debug|x86.Build.0 = Debug|Win32 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x64.ActiveCfg = Release|x64 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x64.Build.0 = Release|x64 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x86.ActiveCfg = Release|Win32 - {326D0AB1-CF2F-4A9B-B612-04B62D4EBA89}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE