Explorar o código

extend migration script to all local users

Armin Schrenk %!s(int64=2) %!d(string=hai) anos
pai
achega
5f9b77241f
Modificáronse 1 ficheiros con 37 adicións e 10 borrados
  1. 37 10
      dist/win/contrib/170FuseMigration.ps1

+ 37 - 10
dist/win/contrib/170FuseMigration.ps1

@@ -1,12 +1,39 @@
-$settingsPath = 'C:\Users\Arbeit\AppData\Roaming\Cryptomator-Dev\settings1617.json'
-$settings = Get-Content -Path $settingsPath | ConvertFrom-Json
-$atLeastOneCustomPath = $false;
-foreach ($vault in $settings.directories){
-    $atLeastOneCustomPath = $atLeastOneCustomPath -or ($vault.useCustomMountPath -eq "True")
-}
+# This script migrates Cryptomator settings for all local users on Windows in case a custom directory is used
+#Requires -RunAsAdministrator
+
+#Get all active, local user profiles
+$profileList = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
+$localUsers = Get-LocalUser | Where-Object {$_.Enabled} | ForEach-Object { $_.Name}
+
+Get-ChildItem $profileList | ForEach-Object { $_.GetValue("ProfileImagePath") } | Where-Object {
+    $matches = ($_ | Select-String -Pattern "\\([^\\]+)$").Matches
+    if($matches.Count -eq 1) {
+        return $localUsers.Contains($matches[0].Groups[1].Value)
+    }
+    return $false;
+} | ForEach-Object {
+    $settingsPath = "$_\AppData\Roaming\Cryptomator\settings.json"
+    if(!(Test-Path -Path $settingsPath)) {
+        #No settings file, nothing to do.
+        return;
+    }
+
+    $settings = Get-Content -Path $settingsPath | ConvertFrom-Json
+    if($settings.preferredVolumeImpl -eq "FUSE") {
+        #Fuse not used, nothing to do
+        return;
+    }
+
+    #check if customMountPoints are used
+    $atLeastOneCustomPath = $false;
+    foreach ($vault in $settings.directories){
+        $atLeastOneCustomPath = $atLeastOneCustomPath -or ($vault.useCustomMountPath -eq "True")
+    }
 
-if( $atLeastOneCustomPath -and ($settings.preferredVolumeImpl -eq "FUSE")) {
-    Add-Member -Force -InputObject $settings -Name "mountService" -Value "org.cryptomator.frontend.fuse.mount.WinFspMountProvider" -MemberType NoteProperty
-    $newSettings  = $settings | Select-Object * -ExcludeProperty "preferredVolumeImpl"
-    ConvertTo-Json $newSettings | Set-Content -Path $settingsPath
+    #if so, use WinFsp Local Drive
+    if( $atLeastOneCustomPath ) {
+        Add-Member -Force -InputObject $settings -Name "mountService" -Value "org.cryptomator.frontend.fuse.mount.WinFspMountProvider" -MemberType NoteProperty
+        $newSettings  = $settings | Select-Object * -ExcludeProperty "preferredVolumeImpl"
+        ConvertTo-Json $newSettings | Set-Content -Path $settingsPath
+    }
 }