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 "c4group/C4Components.h"
22 
23 C4Extra::C4Extra() = default;
24 
25 C4Extra::~C4Extra() = default;
26 
28 {
29  // register extra root into game group set
30  for(const auto & iter : Reloc)
31  {
32  std::unique_ptr<C4Group> pGroup(new C4Group);
33  if(pGroup->Open( (iter.strBuf + DirSep + C4CFN_Extra).getData()))
34  ExtraGroups.emplace_back(std::move(pGroup));
35  }
36 
37  // done, success
38  return true;
39 }
40 
42 {
43  // no group: OK
44  if (ExtraGroups.empty()) return true;
45  // load from all definitions that are activated
46  // add first definition first, so the priority will be lowest
47  // (according to definition load/overload order)
48  char szSegment[_MAX_PATH+1];
49  for (int cseg=0; SCopySegment(Game.DefinitionFilenames,cseg,szSegment,';',_MAX_PATH); cseg++)
50  {
51  for(auto & ExtraGroup : ExtraGroups)
52  {
53  if(LoadDef(*ExtraGroup, GetFilename(szSegment)))
54  {
55  break;
56  }
57  }
58  }
59  // done, success
60  return true;
61 }
62 
63 bool C4Extra::LoadDef(C4Group &hGroup, const char *szName)
64 {
65  // check if file exists
66  if (!hGroup.FindEntry(szName)) return false;
67  // log that extra group is loaded
68  LogF(LoadResStr("IDS_PRC_LOADEXTRA"), hGroup.GetName(), szName);
69  // open and add group to set
70  C4Group *pGrp = new C4Group;
71  if (!pGrp->OpenAsChild(&hGroup, szName)) { Log(LoadResStr("IDS_ERR_FAILURE")); delete pGrp; return false; }
73  // done, success
74  return true;
75 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
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:88
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:87
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:251
#define _MAX_PATH
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * GetName() const
Definition: C4Group.cpp:1845
bool Init()
Definition: C4Extra.cpp:41
bool InitGroup()
Definition: C4Extra.cpp:27
C4Reloc Reloc
Definition: C4Reloc.cpp:21
#define C4GSPrio_Extra
Definition: C4GroupSet.h:26
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
char DefinitionFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:105
std::vector< std::unique_ptr< C4Group > > ExtraGroups
Definition: C4Extra.h:32
#define DirSep
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
bool LoadDef(C4Group &hGroup, const char *szName)
Definition: C4Extra.cpp:63