diff --git a/reactos/subsys/system/explorer/dialogs/searchprogram.cpp b/reactos/subsys/system/explorer/dialogs/searchprogram.cpp index 46ed4412a9d..98400cf742d 100644 --- a/reactos/subsys/system/explorer/dialogs/searchprogram.cpp +++ b/reactos/subsys/system/explorer/dialogs/searchprogram.cpp @@ -176,72 +176,58 @@ void FindProgramDlg::Refresh(bool delete_cache) void FindProgramDlg::collect_programs_callback(Entry* entry, void* param) { FindProgramDlg* pThis = (FindProgramDlg*) param; - ShellPath shell_path; - - if (!get_entry_pidl(entry, shell_path)) - return; IShellLink* pShellLink; - LPCITEMIDLIST pidl_last = NULL; - IShellFolder* pFolder; - - static DynamicFct SHBindToParent(TEXT("SHELL32"), "SHBindToParent"); - - if (!SHBindToParent) - return; - - HRESULT hr = (*SHBindToParent)(shell_path, IID_IShellFolder, (LPVOID*)&pFolder, &pidl_last); + HRESULT hr = entry->GetUIObjectOf(pThis->_hwnd, IID_IShellLink, (LPVOID*)&pShellLink); if (SUCCEEDED(hr)) { - hr = pFolder->GetUIObjectOf(pThis->_hwnd, 1, &pidl_last, IID_IShellLink, NULL, (LPVOID*)&pShellLink); + ShellLinkPtr shell_link(pShellLink); - if (SUCCEEDED(hr)) { - ShellLinkPtr shell_link(pShellLink); + shell_link->Release(); - /*hr = pShellLink->Resolve(pThis->_hwnd, SLR_NO_UI); - if (SUCCEEDED(hr))*/ { - WIN32_FIND_DATA wfd; - TCHAR path[MAX_PATH]; + /*hr = pShellLink->Resolve(pThis->_hwnd, SLR_NO_UI); + if (SUCCEEDED(hr))*/ { + WIN32_FIND_DATA wfd; + TCHAR path[MAX_PATH]; - hr = pShellLink->GetPath(path, MAX_PATH-1, &wfd, SLGP_UNCPRIORITY); + hr = pShellLink->GetPath(path, MAX_PATH-1, &wfd, SLGP_UNCPRIORITY); - if (SUCCEEDED(hr)) { - TCHAR entry_path[MAX_PATH]; + if (SUCCEEDED(hr)) { + TCHAR entry_path[MAX_PATH]; - entry->get_path(entry_path); + entry->get_path(entry_path); - String menu_path; + String menu_path; - int len = pThis->_common_programs.size(); + int len = pThis->_common_programs.size(); - if (len && !_tcsnicmp(entry_path, pThis->_common_programs, len)) - menu_path = ResString(IDS_ALL_USERS) + (String(entry_path)+len); - else if ((len=pThis->_user_programs.size()) && !_tcsnicmp(entry_path, pThis->_user_programs, len)) - menu_path = String(entry_path)+len; + if (len && !_tcsnicmp(entry_path, pThis->_common_programs, len)) + menu_path = ResString(IDS_ALL_USERS) + (String(entry_path)+len); + else if ((len=pThis->_user_programs.size()) && !_tcsnicmp(entry_path, pThis->_user_programs, len)) + menu_path = String(entry_path)+len; - // store info in cache - FPDEntry new_entry; + // store info in cache + FPDEntry new_entry; - new_entry._entry = entry; - new_entry._menu_path = menu_path; - new_entry._path = path; + new_entry._entry = entry; + new_entry._menu_path = menu_path; + new_entry._path = path; - if (entry->_hIcon != (HICON)-1) - new_entry._idxIcon = ImageList_AddIcon(pThis->_himl, entry->_hIcon); - else - new_entry._idxIcon = pThis->_idxNoIcon; + if (entry->_hIcon != (HICON)-1) + new_entry._idxIcon = ImageList_AddIcon(pThis->_himl, entry->_hIcon); + else + new_entry._idxIcon = pThis->_idxNoIcon; - pThis->_cache.push_front(new_entry); - FPDEntry& cache_entry = pThis->_cache.front(); + pThis->_cache.push_front(new_entry); + FPDEntry& cache_entry = pThis->_cache.front(); - Lock lock(pThis->_thread._crit_sect); + Lock lock(pThis->_thread._crit_sect); - // resolve deadlocks while executing Thread::Stop() - if (!pThis->_thread.is_alive()) - return; + // resolve deadlocks while executing Thread::Stop() + if (!pThis->_thread.is_alive()) + return; - pThis->add_entry(cache_entry); - } + pThis->add_entry(cache_entry); } } } diff --git a/reactos/subsys/system/explorer/shell/entries.cpp b/reactos/subsys/system/explorer/shell/entries.cpp index 25a113861d2..95be939529f 100644 --- a/reactos/subsys/system/explorer/shell/entries.cpp +++ b/reactos/subsys/system/explorer/shell/entries.cpp @@ -307,6 +307,59 @@ BOOL Entry::launch_entry(HWND hwnd, UINT nCmdShow) } +HRESULT Entry::GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut) +{ + TCHAR path[MAX_PATH]; +/* + if (!get_path(path)) + return E_FAIL; + + ShellPath shell_path(path); + + IShellFolder* pFolder; + LPCITEMIDLIST pidl_last = NULL; + + static DynamicFct SHBindToParent(TEXT("SHELL32"), "SHBindToParent"); + + if (!SHBindToParent) + return E_NOTIMPL; + + HRESULT hr = (*SHBindToParent)(shell_path, IID_IShellFolder, (LPVOID*)&pFolder, &pidl_last); + if (FAILED(hr)) + return hr; + + ShellFolder shell_folder(pFolder); + + shell_folder->Release(); + + return shell_folder->GetUIObjectOf(hWnd, 1, &pidl_last, riid, NULL, ppvOut); +*/ + if (!_up) + return E_INVALIDARG; + + if (!_up->get_path(path)) + return E_FAIL; + + ShellPath shell_path(path); + ShellFolder shell_folder(shell_path); + + WCHAR wname[MAX_PATH]; + MultiByteToWideChar(CP_ACP, 0, _data.cFileName, -1, wname, MAX_PATH); + + LPITEMIDLIST pidl_last = NULL; + HRESULT hr = shell_folder->ParseDisplayName(hWnd, NULL, wname, NULL, &pidl_last, NULL); + + if (FAILED(hr)) + return hr; + + hr = shell_folder->GetUIObjectOf(hWnd, 1, (LPCITEMIDLIST*)&pidl_last, riid, NULL, ppvOut); + + ShellMalloc()->Free((void*)pidl_last); + + return hr; +} + + // recursively free all child entries void Entry::free_subentries() { diff --git a/reactos/subsys/system/explorer/shell/entries.h b/reactos/subsys/system/explorer/shell/entries.h index 5fcd039638d..75a08acfeba 100644 --- a/reactos/subsys/system/explorer/shell/entries.h +++ b/reactos/subsys/system/explorer/shell/entries.h @@ -91,6 +91,7 @@ public: virtual const void* get_next_path_component(const void*) {return NULL;} virtual Entry* find_entry(const void*) {return NULL;} virtual bool get_path(PTSTR path) const = 0; + virtual HRESULT GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut); virtual BOOL launch_entry(HWND hwnd, UINT nCmdShow=SW_SHOWNORMAL); }; diff --git a/reactos/subsys/system/explorer/shell/shellfs.cpp b/reactos/subsys/system/explorer/shell/shellfs.cpp index d56300f29b2..9d9c4f56fae 100644 --- a/reactos/subsys/system/explorer/shell/shellfs.cpp +++ b/reactos/subsys/system/explorer/shell/shellfs.cpp @@ -151,6 +151,14 @@ bool ShellEntry::get_path(PTSTR path) const } +HRESULT ShellEntry::GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut) +{ + LPCITEMIDLIST pidl = _pidl; + + return get_parent_folder()->GetUIObjectOf(hWnd, 1, &pidl, riid, NULL, ppvOut); +} + + // get full path of a shell folder bool ShellDirectory::get_path(PTSTR path) const { @@ -388,7 +396,6 @@ void ShellDirectory::read_directory(int scan_flags) if (ext) {//@@ int len = ext - entry->_data.cFileName; - entry->_display_name = (LPTSTR) malloc((len+1)*sizeof(TCHAR)); _tcsncpy(entry->_display_name, entry->_data.cFileName, len); entry->_display_name[len] = TEXT('\0'); diff --git a/reactos/subsys/system/explorer/shell/shellfs.h b/reactos/subsys/system/explorer/shell/shellfs.h index 1c86df9acb8..5a009fc1baa 100644 --- a/reactos/subsys/system/explorer/shell/shellfs.h +++ b/reactos/subsys/system/explorer/shell/shellfs.h @@ -34,6 +34,7 @@ struct ShellEntry : public Entry virtual bool get_path(PTSTR path) const; virtual BOOL launch_entry(HWND hwnd, UINT nCmdShow=SW_SHOWNORMAL); + virtual HRESULT GetUIObjectOf(HWND hWnd, REFIID riid, LPVOID* ppvOut); IShellFolder* get_parent_folder() const; ShellPath create_absolute_pidl() const;