Update of /cvsroot/planeshift/planeshift/src/updater/httpclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11086 Modified Files: change.cpp change.h changelist.cpp changelist.h download.cpp download.h fileutil.cpp fileutil.h md5.cpp md5.h registry.cpp registry.h registrycreator.cpp registrycreator.h registryfile.cpp registryfile.h timestamp.cpp updater.cpp updater.h updaterconfig.cpp updaterconfig.h Added Files: globals.h pawsupdaterwindow.cpp pawsupdaterwindow.h psengine.cpp psengine.h Removed Files: error.cpp error.h main.cpp Log Message: New updater --- NEW FILE: globals.h --- /* * globals.h * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* This file holds definitions for ALL global variables in the planeshift * server, normally you should move global variables into the psServer class */ #ifndef __GLOBALS_H__ #define __GLOBALS_H__ #include "psengine.h" #include "util/log.h" #define CRTError(a) \ {printf(a);PS_PAUSEEXIT(1);} #define CRTError2(a,b) \ {printf(a,b);PS_PAUSEEXIT(1);} #define CRTError3(a,b,c) \ {printf(a,b,c);PS_PAUSEEXIT(1);} extern csRef<psEngine> psengine; #endif --- NEW FILE: pawsupdaterwindow.cpp --- /* * pawsupdaterwindow.cpp - Author: Christian Svensson * * Copyright (C) 2004 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ ////////////////////////////////////////////////////////////////////// #include <psconfig.h> #include "globals.h" #include "changelist.h" #include <csutil/cfgfile.h> #include <iengine/engine.h> // PAWS INCLUDES #include "pawsupdaterwindow.h" #include "paws/pawsmanager.h" #include "paws/pawsradio.h" #include "paws/pawscheckbox.h" #include "paws/pawstextbox.h" #include "paws/pawsprogressbar.h" using updater::ChangeList; pawsUpdaterWindow::pawsUpdaterWindow( PawsManager* manager ) :pawsWidget( manager ) { maxFiles=0; lastFile = 0; } bool pawsUpdaterWindow::PostSetup() { btnUpdate = (pawsButton*)FindWidget("UpdateButton"); if(!btnUpdate) return false; btnExit = (pawsButton*)FindWidget("ExitButton"); if(!btnExit) return false; prgBar = (pawsProgressBar*)FindWidget("UpdateProgress"); if(!prgBar) return false; prgTotal = (pawsProgressBar*)FindWidget("TotalProgress"); if(!prgTotal) return false; txtFile = (pawsTextBox*)FindWidget("file"); if(!txtFile) return false; prgBar->SetTotalValue(101); //101 looks nicer prgBar->SetCurrentValue(0); prgTotal->SetTotalValue(101); //101 looks nicer prgTotal->SetCurrentValue(0); return true; } bool pawsUpdaterWindow::OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* widget ) { if (widget==btnUpdate) { psengine->GetUpdater()->StartUpdate(); } else if (widget==btnExit) { psengine->GetUpdater()->Die(); } return false; } void pawsUpdaterWindow::SetTotalFiles(unsigned int value) { maxFiles = value; lastFile = 0; } void pawsUpdaterWindow::UpdateFilename(const char* name,unsigned int file) { txtFile->SetText(name); SetProgressValue(0); file--; //Doing like this, the progress will increase when the next file starts to download if(file == 0) { SetTotalProgressValue(0); return; } float totalprg = float(file)/(float)maxFiles; SetTotalProgressValue(totalprg*100); } void pawsUpdaterWindow::UpdateFilename(const char* name) { lastFile++; UpdateFilename(name,lastFile); } void pawsUpdaterWindow::SetProgressValue(int value) { prgBar->SetCurrentValue(value); } void pawsUpdaterWindow::SetTotalProgressValue(int value) { prgTotal->SetCurrentValue(value); } --- NEW FILE: pawsupdaterwindow.h --- /* * pawsUpdaterWindow.h - Author: Ian Donderwinkel * * Copyright (C) 2004 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ ////////////////////////////////////////////////////////////////////// #ifndef PAWS_UPDATER_WINDOW #define PAWS_UPDATER_WINDOW #include "paws/pawswidget.h" class pawsRadioButtonGroup; class pawsCheckBox; class pawsButton; class pawsTextBox; class pawsProgressBar; class pawsUpdaterWindow : public pawsWidget { public: pawsUpdaterWindow( PawsManager* manager ); bool PostSetup(); bool OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* widget ); void SetProgressValue(int value); void SetTotalProgressValue(int value); void SetTotalFiles(unsigned int value); void UpdateFilename(const char* name, unsigned int file); void UpdateFilename(const char* name); private: pawsButton* btnUpdate; pawsButton* btnExit; pawsProgressBar* prgBar; pawsProgressBar* prgTotal; pawsTextBox* txtFile; unsigned int lastFile; unsigned int maxFiles; }; CREATE_PAWS_FACTORY( pawsUpdaterWindow ); #endif --- NEW FILE: psengine.cpp --- /* * psengine.cpp * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include <psconfig.h> #include <iutil/config.h> #include <iutil/cfgmgr.h> #include <iutil/event.h> #include <iutil/eventq.h> #include <iutil/objreg.h> #include <iutil/plugin.h> #include <iutil/vfs.h> #include <ivideo/natwin.h> #include <imap/parser.h> #include <iutil/cmdline.h> #include <csutil/cmdhelp.h> #include <ivaria/stdrep.h> #include <csutil/debug.h> #include <csutil/cmdline.h> #include <ivideo/graph2d.h> #include <ivideo/graph3d.h> #include "iclient/isoundmngr.h" #include "util/pscssetup.h" #include "globals.h" #include <iengine/engine.h> #include "psengine.h" #include "paws/pawsmanager.h" #include "paws/pawsmainwidget.h" #include "paws/pawstextbox.h" #include "pawsupdaterwindow.h" #include "registry.h" #include "registrycreator.h" #include "updater.h" using updater::Updater; using updater::Registry; using updater::ChangeList; using updater::RegistryCreator; csRef<psEngine> psengine; #define CONFIGFILENAME "/this/psupdater.cfg" #define APPNAME "PlaneShift Updater" /*********************************************************************/ CS_IMPLEMENT_APPLICATION SCF_IMPLEMENT_IBASE (psEngine) SCF_IMPLEMENTS_INTERFACE(iPSEngine) SCF_IMPLEMENT_IBASE_END SCF_IMPLEMENT_IBASE (psEngine::EventHandler) SCF_IMPLEMENTS_INTERFACE (iEventHandler) SCF_IMPLEMENT_IBASE_END /*********************************************************************/ psEngine::psEngine (iObjectRegistry *objectreg, bool silent) { SCF_CONSTRUCT_IBASE(0); object_reg = objectreg; paws = NULL; drawScreen = true; silentMode = silent; } /*********************************************************************/ psEngine::~psEngine () { if (scfiEventHandler && queue) queue->RemoveListener (scfiEventHandler); delete paws; } /*********************************************************************/ #define PSAPP "planeshift.updater.application" #define PS_QUERY_PLUGIN(myref,intf, str) \ myref = CS_QUERY_REGISTRY (object_reg, intf); \ if (!myref) { \ csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, PSAPP, \ "No " str " plugin!");\ return false;\ } bool psEngine::Initialize () { if(!silentMode) { if(!soundmanager->Setup()) { csReport(object_reg, CS_REPORTER_SEVERITY_NOTIFY, PSAPP, "Warning: Cannot initialize iSoundManager"); } } // Initialize updater update = csPtr<Updater> (new Updater); if(update != NULL) update->Initialize(object_reg); if(!silentMode) { graphics2d = graphics3d->GetDriver2D(); iNativeWindow *nw = graphics2d->GetNativeWindow(); if(nw) nw->SetTitle(APPNAME); // Create the PAWS window manager paws = new PawsManager( object_reg ); if ( !paws ) return false; mainWidget = new pawsMainWidget(paws); paws->SetMainWidget( mainWidget ); RegisterFactories(); psengine->LoadWidgets(); pawsWidget* setup = paws->FindWidget("updater"); setup->SetBackgroundAlpha(0); paws->GetMouse()->ChangeImage("Standard Mouse Pointer"); // Register our event handler scfiEventHandler = csPtr<EventHandler> (new EventHandler (this)); queue->RegisterListener(scfiEventHandler, CSMASK_Nothing | CSMASK_Broadcast | CSMASK_Keyboard | CSMASK_Command | CSMASK_MouseDown | CSMASK_MouseUp | CSMASK_MouseMove); //End silent mode skipper } // Inform debug that everything initialized succesfully csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY, PSAPP, "psEngine initialized."); return true; } /*********************************************************************/ bool psEngine::HandleEvent (iEvent &ev) { lastEvent = &ev; static int count=0; if ( paws->HandleEvent( ev ) ) { return true; } switch(ev.Type) { case csevBroadcast: switch (ev.Command.Code) { case cscmdProcess: return true; case cscmdFinalProcess: FinishFrame (); return true; case cscmdPostProcess: { SetupFrame (); if (drawScreen) { graphics3d->BeginDraw(engine->GetBeginDrawFlags() | CSDRAW_2DGRAPHICS ); paws->Draw(); } else { csSleep(150); } break; } case cscmdCanvasHidden: drawScreen = false; break; case cscmdCanvasExposed: drawScreen = true; break; } break; } return false; } /*********************************************************************/ void psEngine::QuitClient() { csRef<iConfigManager> cfg (CS_QUERY_REGISTRY (object_reg, iConfigManager)); if (cfg) cfg->Save(); queue->GetEventOutlet()->Broadcast (cscmdQuit); } /*********************************************************************/ void psEngine::SetupFrame() { } void psEngine::FinishFrame() { graphics3d->FinishDraw (); graphics3d->Print (NULL); } /*********************************************************************/ #define RegisterFactory(factoryclass) \ factory = new factoryclass(paws); void psEngine::RegisterFactories() { pawsWidgetFactory* factory; RegisterFactory (pawsUpdaterWindowFactory); } void psEngine::LoadWidgets() { bool ok = true; ok = ok && paws->LoadWidget( "data/updater/updaterwindow.xml" ); ok = ok && paws->LoadWidget( "data/ok.xml" ); if ( !ok ) { printf("One or more widgets failed to load"); PS_PAUSEEXIT(1); } } void psEngine::OutToScreen(const char* text) { if(silentMode) { printf("%s\n",text); return; } pawsUpdaterWindow* updWnd = (pawsUpdaterWindow*)psengine->GetPAWS()->FindWidget("updater"); pawsMessageTextBox* msgBox = (pawsMessageTextBox*)updWnd->FindWidget("list"); msgBox->AddMessage(text); } bool psEngine::InitializeCS() { if(!object_reg) PS_PAUSEEXIT(1); csDebuggingGraph::SetupGraph(object_reg); //Adding path for CEL plugins char * celpath = getenv("CEL"); if(celpath) { char newpath[1024]; strncpy(newpath, celpath, 1000); strcat(newpath, "/"); iSCF::SCF->ScanPluginsPath(newpath); } else { celpath = getenv("PATH"); if (celpath) { char newpath[1024]; strcpy(newpath,celpath); //non-read only copy char *tok = strtok(newpath,";"); while (tok) { if (strstr(tok,"cel")) { char path[1024]; strcpy(path,tok); strcat(path,"/"); iSCF::SCF->ScanPluginsPath(path); } tok = strtok(NULL,";"); } } } //Load plugins from file. All requests goes AFTER this one if( !csInitializer::SetupConfigManager(object_reg, CONFIGFILENAME)) { csReport(object_reg, CS_REPORTER_SEVERITY_ERROR, "psclient", "csInitializer::SetupConfigManager failed!\n" "Is your CRYSTAL environment variable set?"); PS_PAUSEEXIT(1); } vfs = CS_QUERY_REGISTRY (object_reg, iVFS); configMgr = CS_QUERY_REGISTRY (object_reg, iConfigManager); iConfigFile* cfg = configMgr->AddDomain(CONFIGFILENAME,vfs,iConfigManager::ConfigPriorityApplication+1); configMgr->SetDynamicDomain(cfg); //Load 3D driver based on silent or not if(silentMode) { if(!csInitializer::RequestPlugins(object_reg, CS_REQUEST_NULL3D, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_END)) { csReport(object_reg, CS_REPORTER_SEVERITY_ERROR, "psupdater", "Failed to initialize plugins!"); return 0; } } else { if(!csInitializer::RequestPlugins(object_reg, CS_REQUEST_OPENGL3D, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_END)) { csReport(object_reg, CS_REPORTER_SEVERITY_ERROR, "psupdater", "Failed to initialize plugins!"); return 0; } } // Check for commandline help. if (csCommandLineHelper::CheckHelp (object_reg)) { csCommandLineHelper::Help (object_reg); PS_PAUSEEXIT(1); } //Open application (?) if (!csInitializer::OpenApplication (object_reg)) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "psclient", "csInitializer::OpenApplication failed!\n" "Is your CRYSTAL environment var set?"); csInitializer::DestroyApplication (object_reg); PS_PAUSEEXIT(1); } // tweak reporter plugin to report everything... // is there a command line switch or something to do this which I've missed? csRef<iStandardReporterListener> reporter = CS_QUERY_REGISTRY (object_reg, iStandardReporterListener); if (reporter) { reporter->ShowMessageID(CS_REPORTER_SEVERITY_BUG, true); reporter->ShowMessageID(CS_REPORTER_SEVERITY_ERROR, true); reporter->ShowMessageID(CS_REPORTER_SEVERITY_NOTIFY, true); reporter->ShowMessageID(CS_REPORTER_SEVERITY_DEBUG, true); reporter->ShowMessageID(CS_REPORTER_SEVERITY_WARNING, true); reporter->SetMessageDestination(CS_REPORTER_SEVERITY_NOTIFY, true, false, false, false, true); reporter->SetMessageDestination(CS_REPORTER_SEVERITY_ERROR, true, false, false, false, true); reporter->SetMessageDestination(CS_REPORTER_SEVERITY_WARNING, true, false, false, false, true); reporter->SetMessageDestination(CS_REPORTER_SEVERITY_BUG, true, false, false, false, true); reporter->SetMessageDestination(CS_REPORTER_SEVERITY_DEBUG, true, false, false, false, true); } //mount some paths if ( !vfs->Mount ("/planeshift/", "$.$/") ) return false; if ( !vfs->Mount ("/planeshift/textures/", "$.$/art$/textures$/") ) return false; //set the plugins PS_QUERY_PLUGIN (queue, iEventQueue, "iEventQueue"); PS_QUERY_PLUGIN (engine, iEngine, "iEngine"); PS_QUERY_PLUGIN (cfgmgr, iConfigManager, "iConfigManager"); PS_QUERY_PLUGIN( graphics3d , iGraphics3D, "iGraphics3D" ); PS_QUERY_PLUGIN( soundmanager, iSoundManager, "iSoundManager"); return true; } /************************************************************/ int main(int argc, char** argv) { bool silent = false; bool create = false; //Check for silent and if we should create a new resp csRef<csCommandLineParser> cmdParser = csPtr<csCommandLineParser> (new csCommandLineParser); cmdParser->Initialize(argc,argv); silent = cmdParser->GetBoolOption("silent"); create = cmdParser->GetBoolOption("create"); //We will be in silent mode when creating if(create) silent = true; //Create the standard stuff psCSSetup* CSSetup = new psCSSetup( argc, argv, CONFIGFILENAME, "" ); iObjectRegistry* objreg = CSSetup->GetObjectRegistry(); // Create our application object psengine = csPtr<psEngine> (new psEngine(objreg,silent)); // add ourself to the object registry if (!objreg->Register ((iPSEngine*) psengine, "iPSEngine")) { csReport (objreg, CS_REPORTER_SEVERITY_NOTIFY, PSAPP, "couldn't register iPSEngine class!"); PS_PAUSEEXIT(1); } // Initialize Crystal space for the engine if (!psengine->InitializeCS()) { csReport (objreg, CS_REPORTER_SEVERITY_ERROR, PSAPP, "Failed to init Crystal Space for app!"); PS_PAUSEEXIT(1); } // Initialize engine if (!psengine->Initialize()) { csReport (objreg, CS_REPORTER_SEVERITY_ERROR, PSAPP, "Failed to init app!"); PS_PAUSEEXIT(1); } if(create) { psengine->GetUpdater()->CreateRegistry(objreg); psengine->QuitClient(); } else if(silent) { psengine->GetUpdater()->StartUpdate(); } // start the main event loop csDefaultRunLoop(objreg); // Remove engine from object registry objreg->Unregister ((iPSEngine*) psengine, "iPSEngine"); // delete main object if (psengine->GetRefCount() != 1) { csReport (objreg, CS_REPORTER_SEVERITY_ERROR, PSAPP, "%d References too much for psengine!", psengine->GetRefCount()-1); } // remove engine before destroying Application psengine = NULL; csInitializer::DestroyApplication (objreg); delete CSSetup; return 0; } --- NEW FILE: psengine.h --- /* * psengine.h * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __ENGINE_H__ #define __ENGINE_H__ #include <iutil/eventh.h> #include <csutil/sysfunc.h> #include <csutil/csstring.h> #include <csutil/ref.h> #include "iclient/psengine.h" #include "updater.h" using updater::Updater; struct iEngine; struct iLoader; struct iVFS; struct iEvent; struct iEventQueue; struct iConfigManager; struct iSoundManager; class pawsMainWidget; class psEngine : public iPSEngine, public iEventHandler { public: SCF_DECLARE_IBASE; psEngine (iObjectRegistry *object_reg, bool silent); virtual ~psEngine (); bool InitializeCS(); bool Initialize (); void QuitClient(); void SetupFrame(); void FinishFrame(); bool IsSilent() {return silentMode;} bool HandleEvent (iEvent &Event); iObjectRegistry* GetObjectRegistry(){ return object_reg; }; iEngine* GetEngine(){ return engine; }; iGraphics3D* GetG3D(){ return graphics3d; }; iGraphics2D* GetG2D(){ return graphics2d; }; iVFS* GetVFS(){ return vfs; }; iConfigManager* GetConfig() { return cfgmgr; }; PawsManager* GetPAWS() { return paws; } pawsMainWidget* GetMainWidget() { return mainWidget; } iEvent* GetLastEvent() { return lastEvent; } iSoundManager* GetSoundManager(){ return soundmanager; }; Updater* GetUpdater(){ return update; }; iConfigManager* GetConfigManager(){ return configMgr; }; class EventHandler : public iEventHandler { private: psEngine* parent; public: SCF_DECLARE_IBASE; EventHandler (psEngine* parent) { SCF_CONSTRUCT_IBASE (NULL); EventHandler::parent = parent; } virtual ~EventHandler() { } virtual bool HandleEvent (iEvent& ev) { return parent->HandleEvent (ev); } }; csRef<EventHandler> scfiEventHandler; void LoadWidgets(); void OutToScreen(const char* text); private: csRef<iObjectRegistry> object_reg; csRef<iEngine> engine; csRef<iConfigManager> cfgmgr; csRef<iTextureManager> txtmgr; csRef<iVFS> vfs; csRef<iGraphics2D> graphics2d; csRef<iGraphics3D> graphics3d; csRef<iEventQueue> queue; csRef<iSoundManager> soundmanager; csRef<iConfigManager> configMgr; csRef<Updater> update; // Used to stop rendering when the window is minimized bool drawScreen; // Paws PawsManager* paws; pawsMainWidget* mainWidget; void RegisterFactories(); // Used to store the last event iEvent* lastEvent; bool silentMode; }; #endif Index: change.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/change.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** change.cpp 13 Mar 2004 16:49:07 -0000 1.4 --- change.cpp 30 Apr 2004 15:58:29 -0000 1.5 *************** *** 22,25 **** --- 22,27 ---- #include "change.h" + #include "globals.h" + namespace updater { *************** *** 30,36 **** } ! Change::Change (Type ntype, const char* modulename, const RegistryFile& newfile) ! : type(ntype), file(newfile) { module = csStrNew(modulename); } --- 32,39 ---- } ! Change::Change (Type ntype, const char* modulename, RegistryFile* newfile) ! : type(ntype) { + file = newfile; module = csStrNew(modulename); } Index: change.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/change.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** change.h 4 Mar 2003 13:29:30 -0000 1.3 --- change.h 30 Apr 2004 15:58:30 -0000 1.4 *************** *** 45,52 **** char* module; /// Path + Filename of the change ! RegistryFile file; Change (); ! Change (Type type, const char* modulename, const RegistryFile& file); Change (const Change& other); --- 45,52 ---- char* module; /// Path + Filename of the change ! RegistryFile* file; Change (); ! Change (Type type, const char* modulename, RegistryFile* file); Change (const Change& other); Index: changelist.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/changelist.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** changelist.cpp 13 Mar 2004 16:49:07 -0000 1.4 --- changelist.cpp 30 Apr 2004 15:58:30 -0000 1.5 *************** *** 19,22 **** --- 19,23 ---- #include <psconfig.h> + #include "globals.h" #include "changelist.h" *************** *** 37,75 **** for (int i=0; i<Length(); i++) { - const Change& change = Get(i); - switch (change.type) - { - case Change::CREATEFILE: - printf ("Create "); - break; - case Change::REMOVEFILE: - printf ("Remove "); - break; - case Change::MOVEFILEAWAY: - printf ("MoveAway "); - break; - case Change::UPDATEFILE: - printf ("Update "); - break; - default: - printf ("Unknown Change Type?!?!?"); - } - printf ("%s\n", (const char*) change.file.file); - } - } ! uint32_t ChangeList::GetChangeSize () ! { ! uint32_t result = 0; ! ! for (int i=0;i<Length();i++) ! { ! if (Get(i).type != Change::REMOVEFILE ! && Get(i).type != Change::MOVEFILEAWAY) ! result += Get(i).file.size; ! } ! return result; } } // end of namespace updater --- 38,78 ---- for (int i=0; i<Length(); i++) { ! csString entry; ! Change change = Get(i); ! switch (change.type) ! { ! case Change::CREATEFILE: ! { ! if(change.file->inZip) ! entry = "Merge "; ! else ! entry = "Create "; ! ! break; ! } ! case Change::REMOVEFILE: ! entry = "Remove "; ! break; ! case Change::MOVEFILEAWAY: ! entry = "Move "; ! break; ! case Change::UPDATEFILE: ! entry = "Update "; ! break; ! default: ! entry = "Unknown Change Type (This shouldn't happen)"; ! } ! entry += change.file->file; ! if(change.file->inZip) ! { ! entry += " (ZIP)"; ! } ! ! psengine->OutToScreen(entry.GetData()); ! } } + } // end of namespace updater Index: changelist.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/changelist.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** changelist.h 4 Mar 2003 13:29:30 -0000 1.2 --- changelist.h 30 Apr 2004 15:58:30 -0000 1.3 *************** *** 41,47 **** bool Load (iDocumentNode* node); - /// Return size of all changes in the list - uint32_t GetChangeSize (); - /// Prints the changelist on screen void PrintOut (); --- 41,44 ---- Index: download.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/download.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** download.cpp 13 Mar 2004 16:49:07 -0000 1.4 --- download.cpp 30 Apr 2004 15:58:30 -0000 1.5 *************** *** 23,37 **** #include <curl/easy.h> #include "download.h" namespace updater { ! Downloader::Downloader () throw(Error) : callback (0) { curl = curl_easy_init(); if (!curl) ! throw Error("Couldn't initialize libcurl downloader."); curlerror = new char[CURL_ERROR_SIZE]; --- 23,53 ---- #include <curl/easy.h> + #include <iutil/vfs.h> + #include "download.h" + #include "paws/pawswidget.h" + #include "paws/pawsmanager.h" + #include "paws/pawsprogressbar.h" + #include "pawsupdaterwindow.h" + + #include "globals.h" + + size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) + { + int written = fwrite(ptr, size, nmemb, (FILE *)stream); + return written; + } namespace updater { ! Downloader::Downloader () : callback (0) { + + eng = psengine; curl = curl_easy_init(); if (!curl) ! CRTError("Couldn't initialize libcurl downloader."); curlerror = new char[CURL_ERROR_SIZE]; *************** *** 40,44 **** --- 56,62 ---- curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, ProgressCallback); + curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, this); } *************** *** 50,54 **** } ! void Downloader::SetProxy (bool active, const char* host, int port) throw(Error) { if (!active) --- 68,72 ---- } ! void Downloader::SetProxy (bool active, const char* host, int port) { if (!active) *************** *** 59,62 **** --- 77,81 ---- { curl_easy_setopt (curl, CURLOPT_PROXY, host); + curl_easy_setopt (curl, CURLOPT_PROXYPORT, port); } } *************** *** 67,81 **** } ! void Downloader::DownloadFile (const char* dest, const char* url, ! bool doprogress) throw(Error) { FILE* file; file = fopen (dest, "wb"); if (!file) ! throw Error("Couldn't write file '%s'.\n", dest); curl_easy_setopt (curl, CURLOPT_URL, url); ! // XXX: WE should write to a tempfile, this will overwrite files with junk ! // in case of an error curl_easy_setopt (curl, CURLOPT_WRITEDATA, file); --- 86,105 ---- } ! bool Downloader::DownloadFile (const char* dest, const char* url, ! bool doprogress) { FILE* file; file = fopen (dest, "wb"); + if (!file) ! { ! printf("Couldn't write to file! (%s)\n", dest); ! return false; ! } curl_easy_setopt (curl, CURLOPT_URL, url); ! ! curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); ! curl_easy_setopt (curl, CURLOPT_WRITEDATA, file); *************** *** 85,90 **** CURLcode result = curl_easy_perform(curl); ! if (doprogress) ! printf ("done.\n"); fclose (file); --- 109,113 ---- CURLcode result = curl_easy_perform(curl); ! fclose (file); *************** *** 94,104 **** if (result != CURLE_OK) { ! throw Error ("Error while downloading: %s", curlerror); } if (curlhttpcode != 200) { ! throw Error ("Server returned error code %d %s.", curlhttpcode, curlhttpcode == 404 ? "(file not found)" : ""); } } --- 117,131 ---- if (result != CURLE_OK) { ! printf ("Error while downloading: %s\n\n", curlerror); ! return false; } if (curlhttpcode != 200) { ! printf ("Server error: %d %s.\n\n", curlhttpcode, curlhttpcode == 404 ? "(file not found)" : ""); + return false; } + + return true; } *************** *** 106,133 **** double total, double now, double, double) { ! Downloader* me = (Downloader*) clientp; if (total>0 && now>0) { ! float percent = now/total*100; ! if (me->callback) ! me->callback->StatusUpdate (percent, ""); ! if (me->progress) ! { ! while ( (((int) percent+.001) - me->lastprogress > 5) ! && me->lastprogress<=100) ! { ! if (me->lastprogress % 25 == 0) ! { ! printf ("%d%%", me->lastprogress); ! } ! else if (me->lastprogress % 3 == 0) ! { ! printf ("."); ! } ! fflush(stdout); ! me->lastprogress += 1; ! } ! } } --- 133,201 ---- double total, double now, double, double) { ! Downloader* me = (Downloader*)clientp; ! ! if(!psengine) ! psengine=me->GetEngine(); ! ! //Still null? ! if(!psengine) ! return 0; ! ! if(!psengine->GetUpdater()) ! return 0; ! ! if(psengine->GetUpdater()->WantToDie()) ! return 0; ! ! //Silent progress ! if(psengine->IsSilent()) ! { ! if (total>0 && now>0) ! { ! float percent = now/total*100; ! if (me->callback) ! me->callback->StatusUpdate (percent, ""); ! ! if (me->progress) ! { ! while ( (((int) percent+.001) - me->lastprogress > 5) && me->lastprogress<=100) ! { ! ! if (me->lastprogress % 25 == 0) ! { ! printf ("%d%%", me->lastprogress); ! } ! else if (me->lastprogress % 5 == 0) ! { ! printf ("."); ! } ! ! fflush(stdout); ! me->lastprogress += 1; ! } ! } ! } ! ! int percent = now/total*100; ! if (percent == 100 && me->lastprogress != 100) ! { ! printf("100%%\n"); ! me->lastprogress = 100; ! } ! ! return 0; ! } ! ! //Active progress ! ! //Get PAWS window ! pawsUpdaterWindow* updWnd = (pawsUpdaterWindow*)psengine->GetPAWS()->FindWidget("updater"); ! if(!updWnd) ! return false; if (total>0 && now>0) { ! int percent = now/total*100; ! updWnd->SetProgressValue(percent); } Index: download.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/download.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** download.h 4 Mar 2003 13:29:30 -0000 1.3 --- download.h 30 Apr 2004 15:58:30 -0000 1.4 *************** *** 21,25 **** #include <curl/types.h> ! #include "error.h" namespace updater --- 21,26 ---- #include <curl/types.h> ! #include <csutil/csstring.h> ! #include "psengine.h" namespace updater *************** *** 36,47 **** { public: ! Downloader () throw(Error); ~Downloader (); ! void SetProxy (bool active, const char* host = NULL, int port=0) ! throw(Error); void SetCallback (StatusCallback* callback); ! void DownloadFile (const char* dest, const char* url, ! bool progress = false) throw(Error); private: --- 37,49 ---- { public: ! Downloader (); ~Downloader (); ! void SetProxy (bool active, const char* host = NULL, int port=0); void SetCallback (StatusCallback* callback); ! bool DownloadFile (const char* dest, const char* url, ! bool progress = false); ! ! psEngine* GetEngine() {return eng;} private: *************** *** 55,58 **** --- 57,62 ---- CURL* curl; char* curlerror; + csString tempfile; + psEngine* eng; }; Index: fileutil.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/fileutil.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** fileutil.cpp 13 Mar 2004 16:49:07 -0000 1.6 --- fileutil.cpp 30 Apr 2004 15:58:30 -0000 1.7 *************** *** 24,31 **** #include <sys/stat.h> #include <csutil/util.h> - #include "error.h" #include "fileutil.h" namespace updater { --- 24,33 ---- #include <sys/stat.h> #include <csutil/util.h> + #include <iutil/vfs.h> #include "fileutil.h" + #include "globals.h" + namespace updater { *************** *** 60,68 **** } ! void RemoveFile (const char* filename) throw(Error) { ! int rc = remove(filename); ! if (rc < 0) ! throw Error("Removal of '%s' failed.", filename); } --- 62,81 ---- } ! void RemoveFile (const char* filename) { ! //If vfs deletefile fails, fall back on old variant ! if(!psengine->GetVFS()->DeleteFile(filename)) ! { ! int rc = remove(filename); ! if (rc < 0) ! CRTError2("Removal of '%s' failed.", filename); ! } ! else ! { ! if(!psengine->GetVFS()->Sync()) ! { ! printf("Couldn't sync VFS!\n"); ! } ! } } *************** *** 75,82 **** } ! void MakeDirectory (const char* directory) throw(Error) { if (mkdir (directory, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) ! throw Error("Couldn't create directory '%s'.", directory); } #endif --- 88,95 ---- } ! void MakeDirectory (const char* directory) { if (mkdir (directory, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) ! CRTError("Couldn't create directory '%s'.", directory); } #endif *************** *** 98,102 **** } ! void MakeDirectory (const char* directory) throw(Error) { char* path = ConvertToSystemPath (directory); --- 111,115 ---- } ! void MakeDirectory (const char* directory) { char* path = ConvertToSystemPath (directory); *************** *** 105,109 **** if (rc < 0) ! throw Error("Couldn't create directory '%s'.", directory); } #endif --- 118,122 ---- if (rc < 0) ! CRTError2("Couldn't create directory '%s'.", directory); } #endif Index: fileutil.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/fileutil.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** fileutil.h 7 Mar 2003 19:41:01 -0000 1.4 --- fileutil.h 30 Apr 2004 15:58:30 -0000 1.5 *************** *** 26,30 **** #include <psstdint.h> - #include "error.h" #include "timestamp.h" --- 26,29 ---- *************** *** 57,61 **** FileStat* StatFile (const char* path); ! void RemoveFile (const char* filename) throw(Error); /** Convert path to system specific path (for example changes / into \ on --- 56,60 ---- FileStat* StatFile (const char* path); ! void RemoveFile (const char* filename); /** Convert path to system specific path (for example changes / into \ on *************** *** 65,69 **** /** Creates a directory. */ ! void MakeDirectory (const char* directory) throw(Error); } // end of namespace updater --- 64,68 ---- /** Creates a directory. */ ! void MakeDirectory (const char* directory); } // end of namespace updater Index: md5.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/md5.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** md5.cpp 13 Mar 2004 16:49:07 -0000 1.5 --- md5.cpp 30 Apr 2004 15:58:30 -0000 1.6 *************** *** 24,31 **** #include <csutil/csmd5.h> #include <csutil/util.h> - #include "error.h" #include "md5.h" namespace updater { --- 24,35 ---- #include <csutil/csmd5.h> #include <csutil/util.h> + #include <iutil/vfs.h> #include "md5.h" + #include "globals.h" + + + namespace updater { *************** *** 60,67 **** } ! void MD5Sum::Set (const char* md5sum) throw(Error) { if (strlen (md5sum) != 32) ! throw Error("Tried to set md5 sum with wrong len."); delete[] md5; --- 64,71 ---- } ! void MD5Sum::Set (const char* md5sum) { if (strlen (md5sum) != 32) ! CRTError("Tried to set md5 sum with wrong len."); delete[] md5; *************** *** 74,102 **** } ! void MD5Sum::ReadFile (const char* filename, bool textmode) throw(Error) { ! size_t filesize; ! FILE* file; ! ! // Open file ! file = fopen (filename, textmode ? "r" : "rb"); ! if (!file) ! throw Error ("Couldn't open file '%s' for md5sum calculation.", ! filename); ! ! // get filesize ! fseek (file, 0, SEEK_END); ! filesize = ftell(file); ! fseek (file, 0, SEEK_SET); ! char* buffer = new char[filesize]; ! if (filesize > 0 && fread (buffer, filesize, 1, file) != 1) ! throw Error ("Error when reading file '%s' for md5.", ! filename); ! fclose (file); ! ! Calculate (buffer, filesize); ! delete[] buffer; } --- 78,93 ---- } ! bool MD5Sum::ReadFile (const char* filename, bool textmode) { ! csRef<iDataBuffer> buffer = psengine->GetVFS()->ReadFile(filename,true); ! if(!buffer) ! { ! return false; ! } ! Calculate (buffer->GetData(), buffer->GetSize()); ! //delete[] buffer; ! return true; } Index: md5.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/md5.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** md5.h 4 Mar 2003 13:29:30 -0000 1.2 --- md5.h 30 Apr 2004 15:58:30 -0000 1.3 *************** *** 20,24 **** #define __UPDATER_MD5_H__ - #include "error.h" namespace updater --- 20,23 ---- *************** *** 34,42 **** /// Read a file and calculate it's md5 ! void ReadFile (const char* filename, bool textmode) throw(Error); /// Calculates a new md5 sum of a buffer void Calculate (char* buffer, size_t len); /// Set MD5 sum to value of the string ! void Set (const char* md5sum) throw(Error); /// Get MD5 sum as a string const char* Get() const; --- 33,41 ---- /// Read a file and calculate it's md5 ! bool ReadFile (const char* filename, bool textmode); /// Calculates a new md5 sum of a buffer void Calculate (char* buffer, size_t len); /// Set MD5 sum to value of the string ! void Set (const char* md5sum); /// Get MD5 sum as a string const char* Get() const; Index: registry.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/registry.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** registry.cpp 13 Mar 2004 16:49:07 -0000 1.4 --- registry.cpp 30 Apr 2004 15:58:30 -0000 1.5 *************** *** 24,44 **** #include <iutil/objreg.h> #include <iutil/vfs.h> - #include "error.h" #include "registry.h" #include "sortarray.h" namespace updater { ! Registry::Registry (iObjectRegistry* newobjreg) throw(Error) { objreg = newobjreg; vfs = CS_QUERY_REGISTRY (objreg, iVFS); if (!vfs) ! throw Error("Couldn't find vfs plugin!\n"); xml = csPtr<iDocumentSystem> (new csTinyDocumentSystem); if (!xml) ! throw Error("Error creating xml document system!"); } --- 24,45 ---- #include <iutil/objreg.h> #include <iutil/vfs.h> #include "registry.h" #include "sortarray.h" + #include "globals.h" + namespace updater { ! Registry::Registry (iObjectRegistry* newobjreg) { objreg = newobjreg; vfs = CS_QUERY_REGISTRY (objreg, iVFS); if (!vfs) ! CRTError("Couldn't find vfs plugin!\n"); xml = csPtr<iDocumentSystem> (new csTinyDocumentSystem); if (!xml) ! CRTError("Error creating xml document system!"); } *************** *** 47,69 **** } ! void Registry::Load (const char* filename) throw(Error) { csRef<iDataBuffer> buf = vfs->ReadFile (filename); if (!buf || !buf->GetSize()) ! throw Error("Error loading registry file '%s'", filename); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse (buf); if (error) ! throw Error("Couldn't parse xml: '%s'", error); csRef<iDocumentNode> root = doc->GetRoot (); if (!root) ! throw Error("Error when getting top registry node!"); csRef<iDocumentNode> topnode = root->GetNode ("registry"); if (!topnode) ! throw Error("Couldn't find registry topnode!"); // read list of modules --- 48,82 ---- } ! bool Registry::Load (const char* filename) { csRef<iDataBuffer> buf = vfs->ReadFile (filename); if (!buf || !buf->GetSize()) ! { ! printf("Error loading registry file '%s'", filename); ! return false; ! } csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse (buf); if (error) ! { ! printf("Couldn't parse xml: '%s'", error); ! return false; ! } csRef<iDocumentNode> root = doc->GetRoot (); if (!root) ! { ! printf("Error when getting top registry node!"); ! return false; ! } csRef<iDocumentNode> topnode = root->GetNode ("registry"); if (!topnode) ! { ! printf("Couldn't find registry topnode!"); ! return false; ! } // read list of modules *************** *** 90,153 **** } ! int modindex = modules.Push (Module (name)); ParseModule (node, modules[modindex]); } } ! void Registry::ParseModule (iDocumentNode* node, FileList& objectlist) ! throw(Error) { csRef<iDocumentNodeIterator> it = node->GetNodes (); while (it->HasNext ()) { - csRef<iDocumentNode> node = it->Next(); - if (node->GetType() != CS_NODE_ELEMENT) - continue; ! if (strcmp (node->GetValue(), "file") != 0) ! { ! fprintf (stderr, "Warning: Expected 'file' node got '%s'.\n", ! node->GetValue()); ! continue; ! } ! const char* path = node->GetAttributeValue ("path"); ! if (!path) ! { ! fprintf (stderr, "Warning: Expected filename for file.\n"); ! continue; ! } ! // reading flags ! uint32_t flags = 0; ! if (node->GetAttributeValueAsInt ("executable") == 1) ! flags |= RegistryFile::FLAG_EXECUTABLE; ! if (node->GetAttributeValueAsInt ("textfile") == 1) ! flags |= RegistryFile::FLAG_TEXTFILE; ! if (node->GetAttributeValueAsInt ("config") == 1) ! flags |= RegistryFile::FLAG_CONFIGFILE; ! const char* link = node->GetAttributeValue ("link"); ! if (link) ! flags |= RegistryFile::FLAG_LINK; ! RegistryFile object(path, flags); ! object.size = node->GetAttributeValueAsInt ("size"); ! const char* timestamp = node->GetAttributeValue ("datestamp"); ! if (timestamp) ! object.timestamp.Set (timestamp); ! const char* md5 = node->GetAttributeValue ("md5"); ! if (md5) ! object.md5.Set(md5); ! objectlist.Push (object); } ! SortArray (objectlist); } ! void Registry::Save (const char* filename) const throw(Error) { csRef<iDocument> doc = xml->CreateDocument(); --- 103,220 ---- } ! Module* mod = new Module(name); ! ! int modindex = modules.Push (mod); ParseModule (node, modules[modindex]); } + + return true; } ! void Registry::ParseModule (iDocumentNode* node, Module* objectlist) { csRef<iDocumentNodeIterator> it = node->GetNodes (); while (it->HasNext ()) { ! csRef<iDocumentNode> node = it->Next(); ! if (node->GetType() != CS_NODE_ELEMENT) ! continue; ! if(!strcmp (node->GetValue(),"zip")) ! { ! ! //Do zip ! csString zip = node->GetAttributeValue("file"); ! ! csRef<iDocumentNodeIterator> it2 = node->GetNodes (); ! while (it2->HasNext ()) ! { ! csRef<iDocumentNode> node2 = it2->Next(); ! ! //Add file? ! if(!strcmp(node2->GetValue(),"add")) ! { ! RegistryFile* object = new RegistryFile(node2->GetAttributeValue ("realfile"), 0); ! ! object->zipFile = node2->GetAttributeValue ("zipfile"); ! object->parentZip = zip; ! object->inZip = true; ! object->size = node2->GetAttributeValueAsInt ("size"); ! ! const char* timestamp = node2->GetAttributeValue ("datestamp"); ! if (timestamp) ! object->timestamp.Set (timestamp); ! ! const char* md5 = node2->GetAttributeValue ("md5"); ! if (md5) ! object->md5.Set(md5); ! ! objectlist->AddRegistryFile (object); ! } ! ! //Remove file? ! if(!strcmp(node2->GetValue(),"remove")) ! { ! RegistryFile* object = new RegistryFile(node2->GetAttributeValue ("file"), 0); ! ! object->parentZip = zip; ! object->inZip = true; ! object->removeFromZip = true; ! ! objectlist->AddRegistryFile (object); ! } ! ! ! } ! ! continue; ! ! } ! else if (strcmp (node->GetValue(), "file") != 0) ! { ! fprintf (stderr, "Warning: Expected 'file' node got '%s'.\n", ! node->GetValue()); ! continue; ! } ! ! const char* path = node->GetAttributeValue ("path"); ! if (!path) ! { ! fprintf (stderr, "Warning: Expected filename for file.\n"); ! continue; ! } ! // reading flags ! uint32_t flags = 0; ! if (node->GetAttributeValueAsInt ("executable") == 1) ! flags |= RegistryFile::FLAG_EXECUTABLE; ! if (node->GetAttributeValueAsInt ("textfile") == 1) ! flags |= RegistryFile::FLAG_TEXTFILE; ! if (node->GetAttributeValueAsInt ("config") == 1) ! flags |= RegistryFile::FLAG_CONFIGFILE; ! const char* link = node->GetAttributeValue ("link"); ! if (link) ! flags |= RegistryFile::FLAG_LINK; ! RegistryFile* object = new RegistryFile(path, flags); ! object->size = node->GetAttributeValueAsInt ("size"); ! const char* timestamp = node->GetAttributeValue ("datestamp"); ! if (timestamp) ! object->timestamp.Set (timestamp); ! const char* md5 = node->GetAttributeValue ("md5"); ! if (md5) ! object->md5.Set(md5); ! objectlist->AddRegistryFile (object); } ! // SortArray (objectlist); } ! void Registry::Save (const char* filename) { csRef<iDocument> doc = xml->CreateDocument(); *************** *** 163,167 **** topnode->CreateNodeBefore (CS_NODE_ELEMENT); modulenode->SetValue ("module"); ! modulenode->SetAttribute ("name", modules[i].GetName()); WriteModule (modulenode, modules[i]); --- 230,234 ---- topnode->CreateNodeBefore (CS_NODE_ELEMENT); modulenode->SetValue ("module"); ! modulenode->SetAttribute ("name", modules[i]->GetName()); WriteModule (modulenode, modules[i]); *************** *** 170,209 **** const char* error = doc->Write (vfs, filename); if (error) ! throw Error("When writing '%s': %s", filename, error); } ! void Registry::WriteModule (iDocumentNode* node, ! const FileList& filelist) const throw(Error) { ! for (int i=0;i<filelist.Length();i++) ! { ! const RegistryFile* file = & filelist[i] ; ! csRef<iDocumentNode> filenode = ! node->CreateNodeBefore (CS_NODE_ELEMENT); ! filenode->SetValue ("file"); ! filenode->SetAttribute ("path", file->file); ! filenode->SetAttributeAsInt ("size", file->size); ! filenode->SetAttribute ("datestamp", file->timestamp.Get()); ! if (file->md5.Get()) ! filenode->SetAttribute ("md5", file->md5.Get()); ! if (file->flags & RegistryFile::FLAG_EXECUTABLE) ! filenode->SetAttribute ("executable", "1"); ! if (file->flags & RegistryFile::FLAG_TEXTFILE) ! filenode->SetAttribute ("textfile", "1"); ! if (file->flags & RegistryFile::FLAG_LINK) ! filenode->SetAttribute ("link", file->link); ! if (file->flags & RegistryFile::FLAG_CONFIGFILE) ! filenode->SetAttribute ("config", "1"); } } ! const FileList* Registry::GetModule (const char* modulename) const { for (int i=0;i<modules.Length();i++) { ! if (strcmp(modules[i].GetName(), modulename) == 0) ! return & modules[i]; } --- 237,275 ---- const char* error = doc->Write (vfs, filename); if (error) ! CRTError3("When writing '%s': %s", filename, error); } ! void Registry::WriteModule (iDocumentNode* node,Module* mod) { ! for (unsigned int i=0;i<mod->GetRegistryLength();i++) ! { ! RegistryFile* file = mod->GetRegistryFile(i) ; ! csRef<iDocumentNode> filenode = ! node->CreateNodeBefore (CS_NODE_ELEMENT); ! filenode->SetValue ("file"); ! filenode->SetAttribute ("path", file->file); ! filenode->SetAttributeAsInt ("size", file->size); ! filenode->SetAttribute ("datestamp", file->timestamp.Get()); ! if (file->md5.Get()) ! filenode->SetAttribute ("md5", file->md5.Get()); ! if (file->flags & RegistryFile::FLAG_EXECUTABLE) ! filenode->SetAttribute ("executable", "1"); ! if (file->flags & RegistryFile::FLAG_TEXTFILE) ! filenode->SetAttribute ("textfile", "1"); ! if (file->flags & RegistryFile::FLAG_LINK) ! filenode->SetAttribute ("link", file->link); ! if (file->flags & RegistryFile::FLAG_CONFIGFILE) ! filenode->SetAttribute ("config", "1"); } } ! Module* Registry::GetModule (const char* modulename) { for (int i=0;i<modules.Length();i++) { ! if (strcmp(modules[i]->GetName(), modulename) == 0) ! return modules[i]; } *************** *** 211,233 **** } ! FileList& Registry::CreateModule (const char* modulename) { ! int idx = modules.Push (Module (modulename)); return modules[idx]; } ! bool Registry::operator == (const Registry& other) const { // registries are sorted so just comparing for (int m=0;m<modules.Length();m++) { ! const char* module = modules[m].GetName(); ! const FileList* othermod = other.GetModule (module); ! if (!othermod || modules[m].Length() != (*othermod).Length()) return false; ! for (int f=0;f<modules[m].Length();f++) { ! if (! (modules[m][f] == (*othermod) [f]) ) return false; } --- 277,302 ---- } ! Module* Registry::CreateModule (const char* modulename) { ! Module* mod = new Module (modulename); ! ! int idx = modules.Push (mod); return modules[idx]; } ! bool Registry::operator == (Registry* other) const { // registries are sorted so just comparing for (int m=0;m<modules.Length();m++) { ! const char* module = modules[m]->GetName(); ! Module* othermod = other->GetModule (module); ! ! if (!othermod || modules[m]->GetRegistryLength() != othermod->GetRegistryLength()) return false; ! for (unsigned int f=0;f<modules[m]->GetRegistryLength();f++) { ! if (! (modules[m]->GetRegistryFile(f) == othermod->GetRegistryFile(f) ) ) return false; } *************** *** 239,261 **** //--------------------------------------------------------------------------- ! Registry::Module::Module (const char* newname) { name = csStrNew(newname); } - Registry::Module::Module (const Module& other) - : FileList((const FileList&) other) - { - name = csStrNew(other.name); - } ! Registry::Module::~Module () { delete[] name; } ! const char* Registry::Module::GetName () const { return name; } } // end of namespace updater --- 308,330 ---- //--------------------------------------------------------------------------- ! Module::Module (const char* newname) { name = csStrNew(newname); } ! Module::~Module () { delete[] name; } ! const char* Module::GetName () const { return name; } + RegistryFile* Module::GetRegistryFile(unsigned int id) + { + return list.Get(id); + } + } // end of namespace updater Index: registry.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/updater/httpclient/registry.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** registry.h 7 Mar 2003 19:41:05 -0000 1.3 --- registry.h 30 Apr 2004 15:58:30 -0000 1.4 *************** *** 22,26 **** #include <csutil/ref.h> #include <csutil/array.h> - #include "error.h" #include "registryfile.h" #include "changelist.h" --- 22,25 ---- *************** *** 33,36 **** --- 32,57 ---- { + /** A module combines a list of files. Modules can be used to group files + * (for things like operating system, basic/extended install) + */ + class Module : public FileList + { + public: + /** Create a new module */ + Module (const char* name); + ~Module (); + + /// returns the name of the module + const char* GetName() const; + + RegistryFile* GetRegistryFile(unsigned int id); + void AddRegistryFile(RegistryFile* file) {list.Push(file); } + unsigned int GetRegistryLength() { return list.Length(); } + + private: + FileList list; + char* name; + }; + /** This class holds a tree structure (called registry) which represents * the state of a repository (server or client). It is possible to *************** *** 41,89 **** { public: ! Registry (iObjectRegistry* objreg) throw(Error); ! ~Registry (); /// Load a registry file from disk (vfs path) ! void Load (const char* filename) throw(Error); /// Save a registry file to disk (vfs path) ! void Save (const char* filename) const throw(Error); /// Returns the module with name modulename ! const FileList* GetModule (const char* modulename) const; /// Create a new module with name modulename ! FileList& CreateModule (const char* modulename); /// compared 2 registries ! bool operator == (const Registry& other) const; ! ! private: ! /** A module combines a list of files. Modules can be used to group files ! * (for things like operating system, basic/extended install) ! */ ! class Module : public FileList ! { ! public: ! /** Create a new module */ ! Module (const char* name); ! Module (const Module& other); ! ~Module (); ! ! /// returns the name of the module ! const char* GetName() const; ! private: ! char* name; ! }; /// Parse 1 directory/module entry. ! void ParseModule (iDocumentNode* node, FileList& topdir) throw(Error); /// Write 1 directory/module entry. ! void WriteModule (iDocumentNode* node, const FileList& objlist) ! const throw(Error); /// The module list ! csArray<Module> modules; iObjectRegistry* objreg; --- 62,98 ---- { public: ! Registry (iObjectRegistry* objreg); ! virtual ~Registry (); /// Load a registry file from disk (vfs path) ! bool Load (const c... [truncated message content] |