OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Group.cpp File Reference
#include "C4Include.h"
#include "c4group/C4Group.h"
#include "c4group/C4Components.h"
#include "lib/C4InputValidation.h"
#include <zlib.h>
Include dependency graph for C4Group.cpp:

Go to the source code of this file.

Classes

struct  C4Group::P
 

Functions

void C4Group_SetProcessCallback (bool(*fnCallback)(const char *, int))
 
void C4Group_SetSortList (const char **ppSortList)
 
void C4Group_SetTempPath (const char *szPath)
 
const char * C4Group_GetTempPath ()
 
bool C4Group_TestIgnore (const char *szFilename)
 
bool C4Group_IsGroup (const char *szFilename)
 
bool C4Group_CopyItem (const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
 
bool C4Group_MoveItem (const char *szSource, const char *szTarget1, bool fNoSort)
 
bool C4Group_DeleteItem (const char *szItem, bool fRecycle)
 
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 *szFile, char **pData, size_t *iSize)
 
void MemScramble (BYTE *bypBuffer, int iSize)
 
bool C4Group_IsExcluded (const char *szFile, const char *szExcludeList)
 
int SortRank (const char *szElement, const char *szSortList)
 

Variables

const char * C4CFN_FLS []
 
char C4Group_TempPath [_MAX_PATH+1] =""
 
char C4Group_Ignore [_MAX_PATH+1] ="cvs;CVS;Thumbs.db;.orig;.svn"
 
const char ** C4Group_SortList = nullptr
 
bool(* C4Group_ProcessCallback )(const char *, int) =nullptr
 

Function Documentation

bool C4Group_CopyItem ( const char *  szSource,
const char *  szTarget1,
bool  fNoSort,
bool  fResetAttributes 
)

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:55
bool CreateItem(const char *szItemname)
Definition: StdFile.cpp:825
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool CopyItem(const char *szSource, const char *szTarget, bool fResetAttributes)
Definition: StdFile.cpp:841
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:78
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
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:819
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
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 
)

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:55
bool EraseItemSafe(const char *szFilename)
Definition: C4GroupMain.cpp:41
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
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:819
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:1053
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_IsExcluded ( const char *  szFile,
const char *  szExcludeList 
)

Definition at line 1457 of file C4Group.cpp.

References _MAX_PATH, GetFilename(), SCharCount(), SCopySegment(), and WildcardMatch().

Referenced by C4Group::Extract().

1458 {
1459  // No file or no exclude list
1460  if (!szFile || !szFile[0] || !szExcludeList || !szExcludeList[0]) return false;
1461  // Process segmented exclude list
1462  char cSeparator = (SCharCount(';', szExcludeList) ? ';' : '|');
1463  char szSegment[_MAX_PATH + 1];
1464  for (int i = 0; SCopySegment(szExcludeList, i, szSegment, cSeparator); i++)
1465  if (WildcardMatch(szSegment, GetFilename(szFile)))
1466  return true;
1467  // No match
1468  return false;
1469 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
#define _MAX_PATH
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:290
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384

Here is the call graph for this function:

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 *  szTarget1,
bool  fNoSort 
)

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:55
bool CreateItem(const char *szItemname)
Definition: StdFile.cpp:825
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:78
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
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:819
bool MoveItem(const char *szSource, const char *szTarget)
Definition: StdFile.cpp:859
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
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:122
#define _MAX_PATH
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
bool EraseDirectory(const char *szDirName)
Definition: StdFile.cpp:771
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
bool RenameFile(const char *szFilename, const char *szNewFilename)
Definition: StdFile.cpp:555

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:55
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool EraseFile(const char *szFilename)
Definition: StdFile.cpp:495
#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 DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:819
bool FileExists(const char *szFilename)
Definition: StdFile.cpp:439
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:333
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 *  szFile,
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:55
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:199
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
int iSize
Definition: TstC4NetIO.cpp:35
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:122
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:267
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:55
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:511

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:122
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:642
bool C4Group_UnpackDirectory(const char *szFilename)
Definition: C4Group.cpp:306
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
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 DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:819
bool FileExists(const char *szFilename)
Definition: StdFile.cpp:439
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
bool Extract(const char *szFiles, const char *szExtractTo=nullptr, const char *szExclude=nullptr)
Definition: C4Group.cpp:1471
bool RenameFile(const char *szFilename, const char *szNewFilename)
Definition: StdFile.cpp:555

