2023-07-12 20:37:31 +00:00
|
|
|
#!/bin/pwsh
|
2024-03-21 16:21:02 +00:00
|
|
|
. "$PSScriptRoot/Entrypoints.ps1";
|
2024-08-07 17:08:13 +00:00
|
|
|
. "$PSScriptRoot/../../Common/Software/PowerShell/profile.ps1";
|
2024-03-20 15:33:18 +00:00
|
|
|
|
2023-06-06 22:56:29 +00:00
|
|
|
class Context {
|
2023-06-21 20:04:18 +00:00
|
|
|
[string]$EntryPoint;
|
2023-06-16 18:24:37 +00:00
|
|
|
[string]$RootDir;
|
2023-06-06 22:56:29 +00:00
|
|
|
[string]$BackupName;
|
2024-03-23 14:38:06 +00:00
|
|
|
[string[]]$UserNames;
|
2023-06-22 21:04:13 +00:00
|
|
|
[string]$AdminName = "Admin";
|
2023-06-29 17:03:31 +00:00
|
|
|
[string]$ConfigRoot = "HKLM:\Software\PortValhalla";
|
2023-06-23 18:08:31 +00:00
|
|
|
[string]$RunOnceName = "PortValhalla";
|
2023-06-29 17:08:05 +00:00
|
|
|
[string]$StagePropertyName = "Stage";
|
2023-06-29 17:03:31 +00:00
|
|
|
|
2024-03-21 15:07:29 +00:00
|
|
|
Context() {
|
2024-03-22 16:55:43 +00:00
|
|
|
try {
|
|
|
|
$this.EntryPoint = Get-Entrypoint;
|
|
|
|
}
|
|
|
|
catch { }
|
2024-03-21 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 17:03:31 +00:00
|
|
|
[string] ProjectRoot() {
|
|
|
|
return Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..");
|
|
|
|
}
|
|
|
|
|
2023-06-06 22:56:29 +00:00
|
|
|
[string] BackupRoot() {
|
2023-06-16 18:24:37 +00:00
|
|
|
if (-not $this.RootDir)
|
|
|
|
{
|
2023-07-29 19:19:57 +00:00
|
|
|
return Join-Path $this.ProjectRoot() "backup" $this.BackupName;
|
2023-06-16 18:24:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this.RootDir;
|
|
|
|
}
|
2023-06-06 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 10:32:46 +00:00
|
|
|
[void] RemoveDesktopIcon($pattern) {
|
|
|
|
Remove-Item "$env:PUBLIC/Desktop/$pattern";
|
2023-07-19 01:17:27 +00:00
|
|
|
Remove-Item "~/Desktop/$pattern";
|
2023-07-16 10:32:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 18:04:34 +00:00
|
|
|
[void] RemoveTaskbarItem($pattern) {
|
|
|
|
Import-Module -UseWindowsPowerShell PinnedItem;
|
|
|
|
Get-PinnedItem -Type TaskBar | Where-Object { $_.Name -like "$pattern" } | Remove-PinnedItem;
|
|
|
|
}
|
|
|
|
|
2023-07-26 23:55:44 +00:00
|
|
|
[void] AddPowerShellProfileStatement([string] $statement) {
|
2023-07-27 00:54:14 +00:00
|
|
|
$this.AddPowerShellProfileStatement($true, $statement);
|
2023-07-26 23:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[void] AddPowerShellProfileStatement([string] $category, [string] $statement) {
|
2023-07-27 00:54:14 +00:00
|
|
|
$this.AddPowerShellProfileStatement($true, $category, $statement);
|
|
|
|
}
|
|
|
|
|
2024-03-20 22:49:21 +00:00
|
|
|
[void] AddPowerShellProfileStatement([bool] $system, [string] $statement) {
|
|
|
|
$this.AddPowerShellProfileStatement($system, $null, $statement);
|
2023-07-27 00:54:14 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 22:49:21 +00:00
|
|
|
[void] AddPowerShellProfileStatement([bool] $system, [string] $category, [string] $statement) {
|
2023-07-26 23:55:44 +00:00
|
|
|
if ($category) {
|
2024-03-20 15:33:18 +00:00
|
|
|
$overwrite = $true;
|
|
|
|
} else {
|
|
|
|
$overwrite = $false;
|
2023-07-26 23:55:44 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 22:49:21 +00:00
|
|
|
$this.AddPowerShellProfileStatement($system, $category, $statement, $overwrite);
|
2024-03-20 15:33:18 +00:00
|
|
|
}
|
2023-07-27 00:28:37 +00:00
|
|
|
|
2024-03-20 22:49:21 +00:00
|
|
|
[void] AddPowerShellProfileStatement([bool] $system, [string] $category, [string] $statement, [bool] $overwrite) {
|
|
|
|
if ($system) {
|
|
|
|
Add-PowerShellProfileStatement -System -Category $category -Statement $statement -Overwrite $overwrite;
|
|
|
|
} else {
|
|
|
|
Add-PowerShellProfileStatement -Category $category -Statement $statement -Overwrite $overwrite;
|
|
|
|
}
|
2023-07-26 23:55:44 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 17:03:31 +00:00
|
|
|
[Microsoft.Win32.RegistryKey] EnsureConfigKey() {
|
|
|
|
if (-not (Test-Path $this.ConfigRoot)) {
|
2023-06-29 17:11:41 +00:00
|
|
|
$null = New-Item $this.ConfigRoot;
|
2023-06-29 18:02:12 +00:00
|
|
|
$acl = Get-Acl $this.ConfigRoot;
|
|
|
|
|
|
|
|
$acl.AddAccessRule(
|
|
|
|
[System.Security.AccessControl.RegistryAccessRule]::new(
|
2023-06-29 22:55:42 +00:00
|
|
|
[System.Security.Principal.SecurityIdentifier]::new([System.Security.Principal.WellKnownSidType]::BuiltinUsersSid, $null),
|
2023-06-29 18:02:12 +00:00
|
|
|
[System.Security.AccessControl.RegistryRights]::FullControl,
|
|
|
|
[System.Security.AccessControl.InheritanceFlags]::ObjectInherit -bor [System.Security.AccessControl.InheritanceFlags]::ContainerInherit,
|
|
|
|
[System.Security.AccessControl.PropagationFlags]::None,
|
|
|
|
[System.Security.AccessControl.AccessControlType]::Allow));
|
2023-06-29 23:57:45 +00:00
|
|
|
|
|
|
|
Set-Acl $this.ConfigRoot $acl;
|
2023-06-29 17:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Get-Item $this.ConfigRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
[object] Get([string] $key) {
|
|
|
|
$configKey = $this.EnsureConfigKey();
|
|
|
|
if ($configKey.GetValueNames().Contains($key)) {
|
|
|
|
return $configKey.GetValue($key);
|
|
|
|
} else {
|
|
|
|
return $null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-24 00:10:00 +00:00
|
|
|
[void] Set([string] $key, $value) {
|
|
|
|
$this.Set($key, $value, "ExpandString");
|
|
|
|
}
|
|
|
|
|
2023-06-29 17:11:16 +00:00
|
|
|
[void] Set([string] $key, $value, [Microsoft.Win32.RegistryValueKind] $type) {
|
|
|
|
$configKey = $this.EnsureConfigKey();
|
2023-06-30 00:40:15 +00:00
|
|
|
$null = Set-ItemProperty -Path $configKey.PSPath -Name $key -Value $value -Type $type;
|
2023-06-29 17:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[void] Remove([string] $key) {
|
|
|
|
$configKey = $this.EnsureConfigKey();
|
2023-06-30 02:34:40 +00:00
|
|
|
$null = Remove-ItemProperty -Path $configKey.PSPath -Name $key;
|
2023-06-29 17:11:16 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 17:08:05 +00:00
|
|
|
[void] SetStage([string] $name) {
|
2024-03-24 00:10:44 +00:00
|
|
|
$this.Set($this.StagePropertyName, $name);
|
2023-06-29 17:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[string] GetStage() {
|
|
|
|
return $this.Get($this.StagePropertyName);
|
|
|
|
}
|
|
|
|
|
2023-06-29 17:13:17 +00:00
|
|
|
[void] RemoveStage() {
|
|
|
|
$this.Remove($this.StagePropertyName);
|
|
|
|
}
|
|
|
|
|
2023-06-06 22:56:29 +00:00
|
|
|
[string] ArchivePath($name) {
|
|
|
|
return Join-Path $this.BackupRoot() "$name.7z";
|
|
|
|
}
|
|
|
|
|
|
|
|
[string] FileArchivePath($name) {
|
|
|
|
return $this.ArchivePath($(Join-Path "Files" $name));
|
|
|
|
}
|
|
|
|
|
|
|
|
[string] SoftwareArchive([string]$softwareName) {
|
|
|
|
return $this.ArchivePath($softwareName);
|
|
|
|
}
|
2023-06-06 23:32:14 +00:00
|
|
|
|
2023-08-01 01:34:56 +00:00
|
|
|
[void] Backup([string]$sourcePath, [string]$archivePath) {
|
|
|
|
$this.Backup($sourcePath, $archivePath, @());
|
|
|
|
}
|
|
|
|
|
2023-06-06 23:32:14 +00:00
|
|
|
[void] Backup([string]$sourcePath, [string]$archivePath, [string[]]$arguments) {
|
2023-08-01 10:48:27 +00:00
|
|
|
$this.Backup($sourcePath, $archivePath, $arguments, $true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] Backup([string]$sourcePath, [string]$archivePath, [string[]]$arguments, [bool]$split) {
|
2023-06-06 23:32:14 +00:00
|
|
|
if (Test-Path $archivePath) {
|
|
|
|
Remove-Item -Recurse $archivePath;
|
|
|
|
}
|
|
|
|
|
2023-08-05 01:03:57 +00:00
|
|
|
if (Test-Path "$archivePath.*") {
|
|
|
|
Remove-Item -Recurse "$archivePath.*";
|
|
|
|
}
|
|
|
|
|
2023-06-06 23:32:14 +00:00
|
|
|
Start-Process -WorkingDirectory "$sourcePath" `
|
|
|
|
-FilePath "7z" `
|
|
|
|
-ArgumentList (
|
|
|
|
@(
|
|
|
|
"a",
|
|
|
|
"-xr!desktop.ini",
|
2023-06-09 16:21:26 +00:00
|
|
|
"-xr!thumbs.db",
|
|
|
|
"-xr!Thumbs.db",
|
2023-08-01 15:22:20 +00:00
|
|
|
"-slp",
|
2023-08-01 10:50:48 +00:00
|
|
|
$archivePath) + $arguments + $(
|
2023-08-01 10:48:27 +00:00
|
|
|
if ($split) {
|
2023-08-01 18:32:23 +00:00
|
|
|
@("-v2g");
|
2023-08-01 10:48:27 +00:00
|
|
|
} else {
|
|
|
|
@();
|
|
|
|
}
|
|
|
|
)) `
|
2023-06-06 23:32:14 +00:00
|
|
|
-Wait `
|
|
|
|
-NoNewWindow;
|
|
|
|
}
|
2023-06-16 18:24:22 +00:00
|
|
|
|
|
|
|
[void] Restore([string]$archivePath, [string]$destinationPath) {
|
2024-03-24 17:08:54 +00:00
|
|
|
$this.Restore($archivePath, $destinationPath, @());
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] Restore([string]$archivePath, [string]$destinationPath, [string[]] $arguments) {
|
2023-08-01 10:48:27 +00:00
|
|
|
if (-not (Test-Path -PathType Leaf $archivePath)) {
|
|
|
|
$archivePath = "$archivePath.001";
|
|
|
|
}
|
2023-08-01 10:35:40 +00:00
|
|
|
|
2023-06-30 12:15:48 +00:00
|
|
|
if (-not (Test-Path -PathType Leaf $archivePath)) {
|
|
|
|
Write-Information (
|
|
|
|
[string]::Join(
|
|
|
|
"`n",
|
|
|
|
@(
|
|
|
|
"An archive at the specified path $archivePath does not exist.",
|
|
|
|
"No restoration will be performed.")));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (-not (Test-Path -PathType Container $destinationPath)) {
|
|
|
|
New-Item -ItemType Directory "$destinationPath";
|
|
|
|
}
|
|
|
|
|
|
|
|
Start-Process -WorkingDirectory "$destinationPath" `
|
2023-07-30 12:34:56 +00:00
|
|
|
-FilePath "7z" `
|
2024-03-24 17:08:54 +00:00
|
|
|
-ArgumentList @("x", "$archivePath") + $arguments `
|
2023-06-30 12:15:48 +00:00
|
|
|
-Wait `
|
|
|
|
-NoNewWindow;
|
2023-06-16 18:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-16 18:25:43 +00:00
|
|
|
|
|
|
|
[string] GetTempDirectory() {
|
|
|
|
$tempDir = Join-Path $([System.IO.Path]::GetTempPath()) $([System.IO.Path]::GetRandomFileName());
|
|
|
|
$null = New-Item -ItemType Directory $tempDir;
|
|
|
|
return $tempDir;
|
|
|
|
}
|
2023-06-22 20:58:54 +00:00
|
|
|
|
2023-06-23 18:08:31 +00:00
|
|
|
[void] ProcessDefaultUserKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
2023-06-28 11:40:56 +00:00
|
|
|
$rootPath = "HKLM:\DefaultUser";
|
|
|
|
$regRootPath = $rootPath.Replace(":", "");
|
2023-06-25 15:57:23 +00:00
|
|
|
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat"
|
2023-06-28 11:40:56 +00:00
|
|
|
$null = & reg load $regRootPath $hivePath;
|
|
|
|
$root = Get-Item $rootPath;
|
|
|
|
$action.Invoke($root);
|
|
|
|
$root.Handle.Close();
|
|
|
|
[System.GC]::Collect();
|
|
|
|
& reg unload $regRootPath;
|
2023-06-23 18:08:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-25 16:25:52 +00:00
|
|
|
[void] ProcessLogonKey([System.Action[Microsoft.Win32.RegistryKey]] $action) {
|
|
|
|
$key = Get-Item "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon";
|
|
|
|
$action.Invoke($key);
|
|
|
|
}
|
|
|
|
|
2023-07-03 11:44:51 +00:00
|
|
|
[Microsoft.Win32.RegistryKey] GetSystemPolicyKey() {
|
|
|
|
$keyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
|
|
|
|
return Get-Item "$keyPath";
|
|
|
|
}
|
|
|
|
|
2023-06-25 13:36:58 +00:00
|
|
|
[Microsoft.Win32.RegistryKey] GetRunOnceKey() {
|
|
|
|
return $this.GetRunOnceKey($null);
|
|
|
|
}
|
|
|
|
|
2023-06-23 18:08:31 +00:00
|
|
|
[Microsoft.Win32.RegistryKey] GetRunOnceKey([Microsoft.Win32.RegistryKey] $userKey) {
|
|
|
|
if (-not $userKey) {
|
|
|
|
$userKey = Get-Item "HKCU:\";
|
|
|
|
}
|
|
|
|
|
2023-06-25 14:33:04 +00:00
|
|
|
Push-Location $userKey.PSPath;
|
2023-06-25 16:05:55 +00:00
|
|
|
$runOncePath = "Software\Microsoft\Windows\CurrentVersion\RunOnce";
|
|
|
|
|
|
|
|
if (-not (Test-Path $runOncePath)) {
|
|
|
|
New-Item $runOncePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = Get-Item $runOncePath;
|
2023-06-25 14:28:12 +00:00
|
|
|
Pop-Location;
|
2023-06-25 14:54:10 +00:00
|
|
|
return $result;
|
2023-06-23 18:08:31 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 11:44:51 +00:00
|
|
|
[bool] GetUACState() {
|
|
|
|
return [bool](Get-ItemPropertyValue -Path ($this.GetSystemPolicyKey().PSPath) -Name "EnableLUA");
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] SetUACState([bool] $value) {
|
2023-07-10 19:22:31 +00:00
|
|
|
$null = Set-ItemProperty -Path ($this.GetSystemPolicyKey().PSPath) -Name "EnableLUA" -Value ([int]$value);
|
2023-07-03 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
2023-06-25 13:36:58 +00:00
|
|
|
[void] RegisterReboot() {
|
|
|
|
$this.RegisterReboot($null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] RegisterReboot([Microsoft.Win32.RegistryKey] $userKey) {
|
2023-06-28 11:40:56 +00:00
|
|
|
$runOnceKey = $this.GetRunOnceKey($userKey);
|
2023-06-28 11:43:20 +00:00
|
|
|
Set-ItemProperty -Path $runOnceKey.PSPath -Name $this.RunOnceName -Value "pwsh `"$($this.EntryPoint)`"" -Type "ExpandString";
|
2023-06-28 11:40:56 +00:00
|
|
|
$runOnceKey.Handle.Close();
|
2023-06-23 18:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[void] RegisterNewUserReboot() {
|
|
|
|
$this.ProcessDefaultUserKey({ param ($root) $this.RegisterReboot($root); });
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] DeregisterNewUserReboot() {
|
2023-06-25 16:10:23 +00:00
|
|
|
$this.ProcessDefaultUserKey({ param ($root) Remove-Item -Path $this.GetRunOnceKey($root).PSPath });
|
2023-06-23 18:08:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-25 16:25:52 +00:00
|
|
|
[void] SetAutologin($user, $pw) {
|
|
|
|
$this.ProcessLogonKey(
|
|
|
|
{
|
|
|
|
param ($logon)
|
|
|
|
$path = $logon.PSPath;
|
|
|
|
Set-ItemProperty $path -Name "AutoAdminLogon" 1;
|
|
|
|
Set-ItemProperty $path -Name "DefaultUserName" $user;
|
|
|
|
|
2023-06-30 02:47:31 +00:00
|
|
|
if ($pw) {
|
|
|
|
Set-ItemProperty $path -Name "DefaultPassword" $pw;
|
2023-06-25 16:25:52 +00:00
|
|
|
} else {
|
|
|
|
Remove-ItemProperty $path -Name "DefaultPassword";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] RemoveAutologin() {
|
|
|
|
$this.ProcessLogonKey(
|
|
|
|
{
|
|
|
|
param ($logon)
|
|
|
|
$path = $logon.PSPath;
|
2023-06-25 16:48:13 +00:00
|
|
|
Set-ItemProperty $path -Name "AutoAdminLogon" 0;
|
2023-07-02 23:14:34 +00:00
|
|
|
Remove-ItemProperty $path -Name "DefaultDomainName" -ErrorAction SilentlyContinue;
|
|
|
|
Remove-ItemProperty $path -Name "DefaultUserName" -ErrorAction SilentlyContinue;
|
|
|
|
Remove-ItemProperty $path -Name "DefaultPassword" -ErrorAction SilentlyContinue;
|
2023-06-25 16:25:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-30 11:17:00 +00:00
|
|
|
[string] GetNextcloudConfigFile() {
|
|
|
|
return "$env:APPDATA/Nextcloud/nextcloud.cfg";
|
|
|
|
}
|
|
|
|
|
2023-07-02 13:44:47 +00:00
|
|
|
[void] AddNextcloudSync([string] $localPath, [string] $targetPath) {
|
|
|
|
$this.AddNextcloudSync($localPath, $targetPath, $false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[void] AddNextcloudSync([string] $localPath, [string] $targetPath, [bool] $virtualFiles) {
|
2023-07-25 08:51:16 +00:00
|
|
|
Write-Host "Adding a Nextcloud sync";
|
|
|
|
Write-Information "$targetPath <=> $localPath";
|
2023-07-02 15:38:44 +00:00
|
|
|
$pattern = "^\d+\\Folders(?:WithPlaceholders)?\\(\d+)";
|
2023-07-02 13:44:47 +00:00
|
|
|
|
|
|
|
$folderID = (
|
|
|
|
Get-Content $($this.GetNextcloudConfigFile()) | `
|
|
|
|
Where-Object { $_ -match "$pattern" } | `
|
|
|
|
ForEach-Object { $_ -replace "$pattern.*$","`$1" } | `
|
|
|
|
Sort-Object -Unique | `
|
|
|
|
Measure-Object -Maximum).Maximum + 1;
|
|
|
|
|
2023-07-02 18:45:25 +00:00
|
|
|
$configName = "Folders";
|
2023-07-02 19:49:00 +00:00
|
|
|
$localPath = $localPath.Replace("\", "/");
|
|
|
|
$targetPath = $targetPath.Replace("\", "/");
|
2023-07-02 13:44:47 +00:00
|
|
|
|
2023-07-02 18:45:25 +00:00
|
|
|
if ($virtualFiles) {
|
|
|
|
$configName += "WithPlaceholders";
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:51:16 +00:00
|
|
|
Write-Information "Stopping Nextcloud process";
|
2023-07-02 22:59:11 +00:00
|
|
|
$nextcloudProcess = Get-Process nextcloud;
|
2023-07-03 20:54:30 +00:00
|
|
|
$nextcloudPath = [string]$nextcloudProcess[0].Path;
|
2023-07-02 22:59:11 +00:00
|
|
|
$nextcloudProcess | Stop-Process -Force;
|
|
|
|
|
2023-07-02 22:47:21 +00:00
|
|
|
$accountSectionEntered = $false;
|
2023-07-25 10:15:28 +00:00
|
|
|
$accountSectionLeft = $false;
|
2023-07-02 22:47:21 +00:00
|
|
|
|
2023-07-25 10:15:28 +00:00
|
|
|
$newSettings = [string]::Join(
|
|
|
|
"`n",
|
|
|
|
@(
|
|
|
|
"0\$configName\$folderID\localPath=$localPath",
|
|
|
|
"0\$configName\$folderID\targetPath=$targetPath"));
|
|
|
|
|
|
|
|
$oldContent = Get-Content ($this.GetNextcloudConfigFile());
|
|
|
|
|
2023-07-25 10:39:45 +00:00
|
|
|
$(
|
2023-07-25 10:16:26 +00:00
|
|
|
for ($i = 0; $i -lt $oldContent.Count; $i++) {
|
2023-07-25 10:40:35 +00:00
|
|
|
$line = $oldContent[$i];
|
|
|
|
|
|
|
|
if ($line -eq "[Accounts]") {
|
2023-07-02 22:47:21 +00:00
|
|
|
$accountSectionEntered = $true;
|
|
|
|
}
|
|
|
|
|
2023-07-25 10:42:04 +00:00
|
|
|
if ($line -eq "" -and $accountSectionEntered) {
|
2023-07-25 10:15:28 +00:00
|
|
|
$accountSectionLeft = $true;
|
|
|
|
$newSettings;
|
2023-07-02 22:47:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 10:40:35 +00:00
|
|
|
$line;
|
2023-07-25 10:42:04 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
(-not $accountSectionLeft) -and
|
|
|
|
($i -eq ($oldContent.Count - 1)))
|
|
|
|
{
|
|
|
|
$newSettings;
|
|
|
|
}
|
2023-07-25 10:15:28 +00:00
|
|
|
}) | Set-Content ($this.GetNextcloudConfigFile());
|
2023-07-02 15:38:44 +00:00
|
|
|
|
2023-07-25 08:51:16 +00:00
|
|
|
Write-Information "New nextcloud config:";
|
2023-07-25 10:39:45 +00:00
|
|
|
Write-Information (Get-Content $($this.GetNextcloudConfigFile()) | Out-String);
|
2023-07-25 08:51:16 +00:00
|
|
|
|
|
|
|
Write-Information "Restarting Nextcloud";
|
2023-07-02 15:38:44 +00:00
|
|
|
Start-Process $nextcloudPath;
|
2023-07-02 13:44:47 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 20:58:54 +00:00
|
|
|
[void] Reboot() {
|
|
|
|
Write-Host "Restarting Computer...";
|
2023-06-23 18:08:31 +00:00
|
|
|
$this.RegisterReboot();
|
2023-07-16 09:30:20 +00:00
|
|
|
Restart-Computer -Force;
|
2023-07-16 09:21:58 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:58:00 +00:00
|
|
|
[void] PreventSleepMode() {
|
|
|
|
$performanceScheme = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
|
2023-07-29 09:04:55 +00:00
|
|
|
$currentScheme = [regex]::Match((powercfg /GETACTIVESCHEME), "Power Scheme GUID: ([0-9a-f-]+) ").Groups[1].Value;
|
2023-07-29 00:58:00 +00:00
|
|
|
|
|
|
|
if ($currentScheme -ne $performanceScheme) {
|
2023-07-29 01:01:53 +00:00
|
|
|
Write-Information "Disabling Power Save mode";
|
2024-03-24 00:10:44 +00:00
|
|
|
$this.Set("Power Scheme", $currentScheme);
|
2023-07-29 00:58:00 +00:00
|
|
|
powercfg /S 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 11:24:36 +00:00
|
|
|
[void] Cleanup() {
|
|
|
|
$this.DeregisterNewUserReboot();
|
|
|
|
$this.RemoveAutologin();
|
2023-07-03 12:35:16 +00:00
|
|
|
$this.SetUACState($true);
|
2023-07-29 00:58:00 +00:00
|
|
|
$originalScheme = $this.Get("Power Scheme");
|
2023-07-29 01:25:47 +00:00
|
|
|
Remove-Item $($this.EnsureConfigKey().PSPath);
|
2023-07-29 00:58:00 +00:00
|
|
|
|
|
|
|
if ($originalScheme) {
|
2023-07-29 01:01:53 +00:00
|
|
|
Write-Information "Reset power plan to original state";
|
2023-07-29 00:58:00 +00:00
|
|
|
powercfg /S $originalScheme;
|
|
|
|
}
|
2023-07-03 11:24:36 +00:00
|
|
|
}
|
2023-06-06 22:56:29 +00:00
|
|
|
}
|