AuroraRuntime/Source/Processes/Open.Win32.cpp
Reece 99c5e1fa65 A pretty large patch not worth breaking up into separate commits
[*] Split up Aurora Async
[*] Split Async app into seperate ThreadPool concept
[*] Fix various OSThread bugs and tls transfer issues
[*] Set default affinity to 0xFFFFFFFF
[*] Update Build script
[+] Add AuTuplePopFront
[+] New Network Interface (unimplemented)
[*] Stub out the interfaces required for a better logger
[*] Fix Win32 ShellExecute bug; windows 11 struggles without explicit com init per the docs - now deferring to thread pool
[*] Update gitignore
[*] Follow XDG home standard
[*] Refactor some namespaces to use the shorthand aliases
[*] Various stability fixes
2021-11-05 17:34:23 +00:00

80 lines
2.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Open.Win32.cpp
Date: 2021-6-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Processes.hpp"
#include "Open.Win32.hpp"
#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 AuThreads::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();
}
}
static void OpenerThread()
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
RunTasks();
CoUninitialize();
}
void InitWin32Opener()
{
gCondMutex = AuThreadPrimitives::ConditionMutexUnique();
gCondVariable = AuThreadPrimitives::ConditionVariableUnique(AuUnsafeRaiiToShared(gCondMutex));
gOpenerThread = AuThreads::ThreadUnique(AuThreads::ThreadInfo(
AuMakeShared<AuThreads::IThreadVectorsFunctional>(AuThreads::IThreadVectorsFunctional::OnEntry_t(std::bind(OpenerThread)),
AuThreads::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)
{
AU_LOCK_GUARD(gCondMutex);
gOpenItems.push_back(uri);
gCondVariable->Broadcast();
}
AUKN_SYM void OpenFile(const AuString &file)
{
OpenUri(IO::FS::NormalizePathRet(file));
}
}