@@ -422,66 +422,35 @@ int32 ShowOpenDialog(bool allowMultipleSelection,
422422 ConvertToNativePath (initialDirectory);
423423
424424 if (chooseDirectory) {
425- // check current OS version
426- OSVERSIONINFO osvi;
427- memset (&osvi, 0 , sizeof (OSVERSIONINFO));
428- osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
429- if (GetVersionEx (&osvi) && (osvi.dwMajorVersion >= 6 )) {
430- // for Vista or later, use the MSDN-preferred implementation of the Open File dialog in pick folders mode
431- IFileDialog *pfd;
432- if (SUCCEEDED (CoCreateInstance (CLSID_FileOpenDialog, NULL , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&pfd)))) {
433- // configure the dialog to Select Folders only
434- DWORD dwOptions;
435- if (SUCCEEDED (pfd->GetOptions (&dwOptions))) {
436- pfd->SetOptions (dwOptions | FOS_PICKFOLDERS | FOS_DONTADDTORECENT);
437- IShellItem *shellItem = NULL ;
438- if (SUCCEEDED (SHCreateItemFromParsingName (initialDirectory.c_str (), 0 , IID_IShellItem, reinterpret_cast <void **>(&shellItem))))
439- pfd->SetFolder (shellItem);
440- pfd->SetTitle (title.c_str ());
441- if (SUCCEEDED (pfd->Show (GetActiveWindow ()))) {
442- IShellItem *psi;
443- if (SUCCEEDED (pfd->GetResult (&psi))) {
444- LPWSTR lpwszName = NULL ;
445- if (SUCCEEDED (psi->GetDisplayName (SIGDN_DESKTOPABSOLUTEPARSING, (LPWSTR*)&lpwszName))) {
446- // Add directory path to the result
447- std::wstring wstrName (lpwszName);
448- ExtensionString pathName (wstrName);
449- ConvertToUnixPath (pathName);
450- selectedFiles->SetString (0 , pathName);
451- ::CoTaskMemFree (lpwszName);
452- }
453- psi->Release ();
425+ IFileDialog *pfd;
426+ if (SUCCEEDED (CoCreateInstance (CLSID_FileOpenDialog, NULL , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&pfd)))) {
427+ // configure the dialog to Select Folders only
428+ DWORD dwOptions;
429+ if (SUCCEEDED (pfd->GetOptions (&dwOptions))) {
430+ pfd->SetOptions (dwOptions | FOS_PICKFOLDERS | FOS_DONTADDTORECENT);
431+ IShellItem *shellItem = NULL ;
432+ if (SUCCEEDED (SHCreateItemFromParsingName (initialDirectory.c_str (), 0 , IID_IShellItem, reinterpret_cast <void **>(&shellItem))))
433+ pfd->SetFolder (shellItem);
434+ pfd->SetTitle (title.c_str ());
435+ if (SUCCEEDED (pfd->Show (GetActiveWindow ()))) {
436+ IShellItem *psi;
437+ if (SUCCEEDED (pfd->GetResult (&psi))) {
438+ LPWSTR lpwszName = NULL ;
439+ if (SUCCEEDED (psi->GetDisplayName (SIGDN_DESKTOPABSOLUTEPARSING, (LPWSTR*)&lpwszName))) {
440+ // Add directory path to the result
441+ std::wstring wstrName (lpwszName);
442+ ExtensionString pathName (wstrName);
443+ ConvertToUnixPath (pathName);
444+ selectedFiles->SetString (0 , pathName);
445+ ::CoTaskMemFree (lpwszName);
454446 }
447+ psi->Release ();
455448 }
456- if (shellItem != NULL )
457- shellItem->Release ();
458- }
459- pfd->Release ();
460- }
461- } else {
462- // for XP, use the old-styled SHBrowseForFolder() implementation
463- BROWSEINFO bi = {0 };
464- bi.hwndOwner = GetActiveWindow ();
465- bi.lpszTitle = title.c_str ();
466- bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX;
467- bi.lpfn = SetInitialPathCallback;
468- bi.lParam = (LPARAM)initialDirectory.c_str ();
469-
470- LPITEMIDLIST pidl = SHBrowseForFolder (&bi);
471- if (pidl != 0 ) {
472- if (SHGetPathFromIDList (pidl, szFile)) {
473- // Add directory path to the result
474- ExtensionString pathName (szFile);
475- ConvertToUnixPath (pathName);
476- selectedFiles->SetString (0 , pathName);
477- }
478- IMalloc* pMalloc = NULL ;
479- SHGetMalloc (&pMalloc);
480- if (pMalloc) {
481- pMalloc->Free (pidl);
482- pMalloc->Release ();
483449 }
450+ if (shellItem != NULL )
451+ shellItem->Release ();
484452 }
453+ pfd->Release ();
485454 }
486455 } else {
487456 OPENFILENAME ofn;
@@ -729,7 +698,7 @@ int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double
729698
730699const int BOMLength = 3 ;
731700
732- typedef enum CheckedState { CS_UNKNOWN, CS_NO, CS_YES };
701+ enum CheckedState { CS_UNKNOWN, CS_NO, CS_YES };
733702
734703typedef struct UTFValidationState {
735704
0 commit comments