AuroraRuntime/Source/Processes/Open.Win32.cpp
Reece Wilson 8844e8fe64 [+] AuCrypto::BCrypt
> GetForcedMinRounds
> GenSalt
> HashPW
> HashPWEx
> CheckPassword
> CheckPasswordEx
[*] Refactor AuCompression APIs
[*] Clean up AuTryConstructs
[+] Internal compression API for compression based interceptors
[+] Root-level input stream arg check for all compression apis (harden)
[*] Clean up AuCompression code
[+] Solar Designer / OpenWall blowfish crypt
[*] BlowCrypt: accept length input parameter
[*] Split locale into 2 source files
[-] Ugly comment from Open.Win32.cpp. TODO: Readd later. Might warn on empty string bc it makes sense given, "." and "/" normalizes to nothing, and memory pre-idc-if-drops are dropped siliently.
2022-09-15 20:48:50 +01:00

101 lines
2.8 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 (AuIsThreadRunning())
{
try
{
for (const auto &open : gOpenItems)
{
if (open.empty()) continue; // [*1]
ShellExecuteW(nullptr,
AuIOFS::DirExists(open) ? L"explore" : L"open",
Locale::ConvertFromUTF8(open).c_str(),
nullptr,
nullptr,
SW_SHOWNORMAL);
}
gOpenItems.clear();
gCondVariable->WaitForSignal();
}
catch (...)
{
Debug::PrintError();
AuLogWarn("An error occurred while dispatching a ShellExecute runner frame");
}
}
}
static void OpenerThread()
{
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
RunTasks();
CoUninitialize();
}
void InitWin32Opener()
{
gCondMutex = AuThreadPrimitives::ConditionMutexUnique();
SysAssert(gCondMutex);
gCondVariable = AuThreadPrimitives::ConditionVariableUnique(AuUnsafeRaiiToShared(gCondMutex));
SysAssert(gCondVariable);
gOpenerThread = AuThreads::ThreadUnique(AuThreads::ThreadInfo(
AuMakeShared<AuThreads::IThreadVectorsFunctional>(AuThreads::IThreadVectorsFunctional::OnEntry_t(std::bind(OpenerThread)),
AuThreads::IThreadVectorsFunctional::OnExit_t{}),
"COM ShellExecute Runner"
));
SysAssert(gOpenerThread);
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);
AuTryInsert(gOpenItems, uri);
gCondVariable->Broadcast();
}
AUKN_SYM void OpenFile(const AuString &file)
{
OpenUri(AuIOFS::NormalizePathRet(file));
}
}