Archive: Locked Folders


Locked Folders
The code below works correctly until the very end when it calls the macro to delete the c:\tempunzip folder that it created to unzip the files to.

If I try to delete the folder manually whilst the installer is still open it says it is locked so the NSIS installer is obviously holding it. I know I can set the /reboot flag for rmdir but it is not convenient for this instance.

Can anyone see any reason in the code below why the c:\tempunzip folder would be locked? Is it the 7zip process?


ShowInstDetails show
!include 'nsdialogs.nsh'
!include 'nsdialogs_setimageole.nsh'
!include "FileFunc.nsh"
!include "Locate.nsh"
!include "Sections.nsh"
!include "CharStrip.nsh"
!insertmacro Locate

Var Text
Var Text2
Var Text3
Var PathForInstallLabel
Var PathForInstallFileRequest
Var PathForInstallGroupBox
Var PathForInstallFileBrowse
Var PathForInstallFileRequestState

Function .onInit
InitPluginsDir
SetOutPath $PLUGINSDIR
File logo.jpg
File 7za.exe
FunctionEnd

Page Custom CustomPre

Page instfiles
Function CustomPre
nsDialogs::Create 1018
Pop $R0

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateBitmap} 280 10 100 100 ""
Pop $0

; You should make sure the resource - local or http - is valid!
${NSD_SetImageOLE} $0 "$PLUGINSDIR\logo.jpg" $1

${NSD_CreateLabel} 10 10 300 100 "Welcome To the program"
Pop $Text
CreateFont $0 "Arial Bold" 12
SendMessage $Text ${WM_SETFONT} $0 1

${NSD_CreateLabel} 10 35 300 20 "Select a zip file and press next"
Pop $Text2
${NSD_CreateLabel} 10 50 300 20 "It will then be processed"
Pop $Text3

; Create Controls
${NSD_CreateGroupBox} 0 0 100% 100% ""
Pop $PathForInstallGroupBox

${NSD_CreateLabel} 16 170 280 24 "Please select the install file, and click next to continue"
Pop $PathForInstallLabel

${NSD_CreateFileRequest} 10u 86u 245u 12u $PathForInstallFileRequestState
Pop $PathForInstallFileRequest

${NSD_CreateBrowseButton} 358 166 25 22 "..."
Pop $PathForInstallFileBrowse
GetFunctionAddress $0 OnBrowseForFile
nsDialogs::OnClick /NOUNLOAD $PathForInstallFileBrowse $0

nsDialogs::Show
${NSD_FreeImageOLE} $1 ; Free the image once we're done with it!
FunctionEnd

Function OnBrowseForFile
nsDialogs::SelectFileDialog /NOUNLOAD "open" "" "All files (*.*)|*.*"
Pop $0
StrCpy $PathForInstallFileRequestState $0
${NSD_SetText} $PathForInstallFileRequest $PathForInstallFileRequestState
FunctionEnd

!macro unzip
CreateDirectory "c:\tempunzip"
nsexec::exectolog '"$EXEDIR\7za.exe" x "$0" -y -o"c:\tempunzip"'
${Locate} "C:\tempunzip" "/M=.DS_Store" "LocateCallback"
${locate} "C:\tempunzip" "/L=D /M=__MACOSX" "LocateCallbackFolder"
!macroend

!macro zip
${StrStrip} ".zip" "$0" $R0
nsexec::exectolog '"$EXEDIR\7za.exe" a -r "$R0_CLEAN.zip" "c:\tempunzip\*.*"'
!macroend

!macro delete
SetOutpath $TEMP
RMdir /r "c:\tempunzip"
!macroend

Function LocateCallback
Delete $R9
Push $0
FunctionEnd

Function LocateCallbackFolder
RMDir /r $R9
Push $0
FunctionEnd

Section
!insertmacro unzip
!insertmacro zip
!insertmacro delete
SectionEnd

If the 7za process has already quit (verify this by inserting a messagebox or pause), it cannot be holding the folder anymore. I'd guess the nsexec plugin has a hold on it. Try inserting a dummy nsexec command?


I'm surprised that this works. You are extracting 7za.exe to $PlugInsDir, but calling it in $ExeDir (which is the installer's folder, not the same location you extracted it to).

I don't see why the temp folder doesn't get removed, you are correctly changing the current working directory to 'unlock' it (SetOutPath $Temp).


It works because 7za is in the exe dir as well. I have changed the code so it runs from the Plugindir instead now :)

Using process explorer I can see that my exe file is hanging onto the c:\tempunzip folder and all of the (Now empty) subfolders inside of it.

Can you give an example of a dummy NSexec command?


No idea... Something that uses a different directory. Like, listing the contents of a zip file that's stored in $instdir for example?


Ive put this macro in to try and unlock the folder but its still not making any difference

!macro unlock
nsExec::exectolog '"$PLUGINSDIR\7za.exe" l "$EXEDIR\dummy.zip"'
!macroend


Looking at what it leaves behind, it seems the rmdir /r command deletes all files from all of the subfolders and does delete some of the subfolders themselves. For some reason the same four subfolders remain.

Very strange

As a quick fix I have included unlocker.exe from http://www.emptyloop.com/unlocker/ and then run a command line to unlock the folder

It then lets me delete it. I know this isn't fixing the issue but working around it, but at least it works now :)

Thanks for everybodys input


Either way you should stop using c:\tempunzip as a temp folder. Use $PLUGINSDIR instead.


Thanks MSG, your suggestion of using the PLUGINSDIR to unzip to has worked for me. Thanks for all your help!