OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScenarioSection Class Reference

#include <C4Scenario.h>

Collaboration diagram for C4ScenarioSection:
[legend]

Public Member Functions

 C4ScenarioSection (const char *szName)
 
 ~C4ScenarioSection ()
 
bool ScenarioLoad (const char *szFilename, bool is_temp_file)
 
C4GroupGetGroupfile (C4Group &rGrp)
 
bool EnsureTempStore (bool fExtractLandscape, bool fExtractObjects)
 

Public Attributes

StdCopyStrBuf name
 
StdCopyStrBuf temp_filename
 
StdCopyStrBuf filename
 
bool fModified
 
class C4ScenarioObjectsScriptHostpObjectScripts
 
C4ScenarioSectionpNext
 

Detailed Description

Definition at line 251 of file C4Scenario.h.

Constructor & Destructor Documentation

C4ScenarioSection::C4ScenarioSection ( const char *  szName)

Definition at line 27 of file C4ScenarioSection.cpp.

References StdStrBuf::Copy(), fModified, Game, name, pNext, pObjectScripts, and C4Game::pScenarioSections.

28 {
29  // copy name
30  name.Copy(szName);
31  // zero fields
32  fModified = false;
33  pObjectScripts = nullptr;
34  // link into main list
36  Game.pScenarioSections = this;
37 }
C4Game Game
Definition: C4Globals.cpp:52
C4ScenarioSection * pScenarioSections
Definition: C4Game.h:91
StdCopyStrBuf name
Definition: C4Scenario.h:258
class C4ScenarioObjectsScriptHost * pObjectScripts
Definition: C4Scenario.h:262
C4ScenarioSection * pNext
Definition: C4Scenario.h:264
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

C4ScenarioSection::~C4ScenarioSection ( )

Definition at line 39 of file C4ScenarioSection.cpp.

References EraseItem(), StdStrBuf::getData(), pNext, and temp_filename.

40 {
41  // del following scenario sections
42  while (pNext)
43  {
44  C4ScenarioSection *pDel = pNext;
45  pNext = pNext->pNext;
46  pDel->pNext = nullptr;
47  delete pDel;
48  }
49  // del temp file
50  if (temp_filename.getData())
51  {
53  }
54 }
const char * getData() const
Definition: StdBuf.h:442
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
C4ScenarioSection * pNext
Definition: C4Scenario.h:264
StdCopyStrBuf temp_filename
Definition: C4Scenario.h:259

Here is the call graph for this function:

Member Function Documentation

bool C4ScenarioSection::EnsureTempStore ( bool  fExtractLandscape,
bool  fExtractObjects 
)

Definition at line 116 of file C4ScenarioSection.cpp.

References _MAX_FNAME, C4Config::AtTempPath(), C4FLS_Section, C4FLS_SectionLandscape, C4FLS_SectionObjects, C4Group::Close(), Config, StdStrBuf::Copy(), CreatePath(), C4Group::Delete(), EraseItem(), C4Group::ExtractEntry(), filename, C4Group::FindNextEntry(), Game, StdStrBuf::getData(), GetFilename(), MakeTempFilename(), name, C4Group::Open(), C4Group::ResetSearch(), C4Game::ScenarioFile, temp_filename, and WildcardMatch().

Referenced by C4Game::LoadScenarioSection(), and ScenarioLoad().

