version170-migrate-settings.ps1 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/issues/2652
  3. #
  4. #Requires -RunAsAdministrator
  5. #Get all active, local user profiles
  6. $profileList = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
  7. $localUsers = Get-LocalUser | Where-Object {$_.Enabled} | ForEach-Object { $_.Name}
  8. Get-ChildItem $profileList | ForEach-Object { $_.GetValue("ProfileImagePath") } | Where-Object {
  9. $profileNameMatches = ($_ | Select-String -Pattern "\\([^\\]+)$").Matches
  10. if($profileNameMatches.Count -eq 1) {
  11. #check if the last path part is contained in the local user name list
  12. #otherwise do not touch it
  13. return $localUsers.Contains($profileNameMatches[0].Groups[1].Value)
  14. } else {
  15. return $false;
  16. }
  17. } | ForEach-Object {
  18. $settingsPath = "$_\AppData\Roaming\Cryptomator\settings.json"
  19. if(!(Test-Path -Path $settingsPath)) {
  20. #No settings file, nothing to do.
  21. return;
  22. }
  23. $settings = Get-Content -Path $settingsPath | ConvertFrom-Json
  24. if($settings.preferredVolumeImpl -ne "FUSE") {
  25. #Fuse not used, nothing to do
  26. return;
  27. }
  28. #check if customMountPoints are used
  29. $atLeastOneCustomPath = $false;
  30. foreach ($vault in $settings.directories){
  31. $atLeastOneCustomPath = $atLeastOneCustomPath -or ($vault.useCustomMountPath -eq "True")
  32. }
  33. #if so, use WinFsp Local Drive
  34. if( $atLeastOneCustomPath ) {
  35. Add-Member -Force -InputObject $settings -Name "mountService" -Value "org.cryptomator.frontend.fuse.mount.WinFspMountProvider" -MemberType NoteProperty
  36. $newSettings = $settings | Select-Object * -ExcludeProperty "preferredVolumeImpl"
  37. ConvertTo-Json $newSettings | Set-Content -Path $settingsPath
  38. }
  39. }