Archive: ${DriveSpace} and some strange values


${DriveSpace} and some strange values
Hi I'm sorry to write again for same problem, but I don't know how solve this problem. May some one can help me.

I encounter a strange problem with some value returned by ${DriveSpace}.

- I get any free space values and this values are corrected. So I get space of my C:\, E:\, D:\, H:\, etc. and any values are corrected
- If I compare any values that I get by ${DriveSpace}, the conditions actions ${If} works correctly ONLY with an exception. The exception is with my E:\ value.

What I want to say that a script as this, works with any drive excepeted with my "E:\":

${GetRoot} $MYPATH1 $1
${DriveSpace} "$1\" "/D=F /S=B" $1

${GetRoot} $MYPATH2 $2
${DriveSpace} "$2\" "/D=F /S=B" $2"

${If} "$MYPATH1 " U>= "$MYPATH2"
MessageBox MB_OK "PATH1 >= PATH2"
${Else}
MessageBox MB_OK "PATH1 < PATH2"
${EndIf}

Any one have a suggestion to solve this problem?

Thanksss
Bruno


You know you're performing an Unsigned Integer comparison between the paths you specify ($MYPATH1 and $MYPATH2), right? I would suspect that you'd want to perform that comparison between the drive sizes returned by ${DriveSpace}, which you're storing in $1 and $2


Hi Animaether, I'm sorry upper I made a mistake translating my variables. I correct the script, but the problem that I wrote is that happens.

${GetRoot} $MYPATH1 $1
${DriveSpace} "$1\" "/D=F /S=B" $FreeSpace1

${GetRoot} $MYPATH2 $2
${DriveSpace} "$2\" "/D=F /S=B" $FreeSpace2

${If} "$FreeSpace1" U>= "$FreeSpace2"
MessageBox MB_OK "PATH1 >= PATH2"
${Else}
MessageBox MB_OK "PATH1 < PATH2"
${EndIf}

Regarding the reason to use Unsigned Integer comparison with free space, this is because I obtain different results with other drives if I use it or not.

For example if I compare C:\ and D:\ free space (..and both are hard disk), the comparison with Unsigned Integerworks correctly but doens't work correclty with E:\. But I make same comparison without Unsigned Integer, the good result is with E:\ but is wrong with D:\.

In any case, the values that DriveSpace get are apparently correct so I mean that I can read right free space if I put that values on MessageBox. The problem is only with comparison.

Now I'm reading this your suggestion:
http://forums.winamp.com/showthread.php?t=321260&highlight=%24{DriveSpace}
and I want change way to get the free space and to compare as in that example:
System::Int64Op $2 > $0

thankss again, I write my results
Ciaoo

Bruno


Originally posted by orecchionebruno
Regarding the reason to use Unsigned Integer comparison with free space, this is because I obtain different results with other drives if I use it or not.

For example if I compare C:\ and D:\ free space (..and both are hard disk), the comparison with Unsigned Integerworks correctly but doens't work correclty with E:\. But I make same comparison without Unsigned Integer, the good result is with E:\ but is wrong with D:\.
This is an incredibly wrong reason to use Uint compare. You should use Uint compare when you have two Uints. If you have signed ints, you should obviously use signed int compare. It sounds to me like you don't know what kind of ints you have, at all. Figure that out first, THEN you'll know whether you should compare them as ints or as Uints.

Thanks MSG,

in effect I don't know wich values I have... :)

I just get any values from {DriveSpace} and I started to use "Unsigned Integer comparison" for the problem that I wrote upper.

So what could be the problem using {DriveSpace} values?


I've found where is the problem and it looks works...

if I get size in "Byte" the comparison give me the problem that wrote upper BUT if I get values in "KiloBytes" everything works.

So, now the question is "the problem are the quantity of numbers"?

PS: I forgot I used {DriveSpace}


Originally posted by MSG
Figure that out first, THEN you'll know whether you should compare them as ints or as Uints.
sorry but in my language "figure" could means different words so I didn't understood what you mean with this sentence.. can you please explain me this again?

Thankss

To figure something out = to find out, to learn, to investigate.

First you need to know what kind of int you have (signed or unisigned, etc), THEN you can know how to use them.


