Ajout de la configuration de paritionnement des disques

This commit is contained in:
benoit committed 2026-10-15 23:05:30 +02:00
1 parent 7c724d475e
commit e388cdca45
9 files changed
+450 -123

No files matched your search

+84 -22
View File
@@ -96,7 +96,33 @@ if (-not (Test-Path -LiteralPath $loggingModulePath -PathType Leaf)) {
}
. ([scriptblock]::Create([System.IO.File]::ReadAllText($loggingModulePath)))
Initialize-DeployCenterLogging -LogRoot $script:LogRoot -IPv4 $script:DeployIPv4
$script:HardwareJson = Join-Path $env:TEMP "HardwareInfo.json"
# Les profils de partitionnement sont des fichiers de données PSD1, validés par leur module.
$partitioningModulePath = Join-Path $script:DeployRoot 'Modules\Partitioning.psm1'
if (-not (Test-Path -LiteralPath $partitioningModulePath -PathType Leaf)) {
throw "Module de partitionnement introuvable : $partitioningModulePath"
}
Import-Module $partitioningModulePath -Force
$script:PartitionProfilesRoot = Join-Path $script:DeployRoot 'Partitioning\Profiles'
$script:PartitionProfiles = @()
foreach ($profileName in (Get-DeployCenterPartitionProfileNames -ProfilesRoot $script:PartitionProfilesRoot)) {
try {
$script:PartitionProfiles += Import-DeployCenterPartitionProfile -ProfilesRoot $script:PartitionProfilesRoot -ProfileName $profileName
} catch {
Write-Log "Profil de partitionnement '$profileName' ignoré : $($_.Exception.Message)" 'WARNING'
}
}
if ($script:PartitionProfiles.Count -eq 0) {
throw "Aucun profil de partitionnement valide trouvé dans $script:PartitionProfilesRoot"
}
$script:SelectedPartitionProfileIndex = 0
for ($profileIndex = 0; $profileIndex -lt $script:PartitionProfiles.Count; $profileIndex++) {
if ($script:PartitionProfiles[$profileIndex].Default -eq $true) {
$script:SelectedPartitionProfileIndex = $profileIndex
break
}
}
$script:SelectedPartitionProfile = $script:PartitionProfiles[$script:SelectedPartitionProfileIndex]
# Inventaire de session et UltraVNC portable : tout reste dans le dossier temporaire.
$script:InventoryDir = Join-Path $env:TEMP 'DeployCenter'
@@ -262,6 +288,21 @@ function Write-DeployInventory {
}
$json = $inventory | ConvertTo-Json -Depth 8
Set-Content -LiteralPath $script:InventoryFile -Value $json -Encoding UTF8
# Nettoyer les anciens exports séparés après l'écriture de l'inventaire consolidé.
$legacyInventoryFiles = @(
(Join-Path $env:TEMP 'HardwareInfo.json'),
(Join-Path $script:InventoryDir 'hardware.json')
)
foreach ($legacyFile in $legacyInventoryFiles) {
if (Test-Path -LiteralPath $legacyFile -PathType Leaf) {
try {
Remove-Item -LiteralPath $legacyFile -Force -ErrorAction Stop
} catch {
Write-Log "Impossible de supprimer l'ancien export d'inventaire '$legacyFile' : $($_.Exception.Message)" 'WARNING'
}
}
}
} catch {
Write-Log "Impossible d'écrire l'inventaire temporaire : $($_.Exception.Message)" 'WARNING'
}
@@ -611,13 +652,13 @@ $script:form.Controls.Add($script:groupPC)
# DISQUE PHYSIQUE - SELECTEUR COMPACT
# ============================================================
$script:groupDisks = New-GroupBox -Text "Disque physique" `
-X $margin -Y 220 -Width $usableWidth -Height 78
$script:groupDisks = New-GroupBox -Text "Disque et partitionnement" `
-X $margin -Y 220 -Width $usableWidth -Height 116
$script:cmbDisk = New-Object System.Windows.Forms.ComboBox
$script:cmbDisk.Name = "cmbDisk"
$script:cmbDisk.Location = New-Object System.Drawing.Point(12, 30)
$script:cmbDisk.Size = New-Object System.Drawing.Size(($usableWidth - 24), 28)
$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
@@ -626,13 +667,29 @@ $script:cmbDisk.ForeColor = $script:Theme.Text
$script:cmbDisk.Font = $script:FontSmall
$script:cmbDisk.IntegralHeight = $false
$script:cmbDisk.MaxDropDownItems = 12
$partitionProfileSelector = New-DeployCenterPartitionProfileSelector `
-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: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 }
$script:cmbDisk.Location = New-Object System.Drawing.Point(12, 30)
$script:cmbDisk.Size = New-Object System.Drawing.Size([Math]::Max(250, $script:groupDisks.ClientSize.Width - 24), 28)
$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
}
# ============================================================
@@ -730,6 +787,9 @@ function Set-ControlTheme {
$Control.BackColor = $script:Theme.PanelAlt
$Control.ForeColor = $script:Theme.Text
}
elseif ($Control -is [System.Windows.Forms.ComboBox]) {
Set-DeployCenterComboBoxTheme -ComboBox $Control -Theme $script:Theme
}
elseif ($Control -is [System.Windows.Forms.TextBox]) {
$Control.BackColor = $script:Theme.PanelAlt
$Control.ForeColor = $script:Theme.Text
@@ -1328,8 +1388,8 @@ function Show-WindowsSourcesDialog {
$list.Location = New-Object System.Drawing.Point(16, 112)
$list.Size = New-Object System.Drawing.Size([Math]::Max(300, $clientWidth - 32), [Math]::Max(120, $clientHeight - 205))
$list.Anchor = 'Top,Bottom,Left,Right'
$lblStatus.Location = New-Object System.Drawing.Point(16, ($clientHeight - 40))
$lblStatus.Size = New-Object System.Drawing.Size([Math]::Max(300, $clientWidth - 32), 32)
$lblStatus.Location = New-Object System.Drawing.Point(16, ($clientHeight - 52))
$lblStatus.Size = New-Object System.Drawing.Size([Math]::Max(300, $clientWidth - 32), 24)
$lblStatus.Anchor = 'Bottom,Left,Right'
}
$dlg.Add_Shown({
@@ -1342,7 +1402,7 @@ function Show-WindowsSourcesDialog {
$btnEditions.Add_Click({
if ($list.SelectedItems.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show('Sélectionne d''abord une source dans la liste.', 'Éditions Windows', 'OK', 'Information') | Out-Null
Show-DeployCenterMessage -Message 'Sélectionne d''abord une source dans la liste.' -Title 'Éditions Windows' -Icon Information -Owner $dlg -Theme $script:Theme -Font $script:FontRegular
return
}
@@ -1567,7 +1627,7 @@ function Show-WindowsSourcesDialog {
} catch {
$lblStatus.Text = "Echec de l'analyse des editions de $selectedName."
Write-Log "Erreur analyse editions $selectedPath : $($_.Exception.Message)" 'ERROR'
[System.Windows.Forms.MessageBox]::Show($_.Exception.Message, 'Analyse des editions', 'OK', 'Warning') | Out-Null
Show-DeployCenterMessage -Message $_.Exception.Message -Title 'Analyse des éditions' -Icon Warning -Owner $dlg -Theme $script:Theme -Font $script:FontRegular
} finally {
$dlg.Cursor = [System.Windows.Forms.Cursors]::Default
$btnEditions.Enabled = $true
@@ -1592,7 +1652,7 @@ function Show-WindowsSourcesDialog {
} catch {
$lblStatus.Text = 'Echec de la recherche. Consulte le message.'
Write-Log "Erreur detection sources : $($_.Exception.Message)" 'ERROR'
[System.Windows.Forms.MessageBox]::Show($_.Exception.Message, 'Detection des sources', 'OK', 'Warning') | Out-Null
Show-DeployCenterMessage -Message $_.Exception.Message -Title 'Détection des sources' -Icon Warning -Owner $dlg -Theme $script:Theme -Font $script:FontRegular
} finally {
$dlg.Cursor = [System.Windows.Forms.Cursors]::Default
$btnScan.Enabled = $true
@@ -1643,7 +1703,7 @@ function Update-HardwareView {
try {
$script:cmbDisk.Items.Clear()
foreach ($disk in $info.Disks) {
$diskLabel = "Disque {0} - {1} - {2:N1} Go - {3} - {4}" -f $disk.Index, $disk.Model, $disk.SizeGB, $disk.Interface, $disk.Status
$diskLabel = "Disque {0} - {1} - {2:N1} Go - {3} - {4}" -f $disk.Index, $disk.Model, $disk.SizeGB, $disk.BusType, $disk.Status
$diskChoice = [pscustomobject]@{ Text = $diskLabel; Tag = [string]$disk.Index }
[void]$script:cmbDisk.Items.Add($diskChoice)
}
@@ -1663,8 +1723,6 @@ function Update-HardwareView {
$script:cmbDisk.EndUpdate()
}
$json = $info | ConvertTo-Json -Depth 6
Set-Content -LiteralPath $script:HardwareJson -Value $json -Encoding UTF8
Write-DeployInventory -HardwareInfo $info
Write-Log "Inventaire materiel actualise." "SUCCESS"
@@ -1680,12 +1738,7 @@ function Update-HardwareView {
catch {
Write-Log "Erreur inventaire : $($_.Exception.Message)" "ERROR"
[System.Windows.Forms.MessageBox]::Show(
$_.Exception.Message,
"Erreur DeployCenter",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
) | Out-Null
Show-DeployCenterMessage -Message $_.Exception.Message -Title 'Erreur DeployCenter' -Icon Error -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
}
finally {
$script:btnRefresh.Enabled = $true
@@ -1714,7 +1767,7 @@ 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, 78)
$script:groupDisks.Size = New-Object System.Drawing.Size($contentWidth, 116)
Set-DiskSelectorWidth
# Le journal absorbe l'espace vertical restant au-dessus des actions et du pied de page.
@@ -1765,6 +1818,15 @@ $script:cmbDisk.Add_SizeChanged({
Set-DiskSelectorWidth
})
$script:cmbPartitionProfile.Add_SelectedIndexChanged({
$selectedIndex = $script:cmbPartitionProfile.SelectedIndex
if ($selectedIndex -ge 0 -and $selectedIndex -lt $script:PartitionProfiles.Count) {
$script:SelectedPartitionProfileIndex = $selectedIndex
$script:SelectedPartitionProfile = $script:PartitionProfiles[$selectedIndex]
Write-Log "Profil de partitionnement sélectionné : $($script:SelectedPartitionProfile.Name)" 'INFO'
}
})
$script:form.Add_SizeChanged({
Update-DeployCenterLayout
})