SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SHIII Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 01-15-26, 05:27 PM   #1
Kedishen
Seaman
 
Join Date: Feb 2012
Posts: 36
Downloads: 107
Uploads: 0
Default menu_1024_768.ini Split By Group Powershell Script

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"
To run it:

In the folder it is located

Hold Shift + Right Click → choose Open PowerShell window here

Run:
Code:
powershell -ExecutionPolicy Bypass -File [scriptname].ps1
Enjoy.
Kedishen is offline   Reply With Quote
Old 02-22-26, 12:13 AM   #2
Kirienko
Gunner
 
Join Date: Jan 2013
Posts: 100
Downloads: 32
Uploads: 0
Default

You might be interested in this: https://www.subsim.com/radioroom/sho...d.php?t=259057
Kirienko is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 1995- 2026 Subsim®
"Subsim" is a registered trademark, all rights reserved.