bool DoesFileExist (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
} else {
return false;
}
}
HRESULT DownloadFile(string fileName) {
string url = "
http://beta.muphoenix.it/updates/" + fileName;
//Convert the string to a LPCSTR type so we can use it in the URLDownloadToFile() function
LPCSTR lpcURL = url.c_str();
char result[ MAX_PATH ];
string baseBase = std::string( result, GetModuleFileName( NULL, result, MAX_PATH ) );
string destination = baseBase + "\\" + fileName;
destination = destination.replace(destination.find("\\main.exe"), sizeof("\\main.exe") - 1, "");
//destination = destination.replace(destination.find("\\MuPhoenix.exe"), sizeof("\\MuPhoenix.exe") - 1, "");
//Convert the string to a LPCSTR type so we can use it in the URLDownloadToFile() function
LPCSTR lpcDestination = destination.c_str();
HRESULT hr = URLDownloadToFile( NULL, lpcURL, lpcDestination, 0, NULL );
return hr;
}
int DownloadLauncherOneOff() {
if (DoesFileExist("launcher-v.txt") == 1) {
// File is there ;)
return 1;
}
HRESULT file2 = DownloadFile("mu.ini");
if (file2 != S_OK) {
MessageBox(0, "Cant download launcher info","Error",MB_OK | MB_ICONERROR);
ExitProcess(0);
return 0;
}
MessageBox(NULL, "Update Available for the Launcher! \n\n Press OK and wait few seconds...","Updating",MB_OK | MB_ICONINFORMATION);
Sleep(6000);
HRESULT file3 = DownloadFile("MuPhoenix.exe");
if (file3 != S_OK) {
MessageBox(0, "Cant download new Launcher please download it manually from the website","Error",MB_OK | MB_ICONERROR);
ExitProcess(0);
return 0;
}
HRESULT file1 = DownloadFile("launcher-v.txt");
if (file1 != S_OK) {
MessageBox(0, "Cant download launcher lock file, try later or contact us in Discord","Error",MB_OK | MB_ICONERROR);
ExitProcess(0);
return 0;
}
MessageBox(0, "Launcher Updated!! \n\n Please launch the Game Again!","Info",MB_OK | MB_ICONINFORMATION);
return 0;
}