static void DoRestore(RecycleBinMenu *This) { /*TODO add prompts*/ UINT i; for(i=0;i<This->cidl;i++) { WIN32_FIND_DATAW data; TRASH_UnpackItemID(&((This->apidl[i])->mkid),&data); if(PathFileExistsW(data.cFileName)) { PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data.cFileName); WCHAR message[100]; WCHAR caption[50]; if(_ILIsFolder(ILFindLastID(dest_pidl))) LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITEFOLDER, message,sizeof(message)/sizeof(WCHAR)); else LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITEFILE, message,sizeof(message)/sizeof(WCHAR)); LoadStringW(shell32_hInstance,IDS_RECYCLEBIN_OVERWRITE_CAPTION, caption,sizeof(caption)/sizeof(WCHAR)); if(ShellMessageBoxW(shell32_hInstance,GetActiveWindow(),message, caption,MB_YESNO|MB_ICONEXCLAMATION, data.cFileName)!=IDYES) continue; } if(SUCCEEDED(TRASH_RestoreItem(This->apidl[i]))) { IPersistFolder2 *persist; LPITEMIDLIST root_pidl; PIDLIST_ABSOLUTE dest_pidl = ILCreateFromPathW(data.cFileName); BOOL is_folder = _ILIsFolder(ILFindLastID(dest_pidl)); IShellFolder2_QueryInterface(This->folder,&IID_IPersistFolder2, (void**)&persist); IPersistFolder2_GetCurFolder(persist,&root_pidl); SHChangeNotify(is_folder ? SHCNE_RMDIR : SHCNE_DELETE, SHCNF_IDLIST,ILCombine(root_pidl,This->apidl[i]),0); SHChangeNotify(is_folder ? SHCNE_MKDIR : SHCNE_CREATE, SHCNF_IDLIST,dest_pidl,0); ILFree(dest_pidl); ILFree(root_pidl); } } }
void StaticHelpers::OpenFileInExplorer(QString& file) { file = QDir::toNativeSeparators(file); wchar_t wPath[MAX_PATH] = { 0 }; file.toWCharArray(wPath); ITEMIDLIST* pItem = ILCreateFromPathW(wPath); SHOpenFolderAndSelectItems(pItem, 0, NULL, 0); ILFree(pItem); }
static DWORD CALLBACK DDW_OnExploreFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) { if (!pidl) pidl = ILCreateFromPathW(strPath); if (!pidl) return DDE_FNOTPROCESSED; if (FAILED(SHOpenNewFrame(pidl, NULL, 0, SH_EXPLORER_CMDLINE_FLAG_E))) return DDE_FNOTPROCESSED; return DDE_FACK; }
static DWORD CALLBACK DDE_OnViewFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) { if (!pidl) pidl = ILCreateFromPathW(strPath); if (!pidl) return DDE_FNOTPROCESSED; if (FAILED(SHOpenNewFrame(pidl, NULL, 0, 0))) return DDE_FNOTPROCESSED; return DDE_FACK; }
LPITEMIDLIST CBandSiteMenu::_GetQLaunchPidl(BOOL refresh) { if (m_QLaunchPidl != NULL) { if (refresh) m_QLaunchPidl.Free(); else return m_QLaunchPidl; } WCHAR buffer[MAX_PATH]; HRESULT hr = SHGetFolderPathAndSubDirW(0, CSIDL_APPDATA, NULL, 0, L"Microsoft\\Internet Explorer\\Quick Launch", buffer); if (FAILED_UNEXPECTEDLY(hr)) return NULL; m_QLaunchPidl.Attach(ILCreateFromPathW(buffer)); return m_QLaunchPidl; }
// browse for a folder bool CBrowseForFolder::GetFolder(CString &returnPath) { LPITEMIDLIST pidlRoot = ILCreateFromPathW (strDirRoot);; TCHAR strBuff[MAX_PATH + 1]; returnPath.Empty(); BROWSEINFO brInfo= { hWndOwner, pidlRoot, strBuff, strTitle, flags, BrowseCallbackProc, (LPARAM)&strStartupDir, Image }; if (flags & 0x0040) OleInitialize(NULL); LPITEMIDLIST pidl = SHBrowseForFolder(&brInfo); if (flags & 0x0040) OleUninitialize(); if (pidl) { SHGetPathFromIDList(pidl, strBuff); CoTaskMemFree(pidl); returnPath = strBuff; } if (pidlRoot) CoTaskMemFree(pidlRoot); if (!returnPath.IsEmpty()) return true; else return false; }
static LRESULT explorer_on_end_edit(explorer_info *info,NMCBEENDEDITW *edit_info) { LPITEMIDLIST pidl = NULL; WINE_TRACE("iWhy=%x\n",edit_info->iWhy); switch(edit_info->iWhy) { case CBENF_DROPDOWN: if(edit_info->iNewSelection!=CB_ERR) pidl = (LPITEMIDLIST)SendMessageW(edit_info->hdr.hwndFrom, CB_GETITEMDATA, edit_info->iNewSelection,0); break; case CBENF_RETURN: { WCHAR path[MAX_PATH]; HWND edit_ctrl = (HWND)SendMessageW(edit_info->hdr.hwndFrom, CBEM_GETEDITCONTROL,0,0); *((WORD*)path)=MAX_PATH; SendMessageW(edit_ctrl,EM_GETLINE,0,(LPARAM)path); pidl = ILCreateFromPathW(path); break; } case CBENF_ESCAPE: /*make sure the that the path box resets*/ update_path_box(info); return 0; default: return 0; } if(pidl) IExplorerBrowser_BrowseToIDList(info->browser,pidl,SBSP_ABSOLUTE); if(edit_info->iWhy==CBENF_RETURN) ILFree(pidl); return 0; }
/************************************************************************* * SHCreateFromDesktop [BROWSEUI.106] * parameter is a FolderInfo */ BOOL WINAPI SHCreateFromDesktop(ExplorerCommandLineParseResults * parseResults) { DbgPrint("SHCreateFromDesktop\n"); IEThreadParamBlock * parameters = SHCreateIETHREADPARAM(0, 0, 0, 0); if (!parameters) return FALSE; PCWSTR strPath = NULL; if (parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_STRING) { if (parseResults->pidlPath) { WARN("strPath and pidlPath are both assigned. This shouldn't happen.\n"); } strPath = parseResults->strPath; } parameters->dwFlags = parseResults->dwFlags; parameters->offset8 = parseResults->offsetC; LPITEMIDLIST pidl = parseResults->pidlPath ? ILClone(parseResults->pidlPath) : NULL; if (!pidl && parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_STRING) { if (parseResults->strPath && parseResults->strPath[0]) { pidl = ILCreateFromPathW(parseResults->strPath); } } parameters->directoryPIDL = pidl; // Try to find the owner of the idlist, if we aren't running /SEPARATE HWND desktop = NULL; if (!(parseResults->dwFlags & SH_EXPLORER_CMDLINE_FLAG_SEPARATE)) desktop = FindShellProxy(parameters->directoryPIDL); // If found, ask it to open the new window if (desktop) { DbgPrint("Found desktop hwnd=%p\n", desktop); DWORD dwProcessId; GetWindowThreadProcessId(desktop, &dwProcessId); AllowSetForegroundWindow(dwProcessId); HANDLE hShared = MakeSharedPacket(parameters, strPath, dwProcessId); if (hShared) { DbgPrint("Sending open message...\n"); PostMessageW(desktop, WM_EXPLORER_OPEN_NEW_WINDOW, 0, (LPARAM) hShared); } SHDestroyIETHREADPARAM(parameters); return TRUE; } DbgPrint("Desktop not found or separate flag requested.\n"); // Else, start our own message loop! HRESULT hr = CoInitialize(NULL); CProxyDesktop * proxy = CreateProxyDesktop(parameters); if (proxy) { LONG refCount; CComPtr<IUnknown> thread; if (SHCreateThreadRef(&refCount, &thread) >= 0) { SHSetInstanceExplorer(thread); if (strPath) parameters->directoryPIDL = ILCreateFromPath(strPath); SHOpenFolderWindow(parameters); parameters = NULL; thread.Release(); } MSG Msg; while (GetMessageW(&Msg, 0, 0, 0) && refCount) { TranslateMessage(&Msg); DispatchMessageW(&Msg); } delete proxy; } if (SUCCEEDED(hr)) CoUninitialize(); SHDestroyIETHREADPARAM(parameters); return TRUE; }
UINT WINAPI SHExplorerParseCmdLine(ExplorerCommandLineParseResults * pInfo) { WCHAR strField[MAX_PATH]; WCHAR strDir[MAX_PATH]; PCWSTR strCmdLine = GetCommandLineW(); PCWSTR strFieldArray = PathGetArgsW(strCmdLine); if (!*strFieldArray) { pInfo->dwFlags = 9; pInfo->pidlPath = _GetDocumentsPidl(); if (!pInfo->pidlPath) { GetWindowsDirectoryW(strDir, MAX_PATH); PathStripToRootW(strDir); pInfo->pidlPath = ILCreateFromPathW(strDir); } return (LONG) (pInfo->pidlPath); } PCWSTR strNextArg = _FindFirstField(strFieldArray); BOOL hasNext = TRUE; hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); while (TRUE) { // Basic flags-only params first if (!StrCmpIW(strField, L"/N")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_N | SH_EXPLORER_CMDLINE_FLAG_ONE; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/S")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_S; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/E")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_E; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/SELECT")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_SELECT; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/NOUI")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_NOUI; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"-embedding")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_EMBED; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/SEPARATE")) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_SEPARATE; TRACE("CmdLine Parser: Parsed %S flag. dwFlags=%08lx\n", strField, pInfo->dwFlags); } else if (!StrCmpIW(strField, L"/INPROC")) { // No idea what Inproc is supposed to do, but it gets a GUID, and parses it. TRACE("CmdLine Parser: Found %S flag\n", strField); if (!hasNext) return FALSE; hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); if (!GUIDFromStringW(strField, &(pInfo->guidInproc))) return FALSE; pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_INPROC; TRACE("CmdLine Parser: Parsed /INPROC flag. dwFlags=%08lx, guidInproc=%S\n", pInfo->dwFlags, strField); } else if (!StrCmpIW(strField, L"/ROOT")) { LPITEMIDLIST pidlRoot = NULL; // The window should be rooted TRACE("CmdLine Parser: Found %S flag\n", strField); if (!pInfo->pidlPath) return FALSE; if (!hasNext) return FALSE; hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); // Root may be a pidl if (!StrCmpIW(strField, L"/IDLIST")) { if (hasNext) { hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); } pidlRoot = _ILReadFromSharedMemory(strField); } else { // Or just a path string _ParsePathToPidl(strField, &pidlRoot); } pInfo->pidlRoot = pidlRoot; // The root defaults to the desktop if (!pidlRoot) { if (FAILED(SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, &(pInfo->pidlRoot)))) pInfo->pidlRoot = NULL; } // TODO: Create rooted PIDL from pInfo->pidlPath and pInfo->pidlRoot TRACE("CmdLine Parser: Parsed /ROOT flag. dwFlags=%08lx, pidlRoot=%p\n", pInfo->dwFlags, pInfo->pidlRoot); } else { // Anything else is part of the target path to browse to TRACE("CmdLine Parser: Found target path %S\n", strField); // Which can be a shared-memory itemidlist if (!StrCmpIW(strField, L"/IDLIST")) { LPITEMIDLIST pidlArg; if (!hasNext) return FALSE; hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); pidlArg = _ILReadFromSharedMemory(strField); if (!pidlArg) return FALSE; if (pInfo->pidlPath) ILFree(pInfo->pidlPath); pInfo->pidlPath = pidlArg; TRACE("CmdLine Parser: Parsed target path. dwFlags=%08lx, pidlPath=%p\n", pInfo->dwFlags, pInfo->pidlPath); } else { // Or just a plain old string. WCHAR szPath[MAX_PATH]; DWORD result = GetFullPathNameW(strField, _countof(szPath), szPath, NULL); if (result != 0 && result <= _countof(szPath) && PathFileExistsW(szPath)) StringCchCopyW(strField, _countof(strField), szPath); LPITEMIDLIST pidlPath = ILCreateFromPathW(strField); pInfo->pidlPath = pidlPath; if (pidlPath) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_IDLIST; TRACE("CmdLine Parser: Parsed target path. dwFlags=%08lx, pidlPath=%p\n", pInfo->dwFlags, pInfo->pidlPath); } else { // The path could not be parsed into an ID List, // so pass it on as a plain string. PWSTR field = StrDupW(strField); pInfo->strPath = field; if (field) { pInfo->dwFlags |= SH_EXPLORER_CMDLINE_FLAG_STRING; TRACE("CmdLine Parser: Parsed target path. dwFlags=%08lx, strPath=%S\n", pInfo->dwFlags, field); } } } } if (!hasNext) break; hasNext = _ReadNextArg(&strNextArg, strField, _countof(strField)); } return TRUE; }
bool OsShell::deleteItems(const std::vector<std::wstring>& items, bool moveToTrash, void * parentWindow) { ComInitializer comInitializer; assert_r(parentWindow); std::vector<ITEMIDLIST*> idLists; for (auto& path: items) { __unaligned ITEMIDLIST* idl = ILCreateFromPathW(path.c_str()); if (!idl) { for (auto& pid : idLists) ILFree(pid); qInfo() << "ILCreateFromPathW" << "failed for path" << QString::fromWCharArray(path.c_str()); return false; } idLists.push_back(idl); assert_r(idLists.back()); } IShellItemArray * iArray = 0; HRESULT result = SHCreateShellItemArrayFromIDLists((UINT)idLists.size(), (LPCITEMIDLIST*)idLists.data(), &iArray); // Freeing memory for (auto& pid: idLists) ILFree(pid); idLists.clear(); if (!SUCCEEDED(result) || !iArray) { qInfo() << "SHCreateShellItemArrayFromIDLists failed"; return false; } IFileOperation * iOperation = 0; result = CoCreateInstance(CLSID_FileOperation, 0, CLSCTX_ALL, IID_IFileOperation, (void**)&iOperation); if (!SUCCEEDED(result) || !iOperation) { qInfo() << "CoCreateInstance(CLSID_FileOperation, 0, CLSCTX_ALL, IID_IFileOperation, (void**)&iOperation) failed"; return false; } result = iOperation->DeleteItems(iArray); if (!SUCCEEDED(result)) { qInfo() << "DeleteItems failed"; } else { if (moveToTrash) { result = iOperation->SetOperationFlags(FOF_ALLOWUNDO); } else result = iOperation->SetOperationFlags(FOF_WANTNUKEWARNING); if (!SUCCEEDED(result)) qInfo() << "SetOperationFlags failed"; result = iOperation->SetOwnerWindow((HWND) parentWindow); if (!SUCCEEDED(result)) qInfo() << "SetOwnerWindow failed"; result = iOperation->PerformOperations(); if (!SUCCEEDED(result) && result != COPYENGINE_E_USER_CANCELLED) { qInfo() << "PerformOperations failed"; if (result == COPYENGINE_E_REQUIRES_ELEVATION) qInfo() << "Elevation required"; } else result = S_OK; } iOperation->Release(); iArray->Release(); return SUCCEEDED(result); }
static bool OnCrash(const wchar_t * dumpPath, const wchar_t * miniDumpId, void * context, EXCEPTION_POINTERS * exinfo, MDRawAssertionInfo * assertion, bool succeeded) { if (!succeeded) { constexpr const char * DumpFailedMessage = "Failed to create the dump. Please file an issue with OpenRCT2 on GitHub and provide latest save, and provide information about what you did before the crash occured."; printf("%s\n", DumpFailedMessage); if (!gOpenRCT2SilentBreakpad) { MessageBoxA(NULL, DumpFailedMessage, OPENRCT2_NAME, MB_OK | MB_ICONERROR); } return succeeded; } // Get filenames wchar_t dumpFilePath[MAX_PATH]; wchar_t saveFilePath[MAX_PATH]; swprintf_s(dumpFilePath, sizeof(dumpFilePath), L"%s%s.dmp", dumpPath, miniDumpId); swprintf_s(saveFilePath, sizeof(saveFilePath), L"%s%s.sv6", dumpPath, miniDumpId); // Try to rename the files wchar_t dumpFilePathNew[MAX_PATH]; swprintf_s(dumpFilePathNew, sizeof(dumpFilePathNew), L"%s%s(%s_%s).dmp", dumpPath, miniDumpId, _wszCommitSha1Short, _wszArchitecture); if (_wrename(dumpFilePath, dumpFilePathNew) == 0) { std::wcscpy(dumpFilePath, dumpFilePathNew); } // Log information to output wprintf(L"Dump Path: %s\n", dumpPath); wprintf(L"Dump File Path: %s\n", dumpFilePath); wprintf(L"Dump Id: %s\n", miniDumpId); wprintf(L"Version: %s\n", WSZ(OPENRCT2_VERSION)); wprintf(L"Commit: %s\n", _wszCommitSha1Short); utf8 * saveFilePathUTF8 = widechar_to_utf8(saveFilePath); SDL_RWops * rw = SDL_RWFromFile(saveFilePathUTF8, "wb+"); free(saveFilePathUTF8); bool savedGameDumped = false; if (rw != NULL) { scenario_save(rw, 0x80000000); savedGameDumped = true; SDL_RWclose(rw); } if (gOpenRCT2SilentBreakpad) { return succeeded; } constexpr const wchar_t * MessageFormat = L"A crash has occurred and a dump was created at\n%s.\n\nPlease file an issue with OpenRCT2 on GitHub, and provide the dump and saved game there.\n\nVersion: %s\nCommit: %s"; wchar_t message[MAX_PATH * 2]; swprintf_s(message, MessageFormat, dumpFilePath, WSZ(OPENRCT2_VERSION), _wszCommitSha1Short); // Cannot use platform_show_messagebox here, it tries to set parent window already dead. MessageBoxW(NULL, message, WSZ(OPENRCT2_NAME), MB_OK | MB_ICONERROR); HRESULT coInitializeResult = CoInitialize(NULL); if (SUCCEEDED(coInitializeResult)) { LPITEMIDLIST pidl = ILCreateFromPathW(dumpPath); LPITEMIDLIST files[2]; uint32 numFiles = 0; files[numFiles++] = ILCreateFromPathW(dumpFilePath); if (savedGameDumped) { files[numFiles++] = ILCreateFromPathW(saveFilePath); } if (pidl != nullptr) { HRESULT result = SHOpenFolderAndSelectItems(pidl, numFiles, (LPCITEMIDLIST *)files, 0); ILFree(pidl); for (uint32 i = 0; i < numFiles; i++) { ILFree(files[i]); } } CoUninitialize(); } // Return whether the dump was successful return succeeded; }