OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Group.h File Reference
#include "c4group/CStdFile.h"
Include dependency graph for C4Group.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  C4GroupHeader
 
struct  C4GroupEntryCore
 
class  C4GroupEntry
 
class  C4Group
 

Macros

#define C4GRP_DISABLE_REWINDWARN   ;
 
#define C4GRP_ENABLE_REWINDWARN   ;
 
#define C4GroupFileID   "RedWolf Design GrpFolder"
 

Functions

bool C4Group_TestIgnore (const char *szFilename)
 
void C4Group_SetTempPath (const char *szPath)
 
const char * C4Group_GetTempPath ()
 
void C4Group_SetSortList (const char **ppSortList)
 
void C4Group_SetProcessCallback (bool(*fnCallback)(const char *, int))
 
bool C4Group_IsGroup (const char *szFilename)
 
bool C4Group_CopyItem (const char *szSource, const char *szTarget, bool fNoSort=false, bool fResetAttributes=false)
 
bool C4Group_MoveItem (const char *szSource, const char *szTarget, bool fNoSort=false)
 
bool C4Group_DeleteItem (const char *szItem, bool fRecycle=false)
 
bool C4Group_PackDirectoryTo (const char *szFilename, const char *szFilenameTo)
 
bool C4Group_PackDirectory (const char *szFilename)
 
bool C4Group_UnpackDirectory (const char *szFilename)
 
bool C4Group_ExplodeDirectory (const char *szFilename)
 
bool C4Group_ReadFile (const char *szFilename, char **pData, size_t *iSize)
 

Variables

const int C4GroupFileVer1 =1
 
const int C4GroupFileVer2 =2
 
const int C4GroupMaxError = 100
 
const int32_t C4GroupSwapThreshold = 10 * 1024 * 1024
 
const char * C4CFN_FLS []
 

Class Documentation

struct C4GroupHeader

Definition at line 82 of file C4Group.h.

Class Members
int Entries
char id[24+4]
char reserved[164]
int Ver1
int Ver2

Macro Definition Documentation

#define C4GroupFileID   "RedWolf Design GrpFolder"

Definition at line 61 of file C4Group.h.

Referenced by C4Group::OpenAsChild().

#define C4GRP_DISABLE_REWINDWARN   ;

Definition at line 51 of file C4Group.h.

#define C4GRP_ENABLE_REWINDWARN   ;

Definition at line 52 of file C4Group.h.

Function Documentation

bool C4Group_CopyItem ( const char *  szSource,
const char *  szTarget,
bool  fNoSort = false,
bool  fResetAttributes = false 
)

Definition at line 100 of file C4Group.cpp.

References _MAX_PATH, C4Group_TempPath, C4Group::Close(), CopyItem(), CreateItem(), DirectorySeparator, EraseItem(), C4Group::Extract(), GetFilename(), GetParentPath(), ItemExists(), ItemIdentical(), MakeTempFilename(), C4Group::Move(), C4Group::Open(), SAppend(), SCopy(), C4Group::SetNoSort(), and SLen().

Referenced by C4Network2Res::Derive(), C4MusicFile::ExtractFile(), C4Network2Res::GetStandalone(), C4Network2Res::OptimizeStandalone(), C4ControlJoinPlayer::PreRec(), C4MessageInput::ProcessCommand(), C4Network2::RetrieveScenario(), C4PlayerList::Save(), C4Player::Save(), C4Console::SaveScenario(), and C4Playback::StreamToRecord().

