From a106b04c7e7bbf045b43df3ab96f8aeda7fe1048 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 30 Jan 2023 13:30:06 +0100 Subject: [PATCH 1/7] prototpye for powershell script to be executed after installation --- dist/win/contrib/170FuseMigration.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 dist/win/contrib/170FuseMigration.ps1 diff --git a/dist/win/contrib/170FuseMigration.ps1 b/dist/win/contrib/170FuseMigration.ps1 new file mode 100644 index 000000000..203913ae7 --- /dev/null +++ b/dist/win/contrib/170FuseMigration.ps1 @@ -0,0 +1,12 @@ +$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") +} + +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 +} From 5f9b77241f9f438f49112f917175823a0b0c8822 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 31 Jan 2023 13:40:25 +0100 Subject: [PATCH 2/7] extend migration script to all local users --- dist/win/contrib/170FuseMigration.ps1 | 47 +++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/dist/win/contrib/170FuseMigration.ps1 b/dist/win/contrib/170FuseMigration.ps1 index 203913ae7..8c740b3de 100644 --- a/dist/win/contrib/170FuseMigration.ps1 +++ b/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 -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 +#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 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 + } } From e56e6a8359daa07b99eff90d9314d7aa272aaeb9 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 31 Jan 2023 13:58:56 +0100 Subject: [PATCH 3/7] integrate script into installer --- dist/win/contrib/version170-migrate-settings.bat | 4 ++++ ...Migration.ps1 => version170-migrate-settings.ps1} | 12 ++++++++---- dist/win/resources/main.wxs | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 dist/win/contrib/version170-migrate-settings.bat rename dist/win/contrib/{170FuseMigration.ps1 => version170-migrate-settings.ps1} (81%) diff --git a/dist/win/contrib/version170-migrate-settings.bat b/dist/win/contrib/version170-migrate-settings.bat new file mode 100644 index 000000000..ac8d59dfa --- /dev/null +++ b/dist/win/contrib/version170-migrate-settings.bat @@ -0,0 +1,4 @@ +@echo off + +cd %~dp0 +powershell -NoLogo -NonInteractive -ExecutionPolicy Unrestricted -Command .\version170-migrate-settings.ps1 \ No newline at end of file diff --git a/dist/win/contrib/170FuseMigration.ps1 b/dist/win/contrib/version170-migrate-settings.ps1 similarity index 81% rename from dist/win/contrib/170FuseMigration.ps1 rename to dist/win/contrib/version170-migrate-settings.ps1 index 8c740b3de..92bb037cf 100644 --- a/dist/win/contrib/170FuseMigration.ps1 +++ b/dist/win/contrib/version170-migrate-settings.ps1 @@ -1,4 +1,5 @@ -# This script migrates Cryptomator settings for all local users on Windows in case a custom directory is used +# This script migrates Cryptomator settings for all local users on Windows in case the users uses custom directories as mountpoint +# #Requires -RunAsAdministrator #Get all active, local user profiles @@ -6,11 +7,14 @@ $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) { + $profileNameMatches = ($_ | Select-String -Pattern "\\([^\\]+)$").Matches + if($profileNameMatches.Count -eq 1) { + #check if the last path part is contained in the local user name list + #otherwise do not touch it return $localUsers.Contains($matches[0].Groups[1].Value) + } else { + return $false; } - return $false; } | ForEach-Object { $settingsPath = "$_\AppData\Roaming\Cryptomator\settings.json" if(!(Test-Path -Path $settingsPath)) { diff --git a/dist/win/resources/main.wxs b/dist/win/resources/main.wxs index d6247bf05..58b72b5b4 100644 --- a/dist/win/resources/main.wxs +++ b/dist/win/resources/main.wxs @@ -132,6 +132,9 @@ + + + NOT Installed OR REINSTALL + NOT Installed OR REINSTALL From a771f0a5b7c723001edbb253b5d7d82d1c626185 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 31 Jan 2023 13:59:18 +0100 Subject: [PATCH 4/7] doc doc doc --- dist/win/contrib/version170-migrate-settings.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/dist/win/contrib/version170-migrate-settings.ps1 b/dist/win/contrib/version170-migrate-settings.ps1 index 92bb037cf..bc1c34954 100644 --- a/dist/win/contrib/version170-migrate-settings.ps1 +++ b/dist/win/contrib/version170-migrate-settings.ps1 @@ -1,4 +1,5 @@ # This script migrates Cryptomator settings for all local users on Windows in case the users uses custom directories as mountpoint +# See also https://github.com/cryptomator/cryptomator/issues/2652 # #Requires -RunAsAdministrator From 68d32957e44b85c92166061d56fedcd37baf1e15 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 31 Jan 2023 16:37:25 +0100 Subject: [PATCH 5/7] fix errors --- dist/win/contrib/version170-migrate-settings.ps1 | 5 ++--- dist/win/resources/main.wxs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dist/win/contrib/version170-migrate-settings.ps1 b/dist/win/contrib/version170-migrate-settings.ps1 index bc1c34954..a88912ef6 100644 --- a/dist/win/contrib/version170-migrate-settings.ps1 +++ b/dist/win/contrib/version170-migrate-settings.ps1 @@ -12,7 +12,7 @@ Get-ChildItem $profileList | ForEach-Object { $_.GetValue("ProfileImagePath") } if($profileNameMatches.Count -eq 1) { #check if the last path part is contained in the local user name list #otherwise do not touch it - return $localUsers.Contains($matches[0].Groups[1].Value) + return $localUsers.Contains($profileNameMatches[0].Groups[1].Value) } else { return $false; } @@ -22,9 +22,8 @@ Get-ChildItem $profileList | ForEach-Object { $_.GetValue("ProfileImagePath") } #No settings file, nothing to do. return; } - $settings = Get-Content -Path $settingsPath | ConvertFrom-Json - if($settings.preferredVolumeImpl -eq "FUSE") { + if($settings.preferredVolumeImpl -ne "FUSE") { #Fuse not used, nothing to do return; } diff --git a/dist/win/resources/main.wxs b/dist/win/resources/main.wxs index 58b72b5b4..91315c3f7 100644 --- a/dist/win/resources/main.wxs +++ b/dist/win/resources/main.wxs @@ -133,7 +133,7 @@ - + @@ -185,7 +185,7 @@ NOT Installed OR REINSTALL - NOT Installed OR REINSTALL + NOT Installed OR REINSTALL From c2691842172d36fc6d8965de0b12ccfb0e199408 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 31 Jan 2023 18:05:31 +0100 Subject: [PATCH 6/7] ensure that settings.json is a file --- dist/win/contrib/version170-migrate-settings.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/win/contrib/version170-migrate-settings.ps1 b/dist/win/contrib/version170-migrate-settings.ps1 index a88912ef6..015fd6526 100644 --- a/dist/win/contrib/version170-migrate-settings.ps1 +++ b/dist/win/contrib/version170-migrate-settings.ps1 @@ -18,7 +18,7 @@ Get-ChildItem $profileList | ForEach-Object { $_.GetValue("ProfileImagePath") } } } | ForEach-Object { $settingsPath = "$_\AppData\Roaming\Cryptomator\settings.json" - if(!(Test-Path -Path $settingsPath)) { + if(!(Test-Path -Path $settingsPath -PathType Leaf)) { #No settings file, nothing to do. return; } From 95ea23ee6e69512b3f8a65903629d581f2e13de6 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 1 Feb 2023 11:07:23 +0100 Subject: [PATCH 7/7] add more comments regarding removal evaluation of this workaround --- dist/win/contrib/version170-migrate-settings.bat | 1 + dist/win/contrib/version170-migrate-settings.ps1 | 4 +++- dist/win/resources/main.wxs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dist/win/contrib/version170-migrate-settings.bat b/dist/win/contrib/version170-migrate-settings.bat index ac8d59dfa..94ec16dac 100644 --- a/dist/win/contrib/version170-migrate-settings.bat +++ b/dist/win/contrib/version170-migrate-settings.bat @@ -1,4 +1,5 @@ @echo off +:: see comments in file ./version170-migrate-settings.ps1 cd %~dp0 powershell -NoLogo -NonInteractive -ExecutionPolicy Unrestricted -Command .\version170-migrate-settings.ps1 \ No newline at end of file diff --git a/dist/win/contrib/version170-migrate-settings.ps1 b/dist/win/contrib/version170-migrate-settings.ps1 index 015fd6526..11b9e29e3 100644 --- a/dist/win/contrib/version170-migrate-settings.ps1 +++ b/dist/win/contrib/version170-migrate-settings.ps1 @@ -1,5 +1,7 @@ # This script migrates Cryptomator settings for all local users on Windows in case the users uses custom directories as mountpoint -# See also https://github.com/cryptomator/cryptomator/issues/2652 +# See also https://github.com/cryptomator/cryptomator/pull/2654. +# +# TODO: This script should be evaluated in a yearly interval if it is still needed and if not, should be removed # #Requires -RunAsAdministrator diff --git a/dist/win/resources/main.wxs b/dist/win/resources/main.wxs index 91315c3f7..1fb7b552d 100644 --- a/dist/win/resources/main.wxs +++ b/dist/win/resources/main.wxs @@ -132,7 +132,7 @@ - +