OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GroupEx Class Reference
Inheritance diagram for C4GroupEx:
[legend]
Collaboration diagram for C4GroupEx:
[legend]

Public Member Functions

void SetHead (C4Group &rByGrp)
 
bool HeadIdentical (C4Group &rByGrp, bool fLax)
 
void SaveEntryCore (C4Group &rByGrp, const char *szEntry)
 
void SetSavedEntryCore (const char *szEntry)
 
void SetNoSort (const char *szEntry)
 
bool Close (bool fHeaderUpdate)
 
bool Open (const char *szGroupName, bool fCreate=false)
 
bool Close ()
 
bool Save (bool fReOpen)
 
bool OpenAsChild (C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
 
bool OpenChild (const char *strEntry)
 
bool OpenMother ()
 
bool Add (const char *szFile, const char *szAddAs)
 
bool Add (const char *szName, void *pBuffer, int iSize, bool fChild=false, bool fHoldBuffer=false, bool fExecutable=false)
 
bool Add (const char *szName, StdBuf &pBuffer, bool fChild=false, bool fHoldBuffer=false, bool fExecutable=false)
 
bool Add (const char *szName, StdStrBuf &pBuffer, bool fChild=false, bool fHoldBuffer=false, bool fExecutable=false)
 
bool Merge (const char *szFolders)
 
bool Move (const char *szFile, const char *szAddAs)
 
bool Extract (const char *szFiles, const char *szExtractTo=nullptr, const char *szExclude=nullptr)
 
bool ExtractEntry (const char *szFilename, const char *szExtractTo=nullptr)
 
bool Delete (const char *szFiles, bool fRecursive=false)
 
bool DeleteEntry (const char *szFilename, bool fRecycle=false)
 
bool Rename (const char *szFile, const char *szNewName)
 
bool Sort (const char *szSortList)
 
bool SortByList (const char **ppSortList, const char *szFilename=nullptr)
 
bool AccessEntry (const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
 
bool AccessNextEntry (const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool fStartAtFilename=false)
 
bool LoadEntry (const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int iAppendZeros=0)
 
bool LoadEntry (const char *szEntryName, StdBuf *Buf)
 
bool LoadEntry (const StdStrBuf &name, StdBuf *Buf)
 
bool LoadEntryString (const char *szEntryName, StdStrBuf *Buf)
 
bool LoadEntryString (const StdStrBuf &name, StdStrBuf *Buf)
 
bool FindEntry (const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
 
bool FindEntry (const char *szWildCard, char *sFileName)
 
bool FindNextEntry (const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
 
bool FindNextEntry (const char *szWildCard, char *sFileName, size_t *iSize=nullptr, bool fStartAtFilename=false)
 
bool Read (void *pBuffer, size_t iSize) override
 
bool Advance (int iOffset) override
 
void SetStdOutput (bool fStatus)
 
void ResetSearch (bool reload_contents=false)
 
const char * GetError ()
 
const char * GetName () const
 
StdStrBuf GetFullName () const
 
int EntryCount (const char *szWildCard=nullptr)
 
size_t EntrySize (const char *szWildCard=nullptr)
 
size_t AccessedEntrySize () const override
 
unsigned int EntryCRC32 (const char *szWildCard=nullptr)
 
bool IsOpen () const
 
C4GroupGetMother ()
 
bool IsPacked () const
 
bool HasPackedMother () const
 
bool SetNoSort (bool fNoSort)
 
int PreCacheEntries (const char *szSearchPattern, bool cache_previous=false)
 
const C4GroupHeaderGetHeader () const
 
const C4GroupEntryGetFirstEntry () const
 

Public Attributes

C4GroupEntryCore SavedCore
 

Protected Member Functions

C4GroupEntryGetEntry (const char *szName)
 
void Clear ()
 

Protected Attributes

C4GroupHeader Head
 

Detailed Description

Definition at line 165 of file C4Update.cpp.

Member Function Documentation

size_t C4Group::AccessedEntrySize ( ) const
overridevirtualinherited

Implements CStdStream.

Definition at line 1875 of file C4Group.cpp.

1875 { return p->iCurrFileSize; }
bool C4Group::AccessEntry ( const char *  szWildCard,
size_t *  iSize = nullptr,
char *  sFileName = nullptr,
bool  NeedsToBeAGroup = false 
)
inherited

Definition at line 1695 of file C4Group.cpp.

References C4Group::FindEntry(), StdStrBuf::getData(), C4Group::GetFullName(), StdStrBuf::getMData(), LogF(), and SCopy().

Referenced by C4Group_ReadFile(), C4Landscape::P::CreateMapS2(), C4MassMoverSet::Load(), C4PXSSystem::Load(), C4Surface::Load(), C4PlayerInfo::LoadBigIcon(), C4Group::LoadEntry(), C4Group::LoadEntryString(), C4DefAdditionalResourcesLoader::LoadTexture(), and C4MCParser::ParseFile().

1698 {
1699 #ifdef C4GROUP_DUMP_ACCESS
1700  LogF("Group access in %s: %s", GetFullName().getData(), szWildCard);
1701 #endif
1702  StdStrBuf fname;
1703  if (!FindEntry(szWildCard,&fname,&p->iCurrFileSize))
1704  return false;
1705 #ifdef _DEBUG
1706  szCurrAccessedEntry = fname.getMData();
1707 #endif
1708  bool fResult = SetFilePtr2Entry(fname.getData(), NeedsToBeAGroup);
1709 #ifdef _DEBUG
1710  p->sPrevAccessedEntry.Copy(szCurrAccessedEntry);
1711  szCurrAccessedEntry = nullptr;
1712 #endif
1713  if (!fResult) return false;
1714  if (sFileName) SCopy(fname.getData(),sFileName);
1715  if (iSize) *iSize=p->iCurrFileSize;
1716  return true;
1717 }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
char * getMData()
Definition: StdBuf.h:443
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::AccessNextEntry ( const char *  szWildCard,
size_t *  iSize = nullptr,
char *  sFileName = nullptr,
bool  fStartAtFilename = false 
)
inherited

Definition at line 1719 of file C4Group.cpp.

References _MAX_FNAME, C4Group::FindNextEntry(), and SCopy().

Referenced by C4TextureMap::LoadTextures().

1722 {
1723  char fname[_MAX_FNAME+1];
1724  if (!FindNextEntry(szWildCard,fname,&p->iCurrFileSize,fStartAtFilename)) return false;
1725 #ifdef _DEBUG
1726  szCurrAccessedEntry = fname;
1727 #endif
1728  bool fResult = SetFilePtr2Entry(fname);
1729 #ifdef _DEBUG
1730  szCurrAccessedEntry = nullptr;
1731 #endif
1732  if (!fResult) return false;
1733  if (sFileName) SCopy(fname,sFileName);
1734  if (iSize) *iSize=p->iCurrFileSize;
1735  return true;
1736 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
#define _MAX_FNAME
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Add ( const char *  szFile,
const char *  szAddAs 
)
inherited

Definition at line 1316 of file C4Group.cpp.

References GetFilename().

Referenced by C4Record::AddFile(), C4ControlReInitScenario::C4ControlReInitScenario(), C4Group_CopyEntry(), C4Group_PackDirectoryTo(), C4UpdatePackage::MkUp(), C4UpdatePackageCore::Save(), C4ObjectInfoCore::Save(), C4MassMoverSet::Save(), C4PlayerInfoCore::Save(), C4Def::Save(), C4GameParameters::Save(), C4TeamList::Save(), C4RoundResults::Save(), C4Scenario::Save(), C4PlayerControlFile::Save(), C4PlayerInfoList::Save(), C4Game::SaveData(), C4GameSave::SaveDesc(), C4MaterialMap::SaveEnumeration(), C4Game::SaveGameTitle(), C4TextureMap::SaveMap(), C4ScenarioListLoader::Entry::SetTitleInGroup(), and C4Playback::StreamToRecord().

1317 {
1318  bool fMove = false;
1319 
1320  if (p->StdOutput) printf("%s %s as %s...\n",fMove ? "Moving" : "Adding",GetFilename(szFile),szAddAs);
1321 
1322  return AddEntryOnDisk(szFile, szAddAs, fMove);
1323 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Add ( const char *  szName,
void *  pBuffer,
int  iSize,
bool  fChild = false,
bool  fHoldBuffer = false,
bool  fExecutable = false 
)
inherited

Definition at line 1797 of file C4Group.cpp.

References C4GroupEntry::C4GRES_InMemory.

1798 {
1799  return AddEntry(C4GroupEntry::C4GRES_InMemory,
1800  fChild,
1801  szName,
1802  iSize,
1803  szName,
1804  (BYTE*) pBuffer,
1805  false,
1806  fHoldBuffer,
1807  fExecutable);
1808 }
uint8_t BYTE
Definition: C4Group.h:114
int iSize
Definition: TstC4NetIO.cpp:32
bool C4Group::Add ( const char *  szName,
StdBuf pBuffer,
bool  fChild = false,
bool  fHoldBuffer = false,
bool  fExecutable = false 
)
inherited

Definition at line 1810 of file C4Group.cpp.

References C4GroupEntry::C4GRES_InMemory, StdBuf::getMData(), StdBuf::getSize(), and StdBuf::GrabPointer().

1811 {
1812  if (!AddEntry(C4GroupEntry::C4GRES_InMemory,
1813  fChild,
1814  szName,
1815  pBuffer.getSize(),
1816  szName,
1817  (BYTE*) pBuffer.getMData(),
1818  false,
1819  fHoldBuffer,
1820  fExecutable,
1821  true)) return false;
1822  // Pointer is now owned and released by C4Group!
1823  if (fHoldBuffer) pBuffer.GrabPointer();
1824  return true;
1825 }
void * GrabPointer()
Definition: StdBuf.h:133
uint8_t BYTE
size_t getSize() const
Definition: StdBuf.h:101
Definition: C4Group.h:114
void * getMData()
Definition: StdBuf.h:100

Here is the call graph for this function:

bool C4Group::Add ( const char *  szName,
StdStrBuf pBuffer,
bool  fChild = false,
bool  fHoldBuffer = false,
bool  fExecutable = false 
)
inherited

Definition at line 1827 of file C4Group.cpp.

References C4GroupEntry::C4GRES_InMemory, StdStrBuf::getLength(), StdStrBuf::getMData(), and StdStrBuf::GrabPointer().

1828 {
1829  if (!AddEntry(C4GroupEntry::C4GRES_InMemory,
1830  fChild,
1831  szName,
1832  pBuffer.getLength(),
1833  szName,
1834  (BYTE*) pBuffer.getMData(),
1835  false,
1836  fHoldBuffer,
1837  fExecutable,
1838  true)) return false;
1839  // Pointer is now owned and released by C4Group!
1840  if (fHoldBuffer) pBuffer.GrabPointer();
1841  return true;
1842 }
char * GrabPointer()
Definition: StdBuf.h:459
uint8_t BYTE
char * getMData()
Definition: StdBuf.h:443
Definition: C4Group.h:114
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

bool C4Group::Advance ( int  iOffset)
overridevirtualinherited

Implements CStdStream.

Definition at line 1105 of file C4Group.cpp.

References C4Group::Read(), and C4Group::P::ST_Unpacked.

1106 {
1107  assert(iOffset >= 0);
1108  // cached advance
1109  if (p->pInMemEntry)
1110  {
1111  if (p->iInMemEntrySize < size_t(iOffset)) return false;
1112  p->iInMemEntrySize -= iOffset;
1113  p->pInMemEntry += iOffset;
1114  return true;
1115  }
1116  // uncached advance
1117  if (p->SourceType == P::ST_Unpacked) return !!p->StdFile.Advance(iOffset);
1118  // FIXME: reading the file one byte at a time sounds just slow.
1119  BYTE buf;
1120  for (; iOffset>0; iOffset--)
1121  if (!Read(&buf,1)) return false;
1122  return true;
1123 }
uint8_t BYTE
bool Read(void *pBuffer, size_t iSize) override
Definition: C4Group.cpp:1125

Here is the call graph for this function:

void C4Group::Clear ( )
protectedinherited

Definition at line 898 of file C4Group.cpp.

Referenced by C4Group::Close(), Close(), C4Group::Open(), C4Group::OpenAsChild(), C4Group::OpenMother(), C4Group::Save(), and C4Group::~C4Group().

899 {
900  if (p)
901  {
902  // Delete entries
903  C4GroupEntry *next;
904  while (p->FirstEntry)
905  {
906  next = p->FirstEntry->Next;
907  delete p->FirstEntry;
908  p->FirstEntry = next;
909  }
910  // Close std file
911  p->StdFile.Close();
912  // Delete mother
913  if (p->Mother && p->ExclusiveChild)
914  {
915  delete p->Mother;
916  p->Mother = nullptr;
917  }
918  }
919  // Reset
920  Init();
921 }
Definition: C4Group.h:105

Here is the caller graph for this function:

bool C4Group::Close ( )
inherited

Definition at line 755 of file C4Group.cpp.

References C4GroupEntry::C4GRES_InGroup, C4Group_SortList, C4GroupFileVer1, C4GroupFileVer2, C4Group::Clear(), C4Group::Head, C4GroupEntry::Next, C4Group::Save(), C4Group::SortByList(), C4Group::P::ST_None, C4Group::P::ST_Unpacked, C4GroupEntry::Status, C4GroupHeader::Ver1, and C4GroupHeader::Ver2.

Referenced by C4MainMenu::ActivateNewPlayer(), C4Group_ApplyUpdate(), C4Group_CopyItem(), C4Group_DeleteItem(), C4Group_IsGroup(), C4Group_MoveItem(), C4Group_PackDirectoryTo(), C4Group_ReadFile(), C4Group_UnpackDirectory(), C4UpdatePackage::Check(), C4SoundSystem::Clear(), C4Application::Clear(), C4Language::Clear(), C4GameSave::Close(), Close(), C4Game::CloseScenario(), C4Application::CloseSystemGroup(), DefFileGetID(), C4Group::Delete(), C4ScenarioSection::EnsureTempStore(), C4Language::GetPackGroups(), C4LoaderScreen::Init(), C4DefList::Load(), C4ObjectInfo::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Player::Load(), C4Game::LoadAdditionalSystemGroup(), C4GameResList::LoadFoldersWithLocalDefs(), C4Game::LoadScenarioSection(), C4StartupPlrPropertiesDlg::OnClosed(), C4Network2Res::OptimizeStandalone(), ProcessGroup(), C4Shader::Refresh(), C4DefList::Reload(), C4ScenarioListLoader::Entry::RenameTo(), C4Network2::RetrieveScenario(), C4ObjectInfo::Save(), C4PlayerList::Save(), C4Player::Save(), C4Console::SaveScenario(), C4Landscape::SaveTextures(), C4Record::Stop(), C4Playback::StreamToRecord(), C4Player::Strip(), C4ControlJoinPlayer::Strip(), and C4StartupPlrSelDlg::PlayerListItem::UpdateCore().

756 {
757  C4GroupEntry *centry;
758  bool fRewrite=false;
759 
760  if (p->SourceType==P::ST_None) return false;
761 
762  // Folder: just close
763  if (p->SourceType==P::ST_Unpacked)
764  { CloseExclusiveMother(); Clear(); return true; }
765 
766  // Rewrite check
767  for (centry=p->FirstEntry; centry; centry=centry->Next)
768  if (centry->Status != C4GroupEntry::C4GRES_InGroup)
769  fRewrite=true;
770  if (p->Modified) fRewrite=true;
771 
772  // No rewrite: just close
773  if (!fRewrite)
774  { CloseExclusiveMother(); Clear(); return true; }
775 
776  if (p->StdOutput) printf("Writing group file...\n");
777 
778  // Set new version
781 
782  // Automatic sort
784 
785  // Save group contents to disk
786  bool fSuccess = Save(false);
787 
788  // Close exclusive mother
789  CloseExclusiveMother();
790 
791  // Close file
792  Clear();
793 
794  return !!fSuccess;
795 }
const int C4GroupFileVer2
Definition: C4Group.h:55
const int C4GroupFileVer1
Definition: C4Group.h:55
C4GroupEntry * Next
Definition: C4Group.h:126
bool Save(bool fReOpen)
Definition: C4Group.cpp:797
bool SortByList(const char **ppSortList, const char *szFilename=nullptr)
Definition: C4Group.cpp:2027
C4GroupHeader Head
Definition: C4Group.h:143
Definition: C4Group.h:112
EntryStatus Status
Definition: C4Group.h:120
void Clear()
Definition: C4Group.cpp:898
const char ** C4Group_SortList
Definition: C4Group.cpp:61
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GroupEx::Close ( bool  fHeaderUpdate)
inline

Definition at line 222 of file C4Update.cpp.

References C4Group::Clear(), C4Group::Close(), and C4Group::Save().

Referenced by C4UpdatePackage::DoUpdate(), C4UpdatePackage::Execute(), C4UpdatePackage::MakeUpdate(), C4UpdatePackage::MkUp(), and C4UpdatePackage::Optimize().

223  {
224  if (fHeaderUpdate) return C4Group::Close(); else { bool fSuccess = Save(false); Clear(); return fSuccess; }
225  }
bool Save(bool fReOpen)
Definition: C4Group.cpp:797
bool Close()
Definition: C4Group.cpp:755
void Clear()
Definition: C4Group.cpp:898

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Delete ( const char *  szFiles,
bool  fRecursive = false 
)
inherited

Definition at line 1334 of file C4Group.cpp.

References _MAX_FNAME, C4GroupEntryCore::ChildGroup, C4Group::Close(), C4Group::Delete(), C4Group::DeleteEntry(), C4GroupEntryCore::FileName, C4Group::OpenAsChild(), C4Group::ResetSearch(), SCharCount(), SCopySegment(), and C4Group::SetStdOutput().

Referenced by C4Group::Delete(), C4ScenarioSection::EnsureTempStore(), C4StartupPlrPropertiesDlg::OnClosed(), C4Network2Res::OptimizeStandalone(), C4ScenarioListLoader::Entry::RenameTo(), C4ObjectInfo::Save(), C4MassMoverSet::Save(), C4PXSSystem::Save(), C4GameSave::Save(), C4PlayerInfoCore::Save(), C4Game::SaveData(), C4Player::Strip(), and C4ControlJoinPlayer::Strip().

1335 {
1336  int fcount = 0;
1337  C4GroupEntry *tentry;
1338 
1339  // Segmented file specs
1340  if (SCharCount(';', szFiles) || SCharCount('|', szFiles))
1341  {
1342  char cSeparator = (SCharCount(';', szFiles) ? ';' : '|');
1343  bool success = true;
1344  char filespec[_MAX_FNAME+1];
1345  for (int cseg = 0; SCopySegment(szFiles, cseg, filespec, cSeparator, _MAX_FNAME); cseg++)
1346  if (!Delete(filespec, fRecursive))
1347  success=false;
1348  return success; // Would be nicer to return the file count and add up all counts from recursive actions...
1349  }
1350 
1351  // Delete all matching Entries
1352  ResetSearch();
1353  while ((tentry = SearchNextEntry(szFiles)))
1354  {
1355  // StdOutput
1356  if (p->StdOutput) printf("%s\n",tentry->FileName);
1357  if (!DeleteEntry(tentry->FileName))
1358  return Error("Delete: Could not delete entry");
1359  fcount++;
1360  }
1361 
1362  // Recursive: process sub groups
1363  if (fRecursive)
1364  {
1365  C4Group hChild;
1366  ResetSearch();
1367  while ((tentry = SearchNextEntry("*")))
1368  if (tentry->ChildGroup)
1369  if (hChild.OpenAsChild(this, tentry->FileName))
1370  {
1371  hChild.SetStdOutput(p->StdOutput);
1372  hChild.Delete(szFiles, fRecursive);
1373  hChild.Close();
1374  }
1375  }
1376 
1377  // StdOutput
1378  if (p->StdOutput)
1379  printf("%d file(s) deleted.\n",fcount);
1380 
1381  return true; // Would be nicer to return the file count and add up all counts from recursive actions...
1382 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:251
char FileName[260]
Definition: C4Group.h:93
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:298
void SetStdOutput(bool fStatus)
Definition: C4Group.cpp:509
bool fRecursive
Definition: C4GroupMain.cpp:34
bool Close()
Definition: C4Group.cpp:755
int32_t ChildGroup
Definition: C4Group.h:94
#define _MAX_FNAME
bool DeleteEntry(const char *szFilename, bool fRecycle=false)
Definition: C4Group.cpp:1384
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::DeleteEntry ( const char *  szFilename,
bool  fRecycle = false 
)
inherited

Definition at line 1384 of file C4Group.cpp.

References _MAX_FNAME, C4GroupEntry::C4GRES_Deleted, C4GroupEntry::C4GRES_OnDisk, C4GroupEntry::DeleteOnDisk, DirectorySeparator, C4GroupEntry::DiskPath, C4GroupHeader::Entries, EraseItem(), EraseItemSafe(), C4Group::GetEntry(), C4Group::GetName(), C4Group::Head, C4Group::ResetSearch(), sprintf, C4Group::P::ST_Packed, C4Group::P::ST_Unpacked, and C4GroupEntry::Status.

Referenced by C4Group_DeleteItem(), C4Group_MoveItem(), C4Group::Delete(), C4UpdatePackage::DoGrpUpdate(), C4TeamList::Save(), C4RoundResults::Save(), and C4PlayerInfoList::Save().

1385 {
1386  switch (p->SourceType)
1387  {
1388  case P::ST_Packed:
1389  // Get entry
1390  C4GroupEntry *pEntry;
1391  if (!(pEntry=GetEntry(szFilename))) return false;
1392  // Delete moved source files
1393  if (pEntry->Status == C4GroupEntry::C4GRES_OnDisk)
1394  if (pEntry->DeleteOnDisk)
1395  {
1396  EraseItem(pEntry->DiskPath);
1397  }
1398  // (moved buffers are deleted by ~C4GroupEntry)
1399  // Delete status and update virtual file count
1401  Head.Entries--;
1402  break;
1403  case P::ST_Unpacked:
1404  p->StdFile.Close();
1405  char szPath[_MAX_FNAME+1];
1406  sprintf(szPath,"%s%c%s", GetName(),DirectorySeparator,szFilename);
1407 
1408  if (fRecycle)
1409  {
1410  if (!EraseItemSafe(szPath)) return false;
1411  }
1412  else
1413  {
1414  if (!EraseItem(szPath)) return false;
1415  }
1416  break;
1417  // refresh file list
1418  ResetSearch(true);
1419  default: break; // InGrp & Deleted ignored
1420  }
1421  return true;
1422 }
Definition: C4Group.h:115
#define sprintf
Definition: Standard.h:164
bool EraseItemSafe(const char *szFilename)
Definition: C4GroupMain.cpp:41
const char * GetName() const
Definition: C4Group.cpp:1845
#define _MAX_FNAME
C4GroupEntry * GetEntry(const char *szName)
Definition: C4Group.cpp:744
bool DeleteOnDisk
Definition: C4Group.h:121
C4GroupHeader Head
Definition: C4Group.h:143
Definition: C4Group.h:113
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
EntryStatus Status
Definition: C4Group.h:120
char DiskPath[_MAX_PATH+1]
Definition: C4Group.h:119
#define DirectorySeparator
int Entries
Definition: C4Group.h:87
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

int C4Group::EntryCount ( const char *  szWildCard = nullptr)
inherited

Definition at line 1850 of file C4Group.cpp.

References C4Group::ResetSearch().

Referenced by C4Group_ApplyUpdate(), C4MaterialMap::HasMaterials(), C4TextureMap::HasTextures(), C4MaterialMap::Load(), C4Game::LoadScenarioComponents(), and C4UpdatePackage::MkUp().

1851 {
1852  int fcount;
1853  C4GroupEntry *tentry;
1854  // All files if no wildcard
1855  if (!szWildCard) szWildCard="*";
1856  // Match wildcard
1857  ResetSearch(); fcount=0;
1858  while ((tentry=SearchNextEntry(szWildCard))) fcount++;
1859  return fcount;
1860 }
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int C4Group::EntryCRC32 ( const char *  szWildCard = nullptr)
inherited

Definition at line 1877 of file C4Group.cpp.

References C4Group::ResetSearch().

Referenced by C4UpdatePackage::MkUp(), and C4Network2Res::SetByGroup().

1878 {
1879  if (!szWildCard) szWildCard="*";
1880  // iterate thorugh child
1881  C4GroupEntry *pEntry; unsigned int iCRC = 0;
1882  ResetSearch();
1883  while ((pEntry = SearchNextEntry(szWildCard)))
1884  {
1885  iCRC ^= CalcCRC32(pEntry);
1886  }
1887  // return
1888  return iCRC;
1889 }
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

size_t C4Group::EntrySize ( const char *  szWildCard = nullptr)
inherited

Definition at line 1862 of file C4Group.cpp.

References C4Group::ResetSearch(), and C4GroupEntryCore::Size.

Referenced by C4Group::Extract(), and C4UpdatePackage::MkUp().

1863 {
1864  int fsize;
1865  C4GroupEntry *tentry;
1866  // All files if no wildcard
1867  if (!szWildCard) szWildCard="*";
1868  // Match wildcard
1869  ResetSearch(); fsize=0;
1870  while ((tentry=SearchNextEntry(szWildCard)))
1871  fsize+=tentry->Size;
1872  return fsize;
1873 }
int32_t Size
Definition: C4Group.h:95
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Extract ( const char *  szFiles,
const char *  szExtractTo = nullptr,
const char *  szExclude = nullptr 
)
inherited

Definition at line 1471 of file C4Group.cpp.

References _MAX_PATH, C4Group_IsExcluded(), C4Group::EntrySize(), C4Group::ExtractEntry(), C4GroupEntryCore::FileName, C4Group::ResetSearch(), SCharCount(), SCopySegment(), and C4GroupEntryCore::Size.

Referenced by C4Group_ApplyUpdate(), C4Group_CopyItem(), C4Group_MoveItem(), C4Group_UnpackDirectory(), and C4PlayerInfoList::RecreatePlayerFiles().

1472 {
1473 
1474  // StdOutput
1475  if (p->StdOutput)
1476  {
1477  printf("Extracting");
1478  if (szExtractTo) printf(" to %s",szExtractTo);
1479  printf("...\n");
1480  }
1481 
1482  int fcount=0;
1483  int cbytes,tbytes;
1484  C4GroupEntry *tentry;
1485 
1486  cbytes=0; tbytes=EntrySize();
1487 
1488  // Process segmented list
1489  char cSeparator = (SCharCount(';', szFiles) ? ';' : '|');
1490  char szFileName[_MAX_PATH + 1];
1491  for (int cseg=0; SCopySegment(szFiles, cseg, szFileName, cSeparator); cseg++)
1492  {
1493  // Search all entries
1494  ResetSearch();
1495  while ((tentry = SearchNextEntry(szFileName)))
1496  {
1497  // skip?
1498  if (C4Group_IsExcluded(tentry->FileName, szExclude)) continue;
1499  // Process data & output
1500  if (p->StdOutput) printf("%s\n",tentry->FileName);
1501  cbytes+=tentry->Size;
1502  if (p->fnProcessCallback)
1503  p->fnProcessCallback(tentry->FileName,100*cbytes/std::max(tbytes,1));
1504 
1505  // Extract
1506  if (!ExtractEntry(tentry->FileName,szExtractTo))
1507  return Error("Extract: Could not extract entry");
1508 
1509  fcount++;
1510  }
1511  }
1512 
1513  if (p->StdOutput) printf("%d file(s) extracted.\n",fcount);
1514 
1515  return true;
1516 }
bool C4Group_IsExcluded(const char *szFile, const char *szExcludeList)
Definition: C4Group.cpp:1457
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:251
char FileName[260]
Definition: C4Group.h:93
#define _MAX_PATH
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:298
int32_t Size
Definition: C4Group.h:95
bool ExtractEntry(const char *szFilename, const char *szExtractTo=nullptr)
Definition: C4Group.cpp:1518
size_t EntrySize(const char *szWildCard=nullptr)
Definition: C4Group.cpp:1862
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::ExtractEntry ( const char *  szFilename,
const char *  szExtractTo = nullptr 
)
inherited

Definition at line 1518 of file C4Group.cpp.

References _MAX_FNAME, AppendBackslash(), C4GroupEntryCore::ChildGroup, CStdFile::Close(), CopyItem(), CStdFile::Create(), DirectoryExists(), DirectorySeparator, EraseItem(), C4GroupEntryCore::Executable, C4Group::GetEntry(), C4Group::GetName(), MakeTempFilename(), RenameItem(), SAppend(), SCopy(), sprintf, C4Group::P::ST_Packed, C4Group::P::ST_Unpacked, and CStdFile::Write().

Referenced by C4ScenarioSection::EnsureTempStore(), and C4Group::Extract().

1519 {
1520  CStdFile tfile;
1521  CStdFile hDummy;
1522  char szTempFName[_MAX_FNAME+1],szTargetFName[_MAX_FNAME+1];
1523 
1524  // Target file name
1525  if (szExtractTo)
1526  {
1527  SCopy(szExtractTo,szTargetFName,_MAX_FNAME-1);
1528  if (DirectoryExists(szTargetFName))
1529  {
1530  AppendBackslash(szTargetFName);
1531  SAppend(szFilename,szTargetFName,_MAX_FNAME);
1532  }
1533  }
1534  else
1535  SCopy(szFilename,szTargetFName,_MAX_FNAME);
1536 
1537  // Extract
1538  switch (p->SourceType)
1539  {
1540  case P::ST_Packed: // Copy entry to target
1541  // Get entry
1542  C4GroupEntry *pEntry;
1543  if (!(pEntry=GetEntry(szFilename))) return Error("Extract: Entry not found");
1544  // Create dummy file to reserve target file name
1545  hDummy.Create(szTargetFName,false);
1546  hDummy.Write("Dummy",5);
1547  hDummy.Close();
1548  // Make temp target file name
1549  SCopy(szTargetFName,szTempFName,_MAX_FNAME);
1550  MakeTempFilename(szTempFName);
1551  // Create temp target file
1552  if (!tfile.Create(szTempFName, !!pEntry->ChildGroup, !!pEntry->Executable))
1553  return Error("Extract: Cannot create target file");
1554  // Write entry file to temp target file
1555  if (!AppendEntry2StdFile(pEntry,tfile))
1556  {
1557  // Failure: close and erase temp target file
1558  tfile.Close();
1559  EraseItem(szTempFName);
1560  // Also erase reservation target file
1561  EraseItem(szTargetFName);
1562  // Failure
1563  return false;
1564  }
1565  // Close target file
1566  tfile.Close();
1567  // Make temp file to original file
1568  if (!EraseItem(szTargetFName))
1569  return Error("Extract: Cannot erase temporary file");
1570  if (!RenameItem(szTempFName,szTargetFName))
1571  return Error("Extract: Cannot rename temporary file");
1572  break;
1573  case P::ST_Unpacked: // Copy item from folder to target
1574  char szPath[_MAX_FNAME+1];
1575  sprintf(szPath,"%s%c%s", GetName(),DirectorySeparator,szFilename);
1576  if (!CopyItem(szPath,szTargetFName))
1577  return Error("ExtractEntry: Cannot copy item");
1578  break;
1579  default: break; // InGrp & Deleted ignored
1580  }
1581  return true;
1582 }
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
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 RenameItem(const char *szItemName, const char *szNewItemName)
Definition: StdFile.cpp:803
char Executable
Definition: C4Group.h:99
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
#define sprintf
Definition: Standard.h:164
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
bool Write(const void *pBuffer, int iSize)
Definition: CStdFile.cpp:240
const char * GetName() const
Definition: C4Group.cpp:1845
int32_t ChildGroup
Definition: C4Group.h:94
#define _MAX_FNAME
C4GroupEntry * GetEntry(const char *szName)
Definition: C4Group.cpp:744
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
#define DirectorySeparator
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::FindEntry ( const char *  szWildCard,
StdStrBuf sFileName = nullptr,
size_t *  iSize = nullptr 
)
inherited

Definition at line 1774 of file C4Group.cpp.

References C4Group::FindNextEntry(), and C4Group::ResetSearch().

Referenced by C4Group::AccessEntry(), C4Group_ApplyUpdate(), C4GroupSet::CheckGroupContents(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4Group::FindEntry(), C4Group::FindNextEntry(), C4ComponentHost::FinishLoad(), C4MusicSystem::GrpContainsMusic(), C4Game::InitGame(), C4Game::InitMaterialTexture(), C4FacetSurface::Load(), C4ScenarioListLoader::Entry::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Surface::Load(), C4GameParameters::Load(), C4Player::Load(), C4Game::LoadAdditionalSystemGroup(), C4Surface::LoadAny(), C4Extra::LoadDef(), C4SoundSystem::LoadEffects(), C4Game::LoadScenarioSection(), C4Playback::Open(), C4Network2Res::OptimizeStandalone(), C4PlayerInfoList::RecreatePlayerFiles(), C4ObjectInfo::Save(), C4Game::SaveGameTitle(), C4Landscape::SaveTextures(), C4ScenarioSection::ScenarioLoad(), C4LoaderScreen::SeekLoaderScreens(), C4Player::Strip(), and C4ControlJoinPlayer::Strip().

1775 {
1776  ResetSearch();
1777  return FindNextEntry(szWildCard,sFileName,iSize);
1778 }
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::FindEntry ( const char *  szWildCard,
char *  sFileName 
)
inlineinherited

Definition at line 182 of file C4Group.h.

References C4Group::FindEntry(), StdStrBuf::getData(), and SCopy().

184  {
185  StdStrBuf name;
186  bool r = FindEntry(szWildCard, &name);
187  if(sFileName) SCopy(name.getData(),sFileName);
188  return r;
189  }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130

Here is the call graph for this function:

bool C4Group::FindNextEntry ( const char *  szWildCard,
StdStrBuf sFileName = nullptr,
size_t *  iSize = nullptr,
bool  fStartAtFilename = false 
)
inherited

Definition at line 1780 of file C4Group.cpp.

References StdStrBuf::Copy(), C4GroupEntryCore::FileName, C4Group::FindEntry(), StdStrBuf::getData(), and C4GroupEntryCore::Size.

Referenced by C4Group::AccessNextEntry(), c4_mapgen_handle_new(), C4Group_ApplyUpdate(), C4UpdatePackage::DoGrpUpdate(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4UpdatePackage::DoUpdate(), C4ScenarioSection::EnsureTempStore(), C4UpdatePackage::Execute(), C4Group::FindEntry(), C4Group::FindNextEntry(), C4AchievementGraphics::Init(), C4Language::Init(), C4Game::InitScriptEngine(), C4DefList::Load(), C4ObjectInfoList::Load(), C4DefGraphics::Load(), C4Surface::Load(), C4MaterialMap::Load(), C4Game::LoadAdditionalSystemGroup(), C4MusicSystem::LoadDir(), C4SoundSystem::LoadEffects(), C4Game::LoadScenarioComponents(), C4UpdatePackage::MkUp(), C4UpdatePackage::Optimize(), and C4LoaderScreen::SeekLoaderScreens().

1784 {
1785  C4GroupEntry *centry;
1786  if (!szWildCard) return false;
1787 
1788  // Reset search to specified position
1789  if (fStartAtFilename) FindEntry(sFileName->getData());
1790 
1791  if (!(centry=SearchNextEntry(szWildCard))) return false;
1792  if (sFileName) sFileName->Copy(centry->FileName);
1793  if (iSize) *iSize=centry->Size;
1794  return true;
1795 }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
char FileName[260]
Definition: C4Group.h:93
int32_t Size
Definition: C4Group.h:95
void Copy()
Definition: StdBuf.h:467
Definition: C4Group.h:105
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::FindNextEntry ( const char *  szWildCard,
char *  sFileName,
size_t *  iSize = nullptr,
bool  fStartAtFilename = false 
)
inlineinherited

Definition at line 194 of file C4Group.h.

References C4Group::FindNextEntry(), StdStrBuf::getData(), iSize, and SCopy().

198  {
199  StdStrBuf name(fStartAtFilename ? sFileName : "");
200  bool r = FindNextEntry(szWildCard, &name, iSize, fStartAtFilename);
201  if (r && sFileName) SCopy(name.getData(),sFileName);
202  return r;
203  }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

C4GroupEntry * C4Group::GetEntry ( const char *  szName)
protectedinherited

Definition at line 744 of file C4Group.cpp.

References C4GroupEntry::C4GRES_Deleted, C4GroupEntryCore::FileName, C4GroupEntry::Next, C4Group::P::ST_Unpacked, C4GroupEntry::Status, and WildcardMatch().

Referenced by C4Group::DeleteEntry(), C4Group::ExtractEntry(), C4Group::Rename(), SetNoSort(), and SetSavedEntryCore().

745 {
746  if (p->SourceType==P::ST_Unpacked) return nullptr;
747  C4GroupEntry *centry;
748  for (centry=p->FirstEntry; centry; centry=centry->Next)
749  if (centry->Status != C4GroupEntry::C4GRES_Deleted)
750  if (WildcardMatch(szName,centry->FileName))
751  return centry;
752  return nullptr;
753 }
Definition: C4Group.h:115
char FileName[260]
Definition: C4Group.h:93
C4GroupEntry * Next
Definition: C4Group.h:126
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374
EntryStatus Status
Definition: C4Group.h:120
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Group::GetError ( )
inherited

Definition at line 504 of file C4Group.cpp.

Referenced by c4_mapgen_handle_new(), C4LoaderScreen::Init(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4Group::Open(), ProcessGroup(), C4ScenarioListLoader::Entry::RenameTo(), and C4ScenarioListLoader::Entry::SetTitleInGroup().

505 {
506  return p->ErrorString.c_str();
507 }

Here is the caller graph for this function:

const C4GroupEntry * C4Group::GetFirstEntry ( ) const
inherited

Definition at line 2247 of file C4Group.cpp.

Referenced by DisplayGroup(), and PrintGroupInternals().

2247 { return p->FirstEntry; }

Here is the caller graph for this function:

StdStrBuf C4Group::GetFullName ( ) const
inherited

Definition at line 2078 of file C4Group.cpp.

References _MAX_PATH, StdStrBuf::Copy(), DirectorySeparator, SInsert(), and C4Group::P::ST_Unpacked.

Referenced by C4Group::AccessEntry(), C4GameSaveSavegame::AdjustCore(), C4Language::CloseGroup(), C4ComponentHost::CopyFilePathFromGroup(), DisplayGroup(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4UpdatePackage::DoUpdate(), C4UpdatePackage::Execute(), C4Language::GetPackGroups(), C4MusicSystem::InitForScenario(), C4Game::InitScriptEngine(), C4UpdatePackage::Load(), C4ScenarioListLoader::Entry::Load(), C4GameResList::Load(), C4ParticleDef::Load(), C4PlayerInfoCore::Load(), C4Surface::Load(), C4MaterialCore::Load(), C4GameParameters::Load(), C4Player::Load(), C4Game::LoadAdditionalSystemGroup(), C4DefGraphics::LoadBitmap(), C4ScenarioListLoader::Scenario::LoadCustomPre(), C4ScenarioListLoader::Folder::LoadCustomPre(), C4Def::LoadDefCore(), C4TextureMap::LoadTextures(), C4UpdatePackage::MkUp(), C4Playback::Open(), C4Group::OpenAsChild(), C4Game::OpenScenario(), C4MessageInput::ProcessCommand(), C4ObjectInfo::Save(), C4PlayerInfoCore::Save(), and C4Network2Res::SetByGroup().

2079 {
2080  char str[_MAX_PATH+1]; *str='\0';
2081  char sep[] = "/"; sep[0] = DirectorySeparator;
2082  for (const C4Group *pGroup=this; pGroup; pGroup=pGroup->p->Mother)
2083  {
2084  if (*str) SInsert(str, sep, 0, _MAX_PATH);
2085  // Avoid double slash
2086  if (pGroup == this || pGroup->p->FileName.length() > 1 || pGroup->p->FileName[0] != '/')
2087  SInsert(str, pGroup->GetName(), 0, _MAX_PATH);
2088  if (pGroup->p->SourceType == P::ST_Unpacked) break; // Folder is assumed to have full path
2089  }
2090  StdStrBuf sResult; sResult.Copy(str);
2091  return sResult;
2092 }
#define _MAX_PATH
void SInsert(char *szString, const char *szInsert, int iPosition, int iMaxLen)
Definition: Standard.cpp:481
#define DirectorySeparator
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

const C4GroupHeader & C4Group::GetHeader ( ) const
inherited

Definition at line 2245 of file C4Group.cpp.

References C4Group::Head.

Referenced by DisplayGroup(), and PrintGroupInternals().

2245 { return Head; }
C4GroupHeader Head
Definition: C4Group.h:143

Here is the caller graph for this function:

C4Group * C4Group::GetMother ( )
inherited

Definition at line 2004 of file C4Group.cpp.

Referenced by C4Console::SaveScenario().

2005 {
2006  return p->Mother;
2007 }

Here is the caller graph for this function:

const char * C4Group::GetName ( ) const
inherited
bool C4Group::HasPackedMother ( ) const
inherited

Definition at line 2011 of file C4Group.cpp.

Referenced by C4UpdatePackage::MakeUpdate().

2011 { if (!p->Mother) return false; return p->Mother->IsPacked(); }

Here is the caller graph for this function:

bool C4GroupEx::HeadIdentical ( C4Group rByGrp,
bool  fLax 
)
inline

Definition at line 184 of file C4Update.cpp.

References C4GroupHeader::Entries, and C4Group::Head.

Referenced by C4UpdatePackage::Optimize().

185  {
186  // Cheat away the protection while avoiding
187  // gcc strict aliasing violation warnings.
188  intptr_t iGroup = (intptr_t) &rByGrp;
189  C4GroupHeader *pHdr = &((C4GroupEx*) iGroup)->Head;
190  // overwrite entries field
191  int Entries = Head.Entries;
192  Head.Entries = pHdr->Entries;
193  // compare
194  bool fIdentical = !memcmp(&Head, pHdr, sizeof(C4GroupHeader));
195  // restore field values
196  Head.Entries = Entries;
197  // okay
198  return fIdentical;
199  }
C4GroupHeader Head
Definition: C4Group.h:143
int Entries
Definition: C4Group.h:87

Here is the caller graph for this function:

bool C4Group::IsOpen ( ) const
inherited

Definition at line 1891 of file C4Group.cpp.

References C4Group::P::ST_None.

Referenced by c4_group_handle_is_folder(), C4SoundSystem::Init(), C4Game::LoadScenarioSection(), C4Application::OpenSystemGroup(), C4MessageInput::ProcessCommand(), and C4Landscape::SaveTextures().

1891 { return p->SourceType != P::ST_None; }

Here is the caller graph for this function:

bool C4Group::IsPacked ( ) const
inherited

Definition at line 2009 of file C4Group.cpp.

References C4Group::P::ST_Packed.

Referenced by c4_group_handle_is_folder(), C4UpdatePackage::Check(), C4UpdatePackage::Execute(), C4Game::InitScriptEngine(), C4Game::LoadAdditionalSystemGroup(), C4UpdatePackage::MakeUpdate(), C4Playback::Open(), C4Game::OpenScenario(), C4UpdatePackage::Optimize(), C4MessageInput::ProcessCommand(), C4Console::SaveScenario(), and C4ScenarioSection::ScenarioLoad().

2009 { return p->SourceType == P::ST_Packed; }

Here is the caller graph for this function:

bool C4Group::LoadEntry ( const char *  szEntryName,
char **  lpbpBuf,
size_t *  ipSize = nullptr,
int  iAppendZeros = 0 
)
inherited

Definition at line 1893 of file C4Group.cpp.

References C4Group::AccessEntry(), C4Group::Read(), and ZeroMem().

Referenced by C4ControlReInitScenario::C4ControlReInitScenario(), C4Group_CopyEntry(), C4UpdatePackage::DoGrpUpdate(), C4FontLoader::InitFont(), C4Folder::Load(), C4TextureShape::Load(), C4SoundEffect::Load(), C4ParticleDef::Load(), C4KeyboardInput::LoadCustomConfig(), C4GroupSet::LoadEntry(), C4TextureMap::LoadMap(), C4SolidMask::LoadMaskFromFile(), C4DefGraphics::LoadMesh(), C4DefGraphics::LoadSkeleton(), C4Playback::Open(), and C4Game::SaveGameTitle().

1894 {
1895  size_t size;
1896 
1897  // Access entry, allocate buffer, read data
1898  (*lpbpBuf)=nullptr; if (ipSize) *ipSize=0;
1899  if (!AccessEntry(szEntryName,&size)) return Error("LoadEntry: Not found");
1900  *lpbpBuf = new char[size+iAppendZeros];
1901  if (!Read(*lpbpBuf,size))
1902  {
1903  delete [] (*lpbpBuf); *lpbpBuf = nullptr;
1904  return Error("LoadEntry: Reading error");
1905  }
1906 
1907  if (ipSize) *ipSize=size;
1908 
1909  if (iAppendZeros)
1910  ZeroMem( (*lpbpBuf)+size, iAppendZeros );
1911 
1912  return true;
1913 }
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:60
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:

bool C4Group::LoadEntry ( const char *  szEntryName,
StdBuf Buf 
)
inherited

Definition at line 1915 of file C4Group.cpp.

References C4Group::AccessEntry(), StdBuf::Clear(), StdBuf::getMData(), StdBuf::New(), and C4Group::Read().

1916 {
1917  size_t size;
1918  // Access entry, allocate buffer, read data
1919  if (!AccessEntry(szEntryName,&size)) return Error("LoadEntry: Not found");
1920  // Allocate memory
1921  Buf->New(size);
1922  // Load data
1923  if (!Read(Buf->getMData(),size))
1924  {
1925  Buf->Clear();
1926  return Error("LoadEntry: Reading error");
1927  }
1928  // ok
1929  return true;
1930 }
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
void Clear()
Definition: StdBuf.h:190
void New(size_t inSize)
Definition: StdBuf.h:146
void * getMData()
Definition: StdBuf.h:100
bool Read(void *pBuffer, size_t iSize) override
Definition: C4Group.cpp:1125

Here is the call graph for this function:

bool C4Group::LoadEntry ( const StdStrBuf name,
StdBuf Buf 
)
inlineinherited

Definition at line 176 of file C4Group.h.

References StdStrBuf::getData(), and C4Group::LoadEntry().

Referenced by C4Group::LoadEntry().

176 { return LoadEntry(name.getData(), Buf); }
const char * getData() const
Definition: StdBuf.h:442
bool LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int iAppendZeros=0)
Definition: C4Group.cpp:1893

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::LoadEntryString ( const char *  szEntryName,
StdStrBuf Buf 
)
inherited

Definition at line 1932 of file C4Group.cpp.

References C4Group::AccessEntry(), StdStrBuf::Clear(), StdStrBuf::getMData(), C4Group::Read(), and StdStrBuf::SetLength().

Referenced by C4ComponentHost::Load(), C4UpdatePackageCore::Load(), C4UpdatePackage::Load(), C4ObjectInfoCore::Load(), C4ScenarioListLoader::Entry::Load(), C4ScenarioParameterDefs::Load(), C4PlayerInfoCore::Load(), C4MaterialCore::Load(), C4GameParameters::Load(), C4TeamList::Load(), C4RoundResults::Load(), C4Scenario::Load(), C4PlayerControlFile::Load(), C4MapFolderData::Load(), C4PlayerInfoList::Load(), C4ScenarioListLoader::Scenario::LoadCustomPre(), C4ScenarioListLoader::Folder::LoadCustomPre(), C4Def::LoadDefCore(), C4GroupSet::LoadEntryString(), C4MaterialMap::LoadEnumeration(), C4TextureMap::LoadFlags(), C4DefAdditionalResourcesLoader::LoadShaderCode(), C4Playback::Open(), and C4Shader::Refresh().

1933 {
1934  size_t size;
1935  // Access entry, allocate buffer, read data
1936  if (!AccessEntry(szEntryName,&size)) return Error("LoadEntry: Not found");
1937  // Allocate memory
1938  Buf->SetLength(size);
1939  // other parts crash when they get a zero length buffer, so fail here
1940  if (!size) return false;
1941  // Load data
1942  if (!Read(Buf->getMData(),size))
1943  {
1944  Buf->Clear();
1945  return Error("LoadEntry: Reading error");
1946  }
1947  // ok
1948  return true;
1949 }
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
void Clear()
Definition: StdBuf.h:466
char * getMData()
Definition: StdBuf.h:443
void SetLength(size_t iLength)
Definition: StdBuf.h:509
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:

bool C4Group::LoadEntryString ( const StdStrBuf name,
StdStrBuf Buf 
)
inlineinherited

Definition at line 178 of file C4Group.h.

References StdStrBuf::getData(), and C4Group::LoadEntryString().

Referenced by C4Group::LoadEntryString().

178 { return LoadEntryString(name.getData(), Buf); }
const char * getData() const
Definition: StdBuf.h:442
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Merge ( const char *  szFolders)
inherited

Definition at line 1229 of file C4Group.cpp.

References _MAX_FNAME, GetFilename(), DirectoryIterator::Reset(), SCharCount(), and SCopySegment().

Referenced by C4Network2::RetrieveScenario(), and C4Playback::StreamToRecord().

1230 {
1231  bool fMove = true;
1232 
1233  if (p->StdOutput) printf("%s...\n",fMove ? "Moving" : "Adding");
1234 
1235  // Add files & directories
1236  char szFileName[_MAX_FNAME+1];
1237  int iFileCount = 0;
1239 
1240  // Process segmented path & search wildcards
1241  char cSeparator = (SCharCount(';', szFolders) ? ';' : '|');
1242  for (int cseg=0; SCopySegment(szFolders, cseg, szFileName, cSeparator); cseg++)
1243  {
1244  i.Reset(szFileName);
1245  while (*i)
1246  {
1247  // File count
1248  iFileCount++;
1249  // Process output & callback
1250  if (p->StdOutput) printf("%s\n",GetFilename(*i));
1251  if (p->fnProcessCallback)
1252  p->fnProcessCallback(GetFilename(*i),0); // cbytes/tbytes
1253  // AddEntryOnDisk
1254  AddEntryOnDisk(*i, nullptr, fMove);
1255  ++i;
1256  }
1257  }
1258 
1259  if (p->StdOutput) printf("%d file(s) %s.\n",iFileCount,fMove ? "moved" : "added");
1260 
1261  return true;
1262 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:251
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:298
#define _MAX_FNAME
void Reset(const char *dirname, bool force_reread=false)
Definition: StdFile.cpp:918

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Move ( const char *  szFile,
const char *  szAddAs 
)
inherited

Definition at line 1325 of file C4Group.cpp.

References GetFilename().

Referenced by C4Record::AddFile(), C4Group_CopyItem(), C4Group_MoveItem(), C4Group_PackDirectoryTo(), C4UpdatePackage::DoUpdate(), C4UpdatePackage::MkUp(), C4PlayerList::Save(), C4PXSSystem::Save(), C4Landscape::P::SaveDiffInternal(), C4Game::SaveGameTitle(), C4Landscape::P::SaveInternal(), C4Landscape::SaveMap(), C4Surface::SavePNG(), C4Landscape::SaveTextures(), and C4Playback::StreamToRecord().

1326 {
1327  bool fMove = true;
1328 
1329  if (p->StdOutput) printf("%s %s as %s...\n",fMove ? "Moving" : "Adding",GetFilename(szFile),szAddAs);
1330 
1331  return AddEntryOnDisk(szFile, szAddAs, fMove);
1332 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Open ( const char *  szGroupName,
bool  fCreate = false 
)
inherited

Definition at line 514 of file C4Group.cpp.

References _MAX_FNAME, C4Group::C4Group(), C4Group::Clear(), CStdFile::Close(), CStdFile::Create(), DirectorySeparator, FileExists(), FormatString(), C4Group::GetError(), C4Group::Open(), C4Group::OpenAsChild(), SCopy(), C4Group::SetStdOutput(), SLen(), SReplaceChar(), C4Group::P::ST_Packed, and TruncatePath().

Referenced by C4MainMenu::ActivateNewPlayer(), c4_mapgen_handle_new(), C4ControlReInitScenario::C4ControlReInitScenario(), C4Group_CopyItem(), C4Group_DeleteItem(), C4Group_IsGroup(), C4Group_MoveItem(), C4Group_PackDirectoryTo(), C4Group_ReadFile(), C4Group_UnpackDirectory(), C4UpdatePackage::Check(), DefFileGetID(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4ScenarioSection::EnsureTempStore(), C4UpdatePackage::Execute(), C4ScenarioSection::GetGroupfile(), C4Language::Init(), C4ScenarioListLoader::Entry::Load(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4PlayerInfo::LoadBigIcon(), C4KeyboardInput::LoadCustomConfig(), C4MusicSystem::LoadDir(), C4GameResList::LoadFoldersWithLocalDefs(), C4UpdatePackage::MakeUpdate(), C4UpdatePackage::MkUp(), C4StartupPlrPropertiesDlg::OnClosed(), C4Reloc::Open(), C4Group::Open(), C4Network2Res::OpenAsGrp(), C4Application::OpenSystemGroup(), C4UpdatePackage::Optimize(), C4Network2Res::OptimizeStandalone(), ProcessGroup(), C4Shader::Refresh(), C4DefList::Reload(), C4ParticleDef::Reload(), C4ScriptHost::ReloadScript(), C4ScenarioListLoader::Entry::RenameTo(), C4Network2::RetrieveScenario(), C4PlayerList::Save(), C4Player::Save(), C4Console::SaveScenario(), C4Landscape::SaveTextures(), C4Record::Start(), C4Playback::StreamToRecord(), C4Player::Strip(), C4ControlJoinPlayer::Strip(), and C4StartupPlrSelDlg::PlayerListItem::UpdateCore().

515 {
516  if (!szGroupName) return Error("Open: Null filename");
517  if (!szGroupName[0]) return Error("Open: Empty filename");
518 
519  char szGroupNameN[_MAX_FNAME];
520  SCopy(szGroupName,szGroupNameN,_MAX_FNAME);
521  // Convert to native path
522  SReplaceChar(szGroupNameN, '\\', DirectorySeparator);
523 
524  // Real reference
525  if (FileExists(szGroupNameN))
526  {
527  // Init
528  Init();
529  // Open group or folder
530  return OpenReal(szGroupNameN);
531  }
532 
533  // If requested, try creating a new group file
534  if (fCreate)
535  {
536  CStdFile temp;
537  if (temp.Create(szGroupNameN,false))
538  {
539  // Temporary file has been created
540  temp.Close();
541  // Init
542  Init();
543  p->SourceType=P::ST_Packed; p->Modified=true;
544  p->FileName = szGroupNameN;
545  return true;
546  }
547  }
548 
549  // While not a real reference (child group), trace back to mother group or folder.
550  // Open mother and child in exclusive mode.
551  char szRealGroup[_MAX_FNAME];
552  SCopy(szGroupNameN,szRealGroup,_MAX_FNAME);
553  do
554  { if (!TruncatePath(szRealGroup)) return Error(FormatString(R"(Open("%s"): File not found)", szGroupNameN).getData()); }
555  while (!FileExists(szRealGroup));
556 
557  // Open mother and child in exclusive mode
558  C4Group *pMother = new C4Group;
559  pMother->SetStdOutput(p->StdOutput);
560  if (!pMother->Open(szRealGroup))
561  { Clear(); Error(pMother->GetError()); delete pMother; return false; }
562  if (!OpenAsChild(pMother,szGroupNameN+SLen(szRealGroup)+1,true))
563  { Clear(); return false; }
564 
565  // Success
566  return true;
567 
568 }
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
void SetStdOutput(bool fStatus)
Definition: C4Group.cpp:509
#define _MAX_FNAME
const char * GetError()
Definition: C4Group.cpp:504
bool FileExists(const char *szFileName)
bool TruncatePath(char *szPath)
Definition: StdFile.cpp:240
void Clear()
Definition: C4Group.cpp:898
#define DirectorySeparator
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
C4Group()
Definition: C4Group.cpp:477
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:326
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::OpenAsChild ( C4Group pMother,
const char *  szEntryName,
bool  fExclusive = false,
bool  fCreate = false 
)
inherited

Definition at line 1585 of file C4Group.cpp.

References _MAX_FNAME, C4GroupEntry::C4GRES_InGroup, C4Group::C4Group(), C4GroupFileID, C4GroupFileVer1, C4GroupFileVer2, C4GroupEntryCore::ChildGroup, C4Group::Clear(), DirectoryExists(), DirectorySeparator, C4GroupHeader::Entries, C4GroupEntryCore::Executable, C4GroupEntryCore::FileName, C4Group::GetFullName(), C4Group::GetName(), C4Group::Head, C4GroupHeader::id, iSize, MemScramble(), C4GroupEntryCore::Offset, C4Group::OpenAsChild(), C4Group::ResetSearch(), SCharCount(), SCopy(), SCopyUntil(), SEqual(), C4Group::SetStdOutput(), C4GroupEntryCore::Size, SLen(), C4Group::P::ST_Packed, C4Group::P::ST_Unpacked, C4GroupHeader::Ver1, and C4GroupHeader::Ver2.

Referenced by C4Group_ApplyUpdate(), C4Group::Delete(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4UpdatePackage::DoUpdate(), C4ScenarioSection::GetGroupfile(), C4Language::GetPackGroups(), C4Game::InitMaterialTexture(), C4ObjectInfoList::Load(), C4DefList::Load(), C4ObjectInfo::Load(), C4ScenarioListLoader::Entry::Load(), C4Game::LoadAdditionalSystemGroup(), C4SoundSystem::LoadEffects(), C4UpdatePackage::MkUp(), C4Group::Open(), C4Group::OpenAsChild(), C4Group::OpenChild(), C4Game::OpenScenario(), C4UpdatePackage::Optimize(), PrintGroupInternals(), C4GroupSet::RegisterGroups(), C4GroupSet::RegisterParentFolders(), C4ObjectInfo::Save(), and C4Landscape::SaveTextures().

1587 {
1588 
1589  if (!pMother) return Error("OpenAsChild: No mother specified");
1590 
1591  if (SCharCount('*',szEntryName)) return Error("OpenAsChild: No wildcards allowed");
1592 
1593  // Open nested child group check: If szEntryName is a reference to
1594  // a nested group, open the first mother (in specified mode), then open the child
1595  // in exclusive mode
1596 
1597  if (SCharCount(DirectorySeparator,szEntryName))
1598  {
1599  char mothername[_MAX_FNAME+1];
1600  SCopyUntil(szEntryName,mothername,DirectorySeparator,_MAX_FNAME);
1601 
1602  C4Group *pMother2;
1603  pMother2 = new C4Group;
1604  pMother2->SetStdOutput(p->StdOutput);
1605  if (!pMother2->OpenAsChild(pMother, mothername, fExclusive))
1606  {
1607  delete pMother2;
1608  return Error("OpenAsChild: Cannot open mother");
1609  }
1610  return OpenAsChild(pMother2, szEntryName + SLen(mothername) + 1, true);
1611  }
1612 
1613  // Init
1614  Init();
1615  p->FileName = szEntryName;
1616  p->Mother=pMother;
1617  p->ExclusiveChild=fExclusive;
1618 
1619  // Folder: Simply set status and return
1620  char path[_MAX_FNAME+1];
1621  SCopy( GetFullName().getData(), path, _MAX_FNAME);
1622  if (DirectoryExists(path))
1623  {
1624  p->FileName = path;
1625  p->SourceType=P::ST_Unpacked;
1626  ResetSearch();
1627  return true;
1628  }
1629 
1630  // Get original entry name
1631  C4GroupEntry *centry;
1632  if ((centry = p->Mother->GetEntry(GetName())))
1633  p->FileName = centry->FileName;
1634 
1635  // Access entry in mother group
1636  size_t iSize;
1637  if ((!p->Mother->AccessEntry(GetName(), &iSize, nullptr, true)))
1638  {
1639  if (!fCreate)
1640  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Entry not in mother group"); }
1641  else
1642  {
1643  // Create - will be added to mother in Close()
1644  p->SourceType=P::ST_Packed; p->Modified=true;
1645  return true;
1646  }
1647  }
1648 
1649  // Child Group?
1650  if (centry && !centry->ChildGroup)
1651  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Is not a child group"); }
1652 
1653  // Read header
1654  // Do not do size checks for packed subgroups of unpacked groups (there will be no entry),
1655  // because that would be the PACKED size which can actually be smaller than sizeof(C4GroupHeader)!
1656  if (iSize < sizeof(C4GroupHeader) && centry)
1657  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Entry too small"); }
1658  if (!p->Mother->Read(&Head,sizeof(C4GroupHeader)))
1659  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Entry reading error"); }
1660  MemScramble((BYTE*)&Head,sizeof(C4GroupHeader));
1661  p->EntryOffset+=sizeof(C4GroupHeader);
1662 
1663  // Check Header
1664  if (!SEqual(Head.id,C4GroupFileID)
1666  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Invalid Header"); }
1667 
1668  // Read Entries
1669  C4GroupEntryCore corebuf;
1670  int file_entries=Head.Entries;
1671  Head.Entries=0; // Reset, will be recounted by AddEntry
1672  for (int cnt=0; cnt<file_entries; cnt++)
1673  {
1674  if (!p->Mother->Read(&corebuf,sizeof(C4GroupEntryCore)))
1675  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Entry reading error"); }
1676  p->EntryOffset+=sizeof(C4GroupEntryCore);
1677  if (!AddEntry(C4GroupEntry::C4GRES_InGroup, !!corebuf.ChildGroup,
1678  corebuf.FileName,corebuf.Size,
1679  nullptr, nullptr, false, false,
1680  !!corebuf.Executable))
1681  { CloseExclusiveMother(); Clear(); return Error("OpenAsChild: Insufficient memory"); }
1682  }
1683 
1684  ResetSearch();
1685 
1686  // File
1687  p->SourceType=P::ST_Packed;
1688 
1689  // save position in mother group
1690  if (centry) p->MotherOffset = centry->Offset;
1691 
1692  return true;
1693 }
const int C4GroupFileVer2
Definition: C4Group.h:55
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
char Executable
Definition: C4Group.h:99
char FileName[260]
Definition: C4Group.h:93
uint8_t BYTE
char id[24+4]
Definition: C4Group.h:84
Definition: C4Group.h:91
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:298
const int C4GroupFileVer1
Definition: C4Group.h:55
#define C4GroupFileID
Definition: C4Group.h:61
const char * GetName() const
Definition: C4Group.cpp:1845
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
void SetStdOutput(bool fStatus)
Definition: C4Group.cpp:509
int32_t Offset
Definition: C4Group.h:95
int32_t ChildGroup
Definition: C4Group.h:94
#define _MAX_FNAME
int32_t Size
Definition: C4Group.h:95
C4GroupHeader Head
Definition: C4Group.h:143
Definition: C4Group.h:112
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684
void MemScramble(BYTE *bypBuffer, int iSize)
Definition: C4Group.cpp:390
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
void Clear()
Definition: C4Group.cpp:898
#define DirectorySeparator
int Entries
Definition: C4Group.h:87
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:146
C4Group()
Definition: C4Group.cpp:477
Definition: C4Group.h:105
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::OpenChild ( const char *  strEntry)
inherited

Definition at line 2161 of file C4Group.cpp.

References C4Group::C4Group(), and C4Group::OpenAsChild().

Referenced by C4Language::GetPackGroups().

2162 {
2163  // hack: The seach-handle would be closed twice otherwise
2164  p->FolderSearch.Reset();
2165  // Create a memory copy of ourselves
2166  C4Group *pOurselves = new C4Group;
2167  *pOurselves->p = *p;
2168 
2169  // Open a child from the memory copy
2170  C4Group hChild;
2171  if (!hChild.OpenAsChild(pOurselves, strEntry, false))
2172  {
2173  // Silently delete our memory copy
2174  pOurselves->p.reset();
2175  delete pOurselves;
2176  return false;
2177  }
2178 
2179  // hack: The seach-handle would be closed twice otherwise
2180  p->FolderSearch.Reset();
2181  hChild.p->FolderSearch.Reset();
2182 
2183  // We now become our own child
2184  *p = *hChild.p;
2185 
2186  // Make ourselves exclusive (until we hit our memory copy parent)
2187  for (C4Group *pGroup = this; pGroup != pOurselves; pGroup = pGroup->p->Mother)
2188  pGroup->p->ExclusiveChild = true;
2189 
2190  // Reset the temporary child variable so it doesn't delete anything
2191  hChild.p.reset();
2192 
2193  // Yeehaw
2194  return true;
2195 }
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
C4Group()
Definition: C4Group.cpp:477

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::OpenMother ( )
inherited

Definition at line 2197 of file C4Group.cpp.

References C4Group::Clear().

Referenced by C4Language::GetPackGroups().

2198 {
2199  // This only works if we are an exclusive child
2200  if (!p->Mother || !p->ExclusiveChild) return false;
2201 
2202  // Store a pointer to our mother
2203  C4Group *pMother = p->Mother;
2204 
2205  // Clear ourselves without deleting our mother
2206  p->ExclusiveChild = false;
2207  Clear();
2208 
2209  // hack: The seach-handle would be closed twice otherwise
2210  pMother->p->FolderSearch.Reset();
2211  p->FolderSearch.Reset();
2212  // We now become our own mother (whoa!)
2213  *this = std::move(*pMother);
2214 
2215  // Now silently delete our former mother
2216  delete pMother;
2217 
2218  // Yeehaw
2219  return true;
2220 }
void Clear()
Definition: C4Group.cpp:898

Here is the call graph for this function:

Here is the caller graph for this function:

int C4Group::PreCacheEntries ( const char *  szSearchPattern,
bool  cache_previous = false 
)
inherited

Definition at line 2222 of file C4Group.cpp.

References C4Group::P::ST_Packed, and WildcardListMatch().

Referenced by C4Game::InitMaterialTexture(), and C4ScenarioListLoader::Scenario::LoadCustomPre().

2223 {
2224  assert(szSearchPattern);
2225  int result = 0;
2226  // pre-load entries to memory. return number of loaded entries.
2227  for (C4GroupEntry * e = p->FirstEntry; e; e = e->Next)
2228  {
2229  // is this to be cached?
2230  if (!WildcardListMatch(szSearchPattern, e->FileName)) continue;
2231  // if desired, cache all entries up to that one to allow rewind in unpacked memory
2232  // (only makes sense for groups)
2233  if (cache_previous && p->SourceType == P::ST_Packed)
2234  {
2235  for (C4GroupEntry * e_pre = p->FirstEntry; e_pre != e; e_pre = e_pre->Next)
2236  if (e_pre->Offset >= p->FilePtr)
2237  PreCacheEntry(e_pre);
2238  }
2239  // cache the given entry
2240  PreCacheEntry(e);
2241  }
2242  return result;
2243 }
bool WildcardListMatch(const char *szWildcardList, const char *szString)
Definition: StdFile.cpp:351
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Read ( void *  pBuffer,
size_t  iSize 
)
overridevirtualinherited

Implements CStdStream.

Definition at line 1125 of file C4Group.cpp.

References iSize, C4Group::P::ST_Packed, and C4Group::P::ST_Unpacked.

Referenced by C4Group::Advance(), C4Group_ReadFile(), C4MassMoverSet::Load(), C4PXSSystem::Load(), C4Group::LoadEntry(), C4Group::LoadEntryString(), and C4MCParser::ParseFile().

1126 {
1127  // Access cached entry from memory?
1128  if (p->pInMemEntry)
1129  {
1130  if (p->iInMemEntrySize < iSize) return Error("ReadCached:");
1131  memcpy(pBuffer, p->pInMemEntry, iSize);
1132  p->iInMemEntrySize -= iSize;
1133  p->pInMemEntry += iSize;
1134  return true;
1135  }
1136  // Not cached. Read from file.
1137  switch (p->SourceType)
1138  {
1139  case P::ST_Packed:
1140  // Child group: read from mother group
1141  if (p->Mother)
1142  {
1143  if (!p->Mother->Read(pBuffer,iSize))
1144  { RewindFilePtr(); return Error("Read:"); }
1145  }
1146  // Regular group: read from standard file
1147  else
1148  {
1149  if (!p->StdFile.Read(pBuffer,iSize))
1150  { RewindFilePtr(); return Error("Read:"); }
1151  }
1152  p->FilePtr+=iSize;
1153  break;
1154  case P::ST_Unpacked:
1155  if (!p->StdFile.Read(pBuffer,iSize)) return Error("Read: Error reading from folder contents");
1156  break;
1157  default: break; // InGrp & Deleted ignored
1158  }
1159 
1160  return true;
1161 }
int iSize
Definition: TstC4NetIO.cpp:32

Here is the caller graph for this function:

bool C4Group::Rename ( const char *  szFile,
const char *  szNewName 
)
inherited

Definition at line 1424 of file C4Group.cpp.

References _MAX_FNAME, _MAX_PATH, AppendBackslash(), C4GroupEntryCore::FileName, C4Group::GetEntry(), C4Group::GetName(), RenameFile(), C4Group::ResetSearch(), SAppend(), SCopy(), SEqualNoCase(), C4Group::P::ST_Packed, and C4Group::P::ST_Unpacked.

Referenced by C4ObjectInfo::Save().

1425 {
1426 
1427  if (p->StdOutput) printf("Renaming %s to %s...\n",szFile,szNewName);
1428 
1429  switch (p->SourceType)
1430  {
1431  case P::ST_Packed:
1432  // Get entry
1433  C4GroupEntry *pEntry;
1434  if (!(pEntry=GetEntry(szFile))) return Error("Rename: File not found");
1435  // Check double name
1436  if (GetEntry(szNewName) && !SEqualNoCase(szNewName, szFile)) return Error("Rename: File exists already");
1437  // Rename
1438  SCopy(szNewName,pEntry->FileName,_MAX_FNAME);
1439  p->Modified=true;
1440  break;
1441  case P::ST_Unpacked:
1442  p->StdFile.Close();
1443  char path[_MAX_FNAME+1]; SCopy(GetName(),path,_MAX_PATH-1);
1444  AppendBackslash(path); SAppend(szFile,path,_MAX_PATH);
1445  char path2[_MAX_FNAME+1]; SCopy(GetName(),path2,_MAX_PATH-1);
1446  AppendBackslash(path2); SAppend(szNewName,path2,_MAX_PATH);
1447  if (!RenameFile(path,path2)) return Error("Rename: Failure");
1448  // refresh file list
1449  ResetSearch(true);
1450  break;
1451  default: break; // InGrp & Deleted ignored
1452  }
1453 
1454  return true;
1455 }
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
char FileName[260]
Definition: C4Group.h:93
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:185
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
const char * GetName() const
Definition: C4Group.cpp:1845
#define _MAX_FNAME
C4GroupEntry * GetEntry(const char *szName)
Definition: C4Group.cpp:744
bool RenameFile(const char *szFileName, const char *szNewFileName)
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Group::ResetSearch ( bool  reload_contents = false)
inherited

Definition at line 1013 of file C4Group.cpp.

References C4Group::GetName(), C4Group::P::ST_Packed, and C4Group::P::ST_Unpacked.

Referenced by c4_mapgen_handle_new(), C4Group_ApplyUpdate(), C4Group::Delete(), C4Group::DeleteEntry(), C4UpdatePackage::DoGrpUpdate(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4UpdatePackage::DoUpdate(), C4ScenarioSection::EnsureTempStore(), C4Group::EntryCount(), C4Group::EntryCRC32(), C4Group::EntrySize(), C4UpdatePackage::Execute(), C4Group::Extract(), C4Group::FindEntry(), C4AchievementGraphics::Init(), C4Game::InitScriptEngine(), C4ObjectInfoList::Load(), C4DefList::Load(), C4DefGraphics::Load(), C4MaterialMap::Load(), C4Game::LoadAdditionalSystemGroup(), C4MusicSystem::LoadDir(), C4SoundSystem::LoadEffects(), C4Game::LoadScenarioComponents(), C4TextureMap::LoadTextures(), C4UpdatePackage::MkUp(), C4Group::OpenAsChild(), C4UpdatePackage::Optimize(), and C4Group::Rename().

1014 {
1015  switch (p->SourceType)
1016  {
1017  case P::ST_Unpacked:
1018  p->SearchPtr=nullptr;
1019  p->FolderSearch.Reset(GetName(), reload_contents);
1020  if (*p->FolderSearch)
1021  {
1022  p->FolderSearchEntry.Set(p->FolderSearch, GetName());
1023  p->SearchPtr=&p->FolderSearchEntry;
1024  }
1025  break;
1026  case P::ST_Packed:
1027  p->SearchPtr=p->FirstEntry;
1028  break;
1029  default: break; // InGrp & Deleted ignored
1030  }
1031 }
const char * GetName() const
Definition: C4Group.cpp:1845

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::Save ( bool  fReOpen)
inherited

Definition at line 797 of file C4Group.cpp.

References _MAX_FNAME, C4GroupEntry::C4GRES_Deleted, C4Group_TempPath, C4GroupSwapThreshold, C4Group::Clear(), CStdFile::Close(), CStdFile::Create(), C4GroupHeader::Entries, EraseFile(), C4GroupEntryCore::FileName, GetFilename(), C4Group::GetName(), C4Group::Head, MakeTempFilename(), MemScramble(), C4GroupEntry::Next, C4GroupEntryCore::Offset, RenameFile(), SAppend(), SCopy(), SEqual(), C4GroupEntryCore::Size, C4GroupEntry::Status, and CStdFile::Write().

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

798 {
799 
800  int cscore;
801  C4GroupEntryCore *save_core;
802  C4GroupEntry *centry;
803  char szTempFileName[_MAX_FNAME+1],szGrpFileName[_MAX_FNAME+1];
804 
805  // Create temporary core list with new actual offsets to be saved
806  int32_t iContentsSize = 0;
807  save_core = new C4GroupEntryCore [Head.Entries];
808  cscore=0;
809  for (centry=p->FirstEntry; centry; centry=centry->Next)
810  if (centry->Status != C4GroupEntry::C4GRES_Deleted)
811  {
812  save_core[cscore]=(C4GroupEntryCore)*centry;
813  // Make actual offset
814  save_core[cscore].Offset = iContentsSize;
815  iContentsSize += centry->Size;
816  cscore++;
817  }
818 
819  // Hold contents in memory?
820  bool fToMemory = !fReOpen && p->Mother && iContentsSize < C4GroupSwapThreshold;
821  if (!fToMemory)
822  {
823  // Create target temp file (in temp directory!)
824  SCopy(GetName(),szGrpFileName,_MAX_FNAME);
825  if (C4Group_TempPath[0]) { SCopy(C4Group_TempPath,szTempFileName,_MAX_FNAME); SAppend(GetFilename(GetName()),szTempFileName,_MAX_FNAME); }
826  else SCopy(GetName(),szTempFileName,_MAX_FNAME);
827  MakeTempFilename(szTempFileName);
828  // (Temp file must not have the same name as the group.)
829  if (SEqual(szTempFileName,szGrpFileName))
830  {
831  SAppend(".tmp",szTempFileName); // Add a second temp extension
832  MakeTempFilename(szTempFileName);
833  }
834  }
835 
836  // Create the new (temp) group file
837  CStdFile tfile;
838  if (!tfile.Create(szTempFileName,true,false,fToMemory))
839  { delete [] save_core; return Error("Close: ..."); }
840 
841  // Save header and core list
842  C4GroupHeader headbuf = Head;
843  MemScramble((BYTE*)&headbuf,sizeof(C4GroupHeader));
844  if (!tfile.Write((BYTE*)&headbuf,sizeof(C4GroupHeader))
845  || !tfile.Write((BYTE*)save_core,Head.Entries*sizeof(C4GroupEntryCore)))
846  { tfile.Close(); delete [] save_core; return Error("Close: ..."); }
847  delete [] save_core;
848 
849  // Save Entries to temp file
850  int iTotalSize=0,iSizeDone=0;
851  for (centry=p->FirstEntry; centry; centry=centry->Next) iTotalSize+=centry->Size;
852  for (centry=p->FirstEntry; centry; centry=centry->Next)
853  if (AppendEntry2StdFile(centry,tfile))
854  { iSizeDone+=centry->Size; if (iTotalSize && p->fnProcessCallback) p->fnProcessCallback(centry->FileName,100*iSizeDone/iTotalSize); }
855  else
856  {
857  tfile.Close(); return false;
858  }
859 
860  // Write
861  StdBuf *pBuf;
862  tfile.Close(fToMemory ? &pBuf : nullptr);
863 
864  // Child: move temp file to mother
865  if (p->Mother)
866  {
867  if (fToMemory)
868  {
869  if (!p->Mother->Add(GetFilename(GetName()), *pBuf, true, true))
870  { delete pBuf; CloseExclusiveMother(); Clear(); return Error("Close: Cannot move rewritten child data to mother"); }
871  delete pBuf;
872  }
873  else
874  {
875  if (!p->Mother->Move(szTempFileName,GetFilename(GetName())))
876  { CloseExclusiveMother(); Clear(); return Error("Close: Cannot move rewritten child temp file to mother"); }
877  }
878  Clear();
879  return true;
880  }
881 
882  // Clear (close file)
883  Clear();
884 
885  // Delete old group file, rename new file
886  if (!EraseFile(szGrpFileName))
887  return Error("Close: Cannot erase temp file");
888  if (!RenameFile(szTempFileName,szGrpFileName))
889  return Error("Close: Cannot rename group file");
890 
891  // Should reopen the file?
892  if (fReOpen)
893  OpenReal(szGrpFileName);
894 
895  return true;
896 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
Definition: StdBuf.h:29
Definition: C4Group.h:115
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 Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
char FileName[260]
Definition: C4Group.h:93
uint8_t BYTE
Definition: C4Group.h:91
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
C4GroupEntry * Next
Definition: C4Group.h:126
bool Write(const void *pBuffer, int iSize)
Definition: CStdFile.cpp:240
const char * GetName() const
Definition: C4Group.cpp:1845
int32_t Offset
Definition: C4Group.h:95
bool EraseFile(const char *szFileName)
#define _MAX_FNAME
int32_t Size
Definition: C4Group.h:95
C4GroupHeader Head
Definition: C4Group.h:143
bool RenameFile(const char *szFileName, const char *szNewFileName)
void MemScramble(BYTE *bypBuffer, int iSize)
Definition: C4Group.cpp:390
const int32_t C4GroupSwapThreshold
Definition: C4Group.h:59
EntryStatus Status
Definition: C4Group.h:120
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
void Clear()
Definition: C4Group.cpp:898
int Entries
Definition: C4Group.h:87
Definition: C4Group.h:105
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:

void C4GroupEx::SaveEntryCore ( C4Group rByGrp,
const char *  szEntry 
)
inline

Definition at line 202 of file C4Update.cpp.

References C4GroupEntryCore::Executable.

Referenced by C4UpdatePackage::DoUpdate(), C4UpdatePackage::MkUp(), and C4UpdatePackage::Optimize().

203  {
204  C4GroupEntryCore *pCore = ((C4GroupEx &)rByGrp).GetEntry(szEntry);
205  // copy core
207  }
char Executable
Definition: C4Group.h:99
Definition: C4Group.h:91
C4GroupEntryCore SavedCore
Definition: C4Update.cpp:201

Here is the caller graph for this function:

void C4GroupEx::SetHead ( C4Group rByGrp)
inline

Definition at line 172 of file C4Update.cpp.

References C4GroupHeader::Entries, and C4Group::Head.

Referenced by C4UpdatePackage::DoGrpUpdate(), C4UpdatePackage::MkUp(), and C4UpdatePackage::Optimize().

173  {
174  // Cheat away the protection
175  C4GroupHeader *pHdr = &static_cast<C4GroupEx&>(rByGrp).Head;
176  // save Entries
177  int Entries = Head.Entries;
178  // copy
179  memcpy(&Head, pHdr, sizeof(Head));
180  // restore
181  Head.Entries = Entries;
182  }
C4GroupHeader Head
Definition: C4Group.h:143
int Entries
Definition: C4Group.h:87

Here is the caller graph for this function:

void C4GroupEx::SetNoSort ( const char *  szEntry)
inline

Definition at line 215 of file C4Update.cpp.

References C4Group::GetEntry(), and C4GroupEntry::NoSort.

Referenced by C4UpdatePackage::DoUpdate().

216  {
217  C4GroupEntry *pEntry = GetEntry(szEntry);
218  if (pEntry) pEntry->NoSort = true;
219  }
C4GroupEntry * GetEntry(const char *szName)
Definition: C4Group.cpp:744
bool NoSort
Definition: C4Group.h:124
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::SetNoSort ( bool  fNoSort)
inherited

Definition at line 2013 of file C4Group.cpp.

Referenced by C4Group_CopyItem(), and C4Group_MoveItem().

2013 { p->NoSort = fNoSort; return true; }

Here is the caller graph for this function:

void C4GroupEx::SetSavedEntryCore ( const char *  szEntry)
inline

Definition at line 208 of file C4Update.cpp.

References C4GroupEntryCore::Executable, and C4Group::GetEntry().

Referenced by C4UpdatePackage::DoUpdate(), C4UpdatePackage::MkUp(), and C4UpdatePackage::Optimize().

209  {
210  C4GroupEntryCore *pCore = GetEntry(szEntry);
211  // copy core
213  }
char Executable
Definition: C4Group.h:99
Definition: C4Group.h:91
C4GroupEntry * GetEntry(const char *szName)
Definition: C4Group.cpp:744
C4GroupEntryCore SavedCore
Definition: C4Update.cpp:201

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Group::SetStdOutput ( bool  fStatus)
inherited

Definition at line 509 of file C4Group.cpp.

Referenced by C4Group::Delete(), C4Group::Open(), C4Group::OpenAsChild(), and ProcessGroup().

510 {
511  p->StdOutput=fStatus;
512 }

Here is the caller graph for this function:

bool C4Group::Sort ( const char *  szSortList)
inherited

Definition at line 1963 of file C4Group.cpp.

References C4GroupEntryCore::FileName, C4GroupEntry::Next, SortRank(), and stricmp().

Referenced by C4GameSave::Close(), C4UpdatePackage::DoGrpUpdate(), ProcessGroup(), C4Player::Save(), and C4Group::SortByList().

1964 {
1965  bool fBubble;
1966  C4GroupEntry *centry,*prev,*next,*nextnext;
1967 
1968  if (!szSortList || !szSortList[0]) return false;
1969 
1970  if (p->StdOutput) printf("Sorting...\n");
1971 
1972  do
1973  {
1974  fBubble=false;
1975 
1976  for (prev=nullptr,centry=p->FirstEntry; centry; prev=centry,centry=next)
1977  if ((next=centry->Next))
1978  {
1979  // primary sort by file list
1980  int iS1 = SortRank(centry->FileName,szSortList);
1981  int iS2 = SortRank(next->FileName,szSortList);
1982  if (iS1 > iS2) continue;
1983  // secondary sort by filename
1984  if (iS1 == iS2)
1985  if (stricmp(centry->FileName, next->FileName) <= 0) continue;
1986  // wrong order: Swap!
1987  nextnext=next->Next;
1988  if (prev) prev->Next=next;
1989  else p->FirstEntry=next;
1990  next->Next=centry;
1991  centry->Next=nextnext;
1992  next=nextnext;
1993 
1994  fBubble=true;
1995  p->Modified=true;
1996  }
1997 
1998  }
1999  while (fBubble);
2000 
2001  return true;
2002 }
int stricmp(const char *s1, const char *s2)
char FileName[260]
Definition: C4Group.h:93
C4GroupEntry * Next
Definition: C4Group.h:126
int SortRank(const char *szElement, const char *szSortList)
Definition: C4Group.cpp:1951
Definition: C4Group.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Group::SortByList ( const char **  ppSortList,
const char *  szFilename = nullptr 
)
inherited

Definition at line 2027 of file C4Group.cpp.

References GetFilename(), C4Group::GetName(), C4Group::Sort(), and WildcardMatch().

Referenced by C4Group_PackDirectoryTo(), C4Group::Close(), and C4UpdatePackage::MkUp().

2028 {
2029  // No sort list specified
2030  if (!ppSortList) return false;
2031  // No group name specified, use own
2032  if (!szFilename) szFilename = GetName();
2033  szFilename = GetFilename(szFilename);
2034  // Find matching filename entry in sort list
2035  const char **ppListEntry;
2036  for (ppListEntry = ppSortList; *ppListEntry; ppListEntry+=2)
2037  if (WildcardMatch( *ppListEntry, szFilename ))
2038  break;
2039  // Sort by sort list entry
2040  if (*ppListEntry && *(ppListEntry+1))
2041  Sort(*(ppListEntry+1));
2042  // Success
2043  return true;
2044 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * GetName() const
Definition: C4Group.cpp:1845
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374
bool Sort(const char *szSortList)
Definition: C4Group.cpp:1963

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4GroupHeader C4Group::Head
protectedinherited
C4GroupEntryCore C4GroupEx::SavedCore

Definition at line 201 of file C4Update.cpp.


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