views:

385

answers:

4

I am working on the bootstrap application of an installer, and I have a dialogue that the user can open to select a different target directory from the given default. Currently, I'm using the CFolderDialog for that, but for the user to select a folder that doesn't yet exist, he has to create the folder first. Once the user has specified the directory, I want to be able to delete it so that, when I launch the installer, it can create the folder itself such that it gets flagged for uninstall. Also, if the user cancels out of my bootstrap application at any time, I don't want any unwanted folders lying around from when the user mucked around in the folder browser. The problem that I'm having is that, if I try to remove the folder that the user created while browsing for a new target folder, I get a sharing violation error. (I compare the directory's creation time with what the system time was at the time the dialogue was launched to make sure that it's OK for me to delete the directory.)

What I need is either a way to get around that sharing violation or another standard dialogue that doesn't involve the user having to create a new directory in order to specify it just because it doesn't yet exist.

Edit: When I originally posted this, I forgot that the folder dialogue that I'm using is actually the XFolder Dialog on the Code Project site. While it does let the user browse for a directory, it's not as intuitive as folder browser dialogues that I've seen in installers in the past. What I'd really want is something where the user can browse to the folder in which their new folder is to go and then simply append the new folder to the path in the dialogue's edit box without having to create the new folder.

Update As the XFolder dialogue is a customization of the standard Open File dialogue which uses a template, it does not work on Vista or newer OSs. Because of this, I must abandon use of this for something else. I'm still looking for a solution here. If someone can show me how to set the initial directory (as opposed to the root directory) when using SHBrowseForFolder(), I'd be willing to use that as my solution.

+1  A: 

For your purpose, it would probably make sense to let the user select a base directory, e.g. "C:\Program Files" (creating one in the process if so desired) and install into a subdirectory of that (a name which you append to the selected path and let your installer create). Display the combined path after the user has selected the base. This way, the user doesn't feel like he has taken on responsibility for the directory you're creating, but still has a reasonable level of control over the destination.

Shog9
A default path is provided already. We provide a browse button in case the user wants to change the path, and the browse button currently launches the CFolderDialog, which has the problem of the user only being able to select existing folders or create new ones to select. Additionally, a browse dialogue is used in case the user wants to change the location to a different drive.
RobH
Pretty much every installer I've seen lets the user select the install path -- base path and all -- using one dialogue.
RobH
A: 

Instead of manually creating an installer, have you considered Microsoft's opensource project Wix?

Leonardo Constantino
I never heard of it when I started the project, and now, it's too close to completion to start over.
RobH
A: 

I have never seen such a dialog window, neither in MFC nor in any other technology. I agree with Shog9, you should provide the user with a way to separate the selection of a base directory and the creation of directories.

Benoît
Pretty much every installer I've seen lets the user select the install path -- base path and all -- using one dialogue.
RobH
A: 

You can use SHBrowseForFolder without specifying neither BIF_BROWSEINCLUDEFILES or BIF_NONEWFOLDERBUTTON.

Ryan
Thanks. I'm being sidetracked with bug fixes on another project at the moment, but when I get back onto the new installer project, I'll try that and see how it goes.
RobH
SHBrowseForFolder works. And, thanks to the Microsoft forums, I was able to implement a means to initialize the dialogue with a default folder. While it's not really what I want, it's the best solution that I have for the moment. (The user still has to create directories with this, and I'd prefer a solution where that's not necessary.)
RobH