00001 /* 00002 This file is part of Advanced Strategic Command; http://www.asc-hq.org 00003 Copyright (C) 1994-2010 Martin Bickel 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 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 00015 You should have received a copy of the GNU General Public License 00016 along with this program; see the file COPYING. If not, write to the 00017 Free Software Foundation, Inc., 59 Temple Place, Suite 330, 00018 Boston, MA 02111-1307 USA 00019 */ 00020 00021 #include "packagerepository.h" 00022 #include "strtmesg.h" 00023 #include "packagemanager.h" 00024 00025 00026 PackageRepository packageRepository; 00027 00028 void PackageRepository ::addProgramPackage() 00029 { 00030 Package* prog = _getPackage( "ASC"); 00031 if ( !prog ) { 00032 prog = new Package(); 00033 packageRepository.push_back( prog ); 00034 prog->name = "ASC"; 00035 } 00036 prog->version.fromString( getVersionString() ); 00037 } 00038 00039 void PackageRepository ::readTextFiles( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location ) 00040 { 00041 Package* p = new Package(); 00042 p->runTextIO( prc ); 00043 00044 // p->filename = fileName; 00045 // p->location = location; 00046 00047 packageRepository.push_back( p ); 00048 } 00049 00050 void PackageRepository :: read ( tnstream& stream ) 00051 { 00052 stream.readInt(); 00053 readPointerContainer( packageRepository, stream ); 00054 } 00055 00056 void PackageRepository :: write ( tnstream& stream ) 00057 { 00058 stream.writeInt( 1 ); 00059 writePointerContainer( packageRepository, stream ); 00060 } 00061 00062 SigC::Signal0<void> PackageRepository::packgeDescriptionLoaded; 00063 00064 void PackageRepository :: postChecks() 00065 { 00066 addProgramPackage(); 00067 for ( PackageRepository::iterator i = packageRepository.begin(); i != packageRepository.end(); ++i ) { 00068 checkPackageDependency( *i ); 00069 } 00070 packgeDescriptionLoaded(); 00071 } 00072 00073 void PackageRepository::checkPackageDependency( const Package* pack, const PackageData* packageData ) 00074 { 00075 for ( Package::Dependencies::const_iterator dep = pack->dependencies.begin(); dep != pack->dependencies.end(); ++dep ) { 00076 const Package* p = getPackage( dep->name ); 00077 if ( p ) { 00078 if ( p->version < dep->version ) { 00079 ASCString s = "The package " + dep->name + " on your system is outdated.\n" 00080 + "Package " + pack->name + " requires at least " + dep->version.toString() + "\n"; 00081 00082 if ( !p->description.empty() ) 00083 s += "\nPackage Info:\n" + p->description ; 00084 throw ASCmsgException( s); 00085 } 00086 } else { 00087 ASCString s = "The package " + dep->name + " is missing on your system!" ; 00088 if ( packageData ) { 00089 for ( PackageData::Packages::const_iterator ref = packageData->packages.begin(); ref != packageData->packages.end(); ++ref ) 00090 if ( ref->second->name == dep->name ) 00091 if ( !ref->second->description.empty()) 00092 s += "\nPackage Info:\n" + ref->second->description ; 00093 00094 } 00095 throw ASCmsgException( s ); 00096 } 00097 00098 } 00099 } 00100 00101 00102 Package* PackageRepository::_getPackage( const ASCString& name ) 00103 { 00104 for ( PackageRepository::const_iterator p = packageRepository.begin(); p != packageRepository.end(); ++p ) 00105 if ( (*p)->name.compare_ci( name ) == 0 ) 00106 return *p; 00107 return NULL; 00108 } 00109 00110 const Package* PackageRepository::getPackage( const ASCString& name ) const 00111 { 00112 for ( PackageRepository::const_iterator p = packageRepository.begin(); p != packageRepository.end(); ++p ) 00113 if ( (*p)->name.compare_ci( name ) == 0 ) 00114 return *p; 00115 return NULL; 00116 } 00117 00118
1.5.1