#ifndef __VERSION_INFO_H #define __VERSION_INFO_H #define APP_NAME "MyApp" #define APP_VERSION 1,0,,0 #define APP_VERSION_S "" #define APP_DATE "" #endif
#include "../src/VersionInfo.h"
FILEVERSION APP_VERSION PRODUCTVERSION APP_VERSION
C:\Ruby193\bin\ruby VersionBuild.rb VersionInfo.h
#define APP_VERSION 1,0,$WCREV$,1 #define APP_VERSION_S "1.0.$WCREV$.1" #define APP_DATE "$WCNOW=%d.%m.%Y %H:%M$"
#define APP_VERSION 1,0,$WCREV$,2 #define APP_VERSION_S "1.0.$WCREV$.2" #define APP_DATE "$WCNOW=%d.%m.%Y %H:%M$"
...
SubWCRev.exe .. VersionInfo.h VersionInfo.h
#define APP_VERSION 1,0,29,2 #define APP_VERSION_S "1.0.29.2" #define APP_DATE "01.11.2012 20:09"
FNAME = ARGV[0] file = File::read(FNAME) ANY_IN_QUOTES = Regexp.new('"[^"]*"') def replaceVersion(file) # APP_VERSION matcher = Regexp.new('APP_VERSION\s*[^\r\n]*') line = file.match(matcher)[0] old_ver = /(\d+),(\d+),(.*),(\d+)/ line.match(old_ver) new_ver = [$1, $2, "$WCREV$", $4.to_i + 1] line.sub!(old_ver, new_ver.join(",")) file.sub!(matcher, line) # APP_VERSION_S matcher = Regexp.new('APP_VERSION_S\s*' + ANY_IN_QUOTES.source) line = file.match(matcher)[0] line.sub!(ANY_IN_QUOTES, '"' + new_ver.join(".") + '"') file.sub!(matcher, line) end def replaceDate(file) # APP_DATE matcher = Regexp.new('APP_DATE\s*' + ANY_IN_QUOTES.source) date = file.match(matcher)[0] date.sub!(ANY_IN_QUOTES, '"$WCNOW=%d.%m.%Y %H:%M$"') file.sub!(matcher, date) end replaceVersion(file) replaceDate(file) File::write(FNAME, file)
#include "Version.h" #include "VersionInfo.h" const char *Version() { return APP_VERSION_S; } const char *BuildDate() { return APP_DATE; }
!include "MUI.nsh" ; ;!define APP_NAME "MyApp" ;!define MAJOR_VERSION "1" ;!define MINOR_VERSION "0" ;!define SVN_REVISION "29" ;!define BUILD_NUMBER "2" ;!define APP_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${SVN_REVISION}.${BUILD_NUMBER}" ;!define SETUP_NAME "${APP_NAME}-${APP_VERSION}.exe" Name ${SETUP_NAME} OutFile ${SETUP_NAME} InstallDir $PROGRAMFILES\${APP_NAME} VIProductVersion ${APP_VERSION} VIAddVersionKey "ProductName" ${APP_NAME} VIAddVersionKey "Comments" "" VIAddVersionKey "CompanyName" "" VIAddVersionKey "LegalTrademarks" "" VIAddVersionKey "LegalCopyright" "© " VIAddVersionKey "FileDescription" ${APP_NAME} VIAddVersionKey "FileVersion" ${APP_VERSION} !define MUI_ABORTWARNING !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_WELCOME !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_UNPAGE_FINISH !insertmacro MUI_LANGUAGE "Russian" Section "${APP_NAME} (required)" SetOutPath $INSTDIR File "${APP_NAME}.exe" WriteUninstaller "uninstall.exe" SectionEnd Section "Uninstall" Delete "$INSTDIR\*.*" Delete "$SMPROGRAMS\${APP_NAME}\*.*" Delete "$DESKTOP\${APP_NAME}.lnk" RMDir "$SMPROGRAMS\${APP_NAME}" RMDir "$INSTDIR" SectionEnd Section "Start Menu and Desktop Shortcuts" CreateDirectory "$SMPROGRAMS\${APP_NAME}" CreateShortCut "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" SectionEnd
C:\Ruby193\bin\ruby SetupBuild.rb MyApp.exe
NSIS_MAKE = '"C:\Program Files (x86)\NSIS\makensis.exe"' require 'win32ole' def versionOf(fname) fso = WIN32OLE.new("Scripting.FileSystemObject") return fso.GetFileVersion(fname) end def alert(msg) fso = WIN32OLE.new("WScript.Shell") fso.Popup msg end SRC_FNAME = File::expand_path(ARGV[0]) APP_NAME = File::basename(SRC_FNAME, '.*') params = Hash.new params['APP_NAME'] = APP_NAME params['APP_VERSION'] = versionOf(SRC_FNAME) params['SETUP_NAME'] = "#{APP_NAME}-#{params['APP_VERSION']}.exe" # /D NSIS ( !define) cmd = params.map{|key, val| "/D#{key}=#{val}"}.join(" ") LOG_FNAME = "#{APP_NAME}_#{$0}.log" r = system("#{NSIS_MAKE} #{cmd} #{APP_NAME}.nsi > #{LOG_FNAME}") if r File::delete(LOG_FNAME) else system('notepad', LOG_FNAME) end
C:\Ruby193\bin\ruby "..\src\VersionBuild.rb" "..\src\VersionInfo.h" SubWCRev.exe .. "..\src\VersionInfo.h" "..\src\VersionInfo.h"
C:\Ruby193\bin\ruby SetupBuild.rb MyApp.exe
Source: https://habr.com/ru/post/157197/