new update system

Tobias Zwick 2010-12-01 21:37:47 +01:00
parent 2e5c93b31c
commit 9f8fa02b8e
10 changed files with 60 additions and 75 deletions

View File

@ -750,7 +750,7 @@ IDS_MNU_VIEWPORT=Sichtfenster
IDS_MSG_ACTIVE=Aktiver
IDS_MSG_ALLOWSYOUTOJOINADIFFERENT=Erlaubt die Auswahl eines anderen Teams.
IDS_MSG_ALLPLAYERDATA=Sollen die aktuellen Werte für alle Spieler übernommen werden?
IDS_MSG_ANUPDATETOVERSIONISAVAILA=Ein Update auf Version %s ist verfügbar. Soll das Update heruntergeladen und installiert werden?
IDS_MSG_ANUPDATETOVERSIONISAVAILA=Ein neues Update ist verfügbar. Soll das Update heruntergeladen und installiert werden?
IDS_MSG_BACKTOPLAYERDLG=Zurück zur Spielerauswahl.
IDS_MSG_BLITOFFSET=Blit offset
IDS_MSG_BLITOFFSET_DESC=Gibt das für jede Zeichenoperation benutze Offset zwecks hochgenauer Pixeloperationen an. Wert erhöhen, wenn schwarze Linien unter/rechts von Grafiken auftauchen. Verringern, wenn Linien über/links von Grafiken auftauchen.

View File

@ -750,7 +750,7 @@ IDS_MNU_VIEWPORT=Viewport
IDS_MSG_ACTIVE=Active
IDS_MSG_ALLOWSYOUTOJOINADIFFERENT=Allows you to join a different team.
IDS_MSG_ALLPLAYERDATA=Use current values for all players?
IDS_MSG_ANUPDATETOVERSIONISAVAILA=An update to version %s is available. Do you want to download and install this update?
IDS_MSG_ANUPDATETOVERSIONISAVAILA=A new update is available. Do you want to download and install this update?
IDS_MSG_BACKTOPLAYERDLG=Back to player selection.
IDS_MSG_BLITOFFSET=Blit offset
IDS_MSG_BLITOFFSET_DESC=Determines the offset used for every drawing operation to ensure exact pixels are drawn. Increase this value if you see black borders below/to the right of some graphics. Deacrease it if you see borders above/to the left of some graphics.

View File

@ -86,7 +86,6 @@ void C4ConfigGeneral::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(SaveGameFolder, "SaveGameFolder", "Savegames.c4f", false, true));
pComp->Value(mkNamingAdapt(SaveDemoFolder, "SaveDemoFolder", "Records.c4f", false, true ));
pComp->Value(mkNamingAdapt(s(MissionAccess), "MissionAccess", "", false, true));
pComp->Value(mkNamingAdapt(s(UpdateURL), "UpdateURL", "openclonk.org/builds/updates/from_%s_%d_%d_%d_%d.c4u"));
pComp->Value(mkNamingAdapt(FPS, "FPS", 0 ));
pComp->Value(mkNamingAdapt(Record, "Record", 0 ));
pComp->Value(mkNamingAdapt(DefRec, "DefRec", 0 ));

View File

@ -52,7 +52,6 @@ public:
StdStrBuf SaveDemoFolder;
StdStrBuf ScreenshotFolder;
char MissionAccess[CFG_MaxString+1];
char UpdateURL[CFG_MaxString+1];
int32_t FPS;
int32_t Record;
int32_t DefRec;

View File

