add better error handling to main()

This commit is contained in:
Lion Kortlepel 2024-09-23 21:58:27 +02:00
parent 4bedfc8e96
commit 97f58dd413
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
3 changed files with 13 additions and 39 deletions

View File

@ -75,7 +75,7 @@ void fatal(const std::string& toPrint) {
std::cout << Print;
addToLog(Print);
std::this_thread::sleep_for(std::chrono::seconds(5));
_Exit(-1);
std::exit(1);
}
void except(const std::string& toPrint) {
std::string Print = getDate() + "[EXCEP] " + toPrint + "\n";

View File

@ -290,36 +290,6 @@ bool IDCheck(std::string Man, std::string steam) {
return a;
}
void LegitimacyCheck() {
// std::string K1 = R"(Software\Valve\Steam)";
// std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
/*LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1);
if(fs::exists(Result)){
if(!Find("284160.json",Result))Exit(2);
if(FindHack(Result))SteamExit(1);
}else Exit(3);
T = Result;
Result.clear();
TraceBack++;
}else Exit(4);
K1.clear();
RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 2);
if(Result.empty())lowExit(1);
TraceBack++;
}else lowExit(2);
K2.clear();
RegCloseKey(hKey);*/
#if defined(_WIN32)
std::string Result;
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
@ -329,15 +299,12 @@ RegCloseKey(hKey);*/
Result = QueryKey(hKey, 3);
if (Result.empty())
lowExit(3);
// if(IDCheck(Result,T))lowExit(5);
GameDir = Result;
// TraceBack++;
} else
lowExit(4);
K3.clear();
Result.clear();
RegCloseKey(hKey);
// if(TraceBack < 3)exit(-1);
#elif defined(__linux__)
struct passwd* pw = getpwuid(getuid());
std::string homeDir = pw->pw_dir;

View File

@ -20,7 +20,7 @@
}
}
int main(int argc, char* argv[]) {
int main(int argc, char** argv) try {
#ifdef DEBUG
std::thread th(flush);
th.detach();
@ -40,13 +40,20 @@ int main(int argc, char* argv[]) {
try {
LegitimacyCheck();
} catch (std::exception& e) {
fatal("Main 1 : " + std::string(e.what()));
error("Failure in LegitimacyCheck: " + std::string(e.what()));
throw;
}
HTTP::StartProxy();
try {
HTTP::StartProxy();
} catch (const std::exception& e) {
error(std::string("Failed to start HTTP proxy: Some in-game functions may not work. Error: ") + e.what());
}
PreGame(GetGameDir());
InitGame(GetGameDir());
CoreNetwork();
/// TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
} catch (const std::exception& e) {
error(std::string("Exception in main(): ") + e.what());
info("Closing in 5 seconds");
std::this_thread::sleep_for(std::chrono::seconds(5));
}