version170-migrate-settings.ps1 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # This script migrates Cryptomator settings for all local users on Windows in case the users uses custom directories as mountpoint
  2. # See also https://github.com/cryptomator/cryptomator/pull/2654.
  3. #
  4. # TODO: This script should be evaluated in a yearly interval if it is still needed and if not, should be removed
  5. #
  6. #Requires -RunAsAdministrator
  7. #Get all active, local user profiles
  8. $profileList = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
  9. Get-ChildItem $profileList | ForEach-Object {
  10. $profilePath = $_.GetValue("ProfileImagePath")
  11. $settingsPath = "$profilePath\AppData\Roaming\Cryptomator\settings.json"
  12. if(!(Test-Path -Path $settingsPath -PathType Leaf)) {
  13. #No settings file, nothing to do.
  14. return;
  15. }
  16. $settings = Get-Content -Path $settingsPath | ConvertFrom-Json
  17. if($settings.preferredVolumeImpl -ne "FUSE") {
  18. #Fuse not used, nothing to do
  19. return;
  20. }
  21. #check if customMountPoints are used
  22. $atLeastOneCustomPath = $false;
  23. foreach ($vault in $settings.directories){
  24. $atLeastOneCustomPath = $atLeastOneCustomPath -or ($vault.useCustomMountPath -eq "True")
  25. }
  26. #if so, use WinFsp Local Drive
  27. if( $atLeastOneCustomPath ) {
  28. Add-Member -Force -InputObject $settings -Name "mountService" -Value "org.cryptomator.frontend.fuse.mount.WinFspMountProvider" -MemberType NoteProperty
  29. $newSettings = $settings | Select-Object * -ExcludeProperty "preferredVolumeImpl"
  30. ConvertTo-Json $newSettings | Set-Content -Path $settingsPath
  31. }
  32. }