mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-05-19 16:10:14 +00:00
minor cleanups
This commit is contained in:
@@ -29,74 +29,56 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
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(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;
|
||||||
if(round(d/t*100) < 10)
|
std::cout << "% ] [";
|
||||||
{ std::cout<<"0"<<round(d/t*100)<<"% ]"; }
|
int i;
|
||||||
else
|
for(i = 0; i <= progress_bar_adv; i++)std::cout<<"#";
|
||||||
{ std::cout<<round(d/t*100)<<"% ] "; }
|
for(i = 0; i < nb_bar - progress_bar_adv; i++)std::cout<<".";
|
||||||
|
|
||||||
std::cout<<"[";
|
|
||||||
for(int i = 0 ; i <= progress_bar_adv ; i++)
|
|
||||||
{ std::cout<<"#"; }
|
|
||||||
for(int 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);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FtpFile {
|
struct File {
|
||||||
const char *filename;
|
const char *filename;
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
|
static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream)
|
||||||
void *stream)
|
|
||||||
{
|
{
|
||||||
auto *out = (struct FtpFile *)stream;
|
auto *out = (struct File*)stream;
|
||||||
if(!out->stream) {
|
if(!out->stream) {
|
||||||
fopen_s(&out->stream,out->filename,"wb");
|
fopen_s(&out->stream,out->filename,"wb");
|
||||||
if(!out->stream)
|
if(!out->stream)return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
return fwrite(buffer, size, nmemb, out->stream);
|
return fwrite(buffer, size, nmemb, out->stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Download(const std::string& URL,const std::string& Path)
|
void Download(const std::string& URL,const std::string& Path)
|
||||||
{
|
{
|
||||||
|
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct FtpFile ftpfile = {
|
struct File file = {
|
||||||
Path.c_str(),
|
Path.c_str(),
|
||||||
nullptr
|
nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
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_WRITEFUNCTION, my_fwrite);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &file);
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
|
||||||
//progress_bar : the fonction for the progress bar
|
|
||||||
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);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
@@ -104,7 +86,7 @@ void Download(const std::string& URL,const std::string& Path)
|
|||||||
fprintf(stderr, "Failed to download! Code : %d\n", res);
|
fprintf(stderr, "Failed to download! Code : %d\n", res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ftpfile.stream)fclose(ftpfile.stream);
|
if(file.stream)fclose(file.stream);
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ void TCPSEND(const std::string&Data){
|
|||||||
if (MPDEV)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
|
if (MPDEV)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
} else {
|
} else {
|
||||||
if (MPDEV && Data.length() < 100) {
|
if (MPDEV && Data.length() > 1000) {
|
||||||
std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl;
|
std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl;
|
||||||
}
|
}
|
||||||
//std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl;
|
//std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl;
|
||||||
@@ -56,6 +56,8 @@ void RUDPSEND(const std::string&Data,bool Rel){
|
|||||||
<< " : "
|
<< " : "
|
||||||
<< Data.substr(0, 10)
|
<< Data.substr(0, 10)
|
||||||
<< Data.substr(Data.length() - 10) << std::endl;
|
<< Data.substr(Data.length() - 10) << std::endl;
|
||||||
|
}else if(Data.length() < 100){
|
||||||
|
std::cout << "(Game->Launcher) : " << Data << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user