@ -270,9 +270,9 @@ bool C4StartupNetListEntry::OnReference()
if (eQueryType == NRQT_Masterserver)
{
// masterserver is official: So check version
C4GameVersion MasterVersion;
if (pRefClient->GetMasterVersion(&MasterVersion))
pNetDlg->CheckVersionUpdate(MasterVersion);
StdStrBuf updURL;
if (pRefClient->GetUpdateURL(&updURL))
pNetDlg->CheckVersionUpdate(updURL.getData());
// masterserver: schedule next query
sInfoText[1].Format(LoadResStr("IDS_NET_INFOGAMES"), (int) iNewRefCount);
SetTimeout(TT_Masterserver);
@ -845,7 +845,7 @@ void C4StartupNetDlg::OnBtnRecord(C4GUI::Control *btn)
void C4StartupNetDlg::OnBtnUpdate(C4GUI::Control *btn)
{
// do update
if (!C4UpdateDlg::DoUpdate(UpdateVersion, GetScreen()))
if (!C4UpdateDlg::DoUpdate(UpdateURL.getData(), GetScreen()))
{
GetScreen()->ShowMessage(LoadResStr("IDS_MSG_UPDATEFAILED"), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::Ico_Ex_Update);
}
@ -865,7 +865,9 @@ void C4StartupNetDlg::UpdateMasterserver()
else
{
pMasterserverClient = new C4StartupNetListEntry(pGameSelList, NULL, this);
pMasterserverClient->SetRefQuery(Config.Network.GetLeagueServerAddress(), C4StartupNetListEntry::NRQT_Masterserver);
StdStrBuf strVersion; strVersion.Format("%d.%d.%d.%d", C4XVER1, C4XVER2, C4XVER3, C4XVER4);
StdStrBuf strQuery; strQuery.Format("%s?version=%s&platform=%s&action=version", Config.Network.GetLeagueServerAddress(), strVersion.getData(), C4_OS);
pMasterserverClient->SetRefQuery(strQuery.getData(), C4StartupNetListEntry::NRQT_Masterserver);
}
}
@ -1194,12 +1196,12 @@ void C4StartupNetDlg::OnReferenceEntryAdd(C4StartupNetListEntry *pEntry)
pEntry->UpdateCollapsed(true);
}
void C4StartupNetDlg::CheckVersionUpdate(const C4GameVersion &rNewVer)
void C4StartupNetDlg::CheckVersionUpdate(const char *szUpdateURL)
{
// Is a valid update
if (C4UpdateDlg::IsValidUpdate(rNewVer))
if (C4UpdateDlg::IsValidUpdate(szUpdateURL))
{
UpdateVersion = rNewVer;
UpdateURL = szUpdateURL;
btnUpdate->SetVisibility(true);
}
// Otherwise: no update available

View File

@ -146,7 +146,7 @@ private:
C4StartupNetListEntry *pMasterserverClient; // set if masterserver query is enabled: Checks clonk.de for new games
bool fIsCollapsed; // set if the number of games in the list requires them to be displayed in a condensed format
bool fUpdatingList; // set during list update - prevent selection update calls
C4GameVersion UpdateVersion; // set if update button is visible: Version to be updated to
StdCopyStrBuf UpdateURL; // set if update button is visible: Version to be updated to
C4Network2IODiscoverClient DiscoverClient; // disocver client to search for local hosts
int iGameDiscoverInterval; // next time until a game discovery is started
@ -209,7 +209,7 @@ public:
void OnSec1Timer(); // idle proc: update list
void CheckVersionUpdate(const C4GameVersion &rNewVer); // make an update button visible if the passed verionis an update to this version
void CheckVersionUpdate(const char *szUpdateURL); // make an update button visible if the passed url is a valid update url
};

View File

