patchUpdateCheck.ps1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # PowerShell script to modify Cryptomator.cfg to set disableUpdateCheck property
  2. # This script is executed as a Custom Action during MSI installation
  3. # If the DisableUpdateCheck parameter is set to true, it disables the update check in Cryptomator by modifying the Cryptomator.cfg file.
  4. # NOTE: This file must be located in the same directory as set in the MSI property INSTALLDIR
  5. param(
  6. [Parameter(Mandatory)][string]$DisableUpdateCheck
  7. )
  8. try {
  9. # Log parameters for debugging (visible in MSI verbose logs)
  10. Write-Host "DisableUpdateCheck: $DisableUpdateCheck"
  11. # Parse DisableUpdateCheck value (handle various input formats)
  12. $shouldDisable = $false
  13. if ($DisableUpdateCheck) {
  14. $DisableUpdateCheck = $DisableUpdateCheck.Trim().ToLower()
  15. $shouldDisable = ($DisableUpdateCheck -eq 'true') -or ($DisableUpdateCheck -eq '1') -or ($DisableUpdateCheck -eq 'yes')
  16. }
  17. Write-Host "Setting cryptomator.disableUpdateCheck to: $shouldDisable"
  18. if (-not $shouldDisable) {
  19. Write-Host "Disable-Update-Check property is by default 'false'. Skipping config modification."
  20. exit 0
  21. }
  22. # Determine the .cfg file path
  23. $cfgFile = Join-Path $($PSScriptRoot) "app\Cryptomator.cfg"
  24. if (-not (Test-Path $cfgFile)) {
  25. Write-Error "Configuration file not found at: $cfgFile"
  26. exit 1
  27. }
  28. # Read the current configuration
  29. $content = Get-Content $cfgFile -Raw
  30. # Add the new option based on the property value
  31. # Use regular expressions substitutions to replace the property
  32. $searchExpression = '(?<Prefix>java-options=-Dcryptomator\.disableUpdateCheck)=false'
  33. $replacementExpression = '${Prefix}=true'
  34. $content = $content -replace $searchExpression,$replacementExpression
  35. # Write the modified content back
  36. Set-Content -Path $cfgFile -Value $content -NoNewline
  37. Write-Host "Successfully updated $cfgFile"
  38. exit 0
  39. }
  40. catch {
  41. Write-Error "Error modifying configuration file: $_"
  42. exit 1
  43. }