Page 1 of 1

Pathrequester W/O create new folder option?

Posted: Wed Apr 19, 2006 11:49 pm
by utopiomania
I need a PathRequester() WITHOUT a built-in option to create a new folder. I've rewritten my installer
program, and ran into a problem when testing.

If a user installs in for example 'Program Files', I can safely remove the subfolder the program was
installed in, but not the 'Program Files' folder itself of course.

But if the user creates a new folder using the Path requester, and installs in it, I can't remove it.
I can remove the program folder, but am not shure what to do about the parent folder the user created.

I could delete the parent folder if it is empty when the program is uninstalled, but the user might have
a reason for creating the folder in the first place, empty or not, so I'm not shure?

Anyway, this problem goes away if the user is simply left with the choice to pick another folder to install
in, instead of beeing able to create a new one, hence the request.

I guess this could be done with som API and some appopriate constants.?

Posted: Thu Apr 20, 2006 5:29 am
by ts-soft

Code: Select all

Procedure BrowseCallbackProc(hwnd, msg, lParam, lData)
  szDir$ = Space(#MAX_PATH)
  Select msg
    Case #BFFM_INITIALIZED
      SendMessage_(hwnd, #BFFM_SETSELECTION, #BFFM_INITIALIZED, lData)
    Case #BFFM_SELCHANGED
      If SHGetPathFromIDList_(lParam, @szDir$)
        SendMessage_(hwnd, #BFFM_SETSTATUSTEXT, 0, @szDir$)
      EndIf
  EndSelect
EndProcedure

Procedure.s BrowseForFolder(Style, Titel.s, Path.s)
  Folder.s = Space(#MAX_PATH)
  Dir.BROWSEINFO
  Dir\hwndOwner = GetActiveWindow_()
  Dir\pszDisplayName = @Folder
  Dir\lpszTitle = @Titel
  Dir\ulFlags = Style
  Dir\lpfn = @BrowseCallbackProc()
  Dir\lParam = @Path
  result.l = SHBrowseForFolder_(@Dir)
  SHGetPathFromIDList_(result, @Folder)
  If Folder <> ""
    If FileSize(Folder) = - 2
      If Right(Folder, 1) <> "\" : Folder + "\" : EndIf
    EndIf
  EndIf
  CoTaskMemFree_(result)
  ProcedureReturn Folder
EndProcedure

Style = #BIF_STATUSTEXT | #BIF_BROWSEINCLUDEFILES 
BrowseForFolder(Style, "Please choose your path", "")
Info: http://msdn.microsoft.com/library/defau ... folder.asp
http://msdn.microsoft.com/library/defau ... seinfo.asp

Posted: Thu Apr 20, 2006 12:49 pm
by Trond
Don't you think it's a bit annoying for the user when he can't install to where he wants to install? I'd just delete the folder if it is empty. If he wants to create it again for another installation he can always do so unless the installation program makers use tricks to prevent him from.

Posted: Thu Apr 20, 2006 2:45 pm
by utopiomania
@ts-soft, thanks for the code sample. I've archived it for later use.

@Trond, I agree. I came to the same conclusion myself. If the user browses to a new location
and creates a folder there, it's probably his responsibility to delete it after an uninstall
or use it for some other purpose later.

So I think I will leave the 'create new folder' button in place for convinience, and ignore
folders created with it.

The way the uninstaller works now, it will remove everything the installer puts on disk or in
the registry. Extra files created somewhere in the target folder structure will be listed, and
the user is given a choice to remove all or keep them.

Thanks for the help!