glx@8545: Option Explicit glx@8545: glx@8545: Dim FSO glx@8545: Set FSO = CreateObject("Scripting.FileSystemObject") glx@8545: glx@8545: ' openttd_vs90.sln is for MSVC 2008 glx@8545: ' openttd_vs90.vcproj is for MSVC 2008 glx@8545: ' langs_vs90.vcproj is for MSVC 2008 glx@8545: ' strgen_vs90.vcproj is for MSVC 2008 glx@8545: glx@8545: ' openttd_vs80.sln is for MSVC 2005 glx@8545: ' openttd_vs80.vcproj is for MSVC 2005 glx@8545: ' langs_vs80.vcproj is for MSVC 2005 glx@8545: ' strgen_vs80.vcproj is for MSVC 2005 glx@8545: glx@8545: Sub safety_check(filename) glx@8545: Dim file, line, regexp, list glx@8545: glx@8545: ' Define regexp glx@8545: Set regexp = New RegExp glx@8545: regexp.Pattern = "#|ottdres.rc|win32.cpp|win32_v.cpp" glx@8545: regexp.Global = True glx@8545: glx@8545: ' We use a dictionary to check duplicates glx@8545: Set list = CreateObject("Scripting.Dictionary") glx@8545: glx@8545: Set file = FSO.OpenTextFile(filename, 1, 0, 0) glx@8545: While Not file.AtEndOfStream glx@8545: line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs glx@8545: If Len(line) > 0 And Not regexp.Test(line) Then glx@8545: line = FSO.GetFileName(line) glx@8545: if list.Exists(line) Then glx@8545: WScript.Echo " !! ERROR !!" _ glx@8545: & vbCrLf & "" _ glx@8545: & vbCrLf & "The filename '" & line & "' is already used in this project." _ glx@8545: & vbCrLf & "Because MSVC uses one single directory for all object files, it" _ glx@8545: & vbCrLf & "cannot handle filenames with the same name inside the same project." _ glx@8545: & vbCrLf & "Please rename either one of the file and try generating again." _ glx@8545: & vbCrLf & "" _ glx@8545: & vbCrLf & " !! ERROR !!" glx@8545: WScript.Quit(1) glx@8545: End If glx@8545: list.Add line, line glx@8545: End If glx@8545: Wend glx@8545: file.Close glx@8545: End Sub glx@8545: glx@8545: Function load_main_data(filename) glx@8545: Dim res, file, line, deep, skip, first_time glx@8545: res = "" glx@8545: ' Read the source.list and process it glx@8545: Set file = FSO.OpenTextFile(filename, 1, 0, 0) glx@8545: While Not file.AtEndOfStream glx@8545: line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs glx@8545: If Len(line) > 0 Then glx@8545: Select Case Split(line, " ")(0) glx@8545: Case "#end" glx@8545: If deep = skip Then skip = skip - 1 glx@8545: deep = deep - 1 glx@8545: Case "#else" glx@8545: If deep = skip Then glx@8545: skip = skip - 1 glx@8545: ElseIf deep - 1 = skip Then glx@8545: skip = skip + 1 glx@8545: End If glx@8545: Case "#if" glx@8545: line = Replace(line, "#if ", "") glx@8545: If deep = skip And ( _ glx@8545: line = "SDL" Or _ glx@8545: line = "PNG" Or _ glx@8545: line = "WIN32" Or _ glx@8545: line = "MSVC" Or _ glx@8643: line = "DIRECTMUSIC" Or _ glx@8643: line = "NO_THREADS" _ glx@8545: ) Then skip = skip + 1 glx@8545: deep = deep + 1 glx@8545: Case "#" glx@8545: if deep = skip Then glx@8545: line = Replace(line, "# ", "") glx@8545: if first_time <> 0 Then glx@8545: res = res & " " & vbCrLf glx@8545: Else glx@8545: first_time = 1 glx@8545: End If glx@8545: res = res & _ glx@8545: " " & vbCrLf glx@8545: End If glx@8545: Case Else glx@8545: If deep = skip Then glx@8545: line = Replace(line, "/" ,"\") glx@8545: res = res & _ glx@8545: " " & vbCrLf & _ glx@8545: " " & vbCrLf glx@8545: End If glx@8545: End Select glx@8545: End If glx@8545: Wend glx@8545: res = res & " " glx@8545: file.Close() glx@8545: load_main_data = res glx@8545: End Function glx@8545: glx@8545: Function load_lang_data(dir) glx@8545: Dim res, folder, file glx@8545: res = "" glx@8545: Set folder = FSO.GetFolder(dir) glx@8545: For Each file In folder.Files glx@8545: file = FSO.GetFileName(file) glx@8545: If FSO.GetExtensionName(file) = "txt" Then glx@8545: file = Left(file, Len(file) - 4) glx@8545: res = res _ glx@8545: & vbCrLf & " " _ glx@8545: & vbCrLf & " " _ glx@8545: & vbCrLf & " " _ glx@8545: & vbCrLf & " " _ glx@8545: & vbCrLf & " " glx@8545: End If glx@8545: Next glx@8545: load_lang_data = res glx@8545: End Function glx@8545: glx@8545: Sub generate(data, dest) glx@8545: Dim srcfile, destfile, line glx@8545: WScript.Echo "Generating " & FSO.GetFileName(dest) & "..." glx@8545: Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0) glx@8545: Set destfile = FSO.CreateTextFile(dest, -1, 0) glx@8545: glx@8545: ' Everything above the !!FILES!! marker glx@8545: line = srcfile.ReadLine() glx@8545: While line <> "!!FILES!!" glx@8545: If len(line) > 0 Then destfile.WriteLine(line) glx@8545: line = srcfile.ReadLine() glx@8545: Wend glx@8545: glx@8545: ' Our generated content glx@8545: destfile.WriteLine(data) glx@8545: glx@8545: ' Everything below the !!FILES!! marker glx@8545: While Not srcfile.AtEndOfStream glx@8545: line = srcfile.ReadLine() glx@8545: If len(line) > 0 Then destfile.WriteLine(line) glx@8545: Wend glx@8545: srcfile.Close() glx@8545: destfile.Close() glx@8545: End Sub glx@8545: glx@8545: Dim ROOT_DIR glx@8545: ROOT_DIR = FSO.GetFolder("..").Path glx@8545: If Not FSO.FileExists(ROOT_DIR & "/source.list") Then glx@8545: ROOT_DIR = FSO.GetFolder(".").Path glx@8545: End If glx@8545: If Not FSO.FileExists(ROOT_DIR & "/source.list") Then glx@8545: WScript.Echo "Can't find source.list, needed in order to make this run." _ glx@8545: & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout." glx@8545: WScript.Quit(1) glx@8545: End If glx@8545: glx@8545: safety_check ROOT_DIR & "/source.list" glx@8545: glx@8545: Dim openttd glx@8545: openttd = load_main_data(ROOT_DIR &"/source.list") glx@8545: generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj" glx@8545: generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj" glx@8545: glx@8545: Dim lang glx@8545: lang = load_lang_data(ROOT_DIR & "/src/lang") glx@8545: generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj" glx@8545: generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj"