![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
|
|||||||||
![]() |
|
|
Thread Tools | Display Modes |
01-15-26, 05:27 PM
|
#1 |
|
Seaman
![]() Join Date: Feb 2012
Posts: 36
Downloads: 107
Uploads: 0
|
The following script will split up your menu_1024_768.ini file into the individual [G## # T##] groups and output them into seperate files in a defined folder. Each group filename will be designated using the name of the [G## T1] name.
It will not create the menu_1024_768.ini with all the group names at the top as found in SH5 so you'll have to do that. Code:
# ================================
# USER SETTINGS
# ================================
$InputFile = "menu_1024_768.ini"
$OutputFolder = "SplitByG"
# ================================
# PREPARE OUTPUT FOLDER
# ================================
if (-not (Test-Path $OutputFolder)) {
New-Item -ItemType Directory -Path $OutputFolder | Out-Null
}
# ================================
# READ FILE AS LINES
# ================================
$lines = Get-Content $InputFile
# ================================
# PARSE BLOCKS
# ================================
$groups = @{}
$currentBlock = @()
$currentG = $null
foreach ($line in $lines) {
# Remove inline comments for parsing only
$parseLine = $line
if ($parseLine -match "^(.*?)\s*;") {
$parseLine = $Matches[1]
}
$parseLine = $parseLine.Trim()
# Skip full-line comments for parsing
if ($parseLine.StartsWith(";") -or $parseLine -eq "") {
# Still keep original line in block if we're inside one
if ($currentBlock.Count -gt 0) {
$currentBlock += $line
}
continue
}
# Detect new [Gxx Iyy] header
if ($parseLine -match "^\[(G[0-9A-Za-z]+)\s+I\d+\]") {
# Save previous block
if ($currentBlock.Count -gt 0 -and $currentG) {
if (-not $groups.ContainsKey($currentG)) {
$groups[$currentG] = @()
}
$groups[$currentG] += ,($currentBlock -join "`r`n")
}
# Start new block
$currentG = $Matches[1]
$currentBlock = @($line)
continue
}
# Continue current block
if ($currentBlock.Count -gt 0) {
$currentBlock += $line
}
}
# Save final block
if ($currentBlock.Count -gt 0 -and $currentG) {
if (-not $groups.ContainsKey($currentG)) {
$groups[$currentG] = @()
}
$groups[$currentG] += ,($currentBlock -join "`r`n")
}
# ================================
# WRITE OUTPUT FILES
# ================================
foreach ($g in $groups.Keys | Sort-Object) {
$entries = $groups[$g]
# Extract Name= from first entry (ignoring comments)
$name = $g
foreach ($line in $entries[0] -split "`r`n") {
$parseLine = $line
if ($parseLine -match "^(.*?)\s*;") {
$parseLine = $Matches[1]
}
$parseLine = $parseLine.Trim()
if ($parseLine -match "^Name\s*=\s*(.+)") {
$name = $Matches[1].Trim()
break
}
}
# Sanitize filename
$safeName = $name -replace '[\\\/:\*\?"<>\|]', '_'
$outPath = Join-Path $OutputFolder "$safeName.ini"
# Join all entries for this G group
$content = ($entries -join "`r`n`r`n")
Set-Content -Path $outPath -Value $content -Encoding UTF8
Write-Host "Created: $outPath"
}
Write-Host "`nDone. Files written to: $OutputFolder"
In the folder it is located Hold Shift + Right Click → choose Open PowerShell window here Run: Code:
powershell -ExecutionPolicy Bypass -File [scriptname].ps1 |
|
|
02-22-26, 12:13 AM
|
#2 |
|
Gunner
![]() Join Date: Jan 2013
Posts: 100
Downloads: 32
Uploads: 0
|
You might be interested in this: https://www.subsim.com/radioroom/sho...d.php?t=259057
|
|
|
![]() |
|
|
