--
[ Picked text/plain from multipart/alternative ]
here is the solution. users can put this script in their
Half-Life\svencoop\maps directory. and double click to run it.
a small dialog pops up, saying:
Series Map Search Completed
Please check updated map.cfg's
See search.log for details.
the user has to click ok to dismiss the dialog.
when they open search.log in notepad, they will see something similar to
this:
changelevel bug squished. Summary of changes:
afrikakorps1.cfg
nextmap afrikakorps2
afrikakorps2.cfg
nextmap afrikakorps3
hostage.cfg
nextmap hostage2a
hostage2a.cfg
nextmap hostage2b
svencoop1.cfg
nextmap svencoop2
toonrun1.cfg
nextmap toonrun2
toonrun2.cfg
nextmap toonrun3
the script is a little sloppy. I don't check to see if a previous
search.log exist. and where I read the directory once just to get a count of
map names. then redim the array using the count and read the directory again
to fill the array. also I don't check to see if the correct config file
exist before writing to it. but it does create a log showing which config
files were updated. a couple of days ago I had never written a vbscript
before. check out the for each loop where I step through the dictionary
using the basename and strNumber. that is part is cool and it eliminates a
huge painful nested if.
[code]
Option Explicit
Dim objFSO
Dim ofolder
Dim objStream
Dim intCounter
Dim arrTestNames ()
Dim dicBaseNames
Dim strBase
Dim strName
Dim strNumber
Dim nUBound
Dim arrTemp
Dim strOutput
Set objFSO = CreateObject("Scripting.FileSystemObject")
'create the output file
Set objStream = objFSO.createtextfile("search.log", True)
CheckFolder (objFSO.getfolder(".")), objStream
ReDim Preserve arrTestNames (intCounter)
FillArray(objFSO.getfolder(".")), objStream, arrTestNames
Const TextCompare = 1
'Start by making a dictionary of all the base names. The value will be an
array of the numerals
Set dicBaseNames = CreateObject("Scripting.Dictionary")
dicBaseNames.CompareMode = TextCompare
For Each strName In arrTestNames
strBase = GetBaseName(strName)
strNumber = GetSequenceNumber(strName)
If dicBaseNames.Exists(strBase) Then
nUBound = UBound(dicBaseNames(strBase)) + 1
arrTemp = dicBaseNames(strBase)
ReDim Preserve arrTemp(nUBound)
arrTemp(nUBound) = strNumber
dicBaseNames(strBase) = arrTemp
Else
dicBaseNames.Add strBase, Array(strNumber)
End If
Next
'now step through the dictionary using basenames and numbers to update
config files.
StepThruDic(objFSO.getfolder(".")), objStream
MsgBox "Series Map Search Completed." + vbCr + "Please check updated
map.cfg's."
+ vbCr + "See search.log for details"
Function GetSequenceNumber(strName)
Dim oRE
Dim colMatches
Dim oMatch
Set oRE = New Regexp
oRE.Pattern = "\D*(\d*)(\D*)"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
For Each oMatch In colMatches
GetSequenceNumber = oMatch.Submatches(0) & oMatch.Submatches(1)
Exit Function
Next
GetSequenceNumber = ""
End Function
Function GetBaseName(strName)
Dim oRE
Dim colMatches
Dim oMatch
Set oRE = New Regexp
oRE.Pattern = "(\D*)\d*(\D*)"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
For Each oMatch In colMatches
GetBaseName = oMatch.SubMatches(0)
Exit Function
Next
GetBaseName = "ERROR"
End Function
Sub CheckFolder(objCurrentFolder, objLogFile)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
dim a
strSearch = ".bsp"
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
'Got one
'a=Split(CStr(objFile.Name),".")
intCounter = intCounter + 1
'strOutput = CStr(intCounter) & " " & a(0)
'objLogFile.writeline strOutput
End If
Next
End Sub
Sub FillArray(objCurrentFolder, objLogFile, arrTestNames)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
dim a
dim intIndex
strSearch = ".bsp"
intIndex = 0
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
'Got one
a=Split(CStr(objFile.Name),".")
'populate database
arrTestNames (intIndex) = a(0)
'strOutput = arrTestNames (intIndex)
'objLogFile.writeline strOutput
intIndex = intIndex + 1
End If
Next
End Sub
Sub StepThruDic(objCurrentFolder, objLogFile)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
Dim i
strOutput = "changelevel bug squished. Summary of changes:"
objLogFile.writeline strOutput
For Each strBase in dicBaseNames.Keys
For i = 1 To UBound(dicBaseNames(strBase))
If strBase <> "c" then
strOutput = strBase & dicBaseNames(strBase)(i - 1) & ".cfg"
objLogFile.writeline strOutput
strOutput = " nextmap" & " " & strbase & dicBaseNames(strBase)(i)
objLogFile.writeline strOutput
objFSO.OpenTextFile(strBase & dicBaseNames(strBase)(i - 1) & ".cfg",
8).WriteLine _
"nextmap" & " " & strbase & dicBaseNames(strBase)(i)
End If
Next
Next
End Sub [/code]
Thank You,
--
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders