Skip to content

Instantly share code, notes, and snippets.

@Dystopian
Created May 12, 2019 17:41
Show Gist options
  • Save Dystopian/ac230eb284e33e7f98469f867da37de6 to your computer and use it in GitHub Desktop.
Save Dystopian/ac230eb284e33e7f98469f867da37de6 to your computer and use it in GitHub Desktop.
Clean A3 config files in folders unpacked with Mikero tools
' Author: Dystopian
' Clean A3 config files in folders unpacked with Mikero tools.
'
' Arguments: folder ...
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
If WScript.Arguments.Count = 0 Then
WScript.Echo "Usage: " & WScript.ScriptName & " <folder> ..."
WScript.Quit
End If
Set re = New RegExp
re.Global = True
' Set reTab = New RegExp
' reTab.Global = True
' reTab.Pattern = "\t"
For Each dir in WScript.Arguments
If Not fso.FolderExists(dir) Then
WScript.Echo "no folder " & dir
Else
CheckFolder fso.GetFolder(dir)
End If
Next
Sub CheckFolder(folder)
Dim name, subFolder
For Each name In Array("config.cpp", "mission.sqm")
If fso.FileExists(folder.Path & "\" & name) Then
FixFile folder.Path & "\" & name
End If
Next
For Each subFolder In folder.SubFolders
CheckFolder subFolder
Next
End Sub
Sub FixFile(file)
begin = True
header = True
removeBrace = False
Set f = fso.OpenTextFile(file, ForReading)
Do Until f.AtEndOfStream
line = f.ReadLine
' If 0 = f.Line Mod 1000 Then WScript.Echo Time
If begin And "/" <> Left(line, 1) Then
Exit Do
End If
If begin Then
Set f1 = fso.OpenTextFile(file & "1", ForWriting, True)
End If
begin = False
re.Pattern = "^\s*/" ' skip comments
If Not re.Test(line) Then
If Not (header And (0 = Len(line) Or line = "#define _ARMA_")) Then ' skip empty lines in header
header = False
re.Pattern = "^\s*class [^;]+$" ' add brace after class
If re.Test(line) Then
f1.WriteLine(line & " {")
removeBrace = True
Else
re.Pattern = "^\s*\{$" ' remove alone brace
If removeBrace And re.Test(line) Then
removeBrace = False
Else
f1.WriteLine(line)
End If
End If
End If
End If
Loop
f.Close
If Not begin Then
f1.Close
fso.DeleteFile file
fso.MoveFile file & "1", file
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment