diff --git a/include/Network/network.h b/include/Network/network.h index 936dd25..84ffcab 100644 --- a/include/Network/network.h +++ b/include/Network/network.h @@ -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; diff --git a/include/Startup.h b/include/Startup.h index d0ed404..1303e00 100644 --- a/include/Startup.h +++ b/include/Startup.h @@ -9,6 +9,7 @@ #include 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(); diff --git a/src/Logger.cpp b/src/Logger.cpp index 4a5cbbd..744e026 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -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(); } diff --git a/src/Network/Http.cpp b/src/Network/Http.cpp index 1b9cde6..42f6ad6 100644 --- a/src/Network/Http.cpp +++ b/src/Network/Http.cpp @@ -8,6 +8,7 @@ #include #include +#include #include 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< 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){ diff --git a/src/main.cpp b/src/main.cpp index e9ef33c..8caad53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 }