mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 00:35:55 +00:00
Partial fix for directory startup location
This commit is contained in:
parent
263b6c9c0d
commit
ba5ba4b8b4
@ -18,6 +18,7 @@ extern bool Terminate;
|
|||||||
extern int DEFAULT_PORT;
|
extern int DEFAULT_PORT;
|
||||||
extern uint64_t UDPSock;
|
extern uint64_t UDPSock;
|
||||||
extern uint64_t TCPSock;
|
extern uint64_t TCPSock;
|
||||||
|
extern std::string Role;
|
||||||
extern bool TCPTerminate;
|
extern bool TCPTerminate;
|
||||||
extern std::string LastIP;
|
extern std::string LastIP;
|
||||||
extern std::string MStatus;
|
extern std::string MStatus;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
void InitLauncher(int argc, char* argv[]);
|
void InitLauncher(int argc, char* argv[]);
|
||||||
void CheckDir(int argc,char* args[]);
|
void CheckDir(int argc,char* args[]);
|
||||||
|
std::string GetEP(char*P = nullptr);
|
||||||
std::string GetGamePath();
|
std::string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetEN();
|
std::string GetEN();
|
||||||
|
@ -44,14 +44,14 @@ std::string getDate() {
|
|||||||
}
|
}
|
||||||
void InitLog(){
|
void InitLog(){
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open ("Launcher.log");
|
LFS.open(GetEP() + "Launcher.log");
|
||||||
if(!LFS.is_open()){
|
if(!LFS.is_open()){
|
||||||
error("logger file init failed!");
|
error("logger file init failed!");
|
||||||
}else LFS.close();
|
}else LFS.close();
|
||||||
}
|
}
|
||||||
void addToLog(const std::string& Line){
|
void addToLog(const std::string& Line){
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open("Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + "Launcher.log", std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <Logger.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
class CurlManager{
|
class CurlManager{
|
||||||
@ -53,19 +54,23 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
|
|||||||
|
|
||||||
int nb_bar;
|
int nb_bar;
|
||||||
double last_progress, progress_bar_adv;
|
double last_progress, progress_bar_adv;
|
||||||
|
bool Downloaded;
|
||||||
int progress_bar (void *bar, double t, double d){
|
int progress_bar (void *bar, double t, double d){
|
||||||
if(last_progress != round(d/t*100)){
|
if(t > 0 && last_progress != round(d/t*100)){
|
||||||
nb_bar = 25;
|
nb_bar = 25;
|
||||||
progress_bar_adv = round(d/t*nb_bar);
|
progress_bar_adv = round(d/t*nb_bar);
|
||||||
std::cout<<"\r";
|
std::cout<<"\r";
|
||||||
std::cout<< "Progress : [ ";
|
std::cout<< "Progress : [ ";
|
||||||
if(t!=0)std::cout<<round(d/t*100);else std::cout<<0;
|
std::cout<<round(d/t*100);
|
||||||
std::cout << "% ] [";
|
std::cout << "% ] [";
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i <= progress_bar_adv; i++)std::cout<<"#";
|
for(i = 0; i <= progress_bar_adv; i++)std::cout<<"#";
|
||||||
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
|
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
|
||||||
std::cout<<"]";
|
std::cout<<"]";
|
||||||
last_progress = round(d/t*100);
|
last_progress = round(d/t*100);
|
||||||
|
if(round(d/t*100) == 100){
|
||||||
|
Downloaded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -86,6 +91,7 @@ int Download(const std::string& URL,const std::string& Path,bool close){
|
|||||||
CURL *curl = M.Get();
|
CURL *curl = M.Get();
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct File file = {Path.c_str(),nullptr};
|
struct File file = {Path.c_str(),nullptr};
|
||||||
|
Downloaded = false;
|
||||||
if(curl){
|
if(curl){
|
||||||
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||||
@ -96,9 +102,15 @@ int Download(const std::string& URL,const std::string& Path,bool close){
|
|||||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);
|
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);
|
||||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
if(res != CURLE_OK)return res;
|
if(res != CURLE_OK){
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(file.stream)fclose(file.stream);
|
if(file.stream)fclose(file.stream);
|
||||||
|
if(!Downloaded){
|
||||||
|
remove(Path.c_str());
|
||||||
|
fatal("Failed to download please try again later!");
|
||||||
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
std::string PublicKey;
|
std::string PublicKey;
|
||||||
extern bool LoginAuth;
|
extern bool LoginAuth;
|
||||||
|
std::string Role;
|
||||||
|
|
||||||
void UpdateKey(const char* newKey){
|
void UpdateKey(const char* newKey){
|
||||||
if(newKey){
|
if(newKey){
|
||||||
@ -53,7 +54,7 @@ std::string Login(const std::string& fields){
|
|||||||
return GetFail("Failed to communicate with the auth system!");
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Buffer.find('{') == -1 || d.HasParseError()) {
|
if (Buffer.at(0) != '{' || d.HasParseError()) {
|
||||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
}
|
}
|
||||||
if(!d["success"].IsNull() && d["success"].GetBool()){
|
if(!d["success"].IsNull() && d["success"].GetBool()){
|
||||||
@ -88,13 +89,14 @@ void CheckLocalKey(){
|
|||||||
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"pk":")"+Buffer+"\"}");
|
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"pk":")"+Buffer+"\"}");
|
||||||
json::Document d;
|
json::Document d;
|
||||||
d.Parse(Buffer.c_str());
|
d.Parse(Buffer.c_str());
|
||||||
if (Buffer == "-1" || Buffer.find('{') == -1 || d.HasParseError()) {
|
if (Buffer == "-1" || Buffer.at(0) != '{' || d.HasParseError()) {
|
||||||
fatal("Invalid answer from authentication servers, please try again later!");
|
fatal("Invalid answer from authentication servers, please try again later!");
|
||||||
}
|
}
|
||||||
if(d["success"].GetBool()){
|
if(d["success"].GetBool()){
|
||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
UpdateKey(d["private_key"].GetString());
|
UpdateKey(d["private_key"].GetString());
|
||||||
PublicKey = d["public_key"].GetString();
|
PublicKey = d["public_key"].GetString();
|
||||||
|
Role = d["role"].GetString();
|
||||||
}else{
|
}else{
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
|
@ -18,14 +18,22 @@
|
|||||||
extern int TraceBack;
|
extern int TraceBack;
|
||||||
bool Dev = false;
|
bool Dev = false;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::string GetEN(){
|
std::string GetEN(){
|
||||||
return "BeamMP-Launcher.exe";
|
return "BeamMP-Launcher.exe";
|
||||||
}
|
}
|
||||||
std::string GetVer(){
|
std::string GetVer(){
|
||||||
return "1.80";
|
return "1.81";
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch(){
|
||||||
return ".94";
|
return ".0";
|
||||||
|
}
|
||||||
|
std::string GetEP(char*P){
|
||||||
|
static std::string Ret = [&](){
|
||||||
|
std::string path(P);
|
||||||
|
return path.substr(0, path.find_last_of("\\/") + 1);
|
||||||
|
} ();
|
||||||
|
return Ret;
|
||||||
}
|
}
|
||||||
void ReLaunch(int argc,char*args[]){
|
void ReLaunch(int argc,char*args[]){
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
@ -34,7 +42,7 @@ void ReLaunch(int argc,char*args[]){
|
|||||||
Arg += args[c-1];
|
Arg += args[c-1];
|
||||||
}
|
}
|
||||||
system("cls");
|
system("cls");
|
||||||
ShellExecute(nullptr,"runas",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
ShellExecute(nullptr,"runas",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
ShowWindow(GetConsoleWindow(),0);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -45,7 +53,7 @@ void URelaunch(int argc,char* args[]){
|
|||||||
Arg += " ";
|
Arg += " ";
|
||||||
Arg += args[c-1];
|
Arg += args[c-1];
|
||||||
}
|
}
|
||||||
ShellExecute(nullptr,"open",GetEN().c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
ShellExecute(nullptr,"open",(GetEP() + GetEN()).c_str(),Arg.c_str(),nullptr,SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
ShowWindow(GetConsoleWindow(),0);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -96,19 +104,20 @@ void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
|||||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
||||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
}else link = "https://beammp.com/builds/launcher?download=true";
|
||||||
|
|
||||||
struct stat buffer{};
|
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||||
std::string Back = "BeamMP-Launcher.back";
|
|
||||||
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
|
if(fs::exists(Back))remove(Back.c_str());
|
||||||
|
|
||||||
if(HTTP > CV){
|
if(HTTP > CV){
|
||||||
system("cls");
|
system("cls");
|
||||||
info("Update found!");
|
info("Update found!");
|
||||||
info("Updating...");
|
info("Updating...");
|
||||||
if(std::rename(GetEN().c_str(), Back.c_str()))error("failed creating a backup!");
|
if(std::rename(EP.c_str(), Back.c_str()))error("failed creating a backup!");
|
||||||
int i = Download(link, GetEN(),true);
|
int i = Download(link, EP,true);
|
||||||
if(i != -1){
|
if(i != -1){
|
||||||
error("Launcher Update failed! trying again... code : " + std::to_string(i));
|
error("Launcher Update failed! trying again... code : " + std::to_string(i));
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
int i2 = Download(link, GetEN(),true);
|
int i2 = Download(link, EP,true);
|
||||||
if(i2 != -1){
|
if(i2 != -1){
|
||||||
error("Launcher Update failed! code : " + std::to_string(i2));
|
error("Launcher Update failed! code : " + std::to_string(i2));
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
@ -207,7 +216,7 @@ void CheckMP(const std::string& Path) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
void PreGame(const std::string& GamePath){
|
void PreGame(const std::string& GamePath){
|
||||||
const std::string CurrVer("0.21.2.0");
|
const std::string CurrVer("0.21.3.0");
|
||||||
std::string GameVer = CheckVer(GamePath);
|
std::string GameVer = CheckVer(GamePath);
|
||||||
info("Game Version : " + GameVer);
|
info("Game Version : " + GameVer);
|
||||||
if(GameVer < CurrVer){
|
if(GameVer < CurrVer){
|
||||||
|
@ -25,6 +25,7 @@ int main(int argc, char* argv[]) {
|
|||||||
std::thread th(flush);
|
std::thread th(flush);
|
||||||
th.detach();
|
th.detach();
|
||||||
#endif
|
#endif
|
||||||
|
GetEP(argv[0]);
|
||||||
InitLauncher(argc,argv);
|
InitLauncher(argc,argv);
|
||||||
//CheckDir(argc,argv);
|
//CheckDir(argc,argv);
|
||||||
try {
|
try {
|
||||||
@ -35,4 +36,8 @@ int main(int argc, char* argv[]) {
|
|||||||
PreGame(GetGameDir());
|
PreGame(GetGameDir());
|
||||||
InitGame(GetGameDir());
|
InitGame(GetGameDir());
|
||||||
CoreNetwork();
|
CoreNetwork();
|
||||||
|
|
||||||
|
|
||||||
|
///TODO: make sure to use argv[0] for everything that should be in the same dir (mod down ect...)
|
||||||
|
///move to master create branch then make the new config in json
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user