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