2021-10-23 11:33:01 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-23 11:33:01 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define NOMINMAX
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
2021-11-12 13:49:25 +00:00
|
|
|
#include <unordered_set>
|
2021-10-23 11:33:01 +00:00
|
|
|
#include <SFML/System/Clock.hpp>
|
|
|
|
|
|
|
|
class AppLauncher {
|
|
|
|
public:
|
2022-03-14 19:13:43 +00:00
|
|
|
explicit AppLauncher(
|
|
|
|
std::vector<HWND>& process_hwnds,
|
|
|
|
std::function<void()> shutdown = []() {});
|
2021-10-23 11:33:01 +00:00
|
|
|
|
|
|
|
void launchApp(const std::wstring& path, const std::wstring& args = L"");
|
|
|
|
void update();
|
|
|
|
void close();
|
|
|
|
|
2022-03-14 19:13:43 +00:00
|
|
|
private:
|
2021-10-23 11:33:01 +00:00
|
|
|
std::function<void()> shutdown_;
|
|
|
|
sf::Clock process_check_clock_;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
static bool IsProcessRunning(DWORD pid);
|
2021-11-12 13:49:25 +00:00
|
|
|
void getChildPids(DWORD parent_pid);
|
2022-03-14 19:13:43 +00:00
|
|
|
void getProcessHwnds();
|
|
|
|
std::vector<HWND>& process_hwnds_;
|
|
|
|
|
|
|
|
std::wstring launched_uwp_path_;
|
2021-10-23 11:33:01 +00:00
|
|
|
|
|
|
|
// Valve also hooks "CreateProcess"
|
|
|
|
// Unpatch that so that launched programs don't also get hooked...
|
|
|
|
static inline const std::string CREATE_PROC_ORIG_BYTES = "\x4C\x8B\xDC\x48\x83";
|
|
|
|
static void UnPatchValveHooks();
|
|
|
|
void launchWin32App(const std::wstring& path, const std::wstring& args = L"");
|
2021-10-28 16:14:13 +00:00
|
|
|
void launchUWPApp(LPCWSTR package_full_name, const std::wstring& args = L"");
|
2022-04-09 13:30:14 +00:00
|
|
|
void launchURL(const std::wstring& url, const std::wstring& args = L"", const std::wstring& verb = L"open");
|
2021-10-23 11:33:01 +00:00
|
|
|
STARTUPINFO info{sizeof(info)};
|
|
|
|
PROCESS_INFORMATION process_info{};
|
2022-04-09 12:34:24 +00:00
|
|
|
std::vector<DWORD> pids_;
|
2021-10-23 11:33:01 +00:00
|
|
|
#endif
|
|
|
|
};
|