@ -160,23 +160,20 @@ static bool IsWindowsWithUAC()
return false;
}
bool C4UpdateDlg::DoUpdate(const C4GameVersion &rUpdateVersion, C4GUI::Screen *pScreen)
bool C4UpdateDlg::DoUpdate(const char *szUpdateURL, C4GUI::Screen *pScreen)
{
StdStrBuf strUpdateURL;
// Double check for valid update
if (!IsValidUpdate(rUpdateVersion)) return false;
strUpdateURL.Format(Config.General.UpdateURL, C4_OS, C4XVER1, C4XVER2, C4XVER3, C4XVER4);
// Determine local filename for update group
StdStrBuf strLocalFilename; strLocalFilename.Copy(GetFilename(strUpdateURL.getData()));
strLocalFilename.Copy(Config.AtTempPath(strLocalFilename.getData()));
StdCopyStrBuf strLocalFilename(Config.AtTempPath(GetFilename(szUpdateURL)));
StdCopyStrBuf strRemoteURL(szUpdateURL);
// Download update group
if (!C4DownloadDlg::DownloadFile(LoadResStr("IDS_TYPE_UPDATE"), pScreen, strUpdateURL.getData(), strLocalFilename.getData(), LoadResStr("IDS_MSG_UPDATENOTAVAILABLE")))
if (!C4DownloadDlg::DownloadFile(LoadResStr("IDS_TYPE_UPDATE"), pScreen, strRemoteURL.getData(), strLocalFilename.getData(), LoadResStr("IDS_MSG_UPDATENOTAVAILABLE")))
{
// Download failed, open browser so the user can download a full package
OpenURL("http://wiki.openclonk.org/w/Download");
// return success, because error message has already been shown
return true;
}
// Apply downloaded update
return ApplyUpdate(strLocalFilename.getData(), true, pScreen);
}
@ -255,9 +252,9 @@ bool C4UpdateDlg::ApplyUpdate(const char *strUpdateFile, bool fDeleteUpdate, C4G
return succeeded;
}
bool C4UpdateDlg::IsValidUpdate(const C4GameVersion &rNewVer)
bool C4UpdateDlg::IsValidUpdate(const char *szUpdateURL)
{
return CompareVersion(rNewVer.iVer[0], rNewVer.iVer[1], rNewVer.iVer[2], rNewVer.iVer[3], C4XVER1, C4XVER2, C4XVER3, C4XVER4) > 0;
return szUpdateURL != NULL && strlen(szUpdateURL) > 0;
}
bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
@ -268,8 +265,8 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
return false;
// Store the time of this update check (whether it's automatic or not or successful or not)
Config.Network.LastUpdateTime = time(NULL);
// Get current update version from server
C4GameVersion UpdateVersion;
// Get current update url from server
StdStrBuf UpdateURL;
C4GUI::Dialog *pWaitDlg = NULL;
if (C4GUI::IsGUIValid())
{
@ -277,24 +274,25 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
pWaitDlg->SetDelOnClose(false);
pScreen->ShowDialog(pWaitDlg, false);
}
C4Network2VersionInfoClient VerChecker;
C4Network2UpdateClient UpdateClient;
bool fSuccess = false, fAborted = false;
StdStrBuf strQuery; strQuery.Format("%s?action=version", Config.Network.UpdateServerAddress);
if (VerChecker.Init() && VerChecker.SetServer(strQuery.getData()) && VerChecker.QueryVersion())
StdStrBuf strVersion; strVersion.Format("%d.%d.%d.%d", C4XVER1, C4XVER2, C4XVER3, C4XVER4);
StdStrBuf strQuery; strQuery.Format("%s?version=%s&platform=%s&action=version", Config.Network.UpdateServerAddress, strVersion.getData(), C4_OS);
if (UpdateClient.Init() && UpdateClient.SetServer(strQuery.getData()) && UpdateClient.QueryUpdateURL())
{
VerChecker.SetNotify(&Application.InteractiveThread);
Application.InteractiveThread.AddProc(&VerChecker);
UpdateClient.SetNotify(&Application.InteractiveThread);
Application.InteractiveThread.AddProc(&UpdateClient);
// wait for version check to terminate
while (VerChecker.isBusy())
while (UpdateClient.isBusy())
{
// wait, check for program abort
if (!Application.ScheduleProcs()) { fAborted = true; break; }
// check for dialog close
if (pWaitDlg) if (!C4GUI::IsGUIValid() || !pWaitDlg->IsShown()) { fAborted = true; break; }
}
if (!fAborted) fSuccess = VerChecker.GetVersion(&UpdateVersion);
Application.InteractiveThread.RemoveProc(&VerChecker);
VerChecker.SetNotify(NULL);
if (!fAborted) fSuccess = UpdateClient.GetUpdateURL(&UpdateURL);
Application.InteractiveThread.RemoveProc(&UpdateClient);
UpdateClient.SetNotify(NULL);
}
if (C4GUI::IsGUIValid() && pWaitDlg) delete pWaitDlg;
// User abort
@ -306,7 +304,7 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
if (!fSuccess)
{
StdStrBuf sError; sError.Copy(LoadResStr("IDS_MSG_UPDATEFAILED"));
const char *szErrMsg = VerChecker.GetError();
const char *szErrMsg = UpdateClient.GetError();
if (szErrMsg)
{
sError.Append(": ");
@ -316,13 +314,12 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
return false;
}
// Applicable update available
if (C4UpdateDlg::IsValidUpdate(UpdateVersion))
if (C4UpdateDlg::IsValidUpdate(UpdateURL.getData()))
{
// Prompt user, then apply update
StdStrBuf strMsg; strMsg.Format(LoadResStr("IDS_MSG_ANUPDATETOVERSIONISAVAILA"), UpdateVersion.GetString().getData());
if (pScreen->ShowMessageModal(strMsg.getData(), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::MessageDialog::btnYesNo, C4GUI::Ico_Ex_Update))
if (pScreen->ShowMessageModal(LoadResStr("IDS_MSG_ANUPDATETOVERSIONISAVAILA"), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::MessageDialog::btnYesNo, C4GUI::Ico_Ex_Update))
{
if (!DoUpdate(UpdateVersion, pScreen))
if (!DoUpdate(UpdateURL.getData(), pScreen))
pScreen->ShowMessage(LoadResStr("IDS_MSG_UPDATEFAILED"), LoadResStr("IDS_TYPE_UPDATE"), C4GUI::Ico_Ex_Update);
else
return true;
@ -340,26 +337,23 @@ bool C4UpdateDlg::CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic)
}
// *** C4Network2VersionInfoClient
// *** C4Network2UpdateClient
bool C4Network2VersionInfoClient::QueryVersion()
bool C4Network2UpdateClient::QueryUpdateURL()
{
// Perform an Query query
return Query(NULL, false);
}
bool C4Network2VersionInfoClient::GetVersion(C4GameVersion *piVerOut)
bool C4Network2UpdateClient::GetUpdateURL(StdStrBuf *pUpdateURL)
{
// Sanity check
if (isBusy() || !isSuccess()) return false;
// Parse response
piVerOut->Set("", 0,0,0,0);
try
{
CompileFromBuf<StdCompilerINIRead>(mkNamingAdapt(
mkNamingAdapt(
mkParAdapt(*piVerOut, false),
"Version"),
mkNamingAdapt(*pUpdateURL,"UpdateURL"),
C4ENGINENAME), ResultString);
}
catch (StdCompiler::Exception *pExc)
@ -367,12 +361,6 @@ bool C4Network2VersionInfoClient::GetVersion(C4GameVersion *piVerOut)
SetError(pExc->Msg.getData());
return false;
}
// validate version
if (!piVerOut->iVer[0])
{
SetError(LoadResStr("IDS_ERR_INVALIDREPLYFROMSERVER"));
return false;
}
// done; version OK!
return true;
}

