2016-08-01 93 views
0

我想從(從安裝我試圖創建如果這有什麼差別實際上),如果有可能在運行一個給定的可執行文件閱讀產品版本(optional string) -時間。該字符串將進一步用於從鏈接下載文件。產品版本字符串 - NSIS

非常感謝!

+0

@Anders,該函數的輸出爲'DetailPrint:「ProdVer:$ R2 。$ R3,R4 $。$ R5「'....我需要的實際值...... – gigiman

+0

它工作得很好,我,但它在運行時獲得的價值,這就是你問什麼(」保持它變成一個變量「)。如果你想在編譯時定義它,那麼你應該問這個... – Anders

+0

@安德斯,請原諒我缺乏知識。我只想使用安裝程序的產品版本名稱(它實際上只是一個名稱,而不是像xx.xx.xx.xx之類的東西),以便訪問鏈接以下載與該產品版本完全匹配的一些文件。我不知道任何方法,我想將它存儲在'var'中。你能告訴我我的選擇是什麼,或給我一個有效的例子嗎? – gigiman

回答

0

NSIS沒有閱讀比VS_FIXEDFILEINFO->dwFileVersion所以你要調用Windows API直接以外的任何原生支持:

; Add some version information so we have something to test 
VIProductVersion 1.2.3.4 
VIAddVersionKey "ProductVersion" "One Two Three Four" 
VIAddVersionKey "FileVersion" "Whatever" 
VIAddVersionKey "FileDescription" "Whatever" 
VIAddVersionKey "LegalCopyright" "(C) Whatever" 

!include LogicLib.nsh 
Function GetFileVerFirstLangProductVersion 
System::Store S 
pop $3 
push "" ;failed ret 
System::Call 'version::GetFileVersionInfoSize(t"$3",i.r2)i.r0' 
${If} $0 <> 0 
    System::Alloc $0 
    System::Call 'version::GetFileVersionInfo(t"$3",ir2,ir0,isr1)i.r0 ? e' 
    pop $2 
    ${If} $0 <> 0 
    ${AndIf} $2 = 0 ;a user comment on MSDN said you should check GLE to avoid crash 
     System::Call 'version::VerQueryValue(i r1,t "\VarFileInfo\Translation",*i0r2,*i0)i.r0' 
     ${If} $0 <> 0 
      System::Call '*$2(&i2.r2,&i2.r3)' 
      IntFmt $2 %04x $2 
      IntFmt $3 %04x $3 
      System::Call 'version::VerQueryValue(i r1,t "\StringFileInfo\$2$3\ProductVersion",*i0r2,*i0r3)i.r0' 
      ${If} $0 <> 0 
       pop $0 
       System::Call *$2(&t$3.s) 
      ${EndIf} 
     ${EndIf} 
    ${EndIf} 
    System::Free $1 
${EndIf} 
System::Store L 
FunctionEnd 

Section 
Push "$ExePath" ; Read our own version information in this example 
Call GetFileVerFirstLangProductVersion 
Pop $0 
DetailPrint "ProductVersion=$0" 
SectionEnd 
+0

好吧,我現在有一個更清晰的視野。感謝您花時間幫助我,非常感謝。 – gigiman