SHARE
TWEET

Untitled

a guest May 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Author: Dystopian
  2. ' Clean A3 config files in folders unpacked with Mikero tools.
  3. '
  4. ' Arguments: folder ...
  5.  
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. Const ForReading = 1, ForWriting = 2, ForAppending = 8
  8.  
  9. If WScript.Arguments.Count = 0 Then
  10.     WScript.Echo "Usage: " & WScript.ScriptName & " <folder> ..."
  11.     WScript.Quit
  12. End If
  13.  
  14. Set re = New RegExp
  15. re.Global = True
  16.  
  17. ' Set reTab = New RegExp
  18. ' reTab.Global = True
  19. ' reTab.Pattern = "\t"
  20.  
  21. For Each dir in WScript.Arguments
  22.     If Not fso.FolderExists(dir) Then
  23.         WScript.Echo "no folder " & dir
  24.     Else
  25.         CheckFolder fso.GetFolder(dir)
  26.     End If
  27. Next
  28.  
  29. Sub CheckFolder(folder)
  30.     Dim name, subFolder
  31.     For Each name In Array("config.cpp", "mission.sqm")
  32.         If fso.FileExists(folder.Path & "\" & name) Then
  33.             FixFile folder.Path & "\" & name
  34.         End If
  35.     Next
  36.     For Each subFolder In folder.SubFolders
  37.         CheckFolder subFolder
  38.     Next
  39. End Sub
  40.  
  41. Sub FixFile(file)
  42.     begin = True
  43.     header = True
  44.     removeBrace = False
  45.     Set f = fso.OpenTextFile(file, ForReading)
  46.     Do Until f.AtEndOfStream
  47.         line = f.ReadLine
  48.         ' If 0 = f.Line Mod 1000 Then WScript.Echo Time
  49.  
  50.         If begin And "/" <> Left(line, 1) Then
  51.             Exit Do
  52.         End If
  53.         If begin Then
  54.             Set f1 = fso.OpenTextFile(file & "1", ForWriting, True)
  55.         End If
  56.         begin = False
  57.  
  58.         re.Pattern = "^\s*/" ' skip comments
  59.         If Not re.Test(line) Then
  60.             If Not (header And (0 = Len(line) Or line = "#define _ARMA_")) Then ' skip empty lines in header
  61.                 header = False
  62.                 re.Pattern = "^\s*class [^;]+$" ' add brace after class
  63.                 If re.Test(line) Then
  64.                     f1.WriteLine(line & " {")
  65.                     removeBrace = True
  66.                 Else
  67.                     re.Pattern = "^\s*\{$" ' remove alone brace
  68.                     If removeBrace And re.Test(line) Then
  69.                         removeBrace = False
  70.                     Else
  71.                         f1.WriteLine(line)
  72.                     End If
  73.                 End If
  74.             End If
  75.         End If
  76.     Loop
  77.     f.Close
  78.  
  79.     If Not begin Then
  80.         f1.Close
  81.         fso.DeleteFile file
  82.         fso.MoveFile file & "1", file
  83.     End If
  84. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top