mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-16 08:16:20 +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 uint64_t UDPSock;
|
||||
extern uint64_t TCPSock;
|
||||
extern std::string Role;
|
||||
extern bool TCPTerminate;
|
||||
extern std::string LastIP;
|
||||
extern std::string MStatus;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
void InitLauncher(int argc, char* argv[]);
|
||||
void CheckDir(int argc,char* args[]);
|
||||
std::string GetEP(char*P = nullptr);
|
||||
std::string GetGamePath();
|
||||
std::string GetVer();
|
||||
std::string GetEN();
|
||||
|
@ -44,14 +44,14 @@ std::string getDate() {
|
||||
}
|
||||
void InitLog(){
|
||||
std::ofstream LFS;
|
||||
LFS.open ("Launcher.log");
|
||||
LFS.open(GetEP() + "Launcher.log");
|
||||
if(!LFS.is_open()){
|
||||
error("logger file init failed!");
|
||||
}else LFS.close();
|
||||
}
|
||||
void addToLog(const std::string& Line){
|
||||
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.close();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
#include <Logger.h>
|
||||
#include <mutex>
|
||||
|
||||
class CurlManager{
|
||||
@ -53,19 +54,23 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
|
||||
|
||||
int nb_bar;
|
||||
double last_progress, progress_bar_adv;
|
||||
bool Downloaded;
|
||||
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;
|
||||
progress_bar_adv = round(d/t*nb_bar);
|
||||
std::cout<<"\r";
|
||||
std::cout<< "Progress : [ ";
|
||||
if(t!=0)std::cout<<round(d/t*100);else std::cout<<0;
|
||||
std::cout<<round(d/t*100);
|
||||
std::cout << "% ] [";
|
||||
int i;
|
||||
for(i = 0; i <= progress_bar_adv; i++)std::cout<<"#";
|
||||
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
|
||||
std::cout<<"]";
|
||||
last_progress = round(d/t*100);
|
||||
if(round(d/t*100) == 100){
|
||||
Downloaded = true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -86,6 +91,7 @@ int Download(const std::string& URL,const std::string& Path,bool close){
|
||||
CURL *curl = M.Get();
|
||||
CURLcode res;
|
||||
struct File file = {Path.c_str(),nullptr};
|
||||
Downloaded = false;
|
||||
if(curl){
|
||||
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
|
||||
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_USE_SSL, CURLUSESSL_ALL);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK)return res;
|
||||
if(res != CURLE_OK){
|
||||
return res;
|
||||
}
|
||||
}
|
||||
if(file.stream)fclose(file.stream);
|
||||
if(!Downloaded){
|
||||
remove(Path.c_str());
|
||||
fatal("Failed to download please try again later!");
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
using namespace std::filesystem;
|
||||
std::string PublicKey;
|
||||
extern bool LoginAuth;
|
||||
std::string Role;
|
||||
|
||||
void UpdateKey(const char* newKey){
|
||||
if(newKey){
|
||||
@ -53,7 +54,7 @@ std::string Login(const std::string& fields){
|
||||
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!");
|
||||
}
|
||||
if(!d["success"].IsNull() && d["success"].GetBool()){
|
||||
@ -88,13 +89,14 @@ void CheckLocalKey(){
|
||||
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"pk":")"+Buffer+"\"}");
|
||||
json::Document d;
|
||||
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!");
|
||||
}
|
||||
if(d["success"].GetBool()){
|
||||
LoginAuth = true;
|
||||
UpdateKey(d["private_key"].GetString());
|
||||
PublicKey = d["public_key"].GetString();
|
||||
Role = d["role"].GetString();
|
||||
}else{
|
||||
info("Auto-Authentication unsuccessful please re-login!");
|
||||
UpdateKey(nullptr);
|
||||
|
@ -18,14 +18,22 @@
|
||||
extern int TraceBack;
|
||||
bool Dev = false;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::string GetEN(){
|
||||
return "BeamMP-Launcher.exe";
|
||||
}
|
||||
std::string GetVer(){
|
||||
return "1.80";
|
||||
return "1.81";
|
||||
}
|
||||
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[]){
|
||||
std::string Arg;
|
||||
@ -34,7 +42,7 @@ void ReLaunch(int argc,char*args[]){
|
||||
Arg += args[c-1];
|
||||
}
|
||||
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);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
exit(1);
|
||||
@ -45,7 +53,7 @@ void URelaunch(int argc,char* args[]){
|
||||
Arg += " ";
|
||||
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);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(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";
|
||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
||||
|
||||
struct stat buffer{};
|
||||
std::string Back = "BeamMP-Launcher.back";
|
||||
if(stat(Back.c_str(), &buffer) == 0)remove(Back.c_str());
|
||||
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
|
||||
|
||||
if(fs::exists(Back))remove(Back.c_str());
|
||||
|
||||
if(HTTP > CV){
|
||||
system("cls");
|
||||
info("Update found!");
|
||||
info("Updating...");
|
||||
if(std::rename(GetEN().c_str(), Back.c_str()))error("failed creating a backup!");
|
||||
int i = Download(link, GetEN(),true);
|
||||
if(std::rename(EP.c_str(), Back.c_str()))error("failed creating a backup!");
|
||||
int i = Download(link, EP,true);
|
||||
if(i != -1){
|
||||
error("Launcher Update failed! trying again... code : " + std::to_string(i));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
int i2 = Download(link, GetEN(),true);
|
||||
int i2 = Download(link, EP,true);
|
||||
if(i2 != -1){
|
||||
error("Launcher Update failed! code : " + std::to_string(i2));
|
||||
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){
|
||||
const std::string CurrVer("0.21.2.0");
|
||||
const std::string CurrVer("0.21.3.0");
|
||||
std::string GameVer = CheckVer(GamePath);
|
||||
info("Game Version : " + GameVer);
|
||||
if(GameVer < CurrVer){
|
||||
|
@ -25,6 +25,7 @@ int main(int argc, char* argv[]) {
|
||||
std::thread th(flush);
|
||||
th.detach();
|
||||
#endif
|
||||
GetEP(argv[0]);
|
||||
InitLauncher(argc,argv);
|
||||
//CheckDir(argc,argv);
|
||||
try {
|
||||
@ -35,4 +36,8 @@ int main(int argc, char* argv[]) {
|
||||
PreGame(GetGameDir());
|
||||
InitGame(GetGameDir());
|
||||
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