Old 2nd April 2006, 10:46   #1
empezar
Senior Member
 
empezar's Avatar
 
Join Date: Sep 2003
Posts: 123
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?
empezar is offline   Reply With Quote
Old 2nd April 2006, 11:41   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
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.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 2nd April 2006, 11:59   #3
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
${GetSize} it is macro you shouldn't use relative jumps
code:
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"

Instructor is offline   Reply With Quote
Old 2nd April 2006, 11:59   #4
Takhir
Major Dude
 
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
This is 'not exists' handling in the GetSize macro
code:
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).
Takhir is offline   Reply With Quote
Old 2nd April 2006, 12:20   #5
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
as Instructor mentionent above, it works fine with labels.

this one works fine:
code:
!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:
code:
!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


Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 2nd April 2006, 12:44   #6
empezar
Senior Member
 
empezar's Avatar
 
Join Date: Sep 2003
Posts: 123
Quote:
Originally posted by Takhir
This is 'not exists' handling in the GetSize macro
code:
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

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

empezar is offline   Reply With Quote
Old 2nd April 2006, 17:34   #7
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
You should use the LogicLib. It'd save you a lot of trouble like this one.
code:
!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}


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 2nd April 2006, 17:50   #8
empezar
Senior Member
 
empezar's Avatar
 
Join Date: Sep 2003
Posts: 123
wow i had no idea you could use logiclib with fileexists, thanks alot for that

Bored with the real world? Try QuakeWorld!
empezar is offline   Reply With Quote
Old 2nd April 2006, 17:55   #9
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
You can use it with anything, even if there's no wrapper macro for it. For example:
code:
${If} ${Cmd} `IfFileExists "$WINDIR\notepad.exe"`
DetailPrint "exists"
${Else}
DetailPrint "doesn't exist"
${EndIf}


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik 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