101 {
102  // Parameter check
103  if (!szSource || !szTarget1 || !szSource[0] || !szTarget1[0]) return false;
104  char szTarget[_MAX_PATH+1]; SCopy(szTarget1,szTarget,_MAX_PATH);
105 
106  // Backslash terminator indicates target is a path only (append filename)
107  if (szTarget[SLen(szTarget)-1]==DirectorySeparator) SAppend(GetFilename(szSource),szTarget);
108 
109  // Check for identical source and target
110  // Note that attributes aren't reset here
111  if (ItemIdentical(szSource,szTarget)) return true;
112 
113  // Source and target are simple items
114  if (ItemExists(szSource) && CreateItem(szTarget)) return CopyItem(szSource,szTarget, fResetAttributes);
115 
116  // For items within groups, attribute resetting isn't needed, because packing/unpacking will kill all
117  // attributes anyway
118 
119  // Source & target
120  C4Group hSourceParent, hTargetParent;
121  char szSourceParentPath[_MAX_PATH+1],szTargetParentPath[_MAX_PATH+1];
122  GetParentPath(szSource,szSourceParentPath); GetParentPath(szTarget,szTargetParentPath);
123 
124  // Temp filename
125  char szTempFilename[_MAX_PATH+1];
126  SCopy(C4Group_TempPath,szTempFilename,_MAX_PATH);
127  SAppend(GetFilename(szSource),szTempFilename);
128  MakeTempFilename(szTempFilename);
129 
130  // Extract source to temp file
131  if ( !hSourceParent.Open(szSourceParentPath)
132  || !hSourceParent.Extract(GetFilename(szSource),szTempFilename)
133  || !hSourceParent.Close() ) return false;
134 
135  // Move temp file to target
136  if ( !hTargetParent.Open(szTargetParentPath)
137  || !hTargetParent.SetNoSort(fNoSort)
138  || !hTargetParent.Move(szTempFilename, GetFilename(szTarget))
139  || !hTargetParent.Close() ) { EraseItem(szTempFilename); return false; }
140 
141  return true;
142 }
bool SetNoSort(bool fNoSort)
Definition: C4Group.cpp:2013
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool CreateItem(const char *szItemname)
Definition: StdFile.cpp:815
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235
bool CopyItem(const char *szSource, const char *szTarget, bool fResetAttributes)
Definition: StdFile.cpp:831
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:855
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
bool Extract(const char *szFiles, const char *szExtractTo=nullptr, const char *szExclude=nullptr)
Definition: C4Group.cpp:1471
#define DirectorySeparator
char C4Group_TempPath[_MAX_PATH+1]
Definition: C4Group.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_DeleteItem ( const char *  szItem,
bool  fRecycle = false 
)

Definition at line 194 of file C4Group.cpp.

References _MAX_PATH, C4Group::Close(), C4Group::DeleteEntry(), EraseItem(), EraseItemSafe(), GetFilename(), GetParentPath(), ItemExists(), and C4Group::Open().

Referenced by C4StartupScenSelDlg::DeleteConfirm(), and C4StartupPlrSelDlg::OnDelBtnConfirm().

