Ajout d'un profil avec deux partitions

Correction de la mise en page et ajout de la demande du nom d'hôte
This commit is contained in:
benoit committed 2026-10-15 23:45:54 +02:00
1 parent e388cdca45
commit 1c67cb2630
5 files changed
+519 -79

No files matched your search

+158 -74
View File
@@ -123,6 +123,11 @@ for ($profileIndex = 0; $profileIndex -lt $script:PartitionProfiles.Count; $prof
}
}
$script:SelectedPartitionProfile = $script:PartitionProfiles[$script:SelectedPartitionProfileIndex]
$script:SelectedPartitionSizing = $null
$script:SelectedDiskIndex = $null
$script:SelectedWindowsEdition = $null
$script:RefreshingDiskList = $false
$script:ChangingPartitionProfileSelection = $false
# Inventaire de session et UltraVNC portable : tout reste dans le dossier temporaire.
$script:InventoryDir = Join-Path $env:TEMP 'DeployCenter'
@@ -649,54 +654,40 @@ $script:groupPC.Controls.AddRange(@(
$script:form.Controls.Add($script:groupPC)
# ============================================================
# DISQUE PHYSIQUE - SELECTEUR COMPACT
# PREPARATION DU DEPLOIEMENT
# ============================================================
$script:groupDisks = New-GroupBox -Text "Disque et partitionnement" `
-X $margin -Y 220 -Width $usableWidth -Height 116
$script:groupDisks = New-GroupBox -Text "Préparation du déploiement" `
-X $margin -Y 220 -Width $usableWidth -Height 226
$script:cmbDisk = New-Object System.Windows.Forms.ComboBox
$script:cmbDisk.Name = "cmbDisk"
$script:cmbDisk.Location = New-Object System.Drawing.Point(12, 38)
$script:cmbDisk.Size = New-Object System.Drawing.Size(($usableWidth - 24), 26)
$script:cmbDisk.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right
$script:cmbDisk.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$script:cmbDisk.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$script:cmbDisk.BackColor = $script:Theme.PanelAlt
$script:cmbDisk.ForeColor = $script:Theme.Text
$script:cmbDisk.Font = $script:FontSmall
$script:cmbDisk.IntegralHeight = $false
$script:cmbDisk.MaxDropDownItems = 12
$partitionProfileSelector = New-DeployCenterPartitionProfileSelector `
$deploymentControls = New-DeployCenterDeploymentControls `
-Parent $script:groupDisks `
-ProfileNames @($script:PartitionProfiles | ForEach-Object { [string]$_.Name }) `
-Theme $script:Theme `
-Font $script:FontSmall
$script:lblPartitionProfile = $partitionProfileSelector.Label
$script:cmbPartitionProfile = $partitionProfileSelector.ComboBox
$script:cmbPartitionProfile.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right
$script:cmbDisk = $deploymentControls.DiskComboBox
$script:btnChooseWindows = $deploymentControls.ChooseSystemButton
$script:lblSelectedWindows = $deploymentControls.SelectedSystemLabel
$script:lblPartitionProfile = $deploymentControls.PartitionProfileLabel
$script:cmbPartitionProfile = $deploymentControls.PartitionProfileComboBox
$script:txtHostName = $deploymentControls.HostNameTextBox
$script:cmbPartitionProfile.SelectedIndex = $script:SelectedPartitionProfileIndex
$script:groupDisks.Controls.Add($script:cmbDisk)
$script:form.Controls.Add($script:groupDisks)
function Set-DiskSelectorWidth {
if ($null -eq $script:cmbDisk -or $null -eq $script:groupDisks) { return }
$selectorWidth = [Math]::Max(250, $script:groupDisks.ClientSize.Width - 24)
$script:cmbDisk.Location = New-Object System.Drawing.Point(12, 38)
$script:cmbDisk.Size = New-Object System.Drawing.Size($selectorWidth, 26)
Set-DeployCenterPartitionProfileSelectorLayout `
-Label $script:lblPartitionProfile `
-ComboBox $script:cmbPartitionProfile `
-Width $selectorWidth
Set-DeployCenterDeploymentControlsLayout -Parent $script:groupDisks -Controls $deploymentControls
}
# ============================================================
# JOURNAL
# JOURNAL DANS UNE FENETRE DEDIEE
# ============================================================
$logY = $script:groupDisks.Bottom + 15
$logWindow = New-DeployCenterLogWindow -Theme $script:Theme -Font $script:FontRegular
$script:logForm = $logWindow.Form
$script:txtLog = $logWindow.TextBox
$buttonHeight = 38
# En plein ecran, rapprocher les boutons du bas sans empiéter sur le pied de page.
# En mode fenetre, conserver la position actuelle.
@@ -705,41 +696,16 @@ $buttonY = if ($script:Windowed) {
} else {
$screenHeight - 42 - $buttonHeight
}
$logHeight = [math]::Max(100, $buttonY - $logY - 15)
$script:groupLog = New-GroupBox -Text "Journal" `
-X $margin -Y $logY -Width $usableWidth -Height $logHeight
$script:txtLog = New-Object System.Windows.Forms.TextBox
$script:txtLog.Location = New-Object System.Drawing.Point(12, 28)
$script:txtLog.Size = New-Object System.Drawing.Size(
($usableWidth - 28), ($logHeight - 44)
)
$script:txtLog.Multiline = $true
$script:txtLog.ReadOnly = $true
$script:txtLog.WordWrap = $false
$script:txtLog.ScrollBars = [System.Windows.Forms.ScrollBars]::Both
$script:txtLog.BackColor = $script:Theme.PanelAlt
$script:txtLog.ForeColor = $script:Theme.Text
$script:txtLog.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$script:txtLog.Font = [System.Drawing.Font]::new("Consolas", [single]9, [System.Drawing.FontStyle]::Regular)
$script:groupLog.Controls.Add($script:txtLog)
$script:form.Controls.Add($script:groupLog)
# ============================================================
# BOUTONS ACTUALISER ET FERMER
# BOUTONS JOURNAL, ACTUALISER ET FERMER
# ============================================================
$buttonWidth = 140
$buttonGap = 12
$closeX = $screenWidth - $margin - $buttonWidth
$refreshX = $closeX - $buttonGap - $buttonWidth
$sourcesX = $refreshX - $buttonGap - 170
$script:btnSources = New-Button -Text "Sources Windows" `
-X $sourcesX -Y $buttonY -Width 170 -Height $buttonHeight `
$script:btnLog = New-Button -Text "Journal" `
-X $margin -Y $buttonY -Width $buttonWidth -Height $buttonHeight `
-Role "Button"
$script:btnSources.ForeColor = $script:Theme.Text
$script:btnRefresh = New-Button -Text "Actualiser" `
-X $refreshX -Y $buttonY -Width $buttonWidth -Height $buttonHeight `
@@ -749,7 +715,7 @@ $script:btnClose = New-Button -Text "Fermer" `
-X $closeX -Y $buttonY -Width $buttonWidth -Height $buttonHeight `
-Role "DangerButton"
$script:form.Controls.Add($script:btnSources)
$script:form.Controls.Add($script:btnLog)
$script:form.Controls.Add($script:btnRefresh)
$script:form.Controls.Add($script:btnClose)
Add-SessionFooter -TargetForm $script:form -ShowPassword $true
@@ -776,6 +742,9 @@ function Set-ControlTheme {
}
elseif ($Control -is [System.Windows.Forms.Label]) {
$Control.ForeColor = $script:Theme.Text
if ($Control.Name -eq 'lblSelectedWindows') {
$Control.ForeColor = if ($script:SelectedWindowsEdition) { $script:Theme.Success } else { $script:Theme.Secondary }
}
# Le pied de page VNC suit lui aussi la palette du thème actif.
if ($Control.Name -eq 'DeployCenterSessionFooter') {
$Control.BackColor = $script:Theme.PanelAlt
@@ -818,6 +787,7 @@ function Set-DeployCenterTheme {
$script:cmbTheme.Refresh()
Set-ControlTheme -Control $script:form
Set-ControlTheme -Control $script:logForm
# Met a jour le logo si une variante propre au theme existe.
Update-DeployCenterLogo -ThemeName $script:CurrentTheme
@@ -832,7 +802,8 @@ function Set-DeployCenterTheme {
$script:lblWinPE.ForeColor = $script:Theme.Secondary
}
Set-DeployCenterButtonStyle -Button $script:btnSources -Theme $script:Theme -Role 'Button'
Set-DeployCenterButtonStyle -Button $script:btnChooseWindows -Theme $script:Theme -Role 'Button'
Set-DeployCenterButtonStyle -Button $script:btnLog -Theme $script:Theme -Role 'Button'
Set-DeployCenterButtonStyle -Button $script:btnRefresh -Theme $script:Theme -Role 'PrimaryButton'
Set-DeployCenterButtonStyle -Button $script:btnClose -Theme $script:Theme -Role 'DangerButton'
# Actualise explicitement le pied de page principal lors du changement de thème.
@@ -846,7 +817,6 @@ function Set-DeployCenterTheme {
$script:cmbTheme.Invalidate()
$script:groupPC.Invalidate()
$script:groupDisks.Invalidate()
$script:groupLog.Invalidate()
$script:cmbDisk.BackColor = $script:Theme.PanelAlt
$script:cmbDisk.ForeColor = $script:Theme.Text
$script:cmbDisk.Invalidate()
@@ -1620,6 +1590,8 @@ function Show-WindowsSourcesDialog {
$script:SelectedWindowsEdition = $chosenEdition
$lblStatus.Text = "Édition sélectionnée : $($chosenEdition.Name) (index $($chosenEdition.Index))."
Write-Log "Edition selectionnee : $($chosenEdition.Name), index $($chosenEdition.Index), image $imagePath" 'SUCCESS'
$dlg.DialogResult = [System.Windows.Forms.DialogResult]::OK
$dlg.Close()
} else {
$lblStatus.Text = "$($editions.Count) édition(s) trouvée(s) dans $selectedName. Aucune nouvelle édition sélectionnée."
}
@@ -1635,6 +1607,12 @@ function Show-WindowsSourcesDialog {
}
})
$list.Add_DoubleClick({
if ($list.SelectedItems.Count -gt 0 -and $btnEditions.Enabled) {
$btnEditions.PerformClick()
}
})
$btnScan.Add_Click({
$btnScan.Enabled = $false
$dlg.Cursor = [System.Windows.Forms.Cursors]::WaitCursor
@@ -1695,10 +1673,12 @@ function Update-HardwareView {
$script:lblWinPE.ForeColor = $script:Theme.Secondary
}
$script:HardwareInventory = $info
$previousDiskIndex = $null
if ($null -ne $script:cmbDisk.SelectedItem -and $null -ne $script:cmbDisk.SelectedItem.Tag) {
$previousDiskIndex = [string]$script:cmbDisk.SelectedItem.Tag
}
$script:RefreshingDiskList = $true
$script:cmbDisk.BeginUpdate()
try {
$script:cmbDisk.Items.Clear()
@@ -1721,7 +1701,9 @@ function Update-HardwareView {
}
finally {
$script:cmbDisk.EndUpdate()
$script:RefreshingDiskList = $false
}
$script:SelectedDiskIndex = if ($script:cmbDisk.SelectedIndex -ge 0) { [string]$script:cmbDisk.SelectedItem.Tag } else { $null }
Write-DeployInventory -HardwareInfo $info
@@ -1746,6 +1728,51 @@ function Update-HardwareView {
}
}
function Get-SelectedDeployDiskInfo {
if ($null -eq $script:cmbDisk.SelectedItem -or $null -eq $script:HardwareInventory) { return $null }
$diskIndex = [int]$script:cmbDisk.SelectedItem.Tag
$matches = @($script:HardwareInventory.Disks | Where-Object { [int]$_.Index -eq $diskIndex } | Select-Object -First 1)
if ($matches.Count -gt 0) { return $matches[0] }
return $null
}
function Get-PartitionProfileSizingSelection {
param(
[Parameter(Mandatory=$true)][System.Collections.IDictionary]$Profile,
[Parameter(Mandatory=$true)]$DiskInfo,
[System.Collections.IDictionary]$InitialValues = @{}
)
$capacity = Get-DeployCenterPartitionSizingCapacity -Profile $Profile -DiskSizeBytes ([long]$DiskInfo.SizeBytes)
return Show-DeployCenterPartitionSizingDialog `
-Profile $Profile `
-AvailableGB $capacity.UsableGB `
-Theme $script:Theme `
-Font $script:FontRegular `
-Owner $script:form `
-InitialValues $InitialValues
}
function Set-PartitionProfileSizingSelection {
param(
[Parameter(Mandatory=$true)][System.Collections.IDictionary]$Profile,
[Parameter(Mandatory=$true)]$DiskInfo,
[System.Collections.IDictionary]$InitialValues = @{}
)
$selection = Get-PartitionProfileSizingSelection -Profile $Profile -DiskInfo $DiskInfo -InitialValues $InitialValues
if ($null -eq $selection) { return $false }
$script:SelectedPartitionSizing = [pscustomobject]@{
ProfileId = [string]$Profile.Id
DiskIndex = [int]$DiskInfo.Index
Inputs = $selection.Inputs
RemainderRole = $selection.RemainderRole
RemainderGB = [double]$selection.RemainderGB
AvailableGB = [double]$selection.AvailableGB
}
return $true
}
# ============================================================
# MISE EN PAGE ADAPTATIVE
# Les grandes zones suivent la fenetre ; les marges et hauteurs de controles restent fixes.
@@ -1767,28 +1794,21 @@ function Update-DeployCenterLayout {
$script:groupPC.Location = New-Object System.Drawing.Point($m, 100)
$script:groupPC.Size = New-Object System.Drawing.Size($contentWidth, 105)
$script:groupDisks.Location = New-Object System.Drawing.Point($m, 220)
$script:groupDisks.Size = New-Object System.Drawing.Size($contentWidth, 116)
$script:groupDisks.Size = New-Object System.Drawing.Size($contentWidth, 226)
Set-DiskSelectorWidth
# Le journal absorbe l'espace vertical restant au-dessus des actions et du pied de page.
$footerHeight = 26
$buttonHeightLocal = 38
$buttonYLocal = $h - $footerHeight - 14 - $buttonHeightLocal
$logYLocal = $script:groupDisks.Bottom + 14
$logHeightLocal = [Math]::Max(90, $buttonYLocal - $logYLocal - 12)
$script:groupLog.Location = New-Object System.Drawing.Point($m, $logYLocal)
$script:groupLog.Size = New-Object System.Drawing.Size($contentWidth, $logHeightLocal)
$script:txtLog.Location = New-Object System.Drawing.Point(12, 28)
$script:txtLog.Size = New-Object System.Drawing.Size([Math]::Max(250, $script:groupLog.ClientSize.Width - 24), [Math]::Max(50, $script:groupLog.ClientSize.Height - 40))
$buttonWidthLocal = 140
$buttonGapLocal = 12
$script:btnClose.Size = New-Object System.Drawing.Size($buttonWidthLocal, $buttonHeightLocal)
$script:btnRefresh.Size = New-Object System.Drawing.Size($buttonWidthLocal, $buttonHeightLocal)
$script:btnSources.Size = New-Object System.Drawing.Size(170, $buttonHeightLocal)
$script:btnLog.Size = New-Object System.Drawing.Size($buttonWidthLocal, $buttonHeightLocal)
$script:btnClose.Location = New-Object System.Drawing.Point([Math]::Max($m, $w - $m - $buttonWidthLocal), $buttonYLocal)
$script:btnRefresh.Location = New-Object System.Drawing.Point([Math]::Max($m, $script:btnClose.Left - $buttonGapLocal - $buttonWidthLocal), $buttonYLocal)
$script:btnSources.Location = New-Object System.Drawing.Point([Math]::Max($m, $script:btnRefresh.Left - $buttonGapLocal - 170), $buttonYLocal)
$script:btnLog.Location = New-Object System.Drawing.Point($m, $buttonYLocal)
Set-DiskSelectorWidth
}
@@ -1796,8 +1816,22 @@ function Update-DeployCenterLayout {
# EVENEMENTS
# ============================================================
$script:btnSources.Add_Click({
$script:btnChooseWindows.Add_Click({
Show-WindowsSourcesDialog
if ($script:SelectedWindowsEdition) {
$edition = $script:SelectedWindowsEdition
$sourceDescription = if ($edition.ImagePath) { [string]$edition.ImagePath } else { [string]$edition.SourcePath }
$script:lblSelectedWindows.Text = "{0} (index {1}) — {2}" -f $edition.Name, $edition.Index, $sourceDescription
$script:lblSelectedWindows.ForeColor = $script:Theme.Success
$script:lblSelectedWindows.Name = 'lblSelectedWindows'
$script:cmbPartitionProfile.Enabled = $true
}
})
$script:btnLog.Add_Click({
if ($script:logForm.IsDisposed) { return }
if (-not $script:logForm.Visible) { $script:logForm.Show($script:form) }
$script:logForm.BringToFront()
})
$script:btnRefresh.Add_Click({
@@ -1819,14 +1853,64 @@ $script:cmbDisk.Add_SizeChanged({
})
$script:cmbPartitionProfile.Add_SelectedIndexChanged({
if ($script:ChangingPartitionProfileSelection) { return }
$selectedIndex = $script:cmbPartitionProfile.SelectedIndex
if ($selectedIndex -ge 0 -and $selectedIndex -lt $script:PartitionProfiles.Count) {
$candidateProfile = $script:PartitionProfiles[$selectedIndex]
$sizeInputs = @($candidateProfile.Partitions | Where-Object { $_.Size.Policy -eq 'UserInputGB' })
if ($sizeInputs.Count -gt 0) {
$diskInfo = Get-SelectedDeployDiskInfo
$initialValues = @{}
if ($script:SelectedPartitionSizing -and $script:SelectedPartitionSizing.ProfileId -eq $candidateProfile.Id) {
$initialValues = $script:SelectedPartitionSizing.Inputs
}
if ($null -eq $diskInfo) {
Show-DeployCenterMessage -Message "Sélectionne d’abord un disque physique." -Title 'Partitionnement' -Icon Information -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
}
if ($null -eq $diskInfo -or -not (Set-PartitionProfileSizingSelection -Profile $candidateProfile -DiskInfo $diskInfo -InitialValues $initialValues)) {
$script:ChangingPartitionProfileSelection = $true
try { $script:cmbPartitionProfile.SelectedIndex = $script:SelectedPartitionProfileIndex }
finally { $script:ChangingPartitionProfileSelection = $false }
return
}
} else {
$script:SelectedPartitionSizing = $null
}
$script:SelectedPartitionProfileIndex = $selectedIndex
$script:SelectedPartitionProfile = $script:PartitionProfiles[$selectedIndex]
Write-Log "Profil de partitionnement sélectionné : $($script:SelectedPartitionProfile.Name)" 'INFO'
$script:SelectedPartitionProfile = $candidateProfile
Write-Log "Profil de partitionnement sélectionné : $($candidateProfile.Name)" 'INFO'
if ($script:SelectedPartitionSizing) {
foreach ($role in $script:SelectedPartitionSizing.Inputs.Keys) {
Write-Log "Taille saisie pour $role : $($script:SelectedPartitionSizing.Inputs[$role]) Go ; espace restant : $($script:SelectedPartitionSizing.RemainderGB) Go" 'INFO'
}
}
}
})
$script:cmbDisk.Add_SelectedIndexChanged({
if ($script:RefreshingDiskList -or $script:ChangingPartitionProfileSelection) { return }
$diskInfo = Get-SelectedDeployDiskInfo
if ($null -eq $diskInfo) { $script:SelectedDiskIndex = $null; return }
$profileSizeInputs = @($script:SelectedPartitionProfile.Partitions | Where-Object { $_.Size.Policy -eq 'UserInputGB' })
if ($profileSizeInputs.Count -gt 0) {
$initialValues = if ($script:SelectedPartitionSizing -and $script:SelectedPartitionSizing.ProfileId -eq $script:SelectedPartitionProfile.Id) {
$script:SelectedPartitionSizing.Inputs
} else { @{} }
if (-not (Set-PartitionProfileSizingSelection -Profile $script:SelectedPartitionProfile -DiskInfo $diskInfo -InitialValues $initialValues)) {
$script:RefreshingDiskList = $true
try {
for ($i = 0; $i -lt $script:cmbDisk.Items.Count; $i++) {
if ([string]$script:cmbDisk.Items[$i].Tag -eq [string]$script:SelectedDiskIndex) { $script:cmbDisk.SelectedIndex = $i; break }
}
} finally { $script:RefreshingDiskList = $false }
return
}
}
$script:SelectedDiskIndex = [string]$diskInfo.Index
})
$script:form.Add_SizeChanged({
Update-DeployCenterLayout
})