Here is the call graph for this function:

Here is the caller graph for this function:

void MemScramble ( BYTE bypBuffer,
int  iSize 
)

Definition at line 390 of file C4Group.cpp.

References iSize.

Referenced by C4UpdatePackage::MakeUpdate(), C4Group::OpenAsChild(), and C4Group::Save().

391 {
392  int cnt; BYTE temp;
393  // XOR deface
394  for (cnt=0; cnt<iSize; cnt++)
395  bypBuffer[cnt] ^= 237;
396  // BYTE swap
397  for (cnt=0; cnt+2<iSize; cnt+=3)
398  {
399  temp = bypBuffer[cnt];
400  bypBuffer[cnt] = bypBuffer[cnt+2];
401  bypBuffer[cnt+2] = temp;
402  }
403 }
uint8_t BYTE
int iSize
Definition: TstC4NetIO.cpp:35

Here is the caller graph for this function:

int SortRank ( const char *  szElement,
const char *  szSortList 
)

Definition at line 1951 of file C4Group.cpp.

References _MAX_FNAME, SCharCount(), SCopySegment(), and WildcardMatch().

Referenced by C4Group::Sort().

1952 {
1953  int cnt;
1954  char csegment[_MAX_FNAME+1];
1955 
1956  for (cnt=0; SCopySegment(szSortList,cnt,csegment,'|',_MAX_FNAME); cnt++)
1957  if (WildcardMatch(csegment,szElement))
1958  return (SCharCount('|',szSortList)+1)-cnt;
1959 
1960  return 0;
1961 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:290
#define _MAX_FNAME
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* C4CFN_FLS[]
Initial value:
=
{
nullptr, nullptr
}
#define C4CFN_FolderFiles
Definition: C4Components.h:175
#define C4FLS_Scenario
Definition: C4Components.h:188
#define C4CFN_Material
Definition: C4Components.h:25
#define C4FLS_Section
Definition: C4Components.h:189
#define C4CFN_ObjectInfoFiles
Definition: C4Components.h:169
#define C4FLS_System
Definition: C4Components.h:202
#define C4CFN_PlayerFiles
Definition: C4Components.h:167
#define C4FLS_Music
Definition: C4Components.h:204
#define C4FLS_Sound
Definition: C4Components.h:203
#define C4FLS_Graphics
Definition: C4Components.h:197
#define C4CFN_ScenarioSections
Definition: C4Components.h:38
#define C4FLS_Def
Definition: C4Components.h:192
#define C4CFN_Music
Definition: C4Components.h:30
#define C4CFN_Sound
Definition: C4Components.h:26
#define C4CFN_Graphics
Definition: C4Components.h:28
#define C4FLS_Folder
Definition: C4Components.h:195
#define C4FLS_Player
Definition: C4Components.h:193
#define C4CFN_ScenarioFiles
Definition: C4Components.h:174
#define C4CFN_DefFiles
Definition: C4Components.h:166
#define C4CFN_System
Definition: C4Components.h:29
#define C4FLS_Material
Definition: C4Components.h:196
#define C4FLS_Object
Definition: C4Components.h:194

Definition at line 32 of file C4Group.cpp.

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

char C4Group_Ignore[_MAX_PATH+1] ="cvs;CVS;Thumbs.db;.orig;.svn"

Definition at line 60 of file C4Group.cpp.

Referenced by C4Group_TestIgnore().

bool(* C4Group_ProcessCallback)(const char *, int) =nullptr
const char** C4Group_SortList = nullptr