![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
01-15-26, 10:56 AM
|
#1 |
|
Seaman
![]() Join Date: Feb 2012
Posts: 36
Downloads: 107
Uploads: 0
|
I couldn't get the renumbering program to work properly for me. Even though it output the file to C:/, it didn't seem to change anything. Soo...
Code:
# ================================
# USER SETTINGS
# ================================
$inputFile = "menu_1024_768.ini"
$outputFile = "menu_1024_768_RENUMBERED.ini"
$targetG = "31"
# ================================
$counter = 1
$lines = Get-Content $inputFile
$pattern = "\[G$targetG([A-Za-z]*) I(\d+)\]"
for ($i = 0; $i -lt $lines.Length; $i++) {
$line = $lines[$i]
# Skip full-line comments
if ($line.TrimStart().StartsWith(";")) { continue }
# Find first semicolon
$semicolonPos = $line.IndexOf(";")
if ($semicolonPos -eq -1) { $semicolonPos = $line.Length }
# Split code and comment
$codePart = $line.Substring(0, $semicolonPos)
$commentPart = if ($semicolonPos -lt $line.Length) { $line.Substring($semicolonPos) } else { "" }
# Find all matches in code part
$matches = [regex]::Matches($codePart, $pattern)
if ($matches.Count -gt 0) {
$newCode = ""
$lastIndex = 0
foreach ($m in $matches) {
# Append text before match
$newCode += $codePart.Substring($lastIndex, $m.Index - $lastIndex)
# Append renumbered match
$newCode += "[G$targetG$($m.Groups[1].Value) I$counter]"
$counter++
# Move lastIndex past this match
$lastIndex = $m.Index + $m.Length
}
# Append remaining text after last match
$newCode += $codePart.Substring($lastIndex)
# Recombine code + comment
$lines[$i] = $newCode + $commentPart
}
}
# Save output
Set-Content $outputFile ($lines -join "`n") -Encoding UTF8
Write-Host "Renumbered G$targetG entries sequentially (comment-safe). Total entries: $($counter - 1)"
Write-Host "Output written to: $outputFile"
It will change the I number for each entry (ignoring any comments found on same line) based on the order that it appears in the file. Everything else will remain the same. Put input.txt and [scriptname].ps1 in the same folder. The original file is not altered so you can run it directly on your Menu .ini file if you like. Just change the input file name in user settings. Still good to make a backup of the menu.ini file though. Open that folder Hold Shift + Right Click → choose Open PowerShell window here Run: Code:
powershell -ExecutionPolicy Bypass -File [scriptname].ps1
__________________
Menu.ini Reordering Powershell Script menu_1024_768.ini Split By Group Powershell Script Last edited by Kedishen; 01-15-26 at 12:07 PM. |
|
|
| Thread Tools | |
| Display Modes | |
|
|
