Skip to content

Commit 0271c0e

Browse files
author
Ravbug
committed
Don't use command line to reveal files in Explorer
1 parent 5008120 commit 0271c0e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

source/globals.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <wx/msgdlg.h>
55
#if __APPLE__
66
#include "AppleUtilities.h"
7+
#elif _WIN32
8+
#include <ShlObj_core.h>
79
#endif
810

911
void launch_process(const std::string& command, int flags) {
@@ -26,13 +28,26 @@ void reveal_in_explorer(const std::filesystem::path& path) {
2628
#else
2729
#if defined __linux__
2830
std::string command = "xdg-open \"" + path.string() + "\"";
31+
launch_process(command);
2932

3033
#elif defined _WIN32
3134
//do not surround the paths in quotes, it will not work
32-
std::string command = "\\Windows\\explorer.exe \"" + path.string() + "\"";
3335
#endif
3436
if (std::filesystem::exists(path)) {
35-
launch_process(command);
37+
38+
PIDLIST_ABSOLUTE pidl;
39+
SFGAOF attributes;
40+
HRESULT hr = SHParseDisplayName(path.c_str(), nullptr, &pidl, 0, &attributes);
41+
if (SUCCEEDED(hr)) {
42+
if (pidl) {
43+
LPITEMIDLIST pidlItem = ILFindLastID(pidl);
44+
HRESULT hr2 = SHOpenFolderAndSelectItems(pidl, 1, const_cast<LPCITEMIDLIST*>(&pidlItem), 0);
45+
ILFree(pidl);
46+
if (FAILED(hr2)) {
47+
48+
}
49+
}
50+
}
3651
}
3752
else {
3853
wxMessageBox("The project at " + path.string() + " could not be found.", "Cannot Reveal Project", wxOK | wxICON_ERROR);

0 commit comments

Comments
 (0)