Skip to content

Commit

Permalink
add config for local Microsoft cl compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Nov 15, 2024
1 parent 2d026d6 commit 365c5a5
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 10 deletions.
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,73 @@ pom.xml.versionsBackup
.idea/compiler.xml
.idea/jarRepositories.xml
*.iml

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# Visual Studio 2015/2017 cache/options directory
.vs/

# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
# but not Directory.Build.rsp, as it configures directory-level build defaults
!Directory.Build.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# exclude compile outputs not used by projects
*.exp
*.lib
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
HEADERS := -I"src/main/headers" -I"${JAVA_HOME}\include" -I"${JAVA_HOME}\include\win32"
WIN_SDK_VERSION ?= 10.0.22621.0
MSVC_VERSION ?= 14.41.34120
HEADERS := /I"src/main/headers" \
/I"${JAVA_HOME}\include" \
/I"${JAVA_HOME}\include\win32" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\$(WIN_SDK_VERSION)\cppwinrt" \
/I"C:\Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/$(MSVC_VERSION)/include"
SOURCES := $(wildcard src/main/native/*.cpp)

########

all: install

install:
g++ -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at $(HEADERS) -shared -osrc/main/resources/integrations.dll $(SOURCES) -lcrypt32 -lshell32 -lole32 -luuid
cl /EHsc /std:c++17 /LD /W4 /guard:cf \
/Fe:src/main/resources/integrations.dll \
$(HEADERS) $(SOURCES) \
/link /NXCOMPAT /DYNAMICBASE \
crypt32.lib shell32.lib ole32.lib uuid.lib user32.lib windowsapp.lib
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ This project uses the following JVM properties:

## Building

This project uses JNI, hence you'll nedd Java as well as GCC build tools:
### Requirements

* JDK 22
* Maven
* MinGW GCC compiler (`choco install mingw --version=10.2.0`)
* Make (`choco install make`)
* MSVC 2022 toolchain (Visual Studio 2022, Workset "Desktop development with C++")

### Build
Start the _Developer PowerShell for Visual Studio 2022_ and run the following commands:
```pwsh
mvn clean verify
```
31 changes: 31 additions & 0 deletions integrations-win.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "integrations-win", "integrations-win.vcxproj", "{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x64.ActiveCfg = Debug|x64
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x64.Build.0 = Debug|x64
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x86.ActiveCfg = Debug|Win32
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Debug|x86.Build.0 = Debug|Win32
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x64.ActiveCfg = Release|x64
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x64.Build.0 = Release|x64
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x86.ActiveCfg = Release|Win32
{CF96ACE0-9471-4BD6-AD0E-BE32AF14C358}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCEB853F-9857-4F7D-A508-A7390F37BC50}
EndGlobalSection
EndGlobal
165 changes: 165 additions & 0 deletions integrations-win.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{cf96ace0-9471-4bd6-ad0e-be32af14c358}</ProjectGuid>
<RootNamespace>integrationswin</RootNamespace>
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(ProjectDir)src\main\headers;$(JAVA_HOME)include;$(JAVA_HOME)include\win32;$(IncludePath)</IncludePath>
<IntDir>$(SolutionDir)target\native\$(Platform)\$(Configuration)\</IntDir>
<TargetName>integrations</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ForceSymbolReferences>%(ForceSymbolReferences)</ForceSymbolReferences>
<AdditionalDependencies>crypt32.lib;shell32.lib;ole32.lib;uuid.lib;user32.lib;windowsapp.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;INTEGRATIONSWIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\main\headers\org_cryptomator_windows_autostart_WinShellLinks_Native.h" />
<ClInclude Include="src\main\headers\org_cryptomator_windows_keychain_WinDataProtection_Native.h" />
<ClInclude Include="src\main\headers\org_cryptomator_windows_uiappearance_WinAppearance_Native.h" />
<ClInclude Include="src\main\resources\ktmw32_helper.h" />
<ClInclude Include="target\classes\ktmw32_helper.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main\native\org_cryptomator_windows_autostart_WinShellLinks_Native.cpp" />
<ClCompile Include="src\main\native\org_cryptomator_windows_keychain_WinDataProtection_Native.cpp" />
<ClCompile Include="src\main\native\org_cryptomator_windows_uiappearnce_WinAppearance_Native.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <jni.h>
#include <windows.h>
#include <wincrypt.h>
#include <dpapi.h>
#include "org_cryptomator_windows_keychain_WinDataProtection_Native.h"

JNIEXPORT jbyteArray JNICALL Java_org_cryptomator_windows_keychain_WinDataProtection_00024Native_protect(JNIEnv *env, jobject thisObj, jbyteArray cleartext, jbyteArray salt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ void throwIllegalStateException(JNIEnv *env, const char* message) {
JNIEXPORT jint JNICALL Java_org_cryptomator_windows_uiappearance_WinAppearance_00024Native_getCurrentTheme (JNIEnv *env, jobject thisObject){
DWORD data{};
DWORD dataSize = sizeof(data);
LSTATUS status = RegGetValue(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", "AppsUseLightTheme", RRF_RT_DWORD, NULL, &data, &dataSize);
LSTATUS status = RegGetValueW(HKEY_CURRENT_USER, L"(Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize)", L"AppsUseLightTheme", RRF_RT_DWORD, NULL, &data, &dataSize);
if(status != ERROR_SUCCESS){
char msg[50];
sprintf(msg, "Failed to read registry value (status %d)", (int) status);
sprintf_s(msg, 50, "Failed to read registry value (status %d)", (int) status);
throwIllegalStateException(env, msg);
}
return data ? 1 : 0;
}

JNIEXPORT void JNICALL Java_org_cryptomator_windows_uiappearance_WinAppearance_00024Native_waitForNextThemeChange(JNIEnv *env, jobject thisObj){
HKEY key;
LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", 0, KEY_READ, &key);
LSTATUS status = RegOpenKeyExW(HKEY_CURRENT_USER, L"(Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize)", 0, KEY_READ, &key);
if (status != ERROR_SUCCESS) {
char msg[50];
sprintf(msg, "Failed to open registry key (status %d)", (int) status);
sprintf_s(msg, 50,"Failed to open registry key (status %d)", (int) status);
throwIllegalStateException(env, msg);
}
status = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE);
if (status != ERROR_SUCCESS) {
char msg[50];
sprintf(msg, "Failed to observe registry key (status %d)", (int) status);
sprintf_s(msg, 50, "Failed to observe registry key (status %d)", (int) status);
throwIllegalStateException(env, msg);
}
RegCloseKey(key);
Expand Down

0 comments on commit 365c5a5

Please sign in to comment.