mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 07:56:26 +00:00
Minor tweaking
This commit is contained in:
parent
3f6cdb0dc2
commit
050db169f5
@ -19,8 +19,10 @@ extern int ping;
|
|||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
extern bool TCPTerminate;
|
extern bool TCPTerminate;
|
||||||
extern bool MPDEV;
|
extern bool MPDEV;
|
||||||
|
extern std::string ListOfMods;
|
||||||
|
bool Confirm = false;
|
||||||
void StartSync(const std::string &Data){
|
void StartSync(const std::string &Data){
|
||||||
|
Terminate = false;
|
||||||
std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||||
//std::thread t1(ProxyThread,"127.0.0.1",30814);
|
//std::thread t1(ProxyThread,"127.0.0.1",30814);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
@ -35,8 +37,14 @@ std::string Parse(const std::string& Data){
|
|||||||
case 'B':
|
case 'B':
|
||||||
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
||||||
case 'C':
|
case 'C':
|
||||||
|
ListOfMods.clear();
|
||||||
StartSync(Data);
|
StartSync(Data);
|
||||||
return "";
|
std::cout << "Called Connect" << std::endl;
|
||||||
|
while(ListOfMods.empty() && !Terminate){
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
if(ListOfMods == "-")return "";
|
||||||
|
else return "L"+ListOfMods;
|
||||||
case 'U':
|
case 'U':
|
||||||
if(SubCode == 'l')return UlStatus;
|
if(SubCode == 'l')return UlStatus;
|
||||||
if(SubCode == 'p')return "Up" + std::to_string(ping);
|
if(SubCode == 'p')return "Up" + std::to_string(ping);
|
||||||
@ -50,6 +58,9 @@ std::string Parse(const std::string& Data){
|
|||||||
}
|
}
|
||||||
if(SubCode == 'G')exit(2);
|
if(SubCode == 'G')exit(2);
|
||||||
return "";
|
return "";
|
||||||
|
case 'R': //will send mod name useful??
|
||||||
|
Confirm = true;
|
||||||
|
return "";
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,6 @@ void Reset() {
|
|||||||
UDPSock = -1;
|
UDPSock = -1;
|
||||||
TCPSock = -1;
|
TCPSock = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Compress(const std::string&Data);
|
std::string Compress(const std::string&Data);
|
||||||
std::string Decompress(const std::string&Data);
|
std::string Decompress(const std::string&Data);
|
||||||
void TCPGameServer(const std::string& IP, int Port){
|
void TCPGameServer(const std::string& IP, int Port){
|
||||||
|
@ -15,8 +15,9 @@ void Exit(const std::string& Msg);
|
|||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
extern std::string UlStatus;
|
extern std::string UlStatus;
|
||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
|
extern bool Confirm;
|
||||||
extern bool MPDEV;
|
extern bool MPDEV;
|
||||||
|
std::string ListOfMods;
|
||||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
||||||
std::vector<std::string> Val;
|
std::vector<std::string> Val;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -47,7 +48,7 @@ void STCPSend(SOCKET socket,const std::string&Data){
|
|||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
}
|
}
|
||||||
std::pair<char*,int> STCPRecv(SOCKET socket){
|
std::pair<char*,int> STCPRecv(SOCKET socket){
|
||||||
char buf[64000];
|
char buf[64000];
|
||||||
@ -76,6 +77,13 @@ void CheckForDir(){
|
|||||||
_wmkdir(L"Resources");
|
_wmkdir(L"Resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void WaitForConfirm(){
|
||||||
|
while(!Terminate && !Confirm){
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
Confirm = false;
|
||||||
|
}
|
||||||
|
|
||||||
void SyncResources(SOCKET Sock){
|
void SyncResources(SOCKET Sock){
|
||||||
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
|
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
@ -83,28 +91,50 @@ void SyncResources(SOCKET Sock){
|
|||||||
STCPSend(Sock,"SR");
|
STCPSend(Sock,"SR");
|
||||||
char* Res = STCPRecv(Sock).first;
|
char* Res = STCPRecv(Sock).first;
|
||||||
if(strlen(Res) == 0){
|
if(strlen(Res) == 0){
|
||||||
|
std::cout << "Didn't Receive any mod from server skipping..." << std::endl;
|
||||||
STCPSend(Sock,"Done");
|
STCPSend(Sock,"Done");
|
||||||
|
UlStatus = "UlDone";
|
||||||
|
ListOfMods = "-";
|
||||||
|
std::cout << "Done!" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<std::string> list = Split(std::string(Res), ";");
|
std::vector<std::string> list = Split(std::string(Res), ";");
|
||||||
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
|
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
|
||||||
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
|
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
|
||||||
list.clear();
|
list.clear();
|
||||||
|
int Amount = 0,Pos = 0;
|
||||||
struct stat info{};
|
struct stat info{};
|
||||||
|
std::string a,t;
|
||||||
|
for(const std::string&N : FNames){
|
||||||
|
if(!N.empty()){
|
||||||
|
t += N.substr(N.find_last_of('/')+1) + ";";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(t.empty())ListOfMods = "-";
|
||||||
|
else ListOfMods = t;
|
||||||
|
t.clear();
|
||||||
|
|
||||||
|
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
||||||
|
int pos = FN->find_last_of('/');
|
||||||
|
if (pos == std::string::npos)continue;
|
||||||
|
Amount++;
|
||||||
|
}
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
||||||
std::string a;
|
|
||||||
int pos = FN->find_last_of('/');
|
int pos = FN->find_last_of('/');
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
a = "Resources" + FN->substr(pos);
|
a = "Resources" + FN->substr(pos);
|
||||||
} else continue;
|
} else continue;
|
||||||
char *Data;
|
char *Data;
|
||||||
|
Pos++;
|
||||||
if (stat(a.c_str(), &info) == 0) {
|
if (stat(a.c_str(), &info) == 0) {
|
||||||
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
|
||||||
if (fs::file_size(a) == std::stoi(*FS)) {
|
if (fs::file_size(a) == std::stoi(*FS)){
|
||||||
|
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||||
|
"): " + a.substr(a.find_last_of('/'));
|
||||||
|
fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
|
||||||
|
WaitForConfirm();
|
||||||
continue;
|
continue;
|
||||||
} else remove(a.c_str());
|
}else remove(a.c_str());
|
||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
@ -119,15 +149,21 @@ void SyncResources(SOCKET Sock){
|
|||||||
LFS.write(Data, Pair.second);
|
LFS.write(Data, Pair.second);
|
||||||
float per = LFS.tellp() / std::stof(*FS) * 100;
|
float per = LFS.tellp() / std::stof(*FS) * 100;
|
||||||
std::string Percent = std::to_string(truncf(per * 10) / 10);
|
std::string Percent = std::to_string(truncf(per * 10) / 10);
|
||||||
UlStatus = "UlDownloading Resource: " + a.substr(a.find_last_of('/')) + " (" +
|
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||||
|
"): " + a.substr(a.find_last_of('/')) + " (" +
|
||||||
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
||||||
} while (LFS.tellp() != std::stoi(*FS));
|
} while (LFS.tellp() != std::stoi(*FS));
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||||
if(!FNames.empty()){
|
"): " + a.substr(a.find_last_of('/'));
|
||||||
STCPSend(Sock,"Done");
|
fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
|
||||||
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
FNames.clear();
|
FNames.clear();
|
||||||
FSizes.clear();
|
FSizes.clear();
|
||||||
|
a.clear();
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
UlStatus = "UlDone";
|
||||||
|
STCPSend(Sock,"Done");
|
||||||
std::cout << "Done!" << std::endl;
|
std::cout << "Done!" << std::endl;
|
||||||
}
|
}
|
26
src/main.cpp
26
src/main.cpp
@ -42,27 +42,18 @@ void Exit(const std::string& Msg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string CheckDir(char*dir){
|
std::string CheckDir(char*dir){
|
||||||
char*temp;size_t len;
|
|
||||||
struct stat info{};
|
struct stat info{};
|
||||||
_dupenv_s(&temp, &len,"APPDATA");
|
std::string DN = "BeamMP-Launcher.exe",CDir = dir,FN = CDir.substr(CDir.find_last_of('\\')+1);
|
||||||
std::string DN = "BeamMP-Launcher.exe",CDir = dir, AD = temp,FN = CDir.substr(CDir.find_last_of('\\')+1,CDir.size());
|
|
||||||
AD += "\\BeamMP-Launcher";
|
|
||||||
if(FN != DN){
|
if(FN != DN){
|
||||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||||
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
||||||
}
|
}
|
||||||
if(CDir.substr(0,CDir.find_last_of('\\')) != AD){
|
//SystemExec(R"(powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\BeamMP-Launcher.lnk');$s.TargetPath=')"+AD+"\\"+DN+"';$s.Save()\"");
|
||||||
_mkdir(AD.c_str());
|
|
||||||
SystemExec(R"(move "BeamMP-Launcher.exe" ")" + AD + "\">nul");
|
|
||||||
}
|
|
||||||
SetCurrentDirectoryA(AD.c_str());
|
|
||||||
SystemExec("rename *.exe " + DN + ">nul");
|
|
||||||
SystemExec(R"(powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\BeamMP-Launcher.lnk');$s.TargetPath=')"+AD+"\\"+DN+"';$s.Save()\"");
|
|
||||||
if(stat("BeamNG",&info))SystemExec("mkdir BeamNG>nul");
|
if(stat("BeamNG",&info))SystemExec("mkdir BeamNG>nul");
|
||||||
if(stat("BeamNG\\mods",&info))SystemExec("mkdir BeamNG\\mods>nul");
|
if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul");
|
||||||
|
SystemExec("mkdir BeamNG\\mods>nul");
|
||||||
if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul");
|
if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul");
|
||||||
SetFileAttributesA("BeamNG",2|4);
|
return CDir.substr(0,CDir.find_last_of('\\')) + "\\BeamNG";
|
||||||
return AD + "\\BeamNG";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CheckVer(const std::string &path){
|
std::string CheckVer(const std::string &path){
|
||||||
@ -111,9 +102,12 @@ int main(int argc, char* argv[]){
|
|||||||
if(argc > 1){
|
if(argc > 1){
|
||||||
std::string Port = argv[1];
|
std::string Port = argv[1];
|
||||||
if(Port.find_first_not_of("0123456789") == NPos){
|
if(Port.find_first_not_of("0123456789") == NPos){
|
||||||
DEFAULT_PORT = std::stoi(Port);
|
if(std::stoi(Port) > 1000){
|
||||||
std::cout << "Running on custom port : " << DEFAULT_PORT << std::endl;
|
DEFAULT_PORT = std::stoi(Port);
|
||||||
|
std::cout << "Running on custom port : " << DEFAULT_PORT << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if(argc > 2)MPDEV = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Security
|
//Security
|
||||||
|
Loading…
x
Reference in New Issue
Block a user