From: <mg...@us...> - 2008-02-07 21:57:12
|
Revision: 770 http://planeshift.svn.sourceforge.net/planeshift/?rev=770&view=rev Author: mgist Date: 2008-02-07 13:57:06 -0800 (Thu, 07 Feb 2008) Log Message: ----------- - Updater fixes. Modified Paths: -------------- trunk/docs/history.txt trunk/src/common/util/fileutil.h trunk/src/pslaunch/binarypatch.cpp trunk/src/pslaunch/download.cpp trunk/src/pslaunch/updaterconfig.cpp trunk/src/pslaunch/updaterconfig.h trunk/src/pslaunch/updaterengine.cpp trunk/src/pslaunch/updaterengine.h Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/docs/history.txt 2008-02-07 21:57:06 UTC (rev 770) @@ -1,3 +1,6 @@ +*** 2008-02-07 by Mike Gist +- Updater fixes. + *** 2008-02-07 by Anders Reggestad - Use same function to create new npc's from both adminmanager and entitymanager instad of having two function doing the same stuff. Modified: trunk/src/common/util/fileutil.h =================================================================== --- trunk/src/common/util/fileutil.h 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/common/util/fileutil.h 2008-02-07 21:57:06 UTC (rev 770) @@ -78,10 +78,10 @@ bool CopyFile(csString from, csString to, bool vfsPath, bool executable, bool silent = false); /* Moves a file */ - inline void MoveFile(csString from, csString to, bool vfsPath, bool executable) + inline void MoveFile(csString from, csString to, bool vfsPath, bool executable, bool silent = false) { - CopyFile(from, to, vfsPath, executable); - RemoveFile(from); + CopyFile(from, to, vfsPath, executable, silent); + RemoveFile(from, silent); } /* Returns true is the file at the specified path is executable. */ Modified: trunk/src/pslaunch/binarypatch.cpp =================================================================== --- trunk/src/pslaunch/binarypatch.cpp 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/binarypatch.cpp 2008-02-07 21:57:06 UTC (rev 770) @@ -144,11 +144,28 @@ bool PatchFile(const char *oldFilePath, const char *vcdiff, const char *newFilePath) { FILE* srcFile = fopen(oldFilePath, "rb"); + + if(!srcFile) + { + return false; + } + FILE* patchFile = fopen(vcdiff, "rb"); + + if(!patchFile) + { + fclose(srcFile); + return false; + } + FILE* outFile = fopen(newFilePath, "wb"); - if(!srcFile || !patchFile || !outFile) + if(!outFile) + { + fclose(patchFile); + fclose(srcFile); return false; + } int res = PatchFileHelper(srcFile, patchFile, outFile, 0x1000); Modified: trunk/src/pslaunch/download.cpp =================================================================== --- trunk/src/pslaunch/download.cpp 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/download.cpp 2008-02-07 21:57:06 UTC (rev 770) @@ -41,7 +41,7 @@ vfs = _vfs; config = _config; csRandomGen random = csRandomGen(); - startingMirrorID = random.Get((uint32)config->GetCurrentConfig()->GetMirrors()->GetSize()); + startingMirrorID = random.Get((uint32)config->GetCurrentConfig()->GetMirrors().GetSize()); activeMirrorID = startingMirrorID; } @@ -81,7 +81,7 @@ } else { - mirror = config->GetCurrentConfig()->GetMirrors()->Get(activeMirrorID); + mirror = config->GetCurrentConfig()->GetMirrors().Get(activeMirrorID); } while(mirror) @@ -186,11 +186,11 @@ { activeMirrorID++; // If we've reached the end, go back to the beginning of the list. - if(activeMirrorID == config->GetCurrentConfig()->GetMirrors()->GetSize()) + if(activeMirrorID == config->GetCurrentConfig()->GetMirrors().GetSize()) activeMirrorID = 0; // If true, we've reached our start point. Break the loop. if(activeMirrorID == startingMirrorID) - activeMirrorID = (uint32)config->GetCurrentConfig()->GetMirrors()->GetSize(); + activeMirrorID = (uint32)config->GetCurrentConfig()->GetMirrors().GetSize(); return activeMirrorID; } Modified: trunk/src/pslaunch/updaterconfig.cpp =================================================================== --- trunk/src/pslaunch/updaterconfig.cpp 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/updaterconfig.cpp 2008-02-07 21:57:06 UTC (rev 770) @@ -59,8 +59,8 @@ proxy.port = configFile->GetInt("Updater.Proxy.Port", 0); // Init xml config objects. - currentCon = new Config; - newCon = new Config; + currentCon = new Config(); + newCon = new Config(); } UpdaterConfig::~UpdaterConfig() @@ -120,10 +120,11 @@ if (!strcmp(mNode->GetValue(),"mirror")) { - Mirror* mirror = new Mirror; - mirror->id = mNode->GetAttributeValueAsInt("id"); - mirror->name = mNode->GetAttributeValue("name"); - mirror->baseURL = mNode->GetAttributeValue("url"); + csRef<Mirror> mirror; + mirror.AttachNew(new Mirror); + mirror->SetID(mNode->GetAttributeValueAsInt("id")); + mirror->SetName(mNode->GetAttributeValue("name")); + mirror->SetBaseURL(mNode->GetAttributeValue("url")); mirrors.Push(mirror); } } @@ -144,11 +145,12 @@ csRef<iDocumentNode> cNode = nodeItr->Next(); if(!strcmp(cNode->GetValue(),"version")) { - ClientVersion* cVersion = new ClientVersion; - cVersion->name = cNode->GetAttributeValue("name"); + csRef<ClientVersion> cVersion; + cVersion.AttachNew(new ClientVersion()); + cVersion->SetName(cNode->GetAttributeValue("name")); csString md5 = "md5"; - cVersion->md5sum = cNode->GetAttributeValue(md5.Append(GetPlatform())); - clientVersions.Push(cVersion); + cVersion->SetMD5Sum(cNode->GetAttributeValue(md5.Append(GetPlatform()))); + clientVersions.PushSmart(cVersion); } } } @@ -172,17 +174,3 @@ return mirror; } - -csPDelArray<Mirror>* Config::GetMirrors() -{ - csPDelArray<Mirror>* a; - a = &mirrors; - return a; -} - -csPDelArray<ClientVersion>* Config::GetClientVersions() -{ - csPDelArray<ClientVersion>* a; - a = &clientVersions; - return a; -} Modified: trunk/src/pslaunch/updaterconfig.h =================================================================== --- trunk/src/pslaunch/updaterconfig.h 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/updaterconfig.h 2008-02-07 21:57:06 UTC (rev 770) @@ -22,8 +22,6 @@ #include <csutil/csstring.h> #include <cstool/initapp.h> -#include <csutil/array.h> -#include <csutil/parray.h> #include <csutil/cfgmgr.h> #include <csutil/cfgfile.h> #include <iutil/document.h> @@ -32,25 +30,29 @@ #define UPDATERINFO_FILENAME "/this/updaterinfo.xml" #define UPDATERINFO_OLD_FILENAME "/this/updaterinfo.xml.bak" -class UpdaterConfig; - -class Mirror +class Mirror : public csRefCount { public: + Mirror() {} + ~Mirror() {} + /* Return mirror ID */ unsigned int GetID() const { return id; } /* Return mirror name */ - csString GetName() const { return name; } + const char* GetName() const { return name; } /* Return mirror URL */ - csString GetBaseURL() const { return baseURL; } + const char* GetBaseURL() const { return baseURL; } /* Set mirror URL */ void SetBaseURL(csString url) { baseURL = url; } + void SetID(uint id) { this->id = id; } + void SetName(const char* name) { this->name = name; } + void SetBaseURL(const char* baseURL) { this->baseURL = baseURL; } + protected: - friend class Config; /* Mirror ID */ uint id; @@ -61,16 +63,22 @@ csString baseURL; }; -class ClientVersion +class ClientVersion : public csRefCount { public: + ClientVersion() {} + ~ClientVersion() {} + /* Get client update file name */ - csString GetName() const { return name; } + const char* GetName() const { return name; } /* Get client update file md5sum */ - csString GetMD5Sum() const { return md5sum; } -protected: - friend class Config; + const char* GetMD5Sum() const { return md5sum; } + + void SetName(const char* name) { this->name = name; } + void SetMD5Sum(const char* md5sum) { this->md5sum = md5sum; } + +private: /* Client update file name */ csString name; @@ -92,14 +100,13 @@ { public: Config(); - + Mirror* GetMirror(uint mirrorNumber); /* Get mirrors. */ - csPDelArray<Mirror>* GetMirrors(); - + csRefArray<Mirror>& GetMirrors() { return mirrors; } /* Get clientVersions list. */ - csPDelArray<ClientVersion>* GetClientVersions(); + csRefArray<ClientVersion>& GetClientVersions() { return clientVersions; } /* Init a xml config file. */ bool Initialize(csRef<iDocumentNode> node); @@ -122,10 +129,10 @@ const char* updaterVersionLatestMD5; /* List of mirrors */ - csPDelArray<Mirror> mirrors; + csRefArray<Mirror> mirrors; /* List of client versions */ - csPDelArray<ClientVersion> clientVersions; + csRefArray<ClientVersion> clientVersions; }; class UpdaterConfig Modified: trunk/src/pslaunch/updaterengine.cpp =================================================================== --- trunk/src/pslaunch/updaterengine.cpp 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/updaterengine.cpp 2008-02-07 21:57:06 UTC (rev 770) @@ -284,19 +284,20 @@ */ // Start by fetching the configs. - csPDelArray<ClientVersion>* oldCvs = config->GetCurrentConfig()->GetClientVersions(); - csPDelArray<ClientVersion>* newCvs = config->GetNewConfig()->GetClientVersions(); + const csRefArray<ClientVersion>& oldCvs = config->GetCurrentConfig()->GetClientVersions(); + const csRefArray<ClientVersion>& newCvs = config->GetNewConfig()->GetClientVersions(); // Same size. - if(oldCvs->GetSize() == newCvs->GetSize()) + if(oldCvs.GetSize() == newCvs.GetSize()) { // If both are empty then skip the extra name check! - if(newCvs->GetSize() != 0) + if(newCvs.GetSize() != 0) { - ClientVersion* oldCv = oldCvs->Get(oldCvs->GetSize()-1); - ClientVersion* newCv = newCvs->Get(newCvs->GetSize()-1); + ClientVersion* oldCv = oldCvs.Get(oldCvs.GetSize()-1); + ClientVersion* newCv = newCvs.Get(newCvs.GetSize()-1); - if(!newCv->GetName().Compare(oldCv->GetName())) + csString name(newCv->GetName()); + if(!name.Compare(oldCv->GetName())) { // There's a problem and we can't continue. Throw a boo boo and clean up. printOutput("Local config and server config are incompatible!\n"); @@ -315,7 +316,7 @@ return true; } -csRef<iDocumentNode> UpdaterEngine::GetRootNode(csString nodeName) +csRef<iDocumentNode> UpdaterEngine::GetRootNode(const char* nodeName) { // Load xml. csRef<iDocumentSystem> xml = csPtr<iDocumentSystem> (new csTinyDocumentSystem); @@ -326,10 +327,10 @@ } //Try to read file - csRef<iDataBuffer> buf = vfs->ReadFile (nodeName.GetData()); + csRef<iDataBuffer> buf = vfs->ReadFile(nodeName); if (!buf || !buf->GetSize()) { - printOutput("Couldn't open config file '%s'!\n", nodeName.GetData()); + printOutput("Couldn't open xml file '%s'!\n", nodeName); return NULL; } @@ -338,7 +339,7 @@ const char* error = configdoc->Parse(buf); if (error) { - printOutput("XML Parsing error in file '%s': %s.\n", nodeName.GetData(), error); + printOutput("XML Parsing error in file '%s': %s.\n", nodeName, error); return NULL; } @@ -380,21 +381,24 @@ fileUtil->RemoveFile(appName.GetData()); fileUtil->CopyFile(tempName.GetData(), appName.GetData(), false, true); - // Copy any art, data and dlls. - csString zip = appName; - zip.AppendFmt(config->GetCurrentConfig()->GetPlatform()); - zip.AppendFmt(".zip"); - vfs->Mount("/zip", zip); + // Copy any art and data. + if(appName.Compare("pslaunch")) + { + csString zip = appName; + zip.AppendFmt(config->GetCurrentConfig()->GetPlatform()); + zip.AppendFmt(".zip"); + vfs->Mount("/zip", zip); - csString artPath = "/art/"; - artPath.AppendFmt("%s.zip", appName); - fileUtil->CopyFile("/zip" + artPath, artPath, true, false, true); + csString artPath = "/art/"; + artPath.AppendFmt("%s.zip", appName); + fileUtil->CopyFile("/zip" + artPath, artPath, true, false, true); - csString dataPath = "/data/gui/"; - dataPath.AppendFmt("%s.xml", appName); - fileUtil->CopyFile("/zip" + dataPath, dataPath, true, false, true); + csString dataPath = "/data/gui/"; + dataPath.AppendFmt("%s.xml", appName); + fileUtil->CopyFile("/zip" + dataPath, dataPath, true, false, true); - vfs->Unmount("/zip", zip); + vfs->Unmount("/zip", zip); + } // Create a new process of the updater. CreateProcess(appName.GetData(), "selfUpdateSecond", 0, 0, false, CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo, &piProcessInfo); @@ -565,8 +569,8 @@ */ // Start by fetching the configs. - csPDelArray<ClientVersion>* oldCvs = config->GetCurrentConfig()->GetClientVersions(); - csPDelArray<ClientVersion>* newCvs = config->GetNewConfig()->GetClientVersions(); + csRefArray<ClientVersion>& oldCvs = config->GetCurrentConfig()->GetClientVersions(); + const csRefArray<ClientVersion>& newCvs = config->GetNewConfig()->GetClientVersions(); csRef<iDocumentNode> rootnode = GetRootNode(UPDATERINFO_OLD_FILENAME); csRef<iDocumentNode> confignode = rootnode->GetNode("config"); @@ -580,16 +584,17 @@ while(checkGeneral()) { // Find starting point in newCvs from oldCvs. - size_t index = oldCvs->GetSize(); + size_t index = oldCvs.GetSize(); // Use index to find the first update version in newCvs. - ClientVersion* newCv = newCvs->Get(index); + ClientVersion* newCv = newCvs.Get(index); // Construct zip name. csString zip = config->GetCurrentConfig()->GetPlatform(); - zip.AppendFmt("-%s.zip", newCv->GetName().GetData()); + zip.AppendFmt("-%s.zip", newCv->GetName()); // Download update zip. + printOutput("Downloading update file..\n"); downloader->DownloadFile(zip, zip, false, true); // Check md5sum is correct. @@ -632,7 +637,6 @@ fileUtil->RemoveFile("/this/" + deletedList.Get(i)); } - // Parse new files xml, make a list. csArray<csString> newList; csArray<bool> newListType; @@ -659,13 +663,6 @@ fileUtil->CopyFile("/zip/" + newList.Get(i), "/this/" + newList.Get(i), true, false); } - - // Remove new files from virtual dir. - for(uint i=0; i<newList.GetSize(); i++) - { - fileUtil->RemoveFile("/zip/" + newList.Get(i)); - } - // Parse changed files xml, binary patch each file. csRef<iDocumentNode> changedrootnode = GetRootNode("/zip/changedfiles.xml"); if(changedrootnode) @@ -685,12 +682,10 @@ oldFilePath.AppendFmt(".old"); // Move old file to a temp location ready for input. - fileUtil->CopyFile(newFilePath, oldFilePath, false, false); - fileUtil->RemoveFile("/this/" + newFilePath); + fileUtil->MoveFile("/this/" + newFilePath, "/this/" + oldFilePath, true, false, true); // Move diff to a real location ready for input. fileUtil->CopyFile("/zip/" + diff, "/this/" + newFilePath + ".vcdiff", true, false, true); - fileUtil->RemoveFile("/zip/" + diff, true); diff = newFilePath + ".vcdiff"; // Binary patch. @@ -754,13 +749,14 @@ // Clean up temp files. fileUtil->RemoveFile("/this/" + oldFilePath); } - fileUtil->RemoveFile("/this/" + diff, true); + fileUtil->RemoveFile("/this/" + diff, false); } - } + } // Unmount zip and delete. if(vfs->Unmount("/zip", zip)) { + vfs->Sync(); fileUtil->RemoveFile("/this/" + zip); } else @@ -769,7 +765,9 @@ } // Add version info to updaterinfo.xml.bak and oldCvs. - confignode->GetNode("client")->CreateNodeBefore(CS_NODE_TEXT)->SetValue("<version name=\"" + newCv->GetName() + "\" />"); - oldCvs->Push(newCv); - } + csString value("<version name=\""); + value.AppendFmt("%s\" />", newCv->GetName()); + confignode->GetNode("client")->CreateNodeBefore(CS_NODE_TEXT)->SetValue(value); + oldCvs.PushSmart(newCv); + } } Modified: trunk/src/pslaunch/updaterengine.h =================================================================== --- trunk/src/pslaunch/updaterengine.h 2008-02-07 21:31:57 UTC (rev 769) +++ trunk/src/pslaunch/updaterengine.h 2008-02-07 21:57:06 UTC (rev 770) @@ -99,7 +99,7 @@ csRef<iVFS> GetVFS() const { return vfs; } // Find the config node given an xml file name. - csRef<iDocumentNode> GetRootNode(csString fileName); + csRef<iDocumentNode> GetRootNode(const char* fileName); /* * Starts and finishes a self update This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |