Correction README.md

Ajout modification du fichier Project.gfx
This commit is contained in:
2026-03-05 10:36:52 +01:00
parent 83df3cc4ef
commit bd4fde8190
5 changed files with 204 additions and 19 deletions

View File

@@ -52,4 +52,74 @@ function Get-ZipFilename {
return "fullConfig.$hashString.zip"
}
Export-ModuleMember -Function New-EnoceanZip, Get-ZipFilename
function Read-GfxMainXml {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[byte[]]$GfxBytes
)
$memStream = New-Object System.IO.MemoryStream(, $GfxBytes)
$archive = New-Object System.IO.Compression.ZipArchive($memStream, [System.IO.Compression.ZipArchiveMode]::Read)
$entry = $archive.GetEntry("Main.xml")
if (-not $entry) {
$archive.Dispose()
$memStream.Close()
throw "Main.xml non trouve dans le fichier GFx"
}
$entryStream = $entry.Open()
$reader = New-Object System.IO.StreamReader($entryStream, [System.Text.Encoding]::UTF8)
$content = $reader.ReadToEnd()
$reader.Close()
$entryStream.Close()
$archive.Dispose()
$memStream.Close()
return $content
}
function Update-GfxZip {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[byte[]]$GfxBytes,
[Parameter(Mandatory)]
[string]$ModifiedMainXml
)
# Copier les bytes dans un MemoryStream modifiable
$memStream = New-Object System.IO.MemoryStream
$memStream.Write($GfxBytes, 0, $GfxBytes.Length)
$memStream.Position = 0
$archive = New-Object System.IO.Compression.ZipArchive($memStream, [System.IO.Compression.ZipArchiveMode]::Update, $true)
# Supprimer l'ancien Main.xml et recreer avec le contenu modifie
$entry = $archive.GetEntry("Main.xml")
if ($entry) {
$entry.Delete()
}
$newEntry = $archive.CreateEntry("Main.xml", [System.IO.Compression.CompressionLevel]::Optimal)
$entryStream = $newEntry.Open()
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$writer = New-Object System.IO.StreamWriter($entryStream, $utf8NoBom)
$writer.Write($ModifiedMainXml)
$writer.Flush()
$writer.Close()
$entryStream.Close()
$archive.Dispose()
$newBytes = $memStream.ToArray()
$memStream.Close()
Write-Log -Message "GFx mis a jour en memoire : $($newBytes.Length) octets" -Level INFO
return $newBytes
}
Export-ModuleMember -Function New-EnoceanZip, Get-ZipFilename, Read-GfxMainXml, Update-GfxZip