mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 00:35:55 +00:00
Potential default dir fix
This commit is contained in:
parent
9f821a01f0
commit
e207f2febd
@ -9,7 +9,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
void InitLauncher(int argc, char* argv[]);
|
void InitLauncher(int argc, char* argv[]);
|
||||||
void CheckDir(int argc,char* args[]);
|
void CheckDir(int argc,char* args[]);
|
||||||
std::wstring GetGamePath();
|
std::string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetEN();
|
std::string GetEN();
|
||||||
extern bool Dev;
|
extern bool Dev;
|
@ -8,17 +8,14 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include <ShlObj.h>
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <codecvt>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <locale>
|
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
std::string QueryKey(HKEY hKey,int ID);
|
std::string QueryKey(HKEY hKey,int ID);
|
||||||
std::wstring GetGamePath(){
|
std::string GetGamePath(){
|
||||||
static std::wstring Path;
|
static std::string Path;
|
||||||
if(!Path.empty())return Path;
|
if(!Path.empty())return Path;
|
||||||
|
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
@ -27,17 +24,15 @@ std::wstring GetGamePath(){
|
|||||||
if (openRes != ERROR_SUCCESS){
|
if (openRes != ERROR_SUCCESS){
|
||||||
fatal("Please launch the game at least once");
|
fatal("Please launch the game at least once");
|
||||||
}
|
}
|
||||||
std::string T = QueryKey(hKey,4);
|
Path = QueryKey(hKey,4);
|
||||||
Path = std::wstring(T.begin(),T.end());
|
|
||||||
|
|
||||||
if(Path.empty()){
|
if(Path.empty()){
|
||||||
CoInitialize(nullptr);
|
size_t RS;
|
||||||
wchar_t * path = nullptr;
|
getenv_s(&RS, nullptr, 0, "USERPROFILE");
|
||||||
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path));
|
std::string P(RS-1,0);
|
||||||
CoTaskMemFree(path);
|
getenv_s(&RS, &P[0], RS, "USERPROFILE");
|
||||||
std::wstring ws(path);
|
Path = P + R"(\Documents\BeamNG.drive\)";
|
||||||
ws += L"\\BeamNG.drive\\";
|
return Path;
|
||||||
return ws;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Path;
|
return Path;
|
||||||
|
@ -256,11 +256,10 @@ void SyncResources(SOCKET Sock){
|
|||||||
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if(!fs::exists(GetGamePath() + L"mods/multiplayer")){
|
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||||
fs::create_directory(GetGamePath() + L"mods/multiplayer");
|
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
std::string P = "mods/multiplayer" + a.substr(a.find_last_of('/'));
|
fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')),
|
||||||
fs::copy_file(a, GetGamePath() + std::wstring(P.begin(),P.end()),
|
|
||||||
fs::copy_options::overwrite_existing);
|
fs::copy_options::overwrite_existing);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
error("Failed copy to the mods folder! " + std::string(e.what()));
|
error("Failed copy to the mods folder! " + std::string(e.what()));
|
||||||
@ -298,10 +297,10 @@ void SyncResources(SOCKET Sock){
|
|||||||
|
|
||||||
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
||||||
if(!Terminate){
|
if(!Terminate){
|
||||||
if(!fs::exists(GetGamePath() + L"mods/multiplayer")){
|
if(!fs::exists(GetGamePath() + "mods/multiplayer")){
|
||||||
fs::create_directory(GetGamePath() + L"mods/multiplayer");
|
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
fs::copy_file(a,GetGamePath() + L"mods/multiplayer" + std::wstring(FName.begin(),FName.end()), fs::copy_options::overwrite_existing);
|
fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing);
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ std::string GetVer(){
|
|||||||
return "1.80";
|
return "1.80";
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch(){
|
||||||
return ".4";
|
return ".5";
|
||||||
}
|
}
|
||||||
void ReLaunch(int argc,char*args[]){
|
void ReLaunch(int argc,char*args[]){
|
||||||
std::string Arg;
|
std::string Arg;
|
||||||
@ -187,32 +187,23 @@ void InitLauncher(int argc, char* argv[]) {
|
|||||||
CustomPort(argc, argv);
|
CustomPort(argc, argv);
|
||||||
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
|
||||||
}
|
}
|
||||||
inline std::string to_string(const std::wstring& str){
|
|
||||||
auto loc = std::locale{};
|
|
||||||
std::vector<char> buf(str.size());
|
|
||||||
std::use_facet<std::ctype<wchar_t>>(loc).narrow(str.data(), str.data() + str.size(), '?', buf.data());
|
|
||||||
|
|
||||||
return std::string(buf.data(), buf.size());
|
|
||||||
}
|
|
||||||
void PreGame(const std::string& GamePath){
|
void PreGame(const std::string& GamePath){
|
||||||
info("Game Version : " + CheckVer(GamePath));
|
info("Game Version : " + CheckVer(GamePath));
|
||||||
|
|
||||||
if(!Dev) {
|
if(!Dev) {
|
||||||
info("Downloading mod...");
|
info("Downloading mod...");
|
||||||
//if(fallback)link = "https://backup1.beammp.com/builds/client";
|
|
||||||
std::string link = "https://beammp.com/builds/client";
|
|
||||||
try {
|
try {
|
||||||
if (!fs::exists(GetGamePath() + L"mods")) {
|
if (!fs::exists(GetGamePath() + "mods")) {
|
||||||
fs::create_directory(GetGamePath() + L"mods");
|
fs::create_directory(GetGamePath() + "mods");
|
||||||
}
|
}
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
fs::create_directory(GetGamePath() + L"mods/multiplayer");
|
fs::create_directory(GetGamePath() + "mods/multiplayer");
|
||||||
}
|
}
|
||||||
std::wstring P = GetGamePath() + LR"(mods/multiplayer/BeamMP.zip)";
|
|
||||||
Download(link, to_string(P), true);
|
|
||||||
}catch(std::exception&e){
|
}catch(std::exception&e){
|
||||||
fatal(e.what());
|
fatal(e.what());
|
||||||
}
|
}
|
||||||
|
Download("https://beammp.com/builds/client", GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);
|
||||||
info("Download Complete!");
|
info("Download Complete!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user