[+] Rewrite win32 file/directory opener

This commit is contained in:
Reece Wilson 2021-10-23 19:42:05 +01:00
parent 92f24e2a57
commit 4e804e59c7
6 changed files with 76 additions and 3 deletions

View File

@ -5,6 +5,7 @@
Date: 2021-5-13
Author: Reece
***/
#define _AURORA_RUNTIME_BUILD_API_INTERFACES
#include <AuroraCommon.hpp>
#include <AuroraRuntime.hpp>
#include "RuntimeInternal.hpp"
@ -51,6 +52,7 @@ static void Deinit()
Aurora::RNG::Release();
Aurora::Async::ShutdownAsync();
Aurora::Console::Exit();
Aurora::Processes::Deinit();
}
namespace Aurora

View File

@ -12,15 +12,69 @@
#include <shellapi.h>
#include <tlhelp32.h>
#include <Source/IO/FS/FS.hpp>
#include "Objbase.h"
#include "shellapi.h"
namespace Aurora::Processes
{
static AuList<AuString> gOpenItems;
static AuThreadPrimitives::ConditionMutexUnique_t gCondMutex;
static AuThreadPrimitives::ConditionVariableUnique_t gCondVariable;
static AuThreading::Threads::ThreadUnique_t gOpenerThread;
static void RunTasks()
{
AU_LOCK_GUARD(gCondMutex);
while (!gOpenerThread->Exiting())
{
for (const auto &open : gOpenItems)
{
ShellExecuteW(NULL, IO::FS::DirExists(open) ? L"explore" : NULL, Locale::ConvertFromUTF8(open).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
gOpenItems.clear();
gCondVariable->WaitForSignal();
}
}
void OpenerThread()
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
RunTasks();
CoUninitialize();
}
void InitWin32Opener()
{
gCondMutex = AuThreadPrimitives::ConditionMutexUnique();
gCondVariable = AuThreadPrimitives::ConditionVariableUnique(AuUnsafeRaiiToShared(gCondMutex));
gOpenerThread = AuThreading::Threads::ThreadUnique(AuThreading::Threads::ThreadInfo(
AuMakeShared<AuThreading::Threads::IThreadVectorsFunctional>(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(OpenerThread)),
AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}),
"COM ShellExecute Runner"
));
gOpenerThread->Run();
}
void DeinitWin32Opener()
{
gOpenerThread->SendExitSignal();
gCondVariable->Broadcast();
gOpenerThread.reset();
gCondVariable.reset();
gCondMutex.reset();
}
AUKN_SYM void OpenUri(const AuString &uri)
{
ShellExecuteW(NULL, NULL, Locale::ConvertFromUTF8(uri).c_str(), NULL, NULL, 0);
AU_LOCK_GUARD(gCondMutex);
gOpenItems.push_back(uri);
gCondVariable->Broadcast();
}
AUKN_SYM void OpenFile(const AuString &file)
{
OpenUri(file);
OpenUri(IO::FS::NormalizePathRet(file));
}
}

View File

@ -5,3 +5,10 @@
Date: 2021-6-12
Author: Reece
***/
#pragma once
namespace Aurora::Processes
{
void InitWin32Opener();
void DeinitWin32Opener();
}

View File

@ -8,6 +8,7 @@
#include <Source/RuntimeInternal.hpp>
#include "Processes.hpp"
#include "Process.Win32.hpp"
#include "Open.Win32.hpp"
namespace Aurora::Processes
{
@ -15,6 +16,14 @@ namespace Aurora::Processes
{
#if defined (AURORA_PLATFORM_WIN32)
InitWin32();
InitWin32Opener();
#endif
}
void Deinit()
{
#if defined (AURORA_PLATFORM_WIN32)
DeinitWin32Opener();
#endif
}
}

View File

@ -10,4 +10,5 @@
namespace Aurora::Processes
{
void Init();
void Deinit();
}