Advanced Strategic Command
packagerepository.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.org
3  Copyright (C) 1994-2010 Martin Bickel
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
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 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include "packagerepository.h"
22 #include "strtmesg.h"
23 #include "packagemanager.h"
24 
25 
27 
28 void PackageRepository ::addProgramPackage()
29 {
30  Package* prog = _getPackage( "ASC");
31  if ( !prog ) {
32  prog = new Package();
33  packageRepository.push_back( prog );
34  prog->name = "ASC";
35  }
37 }
38 
39 void PackageRepository ::readTextFiles( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location )
40 {
41  Package* p = new Package();
42  p->runTextIO( prc );
43 
44  // p->filename = fileName;
45  // p->location = location;
46 
47  packageRepository.push_back( p );
48 }
49 
51 {
52  stream.readInt();
53  readPointerContainer( packageRepository, stream );
54 }
55 
57 {
58  stream.writeInt( 1 );
59  writePointerContainer( packageRepository, stream );
60 }
61 
63 
65 {
66  addProgramPackage();
67  for ( PackageRepository::iterator i = packageRepository.begin(); i != packageRepository.end(); ++i ) {
69  }
71 }
72 
73 void PackageRepository::checkPackageDependency( const Package* pack, const PackageData* packageData )
74 {
75  for ( Package::Dependencies::const_iterator dep = pack->dependencies.begin(); dep != pack->dependencies.end(); ++dep ) {
76  const Package* p = getPackage( dep->name );
77  if ( p ) {
78  if ( p->version < dep->version ) {
79  ASCString s = "The package " + dep->name + " on your system is outdated.\n"
80  + "Package " + pack->name + " requires at least " + dep->version.toString() + "\n";
81 
82  if ( !p->description.empty() )
83  s += "\nPackage Info:\n" + p->description ;
84  throw ASCmsgException( s);
85  }
86  } else {
87  ASCString s = "The package " + dep->name + " is missing on your system!" ;
88  if ( packageData ) {
89  for ( PackageData::Packages::const_iterator ref = packageData->packages.begin(); ref != packageData->packages.end(); ++ref )
90  if ( ref->second->name == dep->name )
91  if ( !ref->second->description.empty())
92  s += "\nPackage Info:\n" + ref->second->description ;
93 
94  }
95  throw ASCmsgException( s );
96  }
97 
98  }
99 }
100 
101 
102 Package* PackageRepository::_getPackage( const ASCString& name )
103 {
104  for ( PackageRepository::const_iterator p = packageRepository.begin(); p != packageRepository.end(); ++p )
105  if ( (*p)->name.compare_ci( name ) == 0 )
106  return *p;
107  return NULL;
108 }
109 
111 {
112  for ( PackageRepository::const_iterator p = packageRepository.begin(); p != packageRepository.end(); ++p )
113  if ( (*p)->name.compare_ci( name ) == 0 )
114  return *p;
115  return NULL;
116 }
117 
118 
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
void checkPackageDependency(const Package *pack, const PackageData *packageData=NULL)
PackageRepository packageRepository
ASCString description
Definition: package.h:42
The interface for all kinds of IO stream.
static sigc::signal< void > packgeDescriptionLoaded
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
void runTextIO(PropertyContainer &pc)
Definition: package.cpp:60
Packages packages
void readPointerContainer(vector< BaseType * > &v, tnstream &stream)
Definition: basestrm.h:714
void read(tnstream &stream)
VersionIdentifier version
Definition: package.h:45
const Package * getPackage(const ASCString &name) const
ASCString name
Definition: package.h:41
void fromString(const ASCString &v)
void write(tnstream &stream)
void readTextFiles(PropertyReadingContainer &prc, const ASCString &fileName, const ASCString &location)
Dependencies dependencies
Definition: package.h:49
const char * getVersionString()
Definition: strtmesg.cpp:32
virtual void postChecks()
void writePointerContainer(const C &c, tnstream &stream)
Definition: basestrm.h:704