Archive: getfilesize bug?


getfilesize bug?
This code works as it should:

IfFileExists "${DISTFILES_PATH}\$R0" 0 +3
MessageBox MB_OK "GetSize"
MessageBox MB_OK "Returned size $0"
MessageBox MB_OK "Next Function"

This code works strangely:

IfFileExists "${DISTFILES_PATH}\$R0" 0 +3
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"
MessageBox MB_OK "Next Function"

Note: the file DOES NOT EXIST.

the second code returns "Got size " (no size, however) so I'm guessing it tried to get the size eventhough the file didn't exist.

if I change +3 in IfFileExists to +4, I get "Got size success", and if I change it to +5, I get "Got size 18320" or something like that.

can anyone explain any of this?


Instead of ${GetSize} I'd suggest this one Get File Size using the system plugin from wiki. Give it a try, could solve your problem.


${GetSize} it is macro you shouldn't use relative jumps

IfFileExists "${DISTFILES_PATH}\$R0" 0 notexist
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"

notexist:
MessageBox MB_OK "Next Function"

This is 'not exists' handling in the GetSize macro

error:
SetErrors
StrCpy $0 ''
StrCpy $1 ''
StrCpy $2 ''
So you can check $0 is empty or add IfErrors after the macro (see 4.9.4.18 SetErrors).

as Instructor mentionent above, it works fine with labels.

this one works fine:

!define DISTFILES_PATH 'D:\new'
name 'DISTFILES'
outfile 'distfiles.exe'

!include 'FileFunc.nsh'
!insertmacro GetSize

Function .onInit
push 'exists.dll' ; example file exists
pop $R0
IfFileExists "${DISTFILES_PATH}\$R0" _getsize _nextfunc
_getsize:
;MessageBox MB_OK "GetSize"
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Returned size $0"
_nextfunc:
MessageBox MB_OK "Next Function"
functionend

section -
sectionend

as well as this one:
!define DISTFILES_PATH 'D:\new'
name 'DISTFILES'
outfile 'distfiles.exe'

!include 'FileFunc.nsh'
!insertmacro GetSize

Function .onInit
push 'not_exists.dll' ; example file does not exist
pop $R0
IfFileExists "${DISTFILES_PATH}\$R0" _getsize _nextfunc
_getsize:
;MessageBox MB_OK "GetSize"
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Returned size $0"
_nextfunc:
MessageBox MB_OK "Next Function"
functionend

section -
sectionend

Originally posted by Takhir
This is 'not exists' handling in the GetSize macro
error:
SetErrors
StrCpy $0 ''
StrCpy $1 ''
StrCpy $2 ''
So you can check $0 is empty or add IfErrors after the macro (see 4.9.4.18 SetErrors).
thanks alot that worked wonders :)

  ${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $7 $8 $9
StrCmp $7 "" +2 0
StrCpy $0 $7

You should use the LogicLib. It'd save you a lot of trouble like this one.

!include LogicLib.nsh
# ...
${If} ${FileExists} ${DISTFILES_PATH}\$R0
${GetSize} "${DISTFILES_PATH}" "/M=$R0 /S=0K /G=0" $0 $8 $9
MessageBox MB_OK "Got size $0"
MessageBox MB_OK "Next Function"
${EndIf}

wow i had no idea you could use logiclib with fileexists, thanks alot for that


You can use it with anything, even if there's no wrapper macro for it. For example:

${If} ${Cmd} `IfFileExists "$WINDIR\notepad.exe"`
DetailPrint "exists"
${Else}
DetailPrint "doesn't exist"
${EndIf}