2024-03-06 18:02:52 +01:00
|
|
|
<#
|
|
|
|
.NOTES
|
|
|
|
===========================================================================
|
|
|
|
FileName: spmover1.ps1
|
|
|
|
Author: SebastienQUEROL
|
2024-03-07 08:19:15 +01:00
|
|
|
Created On: 2024/03/07
|
|
|
|
Last Updated: 2024/03/07
|
2024-03-06 18:02:52 +01:00
|
|
|
Organization:
|
|
|
|
Version: v0.1
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
|
|
.DEPENDENCIES
|
|
|
|
#>
|
|
|
|
|
|
|
|
# ScriptBlock to Execute in STA Runspace
|
|
|
|
$sbGUI = {
|
|
|
|
param($BaseDir)
|
|
|
|
|
2024-03-07 08:19:15 +01:00
|
|
|
#region Environment Setup
|
2024-03-06 18:02:52 +01:00
|
|
|
|
2024-03-07 08:19:15 +01:00
|
|
|
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
|
2024-03-06 18:02:52 +01:00
|
|
|
|
|
|
|
#region Dot Sourcing of files
|
|
|
|
|
|
|
|
$dotSourceDir = $BaseDir
|
|
|
|
|
|
|
|
. "$($dotSourceDir)\Functions.ps1"
|
2024-03-07 08:19:15 +01:00
|
|
|
. "$($dotSourceDir)\Events.ps1"
|
2024-03-06 18:02:52 +01:00
|
|
|
|
|
|
|
#endregion Dot Sourcing of files
|
|
|
|
|
|
|
|
#region Form Initialization
|
|
|
|
|
|
|
|
try {
|
|
|
|
ConvertFrom-WinFormsXML -Reference refs -Suppress -Xml @"
|
|
|
|
<Form Name="MainForm" Size="547, 462">
|
|
|
|
<TextBox Name="tbx_SiteURL" CharacterCasing="Lower" Location="44, 133" Size="374, 20" Text="adresse du site" />
|
|
|
|
<TextBox Name="tbx_SourceFolderURL" Location="43, 158" Size="169, 20" Text="Dossier source" />
|
|
|
|
<TextBox Name="tbx_TargetFolderURL" Location="255, 158" Size="165, 20" Text="Dossier de destination" />
|
|
|
|
<Button Name="btn_Start" Location="437, 134" Size="59, 43" Text="GO !" />
|
2024-03-07 08:19:15 +01:00
|
|
|
<Label Name="lbl_byWho" Font="Comic Sans MS, 12pt" Location="40, 86" Text="by squerol" />
|
|
|
|
<Label Name="lbl_arrow" Font="Wingdings, 26.25pt" Location="211, 151" Size="43, 32" Text="F" />
|
|
|
|
<ListBox Name="lbx_results" Font="Lucida Console, 11.25pt" HorizontalScrollbar="True" ItemHeight="15" Location="45, 207" ScrollAlwaysVisible="True" Size="448, 184" />
|
|
|
|
<PictureBox Name="pbx_logo" Image="System.Drawing.Bitmap" Location="41, 18" Size="465, 69" />
|
2024-03-06 18:02:52 +01:00
|
|
|
</Form>
|
|
|
|
"@
|
|
|
|
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Form Initialization."}
|
|
|
|
|
|
|
|
#endregion Form Initialization
|
|
|
|
|
2024-03-07 08:19:15 +01:00
|
|
|
#region Event Assignment
|
|
|
|
|
|
|
|
try {
|
|
|
|
$Script:refs['btn_Start'].Add_Click($eventSB['btn_Start'].Click)
|
|
|
|
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Event Assignment."}
|
|
|
|
|
|
|
|
#endregion Event Assignment
|
|
|
|
|
2024-03-06 18:02:52 +01:00
|
|
|
#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
|