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