Преглед на файлове

Feature: Refactoring for Windows installer build (#3968)

* decouple patchUpdateCheck script from app name
* simplify patchWebdav script and align it with patchUpdate
Armin Schrenk преди 1 седмица
родител
ревизия
c3ada43abb
променени са 5 файла, в които са добавени 41 реда и са изтрити 44 реда
  1. 0 13
      .github/workflows/win-exe.yml
  2. 3 11
      dist/win/build.ps1
  3. 21 15
      dist/win/contrib/patchUpdateCheck.ps1
  4. 15 4
      dist/win/contrib/patchWebDAV.bat
  5. 2 1
      dist/win/resources/main.wxs

+ 0 - 13
.github/workflows/win-exe.yml

@@ -59,9 +59,6 @@ jobs:
             java-dist: 'liberica'
             java-version: '24.0.1+11'
             java-package: 'jdk+fx' #This is needed, as liberica contains JFX 24 Jmods for Windows ARM64
-    env:
-      LOOPBACK_ALIAS: 'cryptomator-vault'
-      WIN_CONSOLE_FLAG: ''
     steps:
       - uses: actions/checkout@v4
       - name: Setup Java
@@ -172,16 +169,6 @@ jobs:
       - name: Patch Application Directory
         run: |
           cp dist/win/contrib/* appdir/Cryptomator
-      - name: Set LOOPBACK_ALIAS in patchWebDAV.bat
-        shell: pwsh
-        run: |
-          $patchScript = "appdir\Cryptomator\patchWebDAV.bat"
-          try {
-            (Get-Content $patchScript ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"${{ env.LOOPBACK_ALIAS}}`"" | Set-Content $patchScript
-          } catch {
-            Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
-            exit 1
-          }
       - name: Fix permissions
         run: |
           attrib -r appdir/Cryptomator/Cryptomator.exe

+ 3 - 11
dist/win/build.ps1

@@ -206,14 +206,6 @@ if ($LASTEXITCODE -ne 0) {
 Copy-Item "contrib\*" -Destination "$AppName"
 attrib -r "$AppName\$AppName.exe"
 attrib -r "$AppName\${AppName} (Debug).exe"
-# patch batch script to set hostfile
-$webDAVPatcher = "$AppName\patchWebDAV.bat"
-try {
-	(Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$LoopbackAlias`"" | Set-Content $webDAVPatcher
-} catch {
-   Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
-   exit 1
-}
 
 # create .msi
 $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources"
@@ -299,9 +291,9 @@ return 0;
 # ============================
 if ($clean) {
 	Write-Host "Cleaning up previous build artifacts..."
-	Remove-Item -Path ".\runtime" -Force -Recurse -ErrorAction Ignore
-	Remove-Item -Path ".\$AppName" -Force -Recurse -ErrorAction Ignore
-	Remove-Item -Path ".\installer" -Force -Recurse -ErrorAction Ignore
+	Remove-Item -Path ".\runtime" -Force -Recurse -ErrorAction Ignore -ProgressAction SilentlyContinue
+	Remove-Item -Path ".\$AppName" -Force -Recurse -ErrorAction Ignore -ProgressAction SilentlyContinue
+	Remove-Item -Path ".\installer" -Force -Recurse -ErrorAction Ignore -ProgressAction SilentlyContinue
 }
 return Main
 

+ 21 - 15
dist/win/contrib/patchUpdateCheck.ps1

@@ -20,30 +20,36 @@ try {
 
     Write-Host "Setting cryptomator.disableUpdateCheck to: $shouldDisable"
     if (-not $shouldDisable) {
-        Write-Host "Disable-Update-Check property is by default 'false'. Skipping config modification."
+        Write-Host 'Disable-Update-Check property is by default "false". Skipping config modification.'
         exit 0
     }
 
     # Determine the .cfg file path
-    $cfgFile = Join-Path $($PSScriptRoot) "app\Cryptomator.cfg"
+    $cfgDir = Join-Path $PSScriptRoot 'app'
+    $cfgFiles = Get-ChildItem -Path $cfgDir -Filter '*.cfg' -File
 
-    if (-not (Test-Path $cfgFile)) {
-        Write-Error "Configuration file not found at: $cfgFile"
+    if ($cfgFiles.Count -eq 0) {
+        Write-Error "No .cfg file found in directory: $cfgDir"
         exit 1
     }
 
-    # Read the current configuration
-    $content = Get-Content $cfgFile -Raw
-
-    # Add the new option based on the property value
-    # Use regular expressions substitutions to replace the property
-    $searchExpression = '(?<Prefix>java-options=-Dcryptomator\.disableUpdateCheck)=false'
-    $replacementExpression = '${Prefix}=true'
-    $content = $content -replace $searchExpression,$replacementExpression
+    foreach ($file in $cfgFiles) {
+        $cfgFile = $file.FullName
+        Write-Host "Modifying configuration file: $cfgFile"
+        # Read the current configuration
+        $content = Get-Content $cfgFile -Raw -ErrorAction Stop
+
+        # Add the new option based on the property value
+        # Use regular expressions substitutions to replace the property
+        $searchExpression = '(?<Prefix>java-options=-Dcryptomator\.disableUpdateCheck)=false'
+        $replacementExpression = '${Prefix}=true'
+        $content = $content -replace $searchExpression,$replacementExpression
+
+        # Write the modified content back
+        Set-Content -Path $cfgFile -Value $content -NoNewline
+        Write-Host "Successfully updated $cfgFile"
+    }
 
-    # Write the modified content back
-    Set-Content -Path $cfgFile -Value $content -NoNewline
-    Write-Host "Successfully updated $cfgFile"
     exit 0
 }
 catch {

+ 15 - 4
dist/win/contrib/patchWebDAV.bat

@@ -1,7 +1,18 @@
 @echo off
-:: Default values for Cryptomator builds
-::REPLACE ME
+:: Batch wrapper for PowerShell script to adjust Windows network settings for the Cryptomator WebDAVAdapter 
+:: This is executed as a Custom Action during MSI installation
+:: This file must be located in the INSTALLDIR
 
+set "LOOPBACK_ALIAS=%1"
+
+:: Log for debugging
+echo LOOPBACK_ALIAS=%LOOPBACK_ALIAS%
+
+:: Change to INSTALLDIR
 cd %~dp0
-powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command .\patchWebDAV.ps1^
- -LoopbackAlias %LOOPBACK_ALIAS%
+:: Execute the PowerShell script
+powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -File .\patchWebDAV.ps1^
+ -LoopbackAlias %LOOPBACK_ALIAS%
+
+:: Return the exit code from PowerShell
+exit /b %ERRORLEVEL%

+ 2 - 1
dist/win/resources/main.wxs

@@ -26,6 +26,7 @@
   <?define IconFileEncryptedData= "Cryptomator-Vault.ico" ?>
   <?define ProgIdContentType= "application/vnd.cryptomator.encrypted" ?>
   <?define CloseApplicationTarget= "cryptomator.exe" ?>
+  <?define LoopbackAlias= "cryptomator-vault" ?>
 
   <?include $(var.JpConfigDir)/overrides.wxi ?>
 
@@ -131,7 +132,7 @@
     <ns0:Property Id="DISABLEUPDATECHECK" Secure="yes" />
 
     <!-- WebDAV patches -->
-    <ns0:SetProperty Id="PatchWebDAV" Value="&quot;[INSTALLDIR]patchWebDAV.bat&quot;" Sequence="execute" Before="PatchWebDAV" />
+    <ns0:SetProperty Id="PatchWebDAV" Value="&quot;[INSTALLDIR]patchWebDAV.bat&quot; &quot;$(var.LoopbackAlias)&quot;" Sequence="execute" Before="PatchWebDAV" />
     <ns0:CustomAction Id="PatchWebDAV" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" DllEntry="WixQuietExec" Execute="deferred" Return="ignore" Impersonate="no"/>
 
     <!-- Update check configuration -->