View File

@ -48,24 +48,23 @@ public:
void Write(const char *szText);
public:
static bool IsValidUpdate(const C4GameVersion &rNewVer); // Returns whether we can update to the specified version
static bool IsValidUpdate(const char *szUpdateURL); // Returns whether we can update to the specified version
static bool CheckForUpdates(C4GUI::Screen *pScreen, bool fAutomatic = false); // Checks for available updates and prompts the user whether to apply
static bool DoUpdate(const C4GameVersion &rUpdateVersion, C4GUI::Screen *pScreen); // Static funtion for downloading and applying updates
static bool DoUpdate(const char *szUpdateURL, C4GUI::Screen *pScreen); // Static funtion for downloading and applying updates
static bool ApplyUpdate(const char *strUpdateFile, bool fDeleteUpdate, C4GUI::Screen *pScreen); // Static funtion for applying updates
};
// Loads current version string (mini-HTTP-client)
class C4Network2VersionInfoClient : public C4Network2HTTPClient
// Loads current update url string (mini-HTTP-client)
class C4Network2UpdateClient : public C4Network2HTTPClient
{
C4GameVersion Version;
protected:
virtual int32_t GetDefaultPort() { return C4NetStdPortHTTP; }
public:
C4Network2VersionInfoClient() : C4Network2HTTPClient() {}
C4Network2UpdateClient() : C4Network2HTTPClient() {}
bool QueryVersion();
bool GetVersion(C4GameVersion *pSaveToVer);
bool QueryUpdateURL();
bool GetUpdateURL(StdStrBuf *pUpdateURL);
};
#endif // INC_C4UpdateDialogs

