Add a script for adding nextcloud sync

This commit is contained in:
Manuel Thalmann 2023-07-02 15:44:47 +02:00
parent 8dadaa875a
commit 63875268ea

View file

@ -219,6 +219,32 @@ class Context {
return "$env:APPDATA/Nextcloud/nextcloud.cfg";
}
[void] AddNextcloudSync([string] $localPath, [string] $targetPath) {
$this.AddNextcloudSync($localPath, $targetPath, $false);
}
[void] AddNextcloudSync([string] $localPath, [string] $targetPath, [bool] $virtualFiles) {
$pattern = "^\d+\\Folders(?:WithPlaceholders)?\\(\d+)"
$folderID = (
Get-Content $($this.GetNextcloudConfigFile()) | `
Where-Object { $_ -match "$pattern" } | `
ForEach-Object { $_ -replace "$pattern.*$","`$1" } | `
Sort-Object -Unique | `
Measure-Object -Maximum).Maximum + 1;
$configName = "Folders" + (if ($virtualFiles) { "WithPlaceholders" } else { "" });
$localPath = $localPath -replace "\","/";
$targetPath = $targetPath -replace "\","/";
Add-Content $this.GetNextcloudConfigFile() `
[string]::Join(
"`n",
@(
"0\$configName\$folderID\localPath=$localPath",
"0\$configName\$folderID\targetPath=$targetPath"));
}
[void] Reboot() {
Write-Host "Restarting Computer...";
$this.RegisterReboot();