OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Extra.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // user-customizable multimedia package Extra.ocg
17 
18 #include "C4Include.h"
19 #include "c4group/C4Extra.h"
20 
21 #include "config/C4Config.h"
22 #include "c4group/C4Components.h"
23 #include "game/C4Game.h"
24 #include "lib/C4Log.h"
25 
27 {
28 }
29 
31 {
32 }
33 
35 {
36  // register extra root into game group set
37  for(C4Reloc::iterator iter = Reloc.begin(); iter != Reloc.end(); ++iter)
38  {
39  std::unique_ptr<C4Group> pGroup(new C4Group);
40  if(pGroup->Open( ((*iter).strBuf + DirSep + C4CFN_Extra).getData()))
41  ExtraGroups.emplace_back(std::move(pGroup));
42  }
43 
44  // done, success
45  return true;
46 }
47 
49 {
50  // no group: OK
51  if (ExtraGroups.empty()) return true;
52  // load from all definitions that are activated
53  // add first definition first, so the priority will be lowest
54  // (according to definition load/overload order)
55  char szSegment[_MAX_PATH+1];
56  for (int cseg=0; SCopySegment(Game.DefinitionFilenames,cseg,szSegment,';',_MAX_PATH); cseg++)
57  {
58  for(unsigned int i = 0; i < ExtraGroups.size(); ++i)
59  {
60  if(LoadDef(*ExtraGroups[i], GetFilename(szSegment)))
61  {
62  break;
63  }
64  }
65  }
66  // done, success
67  return true;
68 }
69 
70 bool C4Extra::LoadDef(C4Group &hGroup, const char *szName)
71 {
72  // check if file exists
73  if (!hGroup.FindEntry(szName)) return false;
74  // log that extra group is loaded
75  LogF(LoadResStr("IDS_PRC_LOADEXTRA"), hGroup.GetName(), szName);
76  // open and add group to set
77  C4Group *pGrp = new C4Group;
78  if (!pGrp->OpenAsChild(&hGroup, szName)) { Log(LoadResStr("IDS_ERR_FAILURE")); delete pGrp; return false; }
80  // done, success
81  return true;
82 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
#define C4CFN_Extra
Definition: C4Components.h:31
#define C4GSCnt_Extra
Definition: C4GroupSet.h:48
bool RegisterGroup(C4Group &rGroup, bool fOwnGrp, int32_t Priority, int32_t Contents, bool fCheckContent=true)
Definition: C4GroupSet.cpp:90
C4Extra()
Definition: C4Extra.cpp:26
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:89
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:250
PathList::const_iterator iterator
Definition: C4Reloc.h:38
#define _MAX_PATH
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
~C4Extra()
Definition: C4Extra.cpp:30
const char * GetName() const
Definition: C4Group.cpp:1845
bool Init()
Definition: C4Extra.cpp:48
bool InitGroup()
Definition: C4Extra.cpp:34
iterator begin() const
Definition: C4Reloc.cpp:59
C4Reloc Reloc
Definition: C4Reloc.cpp:22
#define C4GSPrio_Extra
Definition: C4GroupSet.h:26
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
char DefinitionFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:107
iterator end() const
Definition: C4Reloc.cpp:64
std::vector< std::unique_ptr< C4Group > > ExtraGroups
Definition: C4Extra.h:32
#define DirSep
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
bool LoadDef(C4Group &hGroup, const char *szName)
Definition: C4Extra.cpp:70