![]() |
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. |
|
|
01-15-26, 05:16 PM
|
#2 |
|
Krusty Krab
Join Date: Mar 2002
Location: Decks awash in the North Atlantic
Posts: 1,568
Downloads: 624
Uploads: 0
|
Thanks ! Have to check it out.
__________________
Good judgment comes from experience. Unfortunately, the experience usually comes from bad judgment. |
|
|
02-10-26, 02:56 PM
|
#3 | |
|
Frogman
![]() Join Date: Jun 2010
Location: Germany
Posts: 290
Downloads: 3
Uploads: 1
|
Quote:
Yes, this Bypass is a nice option. I use it every (work)day. ![]() "the renumbering program". ![]() I hope its not my tool that does not work for you. Please be more specific. Whats the Name or from what Author do you talking about. I am aware of at least four (4) different menu.ini-Renumbering-Tools. One from H.Sie, one from Stiebler, one from Fader Berg and my own Tool. H.Sie - SH3MenuIniRenumber (exe/jar) Stiebler - SH3Menu_Renumber Fader Berg - SH3rryPick mySH3-TooL Greetings. |
|
|
|
![]() |
|
|
