Archive: Feature Request: GetFileAttributes


Feature Request: GetFileAttributes
Hi there,

I was faced with the task to write an installer that searches for any occurrence of file A on hte drive and replaces it with a file inside the installer. NSIS provides FindFirst and FindNext, but without determining if something is actually a directory, there is no good way to implemented a depht search- I was thinking GetFileAttributes working like the SetFileAttributes could take care of that :)

Not sure if this is of general interest though...

Thanks, Andi


Use


IfFileExists $1\*.* end
DetailPrint "$1 is a directory"
end:


-Justin

Right... I'll try that, THANKS!

Andi


Hi Justin,

your suggestion was fine, installer is basically working but... it crashes. Installer does a depht first search for files and remembers found directories on the stack. Attached installer at some point crashes with a software exception-no idea why....

Andi


Name "Find Files"
OutFile "NsisFind.exe"
Caption "File Find Installer"
ShowInstDetails show

Section "Find"

StrCpy $6 1

StrCpy $6 0

StrCpy $8 1
Push "c:"
Call FindFiles
SectionEnd

Function PopIt
Pop $9
IntOp $8 $8 - 1
FunctionEnd

Function PushIt
Push "$9\$1"
IntOp $8 $8 + 1
FunctionEnd

Function FindFiles

call PopIt
FindFirst $0 $1 "$9\*.*"

IfErrors NotFound1
DoFindNext1:

IntOp $6 $6 + 1

StrCmp $1 "." DoFindNext2
StrCmp $1 ".." DoFindNext2

IfFileExists "$9\$1\*.*" "" DoFindNext2
call PushIt
DetailPrint "$8 $9\$1"

FileOpen $5 "c:\nsis.log" a
FileSeek $5 0 END
FileWrite $5 "$6 $8 $9\$1$\n"
FileClose $5

DoFindNext2:
FindNext $0 $1
IfErrors "" DoFindNext1
NotFound1:
FindClose $0

StrCmp $8 0 NoRecurse
Call FindFiles
NoRecurse:
FunctionEnd


I found two issues, when I fixed both, it ran perfectly for me.

1) FindClose was being called even if FindFirst failed.
2) Calling the function recursively wasn't really necessary, since you have a stack (a Goto is a lot more efficient, and doesn't have the issues with having the stack overflow).
3) I put some ClearErrors in there just to make sure.

-Justin

Name "Find Files"
OutFile "NsisFind.exe"
Caption "File Find Installer"
ShowInstDetails show

Section "Find"

StrCpy $6 1

StrCpy $6 0

StrCpy $8 1
Push "c:"
Call FindFiles
SectionEnd

Function PopIt
Pop $9
IntOp $8 $8 - 1
FunctionEnd

Function PushIt
Push "$9\$1"
IntOp $8 $8 + 1
FunctionEnd

Function FindFiles
GoAgain:
call PopIt
ClearErrors
FindFirst $0 $1 "$9\*.*"
IfErrors NotFound1
DoFindNext1:
IntOp $6 $6 + 1
StrCmp $1 "." DoFindNext2
StrCmp $1 ".." DoFindNext2
IfFileExists "$9\$1\*.*" "" DoFindNext2
call PushIt
DetailPrint "$8 $9\$1"
FileOpen $5 "c:\nsis.log" a
FileSeek $5 0 END
FileWrite $5 "$6 $8 $9\$1$\n"
FileClose $5
DoFindNext2:
ClearErrors
FindNext $0 $1
IfErrors "" DoFindNext1
FindClose $0
NotFound1:
StrCmp $8 0 "" GoAgain
FunctionEnd


Justin,

thanks for your help, I'll try it. i understand the FileClose error, sorry for that. As for stack overflow I don't think that that's the issue- at most 130 items were on the stack on my disk.

Thanks a lot,
Andi


Justin,

attached is a brushed up version of the installer, including your changes. One thing came to my mind:

Would it make sense to have Pop set the error flag when the stack is empty, instead of failing? This way one wouldn't need to keep count of items on the stack? :eek:

Cheers, Andi


PS.: If interested, please use the attached file for functions.htm or FNSIS ;)

PPS.: The forum doesn't allow to upload .nsi- yuck.


Originally posted by AndiG2
Would it make sense to have Pop set the error flag when the stack is empty, instead of failing? This way one wouldn't need to keep count of items on the stack? :eek:
Good idea, will do for 1.67.
An exch on an empty stack will still give fatal error though, but Pop will fail gracefully.

-Justin