View File

@ -551,7 +551,7 @@ bool C4Network2HTTPClient::SetServer(const char *szServerAddress)
bool C4Network2RefClient::QueryReferences()
{
// invalidate version
fVerSet = false;
fUrlSet = false;
// Perform an Query query
return Query(NULL, false);
}
@ -561,8 +561,7 @@ bool C4Network2RefClient::GetReferences(C4Network2Reference **&rpReferences, int
// Sanity check
if (isBusy() || !isSuccess()) return false;
// Parse response
MasterVersion.Set("", 0,0,0,0);
fVerSet = false;
fUrlSet = false;
// local update test
try
{
@ -572,9 +571,7 @@ bool C4Network2RefClient::GetReferences(C4Network2Reference **&rpReferences, int
Comp.Begin();
// get current version
Comp.Value(mkNamingAdapt(
mkNamingAdapt(
mkParAdapt(MasterVersion, false),
"Version"),
mkNamingAdapt(UpdateURL,"UpdateURL"),
C4ENGINENAME));
// Read reference count
Comp.Value(mkNamingCountAdapt(rRefCount, "Reference"));
@ -597,17 +594,17 @@ bool C4Network2RefClient::GetReferences(C4Network2Reference **&rpReferences, int
for (int i = 0; i < rRefCount; i++)
rpReferences[i]->SetSourceIP(getServerAddress().sin_addr);
// validate version
if (MasterVersion.iVer[0]) fVerSet = true;
if (UpdateURL.getData() != NULL) fUrlSet = true;
// Done
ResetError();
return true;
}
bool C4Network2RefClient::GetMasterVersion(C4GameVersion *piVerOut)
bool C4Network2RefClient::GetUpdateURL(StdStrBuf *pUpdateURL)
{
// call only after GetReferences
if (!fVerSet) return false;
*piVerOut = MasterVersion;
if (!fUrlSet) return false;
*pUpdateURL = UpdateURL;
return true;
}

View File

@ -191,16 +191,17 @@ private:
// Loads references (mini-HTTP-client)
class C4Network2RefClient : public C4Network2HTTPClient
{
C4GameVersion MasterVersion;
bool fVerSet;
private:
StdStrBuf UpdateURL;
bool fUrlSet;
protected:
virtual int32_t GetDefaultPort() { return C4NetStdPortRefServer; }
public:
C4Network2RefClient() : C4Network2HTTPClient(), fVerSet(false) {}
C4Network2RefClient() : C4Network2HTTPClient(), fUrlSet(false) {}
bool QueryReferences();
bool GetReferences(C4Network2Reference **&rpReferences, int32_t &rRefCount);
bool GetMasterVersion(C4GameVersion *pSaveToVer); // call only after GetReferences
bool GetUpdateURL(StdStrBuf *pUpdateURL); // call only after GetReferences
};
#endif // C4NETWORK2REFERENCE_H