使用vbscript增加资源文件中的所有值

时间:2014-03-02 16:35:09

标签: vbscript

我有一个rc文件,我每晚使用vbscript增加,我增加FILEVERSION和PRODUCTVERSION,但我无法增加关键字的所有值。 构建与VS2012。

这是rc文件:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Hebrew (Israel) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HEB)
LANGUAGE LANG_HEBREW, SUBLANG_DEFAULT
#pragma code_page(1255)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 3,0,0,0
 PRODUCTVERSION 3,0,0,0
 FILEFLAGSMASK 0x17L
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040004b0"
        BEGIN
            VALUE "FileDescription", "SHSAppli Dynamic Link Library"
            VALUE "FileVersion", "3.0.0.0"
            VALUE "InternalName", "SHSAppli"
            VALUE "LegalCopyright", "Copyright (C) 2011"
            VALUE "OriginalFilename", "SHSAppli.dll"
            VALUE "ProductName", "SHSAppli Dynamic Link Library"
            VALUE "ProductVersion", "3.0.0.0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x400, 1200
    END
END

#endif    // Hebrew (Israel) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

这是脚本:

rcfile = "C:\Build\VS2012Build\SHClientServer\SHSApplicationDLL\SHSApplicationDLL.rc"

Set fso = CreateObject("Scripting.FileSystemObject")
Set re  = New RegExp
re.Global = True

Function IncMaint(m, g1, g2, g3, pos, src)
  IncMaint = g1 & (Int(g2)+1) & g3
End Function

rctext = fso.OpenTextFile(rcfile).ReadAll

re.Pattern = "((?:PRODUCTVERSION|FILEVERSION) \d+,\d+,)(\d+)(,\d+)"
rctext = re.Replace(rctext, GetRef("IncMaint"))

re.Pattern = "(""(?:ProductVersion|FileVersion)"", ""\d+, \d+, )(\d+)(, \d+"")"
rctext = re.Replace(rctext, GetRef("IncMaint"))

fso.OpenTextFile(rcfile, 2).Write rctext

我还要增加值“VALUE”FileVersion“,”3.0.0.0“和VALUE”ProductVersion“,”3.0.0.0“

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

不确定,如果你真的应该这样做 - 那些.rc文件是不是UTF8编码的?但是,如果必须,让第二种模式反映出这样的事实,即数字用“。”分隔。 (点),而不是“;” (逗号),并注意空格。

"(""(?:ProductVersion|FileVersion)"", ""\d+, \d+, )(\d+)(, \d+"")"
                                           ^    ^^       ^^

更新评论:

在修复第二个模式并将一个诊断线放入替换函数后,我得到了简化的ascii编码文件的输出:

cscript 22130287.vbs
I'M PLAIN ASCII OR ELSE

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 3,0,0,0
 PRODUCTVERSION 3,0,0,0

BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040004b0"
        BEGIN
            VALUE "FileDescription", "SHSAppli Dynamic Link Library"
            VALUE "FileVersion", "3.0.0.0"
            VALUE "ProductVersion", "3.0.0.0"
        END

-----------------
*** FILEVERSION 3,0,|0|,0
*** PRODUCTVERSION 3,0,|0|,0
*** "FileVersion", "3.0.|0|.0"
*** "ProductVersion", "3.0.|0|.0"
I'M PLAIN ASCII OR ELSE

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 3,0,1,0
 PRODUCTVERSION 3,0,1,0

BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040004b0"
        BEGIN
            VALUE "FileDescription", "SHSAppli Dynamic Link Library"
            VALUE "FileVersion", "3.0.1.0"
            VALUE "ProductVersion", "3.0.1.0"
        END

更新II:我使用的脚本:

Option Explicit

Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim sAll : sAll     = goFS.OpenTextFile("22130287.rc").ReadAll()
WScript.Echo sAll
WScript.Echo "-----------------"

Dim re : Set re  = New RegExp
re.Global = True
re.IgnoreCase = True

re.Pattern = "((?:PRODUCTVERSION|FILEVERSION) \d+,\d+,)(\d+)(,\d+)"
sAll = re.Replace(sAll, GetRef("IncMaint"))

re.Pattern = "(""(?:ProductVersion|FileVersion)"", ""\d+\.\d+\.)(\d+)(\.\d+"")"
sAll = re.Replace(sAll, GetRef("IncMaint"))

WScript.Echo sAll
WScript.Quit 0

Function IncMaint(m, g1, g2, g3, pos, src)
  WScript.Echo "***", Join(Array(g1, g2, g3), "|")
  IncMaint = g1 & (Int(g2)+1) & g3
End Function

更新III:

请查看here