195 {
196  // Parameter check
197  if (!szItem || !szItem[0]) return false;
198 
199  // simple item?
200  if (ItemExists(szItem))
201  {
202  if (fRecycle)
203  return EraseItemSafe(szItem);
204  else
205  return EraseItem(szItem);
206  }
207 
208  // delete from parent
209  C4Group hParent;
210  char szParentPath[_MAX_PATH+1];
211  GetParentPath(szItem,szParentPath);
212 
213  // Delete original file
214  if ( !hParent.Open(szParentPath)
215  || !hParent.DeleteEntry(GetFilename(szItem), fRecycle)
216  || !hParent.Close() ) return false;
217 
218  return true;
219 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool EraseItemSafe(const char *szFilename)
Definition: C4GroupMain.cpp:41
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool DeleteEntry(const char *szFilename, bool fRecycle=false)
Definition: C4Group.cpp:1384
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_ExplodeDirectory ( const char *  szFilename)

Definition at line 351 of file C4Group.cpp.

References C4Group_ExplodeDirectory(), C4Group_TestIgnore(), C4Group_UnpackDirectory(), and ForEachFile().

Referenced by C4Group_ApplyUpdate(), C4Group_ExplodeDirectory(), and ProcessGroup().

352 {
353  // Ignore
354  if (C4Group_TestIgnore(szFilename)) return true;
355 
356  // Unpack this directory
357  if (!C4Group_UnpackDirectory(szFilename)) return false;
358 
359  // Explode all children
361 
362  // Success
363  return true;
364 }
bool C4Group_ExplodeDirectory(const char *szFilename)
Definition: C4Group.cpp:351
bool C4Group_UnpackDirectory(const char *szFilename)
Definition: C4Group.cpp:306
int ForEachFile(const char *szDirName, bool(*fnCallback)(const char *))
Definition: StdFile.cpp:1043
bool C4Group_TestIgnore(const char *szFilename)
Definition: C4Group.cpp:85

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4Group_GetTempPath ( )

Definition at line 80 of file C4Group.cpp.

References C4Group_TempPath.

Referenced by C4Surface::SavePNG().

81 {
82  return C4Group_TempPath;
83 }
char C4Group_TempPath[_MAX_PATH+1]
Definition: C4Group.cpp:59

Here is the caller graph for this function:

bool C4Group_IsGroup ( const char *  szFilename)

Definition at line 94 of file C4Group.cpp.

References C4Group::Close(), and C4Group::Open().

Referenced by C4MainMenu::ActivateSavegame(), C4Group_ApplyUpdate(), and C4ScenarioListLoader::Entry::RenameTo().

95 {
96  C4Group hGroup; if (hGroup.Open(szFilename)) { hGroup.Close(); return true; }
97  return false;
98 }
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_MoveItem ( const char *  szSource,
const char *  szTarget,
bool  fNoSort = false 
)

Definition at line 144 of file C4Group.cpp.

References _MAX_PATH, C4Group_TempPath, C4Group::Close(), CreateItem(), C4Group::DeleteEntry(), DirectorySeparator, EraseItem(), C4Group::Extract(), GetFilename(), GetParentPath(), ItemExists(), ItemIdentical(), MakeTempFilename(), C4Group::Move(), MoveItem(), C4Group::Open(), SAppend(), SCopy(), C4Group::SetNoSort(), and SLen().

Referenced by C4ScenarioListLoader::Entry::RenameTo(), and C4Player::Save().

145 {
146  // Parameter check
147  if (!szSource || !szTarget1 || !szSource[0] || !szTarget1[0]) return false;
148  char szTarget[_MAX_PATH+1]; SCopy(szTarget1,szTarget,_MAX_PATH);
149 
150  // Backslash terminator indicates target is a path only (append filename)
151  if (szTarget[SLen(szTarget)-1]==DirectorySeparator) SAppend(GetFilename(szSource),szTarget);
152 
153  // Check for identical source and target
154  if (ItemIdentical(szSource,szTarget)) return true;
155 
156  // Source and target are simple items
157  if (ItemExists(szSource) && CreateItem(szTarget))
158  {
159  // erase test file, because it may block moving a directory
160  EraseItem(szTarget);
161  return MoveItem(szSource,szTarget);
162  }
163 
164  // Source & target
165  C4Group hSourceParent, hTargetParent;
166  char szSourceParentPath[_MAX_PATH+1],szTargetParentPath[_MAX_PATH+1];
167  GetParentPath(szSource,szSourceParentPath); GetParentPath(szTarget,szTargetParentPath);
168 
169  // Temp filename
170  char szTempFilename[_MAX_PATH+1];
171  SCopy(C4Group_TempPath,szTempFilename,_MAX_PATH);
172  SAppend(GetFilename(szSource),szTempFilename);
173  MakeTempFilename(szTempFilename);
174 
175  // Extract source to temp file
176  if ( !hSourceParent.Open(szSourceParentPath)
177  || !hSourceParent.Extract(GetFilename(szSource),szTempFilename)
178  || !hSourceParent.Close() ) return false;
179 
180  // Move temp file to target
181  if ( !hTargetParent.Open(szTargetParentPath)
182  || !hTargetParent.SetNoSort(fNoSort)
183  || !hTargetParent.Move(szTempFilename, GetFilename(szTarget))
184  || !hTargetParent.Close() ) { EraseItem(szTempFilename); return false; }
185 
186  // Delete original file
187  if ( !hSourceParent.Open(szSourceParentPath)
188  || !hSourceParent.DeleteEntry(GetFilename(szSource))
189  || !hSourceParent.Close() ) return false;
190 
191  return true;
192 }
bool SetNoSort(bool fNoSort)
Definition: C4Group.cpp:2013
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool CreateItem(const char *szItemname)
Definition: StdFile.cpp:815
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:855
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool DeleteEntry(const char *szFilename, bool fRecycle=false)
Definition: C4Group.cpp:1384
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
bool MoveItem(const char *szSource, const char *szTarget)
Definition: StdFile.cpp:849
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
bool Extract(const char *szFiles, const char *szExtractTo=nullptr, const char *szExclude=nullptr)
Definition: C4Group.cpp:1471
#define DirectorySeparator
char C4Group_TempPath[_MAX_PATH+1]
Definition: C4Group.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_PackDirectory ( const char *  szFilename)

Definition at line 284 of file C4Group.cpp.

References _MAX_PATH, C4Group_PackDirectoryTo(), EraseDirectory(), MakeTempFilename(), RenameFile(), and SCopy().

Referenced by C4Network2Res::GetStandalone(), ProcessGroup(), and C4Record::Stop().

285 {
286  // Make temporary filename
287  char szTempFilename[_MAX_PATH+1];
288  SCopy(szFilename, szTempFilename, _MAX_PATH);
289  MakeTempFilename(szTempFilename);
290  // Pack directory
291  if (!C4Group_PackDirectoryTo(szFilename, szTempFilename))
292  return false;
293  // Rename folder
294  char szTempFilename2[_MAX_PATH+1];
295  SCopy(szFilename, szTempFilename2, _MAX_PATH);
296  MakeTempFilename(szTempFilename2);
297  if (!RenameFile(szFilename, szTempFilename2))
298  return false;
299  // Name group file
300  if (!RenameFile(szTempFilename,szFilename))
301  return false;
302  // Last: Delete folder
303  return EraseDirectory(szTempFilename2);
304 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
#define _MAX_PATH
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
bool EraseDirectory(const char *szDirName)
Definition: StdFile.cpp:761
bool RenameFile(const char *szFileName, const char *szNewFileName)
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_PackDirectoryTo ( const char *  szFilename,
const char *  szFilenameTo 
)

Definition at line 221 of file C4Group.cpp.

References _MAX_PATH, C4Group::Add(), C4Group_PackDirectoryTo(), C4Group_ProcessCallback, C4Group_SortList, C4Group_TempPath, C4Group_TestIgnore(), C4Group::Close(), DirectoryExists(), EraseFile(), EraseItem(), FileExists(), GetFilename(), MakeTempFilename(), C4Group::Move(), C4Group::Open(), DirectoryIterator::Reset(), SAppend(), SCopy(), and C4Group::SortByList().

Referenced by C4ControlJoinPlayer::C4ControlJoinPlayer(), C4Group_PackDirectory(), C4Group_PackDirectoryTo(), C4Network2Res::GetStandalone(), ProcessGroup(), and C4Console::SaveScenario().

222 {
223  // Check file type
224  if (!DirectoryExists(szFilename)) return false;
225  // Target mustn't exist
226  if (FileExists(szFilenameTo)) return false;
227  // Ignore
228  if (C4Group_TestIgnore(szFilename))
229  return true;
230  // Process message
232  C4Group_ProcessCallback(szFilename,0);
233  // Create group file
234  C4Group hGroup;
235  if (!hGroup.Open(szFilenameTo,true))
236  return false;
237  // Add folder contents to group
238  DirectoryIterator i(szFilename);
239  for (; *i; i++)
240  {
241  // Ignore
242  if (C4Group_TestIgnore(*i))
243  continue;
244  // Must pack?
245  if (DirectoryExists(*i))
246  {
247  // Find temporary filename
248  char szTempFilename[_MAX_PATH+1];
249  // At C4Group temp path
250  SCopy(C4Group_TempPath, szTempFilename, _MAX_PATH);
251  SAppend(GetFilename(*i), szTempFilename, _MAX_PATH);
252  // Make temporary filename
253  MakeTempFilename(szTempFilename);
254  // Pack and move into group
255  if ( !C4Group_PackDirectoryTo(*i, szTempFilename)) break;
256  if (!hGroup.Move(szTempFilename, GetFilename(*i)))
257  {
258  EraseFile(szTempFilename);
259  break;
260  }
261  }
262  // Add normally otherwise
263  else if (!hGroup.Add(*i, nullptr))
264  break;
265  }
266  // Something went wrong?
267  if (*i)
268  {
269  // Close group and remove temporary file
270  hGroup.Close();
271  EraseItem(szFilenameTo);
272  return false;
273  }
274  // Reset iterator
275  i.Reset();
276  // Close group
277  hGroup.SortByList(C4Group_SortList,szFilename);
278  if (!hGroup.Close())
279  return false;
280  // Done
281  return true;
282 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235
#define _MAX_PATH
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
bool(* C4Group_ProcessCallback)(const char *, int)
Definition: C4Group.cpp:62
bool SortByList(const char **ppSortList, const char *szFilename=nullptr)
Definition: C4Group.cpp:2027
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool EraseFile(const char *szFileName)
bool FileExists(const char *szFileName)
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
bool C4Group_TestIgnore(const char *szFilename)
Definition: C4Group.cpp:85
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
const char ** C4Group_SortList
Definition: C4Group.cpp:61
char C4Group_TempPath[_MAX_PATH+1]
Definition: C4Group.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_ReadFile ( const char *  szFilename,
char **  pData,
size_t *  iSize 
)

Definition at line 366 of file C4Group.cpp.

References _MAX_PATH, C4Group::AccessEntry(), C4Group::Close(), GetFilename(), GetParentPath(), C4Group::Open(), and C4Group::Read().

Referenced by C4MusicFileSDL::Play().

367 {
368  // security
369  if (!szFile || !pData) return false;
370  // get mother path & file name
371  char szPath[_MAX_PATH + 1];
372  GetParentPath(szFile, szPath);
373  const char *pFileName = GetFilename(szFile);
374  // open mother group
375  C4Group MotherGroup;
376  if (!MotherGroup.Open(szPath)) return false;
377  // access the file
378  size_t iFileSize;
379  if (!MotherGroup.AccessEntry(pFileName, &iFileSize)) return false;
380  // create buffer
381  *pData = new char [iFileSize];
382  // read it
383  if (!MotherGroup.Read(*pData, iFileSize)) { delete [] *pData; *pData = nullptr; return false; }
384  // ok
385  MotherGroup.Close();
386  if (iSize) *iSize = iFileSize;
387  return true;
388 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
int iSize
Definition: TstC4NetIO.cpp:32
bool Read(void *pBuffer, size_t iSize) override
Definition: C4Group.cpp:1125

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Group_SetProcessCallback ( bool(*)(const char *, int)  fnCallback)

Definition at line 64 of file C4Group.cpp.

References C4Group_ProcessCallback.

Referenced by C4Application::DoInit().

65 {
66  C4Group_ProcessCallback = fnCallback;
67 }
bool(* C4Group_ProcessCallback)(const char *, int)
Definition: C4Group.cpp:62

Here is the caller graph for this function:

void C4Group_SetSortList ( const char **  ppSortList)

Definition at line 69 of file C4Group.cpp.

References C4Group_SortList.

Referenced by C4Application::DoInit(), main(), and ProcessGroup().

70 {
71  C4Group_SortList = ppSortList;
72 }
const char ** C4Group_SortList
Definition: C4Group.cpp:61

Here is the caller graph for this function:

void C4Group_SetTempPath ( const char *  szPath)

Definition at line 74 of file C4Group.cpp.

References _MAX_PATH, AppendBackslash(), C4Group_TempPath, and SCopy().

Referenced by C4Application::DoInit().

75 {
76  if (!szPath || !szPath[0]) C4Group_TempPath[0]=0;
78 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
char C4Group_TempPath[_MAX_PATH+1]
Definition: C4Group.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_TestIgnore ( const char *  szFilename)

Definition at line 85 of file C4Group.cpp.

References C4Group_Ignore, GetFilename(), and SIsModule().

Referenced by C4Group_ExplodeDirectory(), C4Group_PackDirectoryTo(), DirContainsScenarios(), and C4ScenarioListLoader::RegularFolder::DoLoadContents().

86 {
87  if(!*szFilename) return true; //poke out empty strings
88  const char* name = GetFilename(szFilename);
89  return *name == '.' //no hidden files and the directory itself
90  || name[strlen(name) - 1] == '~' //no temp files
91  || SIsModule(C4Group_Ignore,name); //not on Blacklist
92 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
char C4Group_Ignore[_MAX_PATH+1]
Definition: C4Group.cpp:60
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:519

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group_UnpackDirectory ( const char *  szFilename)

Definition at line 306 of file C4Group.cpp.

References _MAX_PATH, C4Group_ProcessCallback, C4Group_UnpackDirectory(), C4Group::Close(), CreatePath(), DirectoryExists(), EraseItem(), C4Group::Extract(), FileExists(), GetParentPath(), MakeTempFilename(), C4Group::Open(), RenameFile(), and SCopy().

Referenced by C4Group_ExplodeDirectory(), C4Group_UnpackDirectory(), C4UpdatePackage::Execute(), C4Language::Init(), ProcessGroup(), C4Network2::RetrieveScenario(), C4Record::Start(), and C4Playback::StreamToRecord().

307 {
308  // Already unpacked: success
309  if (DirectoryExists(szFilename)) return true;
310 
311  // Not a real file: unpack parent directory first
312  char szParentFilename[_MAX_PATH+1];
313  if (!FileExists(szFilename))
314  if (GetParentPath(szFilename,szParentFilename))
315  if (!C4Group_UnpackDirectory(szParentFilename))
316  return false;
317 
318  // Open group
319  C4Group hGroup;
320  if (!hGroup.Open(szFilename)) return false;
321 
322  // Process message
324  C4Group_ProcessCallback(szFilename,0);
325 
326  // Create target directory
327  char szFoldername[_MAX_PATH+1];
328  SCopy(szFilename,szFoldername,_MAX_PATH);
329  MakeTempFilename(szFoldername);
330  if (!CreatePath(szFoldername)) { hGroup.Close(); return false; }
331 
332  // Extract files to folder
333  if (!hGroup.Extract("*",szFoldername)) { hGroup.Close(); return false; }
334 
335  // Close group
336  hGroup.Close();
337 
338  // Rename group file
339  char szTempFilename[_MAX_PATH+1];
340  SCopy(szFilename,szTempFilename,_MAX_PATH);
341  MakeTempFilename(szTempFilename);
342  if (!RenameFile(szFilename, szTempFilename)) return false;
343 
344  // Rename target directory
345  if (!RenameFile(szFoldername,szFilename)) return false;
346 
347  // Delete renamed group file
348  return EraseItem(szTempFilename);
349 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
bool C4Group_UnpackDirectory(const char *szFilename)
Definition: C4Group.cpp:306
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool(* C4Group_ProcessCallback)(const char *, int)
Definition: C4Group.cpp:62
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool FileExists(const char *szFileName)
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684
bool RenameFile(const char *szFileName, const char *szNewFileName)
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
bool Extract(const char *szFiles, const char *szExtractTo=nullptr, const char *szExclude=nullptr)
Definition: C4Group.cpp:1471

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* C4CFN_FLS[]

Definition at line 32 of file C4Group.cpp.

Referenced by C4Application::DoInit(), and main().

const int C4GroupFileVer1 =1

Definition at line 55 of file C4Group.h.

Referenced by C4Group::Close(), and C4Group::OpenAsChild().

const int C4GroupFileVer2 =2

Definition at line 55 of file C4Group.h.

Referenced by C4Group::Close(), and C4Group::OpenAsChild().

const int C4GroupMaxError = 100

Definition at line 57 of file C4Group.h.

const int32_t C4GroupSwapThreshold = 10 * 1024 * 1024

Definition at line 59 of file C4Group.h.

Referenced by C4Group::Save().