Refactor the manipulation of Nextcloud configurations
This commit is contained in:
parent
7ba8fb50b2
commit
1f9d2774dc
1 changed files with 22 additions and 10 deletions
|
@ -273,26 +273,38 @@ class Context {
|
||||||
$nextcloudProcess | Stop-Process -Force;
|
$nextcloudProcess | Stop-Process -Force;
|
||||||
|
|
||||||
$accountSectionEntered = $false;
|
$accountSectionEntered = $false;
|
||||||
|
$accountSectionLeft = $false;
|
||||||
|
|
||||||
(Get-Content $($this.GetNextcloudConfigFile())) | `
|
$newSettings = [string]::Join(
|
||||||
ForEach-Object {
|
"`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]") {
|
if ($_ -eq "[Accounts]") {
|
||||||
$accountSectionEntered = $true;
|
$accountSectionEntered = $true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_ -eq "" -and $accountSectionEntered) {
|
if (
|
||||||
[string]::Join(
|
($_ -eq "" -and $accountSectionEntered) -or
|
||||||
"`n",
|
(
|
||||||
@(
|
(-not $accountSectionLeft) -and
|
||||||
"0\$configName\$folderID\localPath=$localPath",
|
($_ -ne "") -and
|
||||||
"0\$configName\$folderID\targetPath=$targetPath"));
|
($i -eq ($oldContent.Count - 1))
|
||||||
|
)) {
|
||||||
|
$accountSectionLeft = $true;
|
||||||
|
$newSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
$_;
|
$_;
|
||||||
} | Set-Content $this.GetNextcloudConfigFile();
|
}) | Set-Content ($this.GetNextcloudConfigFile());
|
||||||
|
|
||||||
Write-Information "New nextcloud config:";
|
Write-Information "New nextcloud config:";
|
||||||
Write-Information Get-Content $($this.GetNextcloudConfigFile());
|
Write-Information (Get-Content $($this.GetNextcloudConfigFile()));
|
||||||
|
|
||||||
Write-Information "Restarting Nextcloud";
|
Write-Information "Restarting Nextcloud";
|
||||||
Start-Process $nextcloudPath;
|
Start-Process $nextcloudPath;
|
||||||
|
|
Loading…
Reference in a new issue