Annotation of embedaddon/miniupnpc/msvc/genminiupnpcstrings.vbs, revision 1.1

1.1     ! misho       1: ' VBScript to generate miniupnpcstrings.h
        !             2: ' Copyright 2018 Thomas Bernard
        !             3: 'Set WshShell = CreateObject("WScript.Shell")
        !             4: Set FSO = CreateObject("Scripting.FileSystemObject")
        !             5: versionfile = "..\version"
        !             6: infile = "..\miniupnpcstrings.h.in"
        !             7: outfile = "..\miniupnpcstrings.h"
        !             8: outfilerc = "..\rc_version.h"
        !             9: 
        !            10: On Error Resume Next
        !            11: 
        !            12: 'Wscript.Echo revision
        !            13: 
        !            14: Err.Clear
        !            15: Set f = FSO.OpenTextFile(versionfile, 1, False) ' 1 = Read
        !            16: If Err.Number = 0 Then
        !            17:        version = f.ReadLine
        !            18:        f.Close
        !            19: Else
        !            20:        ' Exit error
        !            21:        WScript.Quit 1
        !            22: End If
        !            23: 
        !            24: os_version = "0.0.0"
        !            25: strComputer = "."
        !            26: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        !            27: Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
        !            28: For Each objOperatingSystem in colOperatingSystems
        !            29:     'Wscript.Echo objOperatingSystem.Caption & " -- " 
        !            30:        os_version = objOperatingSystem.Version
        !            31: Next
        !            32: 
        !            33: 'Wscript.Echo os_version
        !            34: 
        !            35: Dim array
        !            36: needWrite = True
        !            37: 
        !            38: ' First Check if the file already contains the right versions
        !            39: Err.Clear
        !            40: Set f_in = FSO.OpenTextFile(outfile, 1, False)
        !            41: If Err.Number = 0 Then
        !            42:        old_version = ""
        !            43:        old_os_version = ""
        !            44:        Do Until f_in.AtEndOfStream
        !            45:                line = f_in.ReadLine
        !            46:                If Len(line) > 0 Then
        !            47:                        array = Split(line, " ")
        !            48:                        If UBound(array) >= 2 And array(0) = "#define" Then
        !            49:                                If array(1) = "OS_STRING" Then
        !            50:                                        old_os_version = Replace(array(2), Chr(34), "")
        !            51:                                ElseIf array(1) = "MINIUPNPC_VERSION_STRING" Then
        !            52:                                        old_version = Replace(array(2), Chr(34), "")
        !            53:                                End if
        !            54:                        End if
        !            55:                End If
        !            56:        Loop
        !            57:        f_in.Close
        !            58:        If old_version = version And old_os_version = "MSWindows/" & os_version Then
        !            59:                needWrite = False
        !            60:        Else
        !            61:                needWrite = True
        !            62:        End If
        !            63: End If
        !            64: 
        !            65: If Not needWrite Then
        !            66:        ' check files dates
        !            67:        Set fIn1 = FSO.GetFile(versionfile)
        !            68:        Set fIn2 = FSO.GetFile(infile)
        !            69:        Set fOut = FSO.GetFile(outfile)
        !            70:        If DateDiff("s", fIn1.DateLastModified, fOut.DateLastModified) < 0 Then
        !            71:                needWrite = True
        !            72:        End If
        !            73:        If DateDiff("s", fIn2.DateLastModified, fOut.DateLastModified) < 0 Then
        !            74:                needWrite = True
        !            75:        End If
        !            76: End If
        !            77: 
        !            78: If Not needWrite Then
        !            79:     ' nothing to do
        !            80:        WScript.Quit 0
        !            81: End if
        !            82: 
        !            83: ' generate the file
        !            84: Err.Clear
        !            85: Set f_in = FSO.OpenTextFile(infile, 1, False)
        !            86: If Err.Number = 0 Then
        !            87:        Set f_out = FSO.OpenTextFile(outfile, 2, True) ' 2 = Write
        !            88:        Do Until f_in.AtEndOfStream
        !            89:                line = f_in.ReadLine
        !            90:                If Len(line) > 0 Then
        !            91:                        array = Split(line, " ")
        !            92:                        If UBound(array) >= 2 And array(0) = "#define" Then
        !            93:                                If array(1) = "OS_STRING" Then
        !            94:                                        line = "#define OS_STRING " & Chr(34) & "MSWindows/" & os_version & Chr(34)
        !            95:                                ElseIf array(1) = "MINIUPNPC_VERSION_STRING" Then
        !            96:                                        line = "#define MINIUPNPC_VERSION_STRING " & Chr(34) & version & Chr(34)
        !            97:                                End if
        !            98:                        End if
        !            99:                End If
        !           100:                f_out.WriteLine line
        !           101:        Loop
        !           102:        f_in.Close
        !           103:        f_out.Close
        !           104: End If
        !           105: 
        !           106: Set f_out = FSO.OpenTextFile(outfilerc, 2, True) ' 2 = Write
        !           107: f_out.WriteLine "#define LIBMINIUPNPC_DOTTED_VERSION " & Chr(34) & version & Chr(34)
        !           108: ver = Split(version, ".")
        !           109: f_out.WriteLine "#define LIBMINIUPNPC_MAJOR_VERSION " & ver(0)
        !           110: f_out.WriteLine "#define LIBMINIUPNPC_MINOR_VERSION " & ver(1)
        !           111: f_out.WriteLine "#define LIBMINIUPNPC_MICRO_VERSION " & ver(2)
        !           112: f_out.Close

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>