Planeshift

updaterconfig.h

Go to the documentation of this file.
00001 /*
00002  * updaterconfig.h - Author: Mike Gist
00003  *
00004  * Copyright (C) 2007 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef __UPDATERCONFIG_H__
00021 #define __UPDATERCONFIG_H__
00022 
00023 #include <csutil/csstring.h>
00024 #include <cstool/initapp.h>
00025 #include <csutil/cfgmgr.h>
00026 #include <csutil/cfgfile.h>
00027 #include <iutil/document.h>
00028 
00029 #include "util/singleton.h"
00030 
00031 #define CONFIG_FILENAME "/this/pslaunch.cfg"
00032 #define UPDATERINFO_FILENAME "/planeshift/userdata/updaterinfo.xml"
00033 #define UPDATERINFO_CURRENT_FILENAME "/this/updaterinfo.xml"
00034 #define INTEGRITY_ZIPNAME "/this/integrity.zip"
00035 #define SERVERS_FILENAME "/planeshift/userdata/updateservers.xml"
00036 #define SERVERS_CURRENT_FILENAME "/this/updateservers.xml"
00037 #define UPDATE_CACHE_DIR "/planeshift/userdata/updatecache"
00038 #define FALLBACK_SERVER "http://www.planeshift.it/"
00039 
00040 
00041 class Mirror : public csRefCount
00042 {
00043 public:
00044     Mirror():
00045     id(0),  repair(false)
00046     {}
00047     
00048     ~Mirror() {}
00049 
00050     /* Return mirror ID */
00051     unsigned int GetID() const { return id; }
00052 
00053     /* Return mirror name */
00054     const char* GetName() const { return name; }
00055 
00056     /* Return mirror URL */
00057     const char* GetBaseURL() const { return baseURL; }
00058 
00062     bool IsRepair() const { return repair; }
00063 
00064     /* Set mirror URL */
00065     void SetBaseURL(csString url) { baseURL = url; }
00066 
00067     void SetID(uint id) { this->id = id; }
00068     void SetName(const char* name) { this->name = name; }
00069     void SetBaseURL(const char* baseURL) { this->baseURL = baseURL; }
00070 
00074     void SetIsRepair(const bool repair) { this->repair = repair; }
00075 
00076 protected:
00077     /* Mirror ID */
00078     uint id;
00079 
00080     /* Mirror name */
00081     csString name;
00082 
00083     /* URL of the mirror (including update dir) */
00084     csString baseURL;
00085 
00087     bool repair;
00088 };
00089 
00090 class ClientVersion : public csRefCount
00091 {
00092 public:
00093     ClientVersion() {}
00094     ~ClientVersion() {}
00095 
00096     /* Get client update file name */
00097     const char* GetName() const { return name; }
00098 
00099     /* Get platform specific update file md5sum */
00100     const char* GetMD5Sum() const { return md5sum; }
00101 
00102     /* Get generic update file md5sum */
00103     const char* GetGenericMD5Sum() const { return genericmd5sum; }
00104 
00105     void SetName(const char* name) { this->name = name; }
00106     void SetMD5Sum(const char* md5sum) { this->md5sum = md5sum; }
00107     void SetGenericMD5Sum(const char* genericmd5sum) { this->genericmd5sum = genericmd5sum; }
00108 
00109 private:
00110     /* Client update file name */
00111     csString name;
00112 
00113     /* md5sum of the platform specific update file */
00114     csString md5sum;
00115 
00116     /* md5sum of the generic update file */
00117     csString genericmd5sum;
00118 };
00119 
00120 struct Proxy
00121 {
00122     /* Hostname of the proxy */
00123     csString host;
00124     /* Port */
00125     uint port;
00126 };
00127 
00131 class Config
00132 {
00133 public:
00134     Config();
00135 
00136     Mirror* GetMirror(uint mirrorNumber);
00137     csArray<Mirror> GetRepairMirrors();
00138 
00142     csRefArray<Mirror>& GetMirrors() { return mirrors; }
00143     
00147     csRefArray<ClientVersion>& GetClientVersions() { return clientVersions; }
00148 
00161     bool LoadMirrors(iDocumentNode* node);
00162 
00166     bool Initialize(iDocumentNode* node);
00167 
00171     const char* GetPlatform() const;
00172 
00173     const char* GetGeneric() const { return "generic"; }
00174 
00178     float GetUpdaterVersionLatest() const { return updaterVersionLatest; }
00179 
00184     unsigned int GetUpdaterVersionLatestMajor() const { return updaterVersionLatestMajor; }
00185 
00190     unsigned int GetUpdaterVersionLatestMinor() const { return updaterVersionLatestMinor; }
00191 
00193     const char* GetUpdaterVersionLatestMD5() const { return updaterVersionLatestMD5; }
00194 
00196     bool IsActive() const { return active; }
00197 
00198 private:
00200     float updaterVersionLatest;
00201 
00203     unsigned int updaterVersionLatestMajor;
00204 
00206     unsigned int updaterVersionLatestMinor;
00207 
00208     /* Latest version md5sum */
00209     csString updaterVersionLatestMD5;
00210 
00211     /* List of mirrors */
00212     csRefArray<Mirror> mirrors;
00213 
00214     /* List of client versions */
00215     csRefArray<ClientVersion> clientVersions;
00216 
00217     /* Whether the updater mirror is active */
00218     bool active;
00219 };
00220 
00221 class UpdaterConfig : public Singleton<UpdaterConfig>
00222 {
00223 public:
00224     UpdaterConfig(csStringArray& args, iObjectRegistry* _object_reg, iVFS* _vfs);
00225     ~UpdaterConfig();
00226 
00230     int IsSelfUpdating() const { return selfUpdating; }
00231 
00235     bool CheckForIntegrity() const { return checkIntegrity; }
00236 
00240     bool SwitchMirror() const { return switchMirror; }
00241 
00245     Proxy GetProxy() { return proxy; }
00246 
00250     Config* GetCurrentConfig() const { return currentCon; }
00251 
00255     Config* GetNewConfig() const { return newCon; }
00256 
00260     bool WasCleanUpdate() const { return cleanUpdate; }
00261 
00265     bool UpdatePlatform() const { return updatePlatform; }
00266 
00270     bool RepairingInZip() const { return repairInZip; }
00271 
00275     bool KeepingRepaired() const { return keepRepaired; }
00276 
00280     bool RepairFailed() const { return repairFailed; }
00281 
00286     bool IsUpdateEnabled() const { return updateEnabled; }
00287 
00291     iConfigFile* GetConfigFile() const { return configFile; }
00292 
00293     void SetSelfUpdating(bool t) { selfUpdating = t ? 1 : 0; }
00294 
00298     const char* GetNewMirrorAddress() const { return newMirror; }
00299 
00300 private:
00301 
00302     /* Holds stage of self updating. */
00303     int selfUpdating;
00304 
00305     /* Holds whether or not the last update was successful. */
00306     bool cleanUpdate;
00307 
00308     /* True if we want the updater to update platform specific files. */
00309     bool updatePlatform;
00310 
00311     /* True if we're being asked to check the integrity of the install. */
00312     bool checkIntegrity;
00313 
00314     /* True if we're being asked to switch the updater mirror. */
00315     bool switchMirror;
00316 
00317     /* True if we want to do in-zip repairs. */
00318     bool repairInZip;
00319 
00320     /* True if we want a repair to keep the old file (*.bak). */
00321     bool keepRepaired;
00322 
00323     /* True if we want to perform a repair when files fail after an update. */
00324     bool repairFailed;
00325 
00326     /* True if we want to use the updater. This could be turned of when third-party
00327      * updater is used
00328      */
00329     bool updateEnabled;
00330 
00331     /* Address of new mirror. */
00332     csString newMirror;
00333 
00334     /* VFS, Object Registry */
00335     csRef<iVFS> vfs;
00336     static iObjectRegistry* object_reg;
00337 
00338     /* Config Manager */
00339     csRef<iConfigManager> configManager;
00340 
00341     /* Config File */
00342     csRef<iConfigFile> configFile;
00343 
00344     /* Proxy server */
00345     Proxy proxy;
00346 
00347     /* Current Config */
00348     Config* currentCon;
00349 
00350     /* New Config */
00351     Config* newCon;
00352 };
00353 
00354 #endif // __UPDATERCONFIG_H__