From d85cea9cb237ef18ad0463aecf4c8e466b53f512 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 3 Jul 2023 00:47:21 +0200 Subject: [PATCH] Refactor manipulation of nextcloud sync file --- scripts/Windows/Scripts/Context.ps1 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index 00fc126b..049deb3d 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -244,13 +244,24 @@ class Context { $configName += "WithPlaceholders"; } - Add-Content $($this.GetNextcloudConfigFile()) ` - -Value ( + $accountSectionEntered = $false; + + Get-Content $($this.GetNextcloudConfigFile()) | ` + ForEach-Object { + if ($_ -eq "[Accounts]") { + $accountSectionEntered = $true; + } + + if ($_ -eq "" -and $accountSectionEntered) { [string]::Join( "`n", @( "0\$configName\$folderID\localPath=$localPath", - "0\$configName\$folderID\targetPath=$targetPath"))); + "0\$configName\$folderID\targetPath=$targetPath")); + } + + $_; + } | Set-Content $this.GetNextcloudConfigFile(); Start-Process $nextcloudPath; }