Old 16th July 2008, 06:03   #1
vcoder
Junior Member
 
Join Date: Jun 2008
Posts: 7
Bug in FileWrite?

This script work well on ANSI version of NSIS and failed on Unicode version:

PHP Code:
OutFile "GetVersion.exe"

!define File "Resources.dll"

RequestExecutionLevel user

Function .onInit
    GetDllVersion 
"${File}$R0 $R1
    IntOp $R2 $R0 
0x00010000
    IntOp $R3 $R0 
0x0000FFFF
    IntOp $R4 $R1 
0x00010000
    IntOp $R5 $R1 
0x0000FFFF
    StrCpy $R1 
"$R2.$R3.$R4.$R5"

    
FileOpen $"$EXEDIR\Version.txt" w
    FileWrite 
$'!define Version "$R1"$\n'
    
FileClose $0
;    MessageBox MB_OK "$R1"
    
Abort
FunctionEnd

Section
SectionEnd 
Result file:
ANSI: !define Version "3.4.0.96"
Unicode: !def
vcoder is offline   Reply With Quote
Old 18th October 2011, 10:43   #2
fhkd
Junior Member
 
Join Date: Oct 2011
Posts: 3
GetVersion.exe is not a valid Win32 application.

Hello,

I compiled following Code with Unicode NSIS 2.46.3:

code:

!define File "program.exe"
OutFile "GetVersion.exe"

Function .onInit
## Get file version
GetDllVersion "${File}" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $R1 "$R2.$R3.$R4.$R5"

## Write it to a !define for use in main script
FileOpen $R0 "DefineValues.txt" w
FileWrite $R0 '!define PRODUCT_VERSION "$R1" $\n'
FileClose $R0

Abort
FunctionEnd

Section
SectionEnd



I get a GetVersion.exe, but if I try to start it from the Windows Explorer, I get the message

Quote:
GetVersion.exe is not a valid Win32 application.
If I use NSIS 2.46, it works fine and I get DefinesValues.txt with the entry !define PRODUCT_VERSION ....

I know the post
Quote:
Originally Posted by vcoder View Post
This script work well on ANSI version of NSIS and failed on Unicode version: ...
I use Windows 7 64 bit, and other more complex Setup-Skript get compiled well with Unicode NSIS.
fhkd is offline   Reply With Quote
Old 19th October 2011, 14:15   #3
fhkd
Junior Member
 
Join Date: Oct 2011
Posts: 3
Hello again!

While I tried to implement the solution with File "program.exe", I noticed the command !define /product_version in the NSIS User Manual.

Solutions like
Quote:
Originally Posted by vcoder View Post
OutFile "GetVersion.exe"
with GetDLLVersion or GetDLLVersionLocal are for getting the version from a file on the building machine as a compiler constant during compile time, I think.

With the command !define /product_version it's quite easier.

So I write a little NSIS header GetVersionLocal.nsh with the macros GetFileVersionLocal and GetProductVersionLocal.
Now I can get a constant with the version number without makeing a dummy setup.

code:

!insertmacro GetProductVersionLocal "$%windir%\system32\kernel32.dll" version
!echo "${version_0}.${version_1}.${version_2}.${version_3}"
!echo "${version}"



For a description see the header file.
fhkd is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump