Implement updating routine
This commit is contained in:
parent
3271a6d510
commit
fb5c47ee11
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit 8c936063570e5ede2ac41cf49aefe1075f1c7251
|
||||
Subproject commit c0a6a6b4628a634f6a0529c9f7e9e1e0fe66d4d6
|
@ -18,6 +18,7 @@ namespace Components
|
||||
int Console::LineBufferIndex = 0;
|
||||
|
||||
bool Console::HasConsole = false;
|
||||
bool Console::SkipShutdown = false;
|
||||
|
||||
std::thread Console::ConsoleThread;
|
||||
|
||||
@ -383,6 +384,7 @@ namespace Components
|
||||
|
||||
void Console::ConsoleRunner()
|
||||
{
|
||||
Console::SkipShutdown = false;
|
||||
Game::Sys_ShowConsole();
|
||||
|
||||
MSG message;
|
||||
@ -391,6 +393,8 @@ namespace Components
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageA(&message);
|
||||
}
|
||||
|
||||
if (Console::SkipShutdown) return;
|
||||
|
||||
if (Game::Sys_Milliseconds() - Console::LastRefresh > 100 &&
|
||||
MessageBoxA(0, "The application is not responding anymore, do you want to force its termination?", "Application is not responding", MB_ICONEXCLAMATION | MB_YESNO) == IDYES)
|
||||
@ -473,6 +477,11 @@ namespace Components
|
||||
// Restore the initial safe area
|
||||
*Game::safeArea = Console::OriginalSafeArea;
|
||||
}
|
||||
|
||||
void Console::SetSkipShutdown()
|
||||
{
|
||||
Console::SkipShutdown = true;
|
||||
}
|
||||
|
||||
Console::Console()
|
||||
{
|
||||
|
@ -13,9 +13,7 @@ namespace Components
|
||||
const char* GetName() { return "Console"; };
|
||||
#endif
|
||||
|
||||
private:
|
||||
static void ToggleConsole();
|
||||
static char** GetAutoCompleteFileList(const char *path, const char *extension, Game::FsListBehavior_e behavior, int *numfiles, int allocTrackType);
|
||||
static void SetSkipShutdown();
|
||||
|
||||
private:
|
||||
// Text-based console stuff
|
||||
@ -35,6 +33,7 @@ namespace Components
|
||||
static int LineBufferIndex;
|
||||
|
||||
static bool HasConsole;
|
||||
static bool SkipShutdown;
|
||||
|
||||
static std::thread ConsoleThread;
|
||||
|
||||
@ -59,5 +58,8 @@ namespace Components
|
||||
static void DrawSolidConsoleStub();
|
||||
static void StoreSafeArea();
|
||||
static void RestoreSafeArea();
|
||||
|
||||
static void ToggleConsole();
|
||||
static char** GetAutoCompleteFileList(const char *path, const char *extension, Game::FsListBehavior_e behavior, int *numfiles, int allocTrackType);
|
||||
};
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
bool News::Terminate;
|
||||
std::thread News::Thread;
|
||||
|
||||
bool News::UnitTest()
|
||||
@ -39,11 +40,99 @@ namespace Components
|
||||
return result;
|
||||
}
|
||||
|
||||
void News::ExitProcessStub(unsigned int exitCode)
|
||||
{
|
||||
std::this_thread::sleep_for(10ms);
|
||||
|
||||
STARTUPINFOA sInfo;
|
||||
PROCESS_INFORMATION pInfo;
|
||||
|
||||
ZeroMemory(&sInfo, sizeof(sInfo));
|
||||
ZeroMemory(&pInfo, sizeof(pInfo));
|
||||
sInfo.cb = sizeof(sInfo);
|
||||
|
||||
CreateProcessA("updater.dat", NULL, NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &sInfo, &pInfo);
|
||||
|
||||
Console::SetSkipShutdown();
|
||||
TerminateProcess(GetCurrentProcess(), exitCode);
|
||||
}
|
||||
|
||||
void News::CheckForUpdate()
|
||||
{
|
||||
std::string caches = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/caches.xml").SetTimeout(5000)->Get();
|
||||
|
||||
if (!caches.empty())
|
||||
{
|
||||
std::string str = "<Cache ID=\"game\" Version=\"";
|
||||
auto pos = caches.find(str);
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
caches = caches.substr(pos + str.size());
|
||||
|
||||
pos = caches.find_first_of("\"");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
caches = caches.substr(0, pos);
|
||||
|
||||
int version = atoi(caches.data());
|
||||
|
||||
Dvar::Var("cl_updateversion").Get<Game::dvar_t*>()->current.integer = version;
|
||||
Dvar::Var("cl_updateavailable").Get<Game::dvar_t*>()->current.boolean = (version > /*REVISION*/1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
News::News()
|
||||
{
|
||||
Dvar::Register<int>("cl_updateoldversion", REVISION, REVISION, REVISION, Game::DVAR_FLAG_WRITEPROTECTED, "Current version number.");
|
||||
Dvar::Register<int>("cl_updateversion", 0, 0, -1, Game::DVAR_FLAG_WRITEPROTECTED, "New version number.");
|
||||
Dvar::Register<bool>("cl_updateavailable", 0, Game::DVAR_FLAG_WRITEPROTECTED, "New update is available.");
|
||||
|
||||
Localization::Set("MPUI_CHANGELOG_TEXT", "Loading...");
|
||||
Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFUALT);
|
||||
|
||||
if (Utils::IO::FileExists("updater.dat"))
|
||||
{
|
||||
remove("updater.dat");
|
||||
}
|
||||
|
||||
Command::Add("checkforupdate", [] (Command::Params)
|
||||
{
|
||||
News::CheckForUpdate();
|
||||
});
|
||||
|
||||
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, ExitProcessStub);
|
||||
|
||||
std::async([] ()
|
||||
{
|
||||
std::string data = Utils::WebIO("IW4x", "http://localhost/iw4/updater/updater.exe").SetTimeout(5000)->Get();
|
||||
|
||||
if (data.empty())
|
||||
{
|
||||
Localization::ClearTemp();
|
||||
Command::Execute("closemenu popup_reconnectingtoparty", false);
|
||||
Game::MessageBox("Failed to download the updater!", "Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils::IO::WriteFile("updater.dat", data);
|
||||
Command::Execute("wait 300; quit;", false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
News::Terminate = false;
|
||||
News::Thread = std::thread([] ()
|
||||
{
|
||||
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/changelog.txt").SetTimeout(5000)->Get());
|
||||
@ -56,11 +145,26 @@ namespace Components
|
||||
}
|
||||
|
||||
// TODO: Implement update checks here!
|
||||
if (!Loader::PerformingUnitTests())
|
||||
{
|
||||
while (!News::Terminate)
|
||||
{
|
||||
News::CheckForUpdate();
|
||||
|
||||
// Sleep for 3 minutes
|
||||
for (int i = 0; i < 180 && !News::Terminate; ++i)
|
||||
{
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
News::~News()
|
||||
{
|
||||
News::Terminate = true;
|
||||
|
||||
if (News::Thread.joinable())
|
||||
{
|
||||
News::Thread.join();
|
||||
|
@ -14,5 +14,9 @@ namespace Components
|
||||
|
||||
private:
|
||||
static std::thread Thread;
|
||||
static bool Terminate;
|
||||
|
||||
static void CheckForUpdate();
|
||||
static void ExitProcessStub(unsigned int exitCode);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user