Planeshift
updaterconfig.h
Go to the documentation of this file.
1 /*
2  * updaterconfig.h - Author: Mike Gist
3  *
4  * Copyright (C) 2007 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef __UPDATERCONFIG_H__
21 #define __UPDATERCONFIG_H__
22 
23 #include <csutil/csstring.h>
24 #include <cstool/initapp.h>
25 #include <csutil/cfgmgr.h>
26 #include <csutil/cfgfile.h>
27 #include <iutil/document.h>
28 
29 #include "util/singleton.h"
30 
31 #define CONFIG_FILENAME "/this/pslaunch.cfg"
32 #define UPDATERINFO_FILENAME "/planeshift/userdata/updaterinfo.xml"
33 #define UPDATERINFO_CURRENT_FILENAME "/this/updaterinfo.xml"
34 #define INTEGRITY_ZIPNAME "/this/integrity.zip"
35 #define SERVERS_FILENAME "/planeshift/userdata/updateservers.xml"
36 #define SERVERS_CURRENT_FILENAME "/this/updateservers.xml"
37 #define UPDATE_CACHE_DIR "/planeshift/userdata/updatecache"
38 #define FALLBACK_SERVER "http://www.planeshift.it/"
39 
40 
41 class Mirror : public csRefCount
42 {
43 public:
44  Mirror():
45  id(0), repair(false)
46  {}
47 
48  ~Mirror() {}
49 
50  /* Return mirror ID */
51  unsigned int GetID() const { return id; }
52 
53  /* Return mirror name */
54  const char* GetName() const { return name; }
55 
56  /* Return mirror URL */
57  const char* GetBaseURL() const { return baseURL; }
58 
62  bool IsRepair() const { return repair; }
63 
64  /* Set mirror URL */
65  void SetBaseURL(csString url) { baseURL = url; }
66 
67  void SetID(uint id) { this->id = id; }
68  void SetName(const char* name) { this->name = name; }
69  void SetBaseURL(const char* baseURL) { this->baseURL = baseURL; }
70 
74  void SetIsRepair(const bool repair) { this->repair = repair; }
75 
76 protected:
77  /* Mirror ID */
78  uint id;
79 
80  /* Mirror name */
81  csString name;
82 
83  /* URL of the mirror (including update dir) */
84  csString baseURL;
85 
87  bool repair;
88 };
89 
90 class ClientVersion : public csRefCount
91 {
92 public:
95 
96  /* Get client update file name */
97  const char* GetName() const { return name; }
98 
99  /* Get platform specific update file md5sum */
100  const char* GetMD5Sum() const { return md5sum; }
101 
102  /* Get generic update file md5sum */
103  const char* GetGenericMD5Sum() const { return genericmd5sum; }
104 
105  void SetName(const char* name) { this->name = name; }
106  void SetMD5Sum(const char* md5sum) { this->md5sum = md5sum; }
107  void SetGenericMD5Sum(const char* genericmd5sum) { this->genericmd5sum = genericmd5sum; }
108 
109 private:
110  /* Client update file name */
111  csString name;
112 
113  /* md5sum of the platform specific update file */
114  csString md5sum;
115 
116  /* md5sum of the generic update file */
117  csString genericmd5sum;
118 };
119 
120 struct Proxy
121 {
122  /* Hostname of the proxy */
123  csString host;
124  /* Port */
125  uint port;
126 };
127 
131 class Config
132 {
133 public:
134  Config();
135 
136  Mirror* GetMirror(uint mirrorNumber);
137  csArray<Mirror> GetRepairMirrors();
138 
142  csRefArray<Mirror>& GetMirrors() { return mirrors; }
143 
147  csRefArray<ClientVersion>& GetClientVersions() { return clientVersions; }
148 
161  bool LoadMirrors(iDocumentNode* node);
162 
166  bool Initialize(iDocumentNode* node);
167 
171  const char* GetPlatform() const;
172 
173  const char* GetGeneric() const { return "generic"; }
174 
178  float GetUpdaterVersionLatest() const { return updaterVersionLatest; }
179 
184  unsigned int GetUpdaterVersionLatestMajor() const { return updaterVersionLatestMajor; }
185 
190  unsigned int GetUpdaterVersionLatestMinor() const { return updaterVersionLatestMinor; }
191 
193  const char* GetUpdaterVersionLatestMD5() const { return updaterVersionLatestMD5; }
194 
196  bool IsActive() const { return active; }
197 
198 private:
200  float updaterVersionLatest;
201 
203  unsigned int updaterVersionLatestMajor;
204 
206  unsigned int updaterVersionLatestMinor;
207 
208  /* Latest version md5sum */
209  csString updaterVersionLatestMD5;
210 
211  /* List of mirrors */
212  csRefArray<Mirror> mirrors;
213 
214  /* List of client versions */
215  csRefArray<ClientVersion> clientVersions;
216 
217  /* Whether the updater mirror is active */
218  bool active;
219 };
220 
221 class UpdaterConfig : public Singleton<UpdaterConfig>
222 {
223 public:
224  UpdaterConfig(csStringArray& args, iObjectRegistry* _object_reg, iVFS* _vfs);
225  ~UpdaterConfig();
226 
230  int IsSelfUpdating() const { return selfUpdating; }
231 
235  bool CheckForIntegrity() const { return checkIntegrity; }
236 
240  bool SwitchMirror() const { return switchMirror; }
241 
245  Proxy GetProxy() { return proxy; }
246 
250  Config* GetCurrentConfig() const { return currentCon; }
251 
255  Config* GetNewConfig() const { return newCon; }
256 
260  bool WasCleanUpdate() const { return cleanUpdate; }
261 
265  bool UpdatePlatform() const { return updatePlatform; }
266 
270  bool RepairingInZip() const { return repairInZip; }
271 
275  bool KeepingRepaired() const { return keepRepaired; }
276 
280  bool RepairFailed() const { return repairFailed; }
281 
286  bool IsUpdateEnabled() const { return updateEnabled; }
287 
291  iConfigFile* GetConfigFile() const { return configFile; }
292 
293  void SetSelfUpdating(bool t) { selfUpdating = t ? 1 : 0; }
294 
298  const char* GetNewMirrorAddress() const { return newMirror; }
299 
300 private:
301 
302  /* Holds stage of self updating. */
303  int selfUpdating;
304 
305  /* Holds whether or not the last update was successful. */
306  bool cleanUpdate;
307 
308  /* True if we want the updater to update platform specific files. */
309  bool updatePlatform;
310 
311  /* True if we're being asked to check the integrity of the install. */
312  bool checkIntegrity;
313 
314  /* True if we're being asked to switch the updater mirror. */
315  bool switchMirror;
316 
317  /* True if we want to do in-zip repairs. */
318  bool repairInZip;
319 
320  /* True if we want a repair to keep the old file (*.bak). */
321  bool keepRepaired;
322 
323  /* True if we want to perform a repair when files fail after an update. */
324  bool repairFailed;
325 
326  /* True if we want to use the updater. This could be turned of when third-party
327  * updater is used
328  */
329  bool updateEnabled;
330 
331  /* Address of new mirror. */
332  csString newMirror;
333 
334  /* VFS, Object Registry */
335  csRef<iVFS> vfs;
336  static iObjectRegistry* object_reg;
337 
338  /* Config Manager */
339  csRef<iConfigManager> configManager;
340 
341  /* Config File */
342  csRef<iConfigFile> configFile;
343 
344  /* Proxy server */
345  Proxy proxy;
346 
347  /* Current Config */
348  Config* currentCon;
349 
350  /* New Config */
351  Config* newCon;
352 };
353 
354 #endif // __UPDATERCONFIG_H__
const char * GetBaseURL() const
Definition: updaterconfig.h:57
bool IsRepair() const
Returns if the server is a server supporting repair.
Definition: updaterconfig.h:62
Proxy GetProxy()
Returns the proxy struct.
csString baseURL
Definition: updaterconfig.h:84
csString host
const char * GetNewMirrorAddress() const
Returns the new mirror address.
void SetName(const char *name)
Definition: updaterconfig.h:68
iConfigFile * GetConfigFile() const
Returns the configfile for the app.
bool WasCleanUpdate() const
Returns true if the last update was successful.
csRefArray< ClientVersion > & GetClientVersions()
Get clientVersions list.
const char * GetName() const
Definition: updaterconfig.h:54
void SetGenericMD5Sum(const char *genericmd5sum)
bool IsUpdateEnabled() const
True if we want to use the updater.
uint port
Holds an updater configuration file.
csString name
Definition: updaterconfig.h:81
bool SwitchMirror() const
Returns true if a mirror switch needs to be done.
unsigned int GetUpdaterVersionLatestMajor() const
Get latest updater major version.
const char * GetGenericMD5Sum() const
void SetName(const char *name)
bool RepairFailed() const
Returns true if we want to perform a repair when files fail after an update.
bool CheckForIntegrity() const
Returns true if a integrity check (repair) needs to be done.
void SetBaseURL(const char *baseURL)
Definition: updaterconfig.h:69
void SetMD5Sum(const char *md5sum)
bool repair
Holds if this is a repair server.
Definition: updaterconfig.h:87
const char * GetMD5Sum() const
const char * GetName() const
Definition: updaterconfig.h:97
bool KeepingRepaired() const
Returns true if we want a repair to keep the old file (*.bak).
uint id
Definition: updaterconfig.h:78
const char * GetGeneric() const
void void Initialize(iObjectRegistry *object_reg)
void SetBaseURL(csString url)
Definition: updaterconfig.h:65
float GetUpdaterVersionLatest() const
Get latest updater version.
unsigned int GetUpdaterVersionLatestMinor() const
Get latest updater minor version.
bool IsActive() const
Get whether the updater mirror is active.
const char * GetUpdaterVersionLatestMD5() const
Get latest updater version md5sum.
void SetIsRepair(const bool repair)
Sets if the current server supports repair.
Definition: updaterconfig.h:74
bool RepairingInZip() const
Returns true if we want to do in-zip repairs.
int IsSelfUpdating() const
Returns true if the updater is self updating.
bool UpdatePlatform() const
Returns true if we want the updater to update platform specific files.
void SetSelfUpdating(bool t)
unsigned int GetID() const
Definition: updaterconfig.h:51
Config * GetCurrentConfig() const
Returns the current/old config from updaterinfo.xml.
Config * GetNewConfig() const
Returns the new/downloaded config from updaterinfo.xml.
csRefArray< Mirror > & GetMirrors()
Get mirrors.
void SetID(uint id)
Definition: updaterconfig.h:67