Pathrequester W/O create new folder option?

Just starting out? Need help? Post your questions and find answers here.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Pathrequester W/O create new folder option?

Post 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.?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post 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!
Post Reply