mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-13 22:49:52 -04:00
run utils::file::openFolder in its own thread (windows)
This commit is contained in:
parent
c02dc7d08b
commit
43cf9fab40
1 changed files with 20 additions and 13 deletions
|
@ -77,22 +77,29 @@ std::string utils::clipboard::read() {
|
|||
}
|
||||
|
||||
bool utils::file::openFolder(ghc::filesystem::path const& path) {
|
||||
// mods can (and do) keep CoInitializeEx initialized on the main thread
|
||||
// which results in this function just not doing anything
|
||||
// which is why we're using a separate thread
|
||||
// feel free to rework later, im just tired of reports of this not working
|
||||
auto success = false;
|
||||
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) == S_OK) {
|
||||
if (auto id = ILCreateFromPathW(path.wstring().c_str())) {
|
||||
ghc::filesystem::path selectPath = path / ".";
|
||||
std::error_code whatever;
|
||||
if (!ghc::filesystem::is_directory(path, whatever)) {
|
||||
selectPath = path;
|
||||
auto thread = std::thread([](auto const& path, bool& success) {
|
||||
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) == S_OK) {
|
||||
if (auto id = ILCreateFromPathW(path.wstring().c_str())) {
|
||||
ghc::filesystem::path selectPath = path / ".";
|
||||
std::error_code whatever;
|
||||
if (!ghc::filesystem::is_directory(path, whatever)) {
|
||||
selectPath = path;
|
||||
}
|
||||
auto selectEntry = ILCreateFromPathW(selectPath.wstring().c_str());
|
||||
if (SHOpenFolderAndSelectItems(id, 1, (PCUITEMID_CHILD_ARRAY)(&selectEntry), 0) == S_OK) {
|
||||
success = true;
|
||||
}
|
||||
ILFree(id);
|
||||
}
|
||||
auto selectEntry = ILCreateFromPathW(selectPath.wstring().c_str());
|
||||
if (SHOpenFolderAndSelectItems(id, 1, (PCUITEMID_CHILD_ARRAY)(&selectEntry), 0) == S_OK) {
|
||||
success = true;
|
||||
}
|
||||
ILFree(id);
|
||||
CoUninitialize();
|
||||
}
|
||||
CoUninitialize();
|
||||
}
|
||||
}, path, std::ref(success));
|
||||
thread.join();
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue