Refactor the manipulation of Nextcloud configurations

This commit is contained in:
Manuel Thalmann 2023-07-25 12:15:28 +02:00
parent 7ba8fb50b2
commit 1f9d2774dc

View file

@ -273,26 +273,38 @@ class Context {
$nextcloudProcess | Stop-Process -Force;
$accountSectionEntered = $false;
$accountSectionLeft = $false;
(Get-Content $($this.GetNextcloudConfigFile())) | `
ForEach-Object {
$newSettings = [string]::Join(
"`n",
@(
"0\$configName\$folderID\localPath=$localPath",
"0\$configName\$folderID\targetPath=$targetPath"));
$oldContent = Get-Content ($this.GetNextcloudConfigFile());
$(
for ($i = 0; i -lt $oldContent.Count; $i++) {
if ($_ -eq "[Accounts]") {
$accountSectionEntered = $true;
}
if ($_ -eq "" -and $accountSectionEntered) {
[string]::Join(
"`n",
@(
"0\$configName\$folderID\localPath=$localPath",
"0\$configName\$folderID\targetPath=$targetPath"));
if (
($_ -eq "" -and $accountSectionEntered) -or
(
(-not $accountSectionLeft) -and
($_ -ne "") -and
($i -eq ($oldContent.Count - 1))
)) {
$accountSectionLeft = $true;
$newSettings;
}
$_;
} | Set-Content $this.GetNextcloudConfigFile();
}) | Set-Content ($this.GetNextcloudConfigFile());
Write-Information "New nextcloud config:";
Write-Information Get-Content $($this.GetNextcloudConfigFile());
Write-Information (Get-Content $($this.GetNextcloudConfigFile()));
Write-Information "Restarting Nextcloud";
Start-Process $nextcloudPath;