bool writePipe(const std::filesystem::path &pipe, const std::wstring &data, bool wait) { HANDLE hPipe = CreateFile(pipe.wstring().c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hPipe != INVALID_HANDLE_VALUE) { DWORD written; const DWORD toWrite = static_cast<DWORD>(data.size() * sizeof(wchar_t)); WriteFile(hPipe, data.c_str(), toWrite, &written, nullptr); const bool success = written == toWrite; tLog << (success ? L"Wrote: " : L"Failed to write: ") << data << " to " << pipe; WriteFile(hPipe, nullptr, sizeof(wchar_t), &written, nullptr); CloseHandle(hPipe); return success; } else if (wait) { // wait and retry Sleep(20000); return writePipe(pipe, data); } tLog << L"Failed to open pipe: " << pipe << L" data: " << data; return false; }
bool startProcess(const std::filesystem::path &app) { STARTUPINFO info = {}; info.cb = sizeof(info); PROCESS_INFORMATION pInfo = {}; const auto application = app.wstring(); if (!CreateProcess(const_cast<wchar_t *>(application.c_str()), const_cast<wchar_t *>(application.c_str()), nullptr, nullptr, false, DETACHED_PROCESS | INHERIT_PARENT_AFFINITY | CREATE_NO_WINDOW, nullptr, nullptr, &info, &pInfo)) { tLog << L"Failed to start: " << app; return false; } WaitForInputIdle(pInfo.hProcess, INFINITE); DWORD status; GetExitCodeProcess(pInfo.hProcess, &status); CloseHandle(pInfo.hProcess); CloseHandle(pInfo.hThread); tLog << L"Started: " << app << L" Status: " << (status == STILL_ACTIVE ? L"STILL_ACTIVE" : std::to_wstring(status)); return status == STILL_ACTIVE; }
void BitmapFont::LoadSkinFontImage(std::filesystem::path Location, Vec2 _CharSize, Vec2 _CellSize, Vec2 _RenderSize, char FontStart) { LoadFontImage(GameState::GetInstance().GetSkinFile(Utility::Narrow(Location.wstring())), _CharSize, _CellSize, _RenderSize, FontStart); }