- NSIS Discussion
- Detecting DirectX 9.0c
Archive: Detecting DirectX 9.0c
Gato Muerto
21st January 2005 18:04 UTC
Detecting DirectX 9.0c
I have a program that needs to have directx 9.0c (no boo-hiss, please) installed in order to function. I tried monkeying around with the function that was on the board, but it doesn't quite work the way I want it to.
My registry shows directx "version" as 4.09.00.0904, so I based my script-piddling around that.
StrCpy $2 $0 8 4 ; get the alpha version : ie 9.0(c)
StrCpy $1 $0 5 5 ; get the minor version
StrCpy $0 $0 2 2 ; get the major version
StrCpy "$DirectXMajorVersion" $0
StrCpy "$DirectXMinorVersion" $1
StrCpy "$DirectXAlphaVersion" $2
IntOp $0 $0 * 100 ; $0 = major * 100 + minor
IntOp $0 $0 + $1
IntOp $0 $0 * 10000 ; $0 = major + minor * 10000 + alpha
IntOp $0 $0 + $2
Later there is a portion that has:
# If version >= 9.0c, then we're golden.
IntCmp $DirectXVersionDetected 9000904 DXOK DXIsOld DXOK
However, I run the installation, it still attempts to install directx, no matter what. Before tinkering with things I don't understand fully (I can't bend me mind 'round the string calls), I thought to ask here.
Thanks in advance for anyone who can help this n00b out.
kichik
21st January 2005 18:13 UTC
To compare version numbers use one of the version compare functions from the Archive (this one for example). It's not safe to assume the length of the numbers between the dots as in your script.
It'll be easier to understand why your script isn't working as should with the entire script. The forum accepts attachment of .nsi files.
Gato Muerto
21st January 2005 20:26 UTC
The entire code is rather messy, a work in progress, but the entire part that deals with the directx is here:
kichik
21st January 2005 20:43 UTC
The problem is with the StrCpy lines. It doesn't copy what is documented that it should. Add DetailPrint lines with $0, $1 and $2 to see what they return.
Try using the function I linked to, it should be simpler. You just give it the two version numbers and it tells you which is newer.
Gato Muerto
21st January 2005 21:59 UTC
Where does the DetailPrint show the output? I know that just plugging in the code will work, but I am trying to learn about this, and am not sure why it isn't working. =P
Curse of those who try to learn.
I added
DetailPrint $0 right after each variable is declared, but don't know where it will end up.
Gato Muerto
24th January 2005 17:44 UTC
I figured out what was causing my problem... mixed the two input string variables by accident. Put the offset and the string length swapped.
Thanks again for the help on the forum. ^_^
Afrow UK
24th January 2005 21:24 UTC
You should note that your code will fail if the version string changes in length or structure (ie the ranges will be changed).
It's easy to think now that it's probably not going to happen, but when or if it does...
e.g.
4.09.00.0904 could become 4.09.00.10 in future.
-Stu
Gato Muerto
11th February 2005 02:07 UTC
Problems elsewhere in the software pushed back the release, so I have the time to do some more tinkering/ understanding of this program. For the idea of future updates, I am trying to integrate the code posted into the installer, but I don't quite understand it. What is the exact output of OutVar? Is it a true/false statement, or is it the greater of the two variables? IE, I make the comparison by using:
ReadRegStr $Ver1 HKLM "Software\Microsoft\DirectX" "Version"
!define Ver2 "4.09.00.0904"
!macro VersionCheckNew2 $Ver1 Ver2 OutVar
I need to know what is being returned, or in what format, and I still can't wrap my head around the strings. I guess I just can visualize/keep what in/out/pop/push straight in my head. Ugh.
kichik
11th February 2005 11:20 UTC
The output variable can be 0, 1 or 2 as described in the Archive page.
There is an example for calling the function on the top of the Archive page. Use it instead of what you've just posted.
Afrow UK
11th February 2005 11:31 UTC
ReadRegStr $R0 HKLM "Software\Microsoft\DirectX" "Version"
!define Ver2 "4.09.00.0904"
${VersionCheckNew} "$R0" "${Ver2}" "$R1"
DetailPrint $R1 # 0, 1, 2
-Stu
Afrow UK
11th February 2005 11:38 UTC
I just noticed a small typo in the macro. I've fixed it and changed function name back to VersionCheckNew (not VersionCheckNew2).
-Stu
Gato Muerto
11th February 2005 19:50 UTC
Ah, K. That explains why I was confused with the reference to both VCheckNew/VCheckNew2. hehe.
Would anyone have a reference they can point me towards that would assist a neophyte in uderstanding how these stacks/ vars work? I started taking programming classes in pascal and C back in '95, before stopping school for undisclosed reasons. 3+ dimensional arrays make my head hurt.
Afrow UK
11th February 2005 20:32 UTC
The stack:
http://nsis.sourceforge.net/archive/...php?pageid=216
Variables store data. As simple as that.
Variables are $var. $var can be $R0-$R9 or $0-$9, or you can create a custom variable with the Var command:
Var myVar ; creates $myVar
Then there's !defines. A !define is used on compile-time and it's value doesn't change (unlike a variable):
!define myDefine "blah"
MessageBox MB_OK "${myDefine}"
This would be the same as using :
MessageBox MB_OK "blah"
The benefit of using !defines is that you can use the value of the define many times in the same script, and you'd then have to only change the define's value once if necessary.
People get confused about variables and defines. Variables are used on run-time, therefore, they will only have a value (e.g. from using StrCpy) when people run your installer.
-Stu