Initialer Import der Synology Scripts

This commit is contained in:
root
2026-08-05 08:43:57 +02:00
commit 5e32a7c411
404 changed files with 79932 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
#region Environment Setup
try {
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Environment Setup."}
#endregion Environment Setup
+111
View File
@@ -0,0 +1,111 @@
#region Functions
function Update-ErrorLog {
param(
[System.Management.Automation.ErrorRecord]$ErrorRecord,
[string]$Message,
[switch]$Promote
)
if ( $Message -ne '' ) {[void][System.Windows.Forms.MessageBox]::Show("$($Message)`r`n`r`nCheck '$($BaseDir)\exceptions.txt' for details.",'Exception Occurred')}
$date = Get-Date -Format 'yyyyMMdd HH:mm:ss'
$ErrorRecord | Out-File "$($BaseDir)\tmpError.txt"
Add-Content -Path "$($BaseDir)\exceptions.txt" -Value "$($date): $($(Get-Content "$($BaseDir)\tmpError.txt") -replace "\s+"," ")"
Remove-Item -Path "$($BaseDir)\tmpError.txt"
if ( $Promote ) {throw $ErrorRecord}
}
function ConvertFrom-WinFormsXML {
param(
[Parameter(Mandatory=$true)]$Xml,
[string]$Reference,
$ParentControl,
[switch]$Suppress
)
try {
if ( $Xml.GetType().Name -eq 'String' ) {$Xml = ([xml]$Xml).ChildNodes}
if ( $Xml.ToString() -ne 'SplitterPanel' ) {$newControl = New-Object System.Windows.Forms.$($Xml.ToString())}
if ( $ParentControl ) {
if ( $Xml.ToString() -match "^ToolStrip" ) {
if ( $ParentControl.GetType().Name -match "^ToolStrip" ) {[void]$ParentControl.DropDownItems.Add($newControl)} else {[void]$ParentControl.Items.Add($newControl)}
} elseif ( $Xml.ToString() -eq 'ContextMenuStrip' ) {$ParentControl.ContextMenuStrip = $newControl}
elseif ( $Xml.ToString() -eq 'SplitterPanel' ) {$newControl = $ParentControl.$($Xml.Name.Split('_')[-1])}
else {$ParentControl.Controls.Add($newControl)}
}
$Xml.Attributes | ForEach-Object {
$attrib = $_
$attribName = $_.ToString()
if ( $Script:specialProps.Array -contains $attribName ) {
if ( $attribName -eq 'Items' ) {
$($_.Value -replace "\|\*BreakPT\*\|","`n").Split("`n") | ForEach-Object{[void]$newControl.Items.Add($_)}
} else {
# Other than Items only BoldedDate properties on MonthCalendar control
$methodName = "Add$($attribName)" -replace "s$"
$($_.Value -replace "\|\*BreakPT\*\|","`n").Split("`n") | ForEach-Object{$newControl.$attribName.$methodName($_)}
}
} else {
switch ($attribName) {
FlatAppearance {
$attrib.Value.Split('|') | ForEach-Object {$newControl.FlatAppearance.$($_.Split('=')[0]) = $_.Split('=')[1]}
}
default {
if ( $null -ne $newControl.$attribName ) {
if ( $newControl.$attribName.GetType().Name -eq 'Boolean' ) {
if ( $attrib.Value -eq 'True' ) {$value = $true} else {$value = $false}
} else {$value = $attrib.Value}
} else {$value = $attrib.Value}
$newControl.$attribName = $value
}
}
}
if (( $attrib.ToString() -eq 'Name' ) -and ( $Reference -ne '' )) {
try {$refHashTable = Get-Variable -Name $Reference -Scope Script -ErrorAction Stop}
catch {
New-Variable -Name $Reference -Scope Script -Value @{} | Out-Null
$refHashTable = Get-Variable -Name $Reference -Scope Script -ErrorAction SilentlyContinue
}
$refHashTable.Value.Add($attrib.Value,$newControl)
}
}
if ( $Xml.ChildNodes ) {$Xml.ChildNodes | ForEach-Object {ConvertFrom-WinformsXML -Xml $_ -ParentControl $newControl -Reference $Reference -Suppress}}
if ( $Suppress -eq $false ) {return $newControl}
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered adding $($Xml.ToString()) to $($ParentControl.Name)"}
}
function Get-CustomControl {
param(
[Parameter(Mandatory=$true)][hashtable]$ControlInfo,
[string]$Reference,
[switch]$Suppress
)
try {
$refGuid = [guid]::NewGuid()
$control = ConvertFrom-WinFormsXML -Xml "$($ControlInfo.XMLText)" -Reference $refGuid
$refControl = Get-Variable -Name $refGuid -ValueOnly
if ( $ControlInfo.Events ) {$ControlInfo.Events.ForEach({$refControl[$_.Name]."add_$($_.EventType)"($_.ScriptBlock)})}
if ( $Reference -ne '' ) {New-Variable -Name $Reference -Scope Script -Value $refControl}
Remove-Variable -Name refGuid -Scope Script
if ( $Suppress -eq $false ) {return $control}
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered getting special control."}
}
#endregion Functions
+112
View File
@@ -0,0 +1,112 @@
<#
.NOTES
===========================================================================
FileName: tst.ps1
Author: micha
Created On: 2024.04.26
Last Updated: 2024.04.26
Organization:
Version: v0.1
===========================================================================
.DESCRIPTION
.DEPENDENCIES
#>
# ScriptBlock to Execute in STA Runspace
$sbGUI = {
param($BaseDir)
#region Child Forms
$Script:childFormInfo = @{
'MainForm' = @{
XMLText = @"
<Form Name="MainForm" Size="2714; 988">
<Label Name="lbl_Programs" Font="Segoe UI; 18pt" Location="0; 10" Size="200; 50" TextAlign="MiddleCenter" Text="Install Options" />
<Label Name="lbl_config" Font="Segoe UI; 18pt" Location="500; 10" Size="260; 50" TextAlign="MiddleCenter" Text="Configuration Options" />
<Label Name="lbl_symantec" Font="Segoe UI; 18pt" Location="0; 100" Size="150; 30" TextAlign="MiddleCenter" Text="Symantec" />
<Label Name="lbl_Packages" Location="0; 140" TextAlign="MiddleCenter" Text="Packages" />
</Form>
"@
}
#endregion Child Forms
#region Dot Sourcing of files
$dotSourceDir = $BaseDir
. "$($dotSourceDir)\Functions.ps1"
. "$($dotSourceDir)\EnvSetup.ps1"
#endregion Dot Sourcing of files
#region Form Initialization
try {
ConvertFrom-WinFormsXML -Reference refs -Suppress -Xml @"
<Form Name="MainForm" />
"@
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Form Initialization."}
#endregion Form Initialization
#region Other Actions Before ShowDialog
try {
Remove-Variable -Name eventSB
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered before ShowDialog."}
#endregion Other Actions Before ShowDialog
# Show the form
try {[void]$Script:refs['MainForm'].ShowDialog()} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered unexpectedly at ShowDialog."}
<#
#region Actions After Form Closed
try {
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered after Form close."}
#endregion Actions After Form Closed
#>
}
#region Start Point of Execution
# Initialize STA Runspace
$rsGUI = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
$rsGUI.ApartmentState = 'STA'
$rsGUI.ThreadOptions = 'ReuseThread'
$rsGUI.Open()
# Create the PSCommand, Load into Runspace, and BeginInvoke
$cmdGUI = [Management.Automation.PowerShell]::Create().AddScript($sbGUI).AddParameter('BaseDir',$PSScriptRoot)
$cmdGUI.RunSpace = $rsGUI
$handleGUI = $cmdGUI.BeginInvoke()
# Hide Console Window
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0)
#Loop Until GUI Closure
while ( $handleGUI.IsCompleted -eq $false ) {Start-Sleep -Seconds 5}
# Dispose of GUI Runspace/Command
$cmdGUI.EndInvoke($handleGUI)
$cmdGUI.Dispose()
$rsGUI.Dispose()
Exit
#endregion Start Point of Execution