- NSIS Discussion
- Suggestion: IfFileInUse
Archive: Suggestion: IfFileInUse
gLes
3rd June 2003 14:47 UTC
Suggestion: IfFileInUse
Hi there!
Above you see the thing I'm really missing from NSIS. I know I could do it with a little *hard* coding (at least for me), but it would be much better if I could use this function like this:
IfFileInUse file_to_check_for jump_if_inuse [jump_otherwise]
Just like the IfFileExists function. Actually the two function should be combined. I imagine the code (the *real* code like this):
function IfFileInUse(F: PChar): Boolean;
begin
Result := False; //Initial result
if FileExists(F) then //Check if file exists, and if so, then check whether it's in use
Result := CreateFile(F, GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0) = INVALID_HANDLE_VALUE;
end;
Sorry, but since I only know Delphi Pascal my imagination can't do better either ;)
Best regards,
gLes
kichik
3rd June 2003 18:39 UTC
It's not hard coding at all:
ClearErrors
FileOpen $0 "path" "a"
FileClose $0
IfErrors locked notlocked
gLes
3rd June 2003 19:57 UTC
Doh! But wouldn't it be easier to do it my way?:)
Joost Verburg
3rd June 2003 20:47 UTC
That will increase the overhead. This is easy enough (if you want to make it even easier, create a macro).
gLes
3rd June 2003 21:21 UTC
How that look like?:)
Joost Verburg
3rd June 2003 21:56 UTC
!macro IfFileInUse FILE GOTONOTLOCKED GOTOLOCKED
ClearErrors
Push $R0
FileOpen $R0 "${FILE}" "a"
FileClose $R0
Pop $R0
IfErrors "${GOTONOTLOCKED}" "${GOTOLOCKED}"
!macroend
Usage:
!insertmacro IfFileInUse "c:\bla.txt" notlocked locked
Joel
3rd June 2003 22:08 UTC
Maybe I'll be cool if there is an instruction like the one:
IfFileExists
Simple, easy and handy :)
gLes
3rd June 2003 22:08 UTC
Thx. :)
Joost Verburg
3rd June 2003 22:18 UTC
Lobo Lunar, that will increase the installer overhead. I think a macro is simple enough.
bradkohl
11th December 2007 07:27 UTC
I don't think that's a reasonable solution to the problem at all. What happens if the file is a 30 MB data file?
kichik
11th December 2007 09:28 UTC
How does the size affect anything?
And with LogicLib this is even easier.
!macro _FileInUse _a _b _t _f
!insertmacro _LOGICLIB_TEMP
ClearErrors
FileOpen $_LOGICLIB_TEMP `${_b}` "a"
FileClose $_LOGICLIB_TEMP
IfErrors `${_t}` `${_f}`
!macroend
!define FileInUse `"" FileInUse`
${If} ${FileInUse} $INSTDIR\file
DetailPrint "in use"
${EndIf}
bradkohl
11th December 2007 10:45 UTC
It all depends on the system and file but in my experience the larger the file the longer fileopen takes, I just think there could be a better way.
bradkohl
11th December 2007 11:02 UTC
oh I didn't see the "a" my bad