mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
reformat
This commit is contained in:
+28
-47
@@ -6,83 +6,83 @@
|
||||
/// Created by Anonymous275 on 7/19/2020
|
||||
///
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
#include "vdf_parser.hpp"
|
||||
#include <pwd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Startup.h"
|
||||
#include <Security/Init.h>
|
||||
#include <filesystem>
|
||||
#include "Startup.h"
|
||||
#include "Logger.h"
|
||||
#include <thread>
|
||||
|
||||
unsigned long GamePID = 0;
|
||||
#if defined(_WIN32)
|
||||
std::string QueryKey(HKEY hKey,int ID);
|
||||
std::string GetGamePath(){
|
||||
std::string QueryKey(HKEY hKey, int ID);
|
||||
std::string GetGamePath() {
|
||||
static std::string Path;
|
||||
if(!Path.empty())return Path;
|
||||
if (!Path.empty())
|
||||
return Path;
|
||||
|
||||
HKEY hKey;
|
||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (openRes != ERROR_SUCCESS){
|
||||
if (openRes != ERROR_SUCCESS) {
|
||||
fatal("Please launch the game at least once!");
|
||||
}
|
||||
Path = QueryKey(hKey,4);
|
||||
Path = QueryKey(hKey, 4);
|
||||
|
||||
if(Path.empty()){
|
||||
if (Path.empty()) {
|
||||
sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)";
|
||||
openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (openRes != ERROR_SUCCESS){
|
||||
fatal("Cannot get Local Appdata directory!");
|
||||
if (openRes != ERROR_SUCCESS) {
|
||||
fatal("Cannot get Local Appdata directory!");
|
||||
}
|
||||
Path = QueryKey(hKey,5);
|
||||
Path = QueryKey(hKey, 5);
|
||||
Path += "\\BeamNG.drive\\";
|
||||
}
|
||||
std::string Ver = CheckVer(GetGameDir());
|
||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
||||
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||
Path += Ver + "\\";
|
||||
return Path;
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
std::string GetGamePath(){
|
||||
std::string GetGamePath() {
|
||||
// Right now only steam is supported
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
std::string homeDir = pw->pw_dir;
|
||||
|
||||
|
||||
std::string Path = homeDir + "/.local/share/BeamNG.drive/";
|
||||
std::string Ver = CheckVer(GetGameDir());
|
||||
Ver = Ver.substr(0,Ver.find('.',Ver.find('.')+1));
|
||||
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||
Path += Ver + "/";
|
||||
return Path;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
void StartGame(std::string Dir){
|
||||
void StartGame(std::string Dir) {
|
||||
BOOL bSuccess = FALSE;
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si = {0};
|
||||
STARTUPINFO si = { 0 };
|
||||
si.cb = sizeof(si);
|
||||
std::string BaseDir = Dir; //+"\\Bin64";
|
||||
//Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||
// Dir += R"(\Bin64\BeamNG.drive.x64.exe)";
|
||||
Dir += "\\BeamNG.drive.exe";
|
||||
bSuccess = CreateProcessA(Dir.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, BaseDir.c_str(), &si, &pi);
|
||||
if (bSuccess){
|
||||
if (bSuccess) {
|
||||
info("Game Launched!");
|
||||
GamePID = pi.dwProcessId;
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
error("Game Closed! launcher closing soon");
|
||||
}else{
|
||||
} else {
|
||||
error("Failed to Launch the game! launcher closing soon");
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
@@ -92,26 +92,7 @@ void StartGame(std::string Dir){
|
||||
void StartGame(std::string Dir) {
|
||||
int status;
|
||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
||||
char *argv[] = {filename.data(), NULL};
|
||||
pid_t pid;
|
||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
||||
|
||||
if (result != 0) {
|
||||
error("Failed to Launch the game! launcher closing soon");
|
||||
return;
|
||||
} else {
|
||||
waitpid(pid, &status, 0);
|
||||
error("Game Closed! launcher closing soon");
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(2);
|
||||
}
|
||||
#endif
|
||||
void StartGame(std::string Dir) {
|
||||
int status;
|
||||
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
|
||||
char *argv[] = {filename.data(), NULL};
|
||||
char* argv[] = { filename.data(), NULL };
|
||||
pid_t pid;
|
||||
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
|
||||
|
||||
@@ -128,8 +109,8 @@ void StartGame(std::string Dir) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void InitGame(const std::string& Dir){
|
||||
if(!Dev){
|
||||
void InitGame(const std::string& Dir) {
|
||||
if (!Dev) {
|
||||
std::thread Game(StartGame, Dir);
|
||||
Game.detach();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user