I'm not sure why either are you are worried about the type of integer comparison test to perform in this case. Unless you've got negative disk space (lol) then you can do an unsigned integer comparison. The unsigned integer comparison here is purely to ignore the sign if one exists. Are you confusing the data type with the comparison? In NSIS integers are just strings; there are no int/uint data types.

Edit: Also how about displaying the actual values in a message box? You may find that you need to do a 64-bit unsigned integer test if the value is too big.

Stu


so signed and unsigned means positive or negative numbers?

I write a better way this test:

Drive | free space
C:\ = 417290768 kb = 427305746432 byte
D:\ = 443209756 kb = 453846790144 byte
E:\ = 2616004 kb = 2678788096 byte
H:\ = 164932 kb = 168890368 byte

Method 1:

section "test"
StrCpy $0 'C:\'
; StrCpy $1 'D:\'
StrCpy $1 'E:\'
; StrCpy $1 'H:\'

System::Call 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i(r0,.r2,,.)'
System::Int64Op $2 / 1024 ;convert value in KiloByte
Pop $2
StrCpy $4 $2

System::Call 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i(r1,.r2,,.)'
System::Int64Op $2 / 1024 ;convert value in KiloByte
Pop $2
StrCpy $5 $2

${If} $4 U< $5
MessageBox MB_OK "$4 < $5"
${Else}
MessageBox MB_OK "$4 > $5"
${EndIf}
sectionend

Method 2:

section "test"
StrCpy $1 'C:\'
; StrCpy $1 'D:\'
StrCpy $1 'E:\'
; StrCpy $1 'H:\'


;${DriveSpace} "$0\" "/D=F /S=B" $4 ;retrieves value in byte
;${DriveSpace} "$1\" "/D=F /S=B" $5 ;retrieves value in byte
${DriveSpace} "$0\" "/D=F /S=K" $4 ;retrieves value in Kilobyte
${DriveSpace} "$1\" "/D=F /S=K" $5 ;retrieves value in Kilobyte

${If} $4 U< $5
MessageBox MB_OK "$4 < $5"
${Else}
MessageBox MB_OK "$4 > $5"
${EndIf}
sectionend

I made this test, and with both methods in conditional script I've obtained this result:

With "${If} $4 U< $5":
417290768 > 443209756 works (also with >= , <, <=)
417290768 > 2616004 Works
417290768 > 164932 Works

427305746432 > 453846790144 Works
427305746432 > 2678788096 Doesn't work
427305746432 > 168890368 Works

With "${If} $4 < $5":
417290768 > 443209756 Works (also with >= , <, <=)
417290768 > 2616004 Works
417290768 > 164932 Works

427305746432 > 453846790144 Doesn't work
427305746432 > 2678788096 works
427305746432 > 168890368 Works


Originally posted by orecchionebruno
so signed and unsigned means positive or negative numbers?
No. Google can tell you the difference between a signed and unsigned int.

Afrow UK is right of course, it shouldn't really matter in this case. The reason why you're seeing different behavior between int and uint compare is that your numbers overflow the 32 bits available to NSIS (you'll find out why this is once you learn the difference between signed and unsigned, btw).

You need to compare with 64 bits precision. You can do this with the system plugin (Int64Op command).

Originally posted by Afrow UK
Are you confusing the data type with the comparison? In NSIS integers are just strings; there are no int/uint data types.
yes I am, but why If do this, teh condition say that $4 < $5?:

section "test"
StrCpy $4 427305746432
StrCpy $5 453846790144

${If} $4 < $5
MessageBox MB_OK "True: $4 < $5"
${Else}
MessageBox MB_OK "False: $4 > $5"
${EndIf}
sectionend

Originally posted by Afrow UK
You may find that you need to do a 64-bit unsigned integer test if the value is too big.
Sorry.. what I have to do? :D if you mean to do the test "64-bit integer tests" and "Unsigned integer tests" included in LogicLib.nsi, I dot it and I passed.

Originally posted by MSG
You need to compare with 64 bits precision. You can do this with the system plugin (Int64Op command).
thanks now I try ...and I search

Thankss this way does what I expected:
System::Int64Op $4 < $5