117 {
118  // if it's temp store already, don't do anything
119  if (temp_filename.getData()) return true;
120  // make temp filename
121  char *szTmp = const_cast<char *>(Config.AtTempPath(filename.getData() ? GetFilename(filename.getData()) : name.getData()));
122  MakeTempFilename(szTmp);
123  // main section: extract section files from main scenario group (create group as open dir)
124  if (!filename.getData())
125  {
126  if (!CreatePath(szTmp)) return false;
127  C4Group hGroup;
128  if (!hGroup.Open(szTmp, true)) { EraseItem(szTmp); return false; }
129  // extract all desired section files
131  char fn[_MAX_FNAME+1]; *fn=0;
133  if (fExtractLandscape || !WildcardMatch(C4FLS_SectionLandscape, fn))
134  if (fExtractObjects || !WildcardMatch(C4FLS_SectionObjects, fn))
135  Game.ScenarioFile.ExtractEntry(fn, szTmp);
136  hGroup.Close();
137  }
138  else
139  {
140  // subsection: simply extract section from main group
141  if (!Game.ScenarioFile.ExtractEntry(filename.getData(), szTmp)) return false;
142  // delete undesired landscape/object files
143  if (!fExtractLandscape || !fExtractObjects)
144  {
145  C4Group hGroup;
146  if (hGroup.Open(filename.getData()))
147  {
148  if (!fExtractLandscape) hGroup.Delete(C4FLS_SectionLandscape);
149  if (!fExtractObjects) hGroup.Delete(C4FLS_SectionObjects);
150  }
151  }
152  }
153  // copy temp filename
154  temp_filename.Copy(szTmp);
155  // done, success
156  return true;
157 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * getData() const
Definition: StdBuf.h:442
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
#define C4FLS_Section
Definition: C4Components.h:189
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
StdCopyStrBuf filename
Definition: C4Scenario.h:260
#define C4FLS_SectionLandscape
Definition: C4Components.h:190
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
C4Group ScenarioFile
Definition: C4Game.h:86
bool Close()
Definition: C4Group.cpp:755
#define _MAX_FNAME
#define C4FLS_SectionObjects
Definition: C4Components.h:191
StdCopyStrBuf name
Definition: C4Scenario.h:258
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374
bool ExtractEntry(const char *szFilename, const char *szExtractTo=nullptr)
Definition: C4Group.cpp:1518
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
void Copy()
Definition: StdBuf.h:467
StdCopyStrBuf temp_filename
Definition: C4Scenario.h:259

Here is the call graph for this function:

Here is the caller graph for this function:

C4Group * C4ScenarioSection::GetGroupfile ( C4Group rGrp)

Definition at line 96 of file C4ScenarioSection.cpp.

References C4ScenSect_Main, filename, Game, StdStrBuf::getData(), name, C4Group::Open(), C4Group::OpenAsChild(), C4Game::ScenarioFile, SEqualNoCase(), and temp_filename.

Referenced by C4Game::LoadScenarioSection(), and ScenarioLoad().

97 {
98  // check temp filename
99  if (temp_filename.getData())
100  {
101  if (rGrp.Open(temp_filename.getData())) return &rGrp;
102  else return nullptr;
103  }
104  // check filename within scenario
105  if (filename.getData())
106  {
107  if (rGrp.OpenAsChild(&Game.ScenarioFile, filename.getData())) return &rGrp;
108  else return nullptr;
109  }
110  // unmodified main section: return main group
112  // failure
113  return nullptr;
114 }
const char * getData() const
Definition: StdBuf.h:442
C4Game Game
Definition: C4Globals.cpp:52
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:185
StdCopyStrBuf filename
Definition: C4Scenario.h:260
const char * C4ScenSect_Main
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
C4Group ScenarioFile
Definition: C4Game.h:86
StdCopyStrBuf name
Definition: C4Scenario.h:258
StdCopyStrBuf temp_filename
Definition: C4Scenario.h:259
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScenarioSection::ScenarioLoad ( const char *  szFilename,
bool  is_temp_file 
)

Definition at line 56 of file C4ScenarioSection.cpp.

References C4CFN_ScenarioObjectsScript, C4ScenSect_Main, Config, StdStrBuf::Copy(), EnsureTempStore(), filename, C4Group::FindEntry(), Game, C4Config::General, StdStrBuf::getData(), GetGroupfile(), C4Group::IsPacked(), C4ConfigGeneral::LanguageEx, C4ScriptHost::Load(), name, pObjectScripts, C4Game::pScenarioObjectsScript, C4ScriptHost::Reg2List(), C4Game::ScenarioFile, C4Game::ScenarioLangStringTable, ScriptEngine, SEqualNoCase(), and temp_filename.

Referenced by C4Game::CreateSectionFromTempFile(), and C4Game::LoadScenarioComponents().

57 {
58  // safety
59  if (filename.getData() || !szFilename) return false;
60  // store name
61  filename.Copy(szFilename);
62  if (is_temp_file)
63  {
64  // temp: Remember temp filename to be deleted on destruction
65  temp_filename.Copy(szFilename);
66  }
67  else
68  {
69  // non-temp: extract if it's not an open folder
70  if (Game.ScenarioFile.IsPacked()) if (!EnsureTempStore(true, true)) return false;
71  }
72  // load section object script
74  {
75  C4Group GrpSect, *pGrp;
76  if ((pGrp = GetGroupfile(GrpSect)) && pGrp->FindEntry(C4CFN_ScenarioObjectsScript))
77  {
81  }
82  else
83  {
84  pObjectScripts = nullptr;
85  }
86  }
87  else
88  {
89  // Object script for main section
91  }
92  // donce, success
93  return true;
94 }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:833
C4Game Game
Definition: C4Globals.cpp:52
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4ConfigGeneral General
Definition: C4Config.h:251
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:185
class C4ScenarioObjectsScriptHost * pScenarioObjectsScript
Definition: C4Game.h:90
StdCopyStrBuf filename
Definition: C4Scenario.h:260
void Reg2List(C4AulScriptEngine *pEngine)
C4LangStringTable ScenarioLangStringTable
Definition: C4Game.h:80
const char * C4ScenSect_Main
#define C4CFN_ScenarioObjectsScript
Definition: C4Components.h:74
C4Group ScenarioFile
Definition: C4Game.h:86
C4Group * GetGroupfile(C4Group &rGrp)
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:37
bool EnsureTempStore(bool fExtractLandscape, bool fExtractObjects)
StdCopyStrBuf name
Definition: C4Scenario.h:258
class C4ScenarioObjectsScriptHost * pObjectScripts
Definition: C4Scenario.h:262
bool IsPacked() const
Definition: C4Group.cpp:2009
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
void Copy()
Definition: StdBuf.h:467
StdCopyStrBuf temp_filename
Definition: C4Scenario.h:259

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

StdCopyStrBuf C4ScenarioSection::filename

Definition at line 260 of file C4Scenario.h.

Referenced by EnsureTempStore(), GetGroupfile(), and ScenarioLoad().

bool C4ScenarioSection::fModified

Definition at line 261 of file C4Scenario.h.

Referenced by C4ScenarioSection(), and C4Game::LoadScenarioSection().

class C4ScenarioObjectsScriptHost* C4ScenarioSection::pObjectScripts
StdCopyStrBuf C4ScenarioSection::temp_filename

Definition at line 259 of file C4Scenario.h.

Referenced by EnsureTempStore(), GetGroupfile(), ScenarioLoad(), and ~C4ScenarioSection().


The documentation for this class was generated from the following files: