[Maps] Install dlcs using the updater

This also fixes @iw4x-dev-urandom's bug that prevents the updater from starting!!!
This commit is contained in:
momo5502 2017-02-11 19:47:48 +01:00
parent 989c4f64a5
commit 60f96edcce
4 changed files with 55 additions and 37 deletions

View File

@ -416,7 +416,6 @@ namespace Components
{
if (pack.index == dlc.index)
{
pack.url = dlc.url;
pack.maps = dlc.maps;
Maps::UpdateDlcStatus();
return;
@ -536,14 +535,14 @@ namespace Components
{
Dvar::Register<bool>("isDlcInstalled_All", false, Game::DVAR_FLAG_USERCREATED | Game::DVAR_FLAG_WRITEPROTECTED, "");
Maps::AddDlc({ 1, "Stimulus Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash" } });
Maps::AddDlc({ 2, "Resergence Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2" } });
Maps::AddDlc({ 3, "Nuketown", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_nuked" } });
Maps::AddDlc({ 4, "Classics Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_cross_fire", "mp_cargoship", "mp_bloc" } });
Maps::AddDlc({ 5, "Classics Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_killhouse", "mp_bog_sh" } });
Maps::AddDlc({ 6, "Freighter", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_cargoship_sh" } });
Maps::AddDlc({ 7, "Resurrection Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_shipment_long", "mp_rust_long", "mp_firingrange" } });
Maps::AddDlc({ 8, "Recycled Pack", Utils::Cache::GetStaticUrl("/dlc/"), { "mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring" } });
Maps::AddDlc({ 1, "Stimulus Pack", { "mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash" } });
Maps::AddDlc({ 2, "Resergence Pack", { "mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2" } });
Maps::AddDlc({ 3, "Nuketown", { "mp_nuked" } });
Maps::AddDlc({ 4, "Classics Pack", { "mp_cross_fire", "mp_cargoship", "mp_bloc" } });
Maps::AddDlc({ 5, "Classics Pack", { "mp_killhouse", "mp_bog_sh" } });
Maps::AddDlc({ 6, "Freighter", { "mp_cargoship_sh" } });
Maps::AddDlc({ 7, "Resurrection Pack", { "mp_shipment_long", "mp_rust_long", "mp_firingrange" } });
Maps::AddDlc({ 8, "Recycled Pack", { "mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring" } });
Maps::UpdateDlcStatus();
@ -555,7 +554,8 @@ namespace Components
{
if (pack.index == dlc)
{
ShellExecuteA(nullptr, "open", pack.url.data(), nullptr, nullptr, SW_SHOWNORMAL);
News::LaunchUpdater(Utils::String::VA("-dlc %i -c", pack.index));
//ShellExecuteA(nullptr, "open", pack.url.data(), nullptr, nullptr, SW_SHOWNORMAL);
return;
}
}

View File

@ -28,7 +28,6 @@ namespace Components
public:
int index;
std::string name;
std::string url;
std::vector<std::string> maps;
};

View File

@ -6,6 +6,7 @@ namespace Components
{
bool News::Terminate;
std::thread News::Thread;
std::string News::UpdaterArgs;
bool News::unitTest()
{
@ -41,7 +42,7 @@ namespace Components
ZeroMemory(&pInfo, sizeof(pInfo));
sInfo.cb = sizeof(sInfo);
CreateProcessA("updater.exe -update -c", nullptr, nullptr, nullptr, false, NULL, nullptr, nullptr, &sInfo, &pInfo);
CreateProcessA("updater.exe", const_cast<char*>(Utils::String::VA("updater.exe %s", News::UpdaterArgs.data())), nullptr, nullptr, false, NULL, nullptr, nullptr, &sInfo, &pInfo);
if (pInfo.hThread && pInfo.hThread != INVALID_HANDLE_VALUE) CloseHandle(pInfo.hThread);
if (pInfo.hProcess && pInfo.hProcess != INVALID_HANDLE_VALUE) CloseHandle(pInfo.hProcess);
@ -82,8 +83,45 @@ namespace Components
}
}
void News::LaunchUpdater(std::string params)
{
if (News::Updating()) return;
News::UpdaterArgs = params;
Localization::SetTemp("MENU_RECONNECTING_TO_PARTY", "Downloading updater");
Command::Execute("openmenu popup_reconnectingtoparty", true);
// Run the updater on shutdown
Utils::Hook::Set(0x6D72A0, News::ExitProcessStub);
std::thread([]()
{
std::string data = Utils::Cache::GetFile("/iw4/updater.exe");
if (data.empty())
{
Localization::ClearTemp();
Command::Execute("closemenu popup_reconnectingtoparty", false);
Game::ShowMessageBox("Failed to download the updater!", "Error");
}
else
{
Console::SetSkipShutdown();
Utils::IO::WriteFile("updater.exe", data);
Command::Execute("wait 300; quit;", false);
}
}).detach();
}
bool News::Updating()
{
return !News::UpdaterArgs.empty();
}
News::News()
{
News::UpdaterArgs.clear();
if (ZoneBuilder::IsEnabled()) return; // Maybe also dedi?
Dvar::Register<bool>("g_firstLaunch", true, Game::DVAR_FLAG_SAVED, "");
@ -134,30 +172,7 @@ namespace Components
Command::Add("getautoupdate", [] (Command::Params*)
{
if (!Dvar::Var("cl_updateavailable").get<Game::dvar_t*>()->current.boolean) return;
Localization::SetTemp("MENU_RECONNECTING_TO_PARTY", "Downloading updater");
Command::Execute("openmenu popup_reconnectingtoparty", true);
// Run the updater on shutdown
Utils::Hook::Set(0x6D72A0, News::ExitProcessStub);
std::thread([] ()
{
std::string data = Utils::Cache::GetFile("/iw4/updater.exe");
if (data.empty())
{
Localization::ClearTemp();
Command::Execute("closemenu popup_reconnectingtoparty", false);
Game::ShowMessageBox("Failed to download the updater!", "Error");
}
else
{
Console::SetSkipShutdown();
Utils::IO::WriteFile("updater.exe", data);
Command::Execute("wait 300; quit;", false);
}
}).detach();
News::LaunchUpdater("-update -c");
});
if (!Utils::IsWineEnvironment() && !Loader::PerformingUnitTests())
@ -193,7 +208,7 @@ namespace Components
News::~News()
{
News::UpdaterArgs.clear();
}
void News::preDestroy()

View File

@ -15,7 +15,11 @@ namespace Components
void preDestroy() override;
bool unitTest() override;
static void LaunchUpdater(std::string params);
static bool Updating();
private:
static std::string UpdaterArgs;
static std::thread Thread;
static bool Terminate;