mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Autoupdater asks for permission to update + Autoupdater fixes
This commit is contained in:
parent
ba9259bfdf
commit
42811dc896
|
@ -13,6 +13,7 @@ class IAutoUpdate : public IInterface
|
|||
MACRO_INTERFACE("autoupdate", 0)
|
||||
public:
|
||||
virtual void CheckUpdates(CMenus *pMenus) = 0;
|
||||
virtual void DoUpdates(CMenus *pMenus) = 0;
|
||||
virtual bool Updated() = 0;
|
||||
virtual bool NeedResetClient() = 0;
|
||||
virtual void ExecuteExit() = 0;
|
||||
|
|
|
@ -53,6 +53,7 @@ void CAutoUpdate::Reset()
|
|||
m_NeedUpdate = false;
|
||||
m_NeedUpdateBackground = false;
|
||||
m_NeedUpdateClient = false;
|
||||
m_NeedUpdateServer = false;
|
||||
m_NeedResetClient = false;
|
||||
m_Updated = false;
|
||||
m_vFiles.clear();
|
||||
|
@ -112,8 +113,6 @@ void CAutoUpdate::ExecuteExit()
|
|||
void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
||||
{
|
||||
char aReadBuf[512];
|
||||
char aBuf[512];
|
||||
|
||||
dbg_msg("autoupdate", "Checking for updates");
|
||||
if (!GetFile("ddnet.upd", "ddnet.upd"))
|
||||
{
|
||||
|
@ -123,6 +122,55 @@ void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
|||
|
||||
dbg_msg("autoupdate", "Processing data");
|
||||
|
||||
Reset();
|
||||
IOHANDLE updFile = io_open("ddnet.upd", IOFLAG_READ);
|
||||
if (!updFile)
|
||||
return;
|
||||
|
||||
//read data
|
||||
std::string ReadData;
|
||||
char last_version[15];
|
||||
char cmd;
|
||||
while (io_read(updFile, aReadBuf, sizeof(aReadBuf)) > 0)
|
||||
{
|
||||
for (size_t i=0; i<sizeof(aReadBuf); i++)
|
||||
{
|
||||
if (aReadBuf[i]=='\n')
|
||||
{
|
||||
if (i>0 && aReadBuf[i-1] == '\r')
|
||||
ReadData = ReadData.substr(0, -2);
|
||||
|
||||
//Parse Command
|
||||
cmd = ReadData[0];
|
||||
if (cmd == '#')
|
||||
{
|
||||
str_copy(last_version, ReadData.substr(1).c_str(), sizeof(last_version));
|
||||
|
||||
if (ReadData.substr(1).compare(GAME_RELEASE_VERSION) != 0)
|
||||
pMenus->setPopup(CMenus::POPUP_AUTOUPDATE);
|
||||
else
|
||||
dbg_msg("autoupdate", "Version match");
|
||||
|
||||
io_close(updFile);
|
||||
return;
|
||||
}
|
||||
ReadData.clear();
|
||||
}
|
||||
|
||||
ReadData+=aReadBuf[i];
|
||||
}
|
||||
}
|
||||
|
||||
io_close(updFile);
|
||||
}
|
||||
|
||||
void CAutoUpdate::DoUpdates(CMenus *pMenus)
|
||||
{
|
||||
char aReadBuf[512];
|
||||
char aBuf[512];
|
||||
|
||||
dbg_msg("autoupdate", "Processing data");
|
||||
|
||||
Reset();
|
||||
IOHANDLE updFile = io_open("ddnet.upd", IOFLAG_READ);
|
||||
if (!updFile)
|
||||
|
@ -152,7 +200,7 @@ void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
|||
else
|
||||
{
|
||||
dbg_msg("autoupdate", "Version match");
|
||||
break;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
str_copy(current_version, ReadData.substr(1).c_str(), sizeof(current_version));
|
||||
|
@ -179,13 +227,12 @@ void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
|||
#endif
|
||||
dbg_msg("autoupdate", "Error downloading new version");
|
||||
}
|
||||
if (ReadData.substr(2).compare("UPDATE_SERVER") == 0)
|
||||
if (!m_NeedUpdateServer && ReadData.substr(2).compare("UPDATE_SERVER") == 0)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "Updating DDNet Server to %s", last_version);
|
||||
pMenus->RenderUpdating(aBuf);
|
||||
|
||||
m_NeedUpdateClient = true;
|
||||
m_NeedResetClient = true;
|
||||
m_NeedUpdateServer = true;
|
||||
dbg_msg("autoupdate", "Updating server");
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
if (!GetFile("DDNet-Server.exe", "DDNet-Server.exe"))
|
||||
|
@ -245,7 +292,8 @@ void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
|||
if (!m_NeedUpdate)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
finish:
|
||||
if (m_NeedUpdate)
|
||||
{
|
||||
m_Updated = true;
|
||||
|
@ -260,7 +308,25 @@ void CAutoUpdate::CheckUpdates(CMenus *pMenus)
|
|||
dbg_msg("autoupdate", "No updates available");
|
||||
|
||||
io_close(updFile);
|
||||
remove("ddnet.upd");
|
||||
|
||||
if (m_Updated)
|
||||
{
|
||||
if (m_NeedUpdateClient)
|
||||
{
|
||||
pMenus->setPopup(CMenus::POPUP_QUIT);
|
||||
return;
|
||||
}
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "DDNet Client updated successfully");
|
||||
pMenus->RenderUpdating(aBuf);
|
||||
thread_sleep(200);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "No update available");
|
||||
pMenus->RenderUpdating(aBuf);
|
||||
thread_sleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
bool CAutoUpdate::GetFile(const char *pFile, const char *dst)
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
void Reset();
|
||||
|
||||
void CheckUpdates(CMenus *pMenus);
|
||||
void DoUpdates(CMenus *pMenus);
|
||||
bool Updated() { return m_Updated; }
|
||||
bool NeedResetClient() { return m_NeedResetClient; }
|
||||
void ExecuteExit();
|
||||
|
@ -26,6 +27,7 @@ private:
|
|||
bool m_NeedUpdate;
|
||||
bool m_NeedUpdateBackground;
|
||||
bool m_NeedUpdateClient;
|
||||
bool m_NeedUpdateServer;
|
||||
bool m_NeedResetClient;
|
||||
std::list<std::string> m_vFiles;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <engine/serverbrowser.h>
|
||||
#include <engine/storage.h>
|
||||
#include <engine/textrender.h>
|
||||
#include <engine/autoupdate.h>
|
||||
#include <engine/shared/config.h>
|
||||
|
||||
#include <game/version.h>
|
||||
|
@ -954,6 +955,12 @@ int CMenus::Render()
|
|||
pButtonText = Localize("Ok");
|
||||
ExtraAlign = -1;
|
||||
}
|
||||
else if(m_Popup == POPUP_AUTOUPDATE)
|
||||
{
|
||||
pTitle = Localize("Auto-Update");
|
||||
pExtraText = Localize("An update to DDNet client is available. Do you want to update now? This may restart the client. If an update fails, make sure the client has permissions to modify files.");
|
||||
ExtraAlign = -1;
|
||||
}
|
||||
|
||||
CUIRect Box, Part;
|
||||
Box = Screen;
|
||||
|
@ -1005,6 +1012,26 @@ int CMenus::Render()
|
|||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
Client()->Quit();
|
||||
}
|
||||
else if(m_Popup == POPUP_AUTOUPDATE)
|
||||
{
|
||||
CUIRect Yes, No;
|
||||
Box.HSplitBottom(20.f, &Box, &Part);
|
||||
Box.HSplitBottom(24.f, &Box, &Part);
|
||||
|
||||
// buttons
|
||||
Part.VMargin(80.0f, &Part);
|
||||
Part.VSplitMid(&No, &Yes);
|
||||
Yes.VMargin(20.0f, &Yes);
|
||||
No.VMargin(20.0f, &No);
|
||||
|
||||
static int s_ButtonAbort = 0;
|
||||
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
|
||||
m_Popup = POPUP_NONE;
|
||||
|
||||
static int s_ButtonTryAgain = 0;
|
||||
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
|
||||
m_pClient->AutoUpdate()->DoUpdates(this);
|
||||
}
|
||||
else if(m_Popup == POPUP_PASSWORD)
|
||||
{
|
||||
CUIRect Label, TextBox, TryAgain, Abort;
|
||||
|
|
|
@ -92,24 +92,6 @@ class CMenus : public CComponent
|
|||
//static void demolist_listdir_callback(const char *name, int is_dir, void *user);
|
||||
//static void demolist_list_callback(const CUIRect *rect, int index, void *user);
|
||||
|
||||
enum
|
||||
{
|
||||
POPUP_NONE=0,
|
||||
POPUP_FIRST_LAUNCH,
|
||||
POPUP_CONNECTING,
|
||||
POPUP_MESSAGE,
|
||||
POPUP_DISCONNECTED,
|
||||
POPUP_PURE,
|
||||
POPUP_LANGUAGE,
|
||||
POPUP_COUNTRY,
|
||||
POPUP_DELETE_DEMO,
|
||||
POPUP_RENAME_DEMO,
|
||||
POPUP_REMOVE_FRIEND,
|
||||
POPUP_SOUNDERROR,
|
||||
POPUP_PASSWORD,
|
||||
POPUP_QUIT,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PAGE_NEWS=1,
|
||||
|
@ -325,6 +307,26 @@ public:
|
|||
CGhostItem *m_OwnGhost;
|
||||
int m_DDRacePage;
|
||||
void GhostlistPopulate();
|
||||
void setPopup(int Popup) { m_Popup = Popup; }
|
||||
|
||||
enum
|
||||
{
|
||||
POPUP_NONE=0,
|
||||
POPUP_FIRST_LAUNCH,
|
||||
POPUP_CONNECTING,
|
||||
POPUP_MESSAGE,
|
||||
POPUP_DISCONNECTED,
|
||||
POPUP_PURE,
|
||||
POPUP_LANGUAGE,
|
||||
POPUP_COUNTRY,
|
||||
POPUP_DELETE_DEMO,
|
||||
POPUP_RENAME_DEMO,
|
||||
POPUP_REMOVE_FRIEND,
|
||||
POPUP_SOUNDERROR,
|
||||
POPUP_PASSWORD,
|
||||
POPUP_QUIT,
|
||||
POPUP_AUTOUPDATE
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -1358,23 +1358,6 @@ void CMenus::RenderSettingsDDRace(CUIRect MainView)
|
|||
str_format(aBuf, sizeof(aBuf), "Checking for an update");
|
||||
RenderUpdating(aBuf);
|
||||
AutoUpdate()->CheckUpdates(this);
|
||||
if (AutoUpdate()->Updated())
|
||||
{
|
||||
if (AutoUpdate()->NeedResetClient())
|
||||
{
|
||||
Client()->Quit();
|
||||
return;
|
||||
}
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "DDNet Client updated");
|
||||
|
||||
RenderUpdating(aBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "No update available");
|
||||
RenderUpdating(aBuf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -294,24 +294,6 @@ void CGameClient::OnInit()
|
|||
str_format(aBuf, sizeof(aBuf), "Checking for updates");
|
||||
g_GameClient.m_pMenus->RenderUpdating(aBuf);
|
||||
AutoUpdate()->CheckUpdates(m_pMenus);
|
||||
if (AutoUpdate()->Updated())
|
||||
{
|
||||
if (AutoUpdate()->NeedResetClient())
|
||||
{
|
||||
Client()->Quit();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "DDNet Client updated successfully");
|
||||
g_GameClient.m_pMenus->RenderUpdating(aBuf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "No updates available");
|
||||
g_GameClient.m_pMenus->RenderUpdating(aBuf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#ifndef GAME_VERSION_H
|
||||
#define GAME_VERSION_H
|
||||
#include "generated/nethash.cpp"
|
||||
#define GAME_VERSION "0.6.2, 3.9"
|
||||
#define GAME_VERSION "0.6.2, 3.8"
|
||||
#define GAME_NETVERSION "0.6 626fce9a778df4d4"
|
||||
static const char GAME_RELEASE_VERSION[8] = "3.9";
|
||||
#define CLIENT_VERSIONNR 309
|
||||
static const char GAME_RELEASE_VERSION[8] = "3.8";
|
||||
#define CLIENT_VERSIONNR 308
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue