2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-19 03:25:29 +00:00
GlosSI-fork/GlosSITarget/AppLauncher.h
2021-10-23 13:33:01 +02:00

54 lines
1.5 KiB
C++

/*
Copyright 2021 Peter Repukat - FlatspotSoftware
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>
#include <SFML/System/Clock.hpp>
class AppLauncher {
public:
explicit AppLauncher(std::function<void()> shutdown = [](){});
void launchApp(const std::wstring& path, const std::wstring& args = L"");
void update();
void close();
private:
std::function<void()> shutdown_;
sf::Clock process_check_clock_;
#ifdef _WIN32
static bool IsProcessRunning(DWORD pid);
// 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"");
void launchUWPApp(LPCWSTR package_full_name);
STARTUPINFO info{sizeof(info)};
PROCESS_INFORMATION process_info{};
DWORD uwp_pid_ = 0;
#endif
};