FileChooser initialFileOrDirectory ignored on Windows 7/8/10


#1

Hello !

I would like to talk about an issue with Windows that I see very often and which is bothering me.

Imagine that I use Reaper 64 bits on Windows 8 and save / render an audio file somewhere after having opened a native Save As dialog box. Then, I close Reaper, I open another project, I load a plug-in where there is a TextButton allowing me to use a native Open Dialog box to select a file.

That native window is opened with JUCE FileChooser::browseForFileToOpen, and I set a very specific folder there for the initial path with the FileChooser constructor argument “initialFileOrDirectory”. However, the initial path I see in the native Open dialog box isn’t the one I specified, but the last path I used in the other Reaper project instead…

Is it a Reaper issue ? A JUCE issue ? After some research, I found the guilty : it’s the WIN32 API !

https://msdn.microsoft.com/en-us/library/ms646839(VS.85).aspx
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/7c6614ea-bef9-4421-9778-f8e42b95456a/openfilename-lpstrinitialdir-behavior-change-in-windows-7-how-to-avoid?forum=windowsuidevelopment

Here is what they say :

lpstrInitialDir

Type: LPCTSTR

The initial directory. The algorithm for selecting the initial directory varies on different platforms.

Windows 7:

  1. If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
  2. Otherwise, if lpstrFile contains a path, that path is the initial directory.
  3. Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
  4. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
  5. Otherwise, the initial directory is the personal files directory of the current user.
  6. Otherwise, the initial directory is the Desktop folder.

Really stupid isn’t it ? In some random cases, the parameter is ignored, and there is nothing to do about it with the given input parameters.

I don’t know if there is an easy workaround for that (such as resetting in the registry that previous folder, or opening a fake dialog with a random initial folder before each call) but at least I think it would be important to talk about the issue in the FileChooser documentation.


#2

Bumping this as I’m running into exactly this problem. Has anyone found a fix they can share?

Edit: I’m on Windows 10, and get a variation of this problem in Ableton.