improve genminiupnpcstrings.vbs to generate file only if changed

This commit is contained in:
Thomas Bernard 2018-07-14 13:29:37 +02:00
parent 8babc5d013
commit 6f99427d69
3 changed files with 62 additions and 1 deletions

View File

@ -29,8 +29,58 @@ For Each objOperatingSystem in colOperatingSystems
os_version = objOperatingSystem.Version
Next
Dim array
'Wscript.Echo os_version
Dim array
needWrite = True
' First Check if the file already contains the right versions
Err.Clear
Set f_in = FSO.OpenTextFile(outfile, 1, False)
If Err.Number = 0 Then
old_version = ""
old_os_version = ""
Do Until f_in.AtEndOfStream
line = f_in.ReadLine
If Len(line) > 0 Then
array = Split(line, " ")
If UBound(array) >= 2 And array(0) = "#define" Then
If array(1) = "OS_STRING" Then
old_os_version = Replace(array(2), Chr(34), "")
ElseIf array(1) = "MINIUPNPC_VERSION_STRING" Then
old_version = Replace(array(2), Chr(34), "")
End if
End if
End If
Loop
f_in.Close
If old_version = version And old_os_version = "MSWindows/" & os_version Then
needWrite = False
Else
needWrite = True
End If
End If
If Not needWrite Then
' check files dates
Set fIn1 = FSO.GetFile(versionfile)
Set fIn2 = FSO.GetFile(infile)
Set fOut = FSO.GetFile(outfile)
If DateDiff("s", fIn1.DateLastModified, fOut.DateLastModified) < 0 Then
needWrite = True
End If
If DateDiff("s", fIn2.DateLastModified, fOut.DateLastModified) < 0 Then
needWrite = True
End If
End If
If Not needWrite Then
' nothing to do
WScript.Quit 0
End if
' generate the file
Err.Clear
Set f_in = FSO.OpenTextFile(infile, 1, False)
If Err.Number = 0 Then
Set f_out = FSO.OpenTextFile(outfile, 2, True) ' 2 = Write

View File

@ -178,6 +178,9 @@
<ClInclude Include="..\upnperrors.h" />
<ClInclude Include="..\upnpreplyparse.h" />
</ItemGroup>
<ItemGroup>
<None Include="genminiupnpcstrings.vbs" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -104,5 +104,13 @@
<Filter Include="headers">
<UniqueIdentifier>{2b3996de-1bc4-418b-8a83-a5f34fdf0df5}</UniqueIdentifier>
</Filter>
<Filter Include="scripts">
<UniqueIdentifier>{45dbc39d-c3ca-4a75-adf0-76070e20415a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="genminiupnpcstrings.vbs">
<Filter>scripts</Filter>
</None>
</ItemGroup>
</Project>