applied patch #2016003 - nsDialogs: Initial folder for SelectFileDialog

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5722 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2008-09-16 19:38:14 +00:00
parent 0215951357
commit 3c2db22eda
2 changed files with 873 additions and 859 deletions

View file

@ -511,6 +511,8 @@ SectionEnd</pre></blockquote>
<p>Displays a file selection dialog to the user. If <i>mode</i> is set to <i>save</i>, displays a file save dialog. If <i>mode</i> is set to <i>open</i>, displays a file open dialog. <i>filter</i> is a list of available file filters separated by pipes. If an empty string is passed, the default is used - <i>All Files|*.*</i>.</p>
<p><i>initial_selection</i> can be used to provide the user with a default file to look for and/or a default folder to look in. If <i>initial_selection</i> is empty no default filename will be provided for the user and the dialog will start in the current working directory. If <i>initial_selection</i> specifies just a filename, for example "test.exe", the dialog will be set up to look for a file called test.exe in the current working directory. If <i>initial_selection</i> specifies just a directory, for example "C:\Program Files", the dialog starts in the provided directory with no file name provided. If <i>initial_selection</i> specifies a directory and a filename, for example "C:\Windows\System32\calc.exe", the dialog will be set up to look for a file called calc.exe in the directory C:\Windows\System32.</p>
<p>Returns the selected file on the stack or an empty string if the user canceled the operation.</p>
<h3><a name="ref-selectfolderdialog"></a>SelectFolderDialog</h3>

View file

@ -84,9 +84,11 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch
OPENFILENAME ofn={0,}; // XXX WTF
int save;
char type[5];
char path[1024];
char filter[1024];
char currentDirectory[1024];
static char path[1024];
static char filter[1024];
static char currentDirectory[1024];
static char initialDir[1024];
DWORD gfa;
EXDLL_INIT();
@ -104,6 +106,16 @@ void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, ch
save = !lstrcmpi(type, "save");
// Check if the path given is a folder. If it is we initialize the
// ofn.lpstrInitialDir parameter
gfa = GetFileAttributes(path);
if ((gfa != INVALID_FILE_ATTRIBUTES) && (gfa & FILE_ATTRIBUTE_DIRECTORY))
{
lstrcpy(initialDir, path);
ofn.lpstrInitialDir = initialDir;
path[0] = '\0'; // disable initial file selection as path is actually a directory
}
if (!filter[0])
{
lstrcpy(filter, "All Files|*.*");