comdlg32: Avoid generating filenames twice in filedlg.

Signed-off-by: Lauri Kenttä <lauri.kentta@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Lauri Kenttä 2016-07-06 13:27:43 +03:00 committed by Alexandre Julliard
parent 86a993ea3c
commit f99da3f3a1
1 changed files with 46 additions and 64 deletions

View File

@ -3647,9 +3647,8 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
{ {
FileOpenDlgInfos *fodInfos; FileOpenDlgInfos *fodInfos;
LPITEMIDLIST pidl; LPITEMIDLIST pidl;
UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0; LPWSTR lpstrAllFiles, lpstrTmp;
WCHAR lpstrTemp[MAX_PATH]; UINT nFiles = 0, nFileToOpen, nFileSelected, nAllFilesLength = 0, nThisFileLength, nAllFilesMaxLength;
LPWSTR lpstrAllFile, lpstrCurrFile;
TRACE("\n"); TRACE("\n");
fodInfos = GetPropA(hwnd,FileOpenDlgInfosStr); fodInfos = GetPropA(hwnd,FileOpenDlgInfosStr);
@ -3657,74 +3656,57 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
/* Count how many files we have */ /* Count how many files we have */
nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject ); nFileSelected = GetNumSelected( fodInfos->Shell.FOIDataObject );
/* calculate the string length, count files */ /* Allocate a buffer */
if (nFileSelected >= 1) nAllFilesMaxLength = MAX_PATH + 3;
lpstrAllFiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nAllFilesMaxLength * sizeof(WCHAR));
if (!lpstrAllFiles)
goto ret;
/* Loop through the selection, handle only files (not folders) */
for (nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++)
{ {
nLength += 3; /* first and last quotes, trailing \0 */
for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ )
{
pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 ); pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 );
if (pidl) if (pidl)
{ {
/* get the total length of the selected file names */ if (!IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl))
lpstrTemp[0] = '\0'; {
GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER|SHGDN_FORPARSING, lpstrTemp ); if (nAllFilesLength + MAX_PATH + 3 > nAllFilesMaxLength)
{
if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */ nAllFilesMaxLength *= 2;
{ lpstrTmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpstrAllFiles, nAllFilesMaxLength * sizeof(WCHAR));
nLength += lstrlenW( lpstrTemp ) + 3; if (!lpstrTmp)
nFiles++; goto ret;
} lpstrAllFiles = lpstrTmp;
COMDLG32_SHFree( pidl ); }
} nFiles += 1;
} lpstrAllFiles[nAllFilesLength++] = '"';
GetName(fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, lpstrAllFiles + nAllFilesLength);
nThisFileLength = lstrlenW(lpstrAllFiles + nAllFilesLength);
nAllFilesLength += nThisFileLength;
lpstrAllFiles[nAllFilesLength++] = '"';
lpstrAllFiles[nAllFilesLength++] = ' ';
}
COMDLG32_SHFree(pidl);
}
} }
/* allocate the buffer */ if (nFiles != 0)
if (nFiles <= 1) nLength = MAX_PATH;
lpstrAllFile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength * sizeof(WCHAR));
/* Generate the string for the edit control */
if(nFiles >= 1)
{ {
lpstrCurrFile = lpstrAllFile; /* If there's only one file, use the name as-is without quotes */
for ( nFileToOpen = 0; nFileToOpen < nFileSelected; nFileToOpen++ ) lpstrTmp = lpstrAllFiles;
{ if (nFiles == 1)
pidl = GetPidlFromDataObject( fodInfos->Shell.FOIDataObject, nFileToOpen+1 ); {
lpstrTmp += 1;
if (pidl) lpstrTmp[nThisFileLength] = 0;
{ }
/* get the file name */ SetWindowTextW(fodInfos->DlgInfos.hwndFileName, lpstrTmp);
lpstrTemp[0] = '\0'; /* Select the file name like Windows does */
GetName( fodInfos->Shell.FOIShellFolder, pidl, SHGDN_INFOLDER|SHGDN_FORPARSING, lpstrTemp ); if (filename_is_edit(fodInfos))
SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, -1);
if (! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl)) /* Ignore folders */
{
if ( nFiles > 1)
{
*lpstrCurrFile++ = '\"';
lstrcpyW( lpstrCurrFile, lpstrTemp );
lpstrCurrFile += lstrlenW( lpstrTemp );
*lpstrCurrFile++ = '\"';
*lpstrCurrFile++ = ' ';
*lpstrCurrFile = 0;
}
else
{
lstrcpyW( lpstrAllFile, lpstrTemp );
}
}
COMDLG32_SHFree( pidl );
}
}
SetWindowTextW( fodInfos->DlgInfos.hwndFileName, lpstrAllFile );
/* Select the file name like Windows does */
if (filename_is_edit( fodInfos ))
SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, -1);
} }
HeapFree(GetProcessHeap(),0, lpstrAllFile );
ret:
HeapFree(GetProcessHeap(), 0, lpstrAllFiles);
} }