patchUpdateCheck.ps1 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. $cfgDir = Join-Path $PSScriptRoot 'app'
  24. $cfgFiles = Get-ChildItem -Path $cfgDir -Filter '*.cfg' -File
  25. if ($cfgFiles.Count -eq 0) {
  26. Write-Error "No .cfg file found in directory: $cfgDir"
  27. exit 1
  28. }
  29. foreach ($file in $cfgFiles) {
  30. $cfgFile = $file.FullName
  31. Write-Host "Modifying configuration file: $cfgFile"
  32. # Read the current configuration
  33. $content = Get-Content $cfgFile -Raw -ErrorAction Stop
  34. # Add the new option based on the property value
  35. # Use regular expressions substitutions to replace the property
  36. $searchExpression = '(?<Prefix>java-options=-Dcryptomator\.disableUpdateCheck)=false'
  37. $replacementExpression = '${Prefix}=true'
  38. $content = $content -replace $searchExpression,$replacementExpression
  39. # Write the modified content back
  40. Set-Content -Path $cfgFile -Value $content -NoNewline
  41. Write-Host "Successfully updated $cfgFile"
  42. }
  43. exit 0
  44. }
  45. catch {
  46. Write-Error "Error modifying configuration file: $_"
  47. exit 1
  48. }