2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2013 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// a set of group files
// manages system file overwriting by scearios or folders
# ifndef INC_C4GroupSet
# define INC_C4GroupSet
// group set priorities
2010-03-28 17:58:21 +00:00
# define C4GSPrio_Base 0 // lowest priority for global system files
# define C4GSPrio_Pack 1 // overloads by object packs
2011-03-13 15:16:45 +00:00
# define C4GSPrio_ExtraRoot 2 // overloads by Extra.ocg root folder
# define C4GSPrio_Extra 3 // overloads by Extra.ocg
2009-05-08 13:28:41 +00:00
# define C4GSPrio_Definition 4 // overloads by definition file - latter defined definition files have higher priority
# define C4GSPrio_Definition2 99 // highest priority a given definition may have
2010-03-28 17:58:21 +00:00
# define C4GSPrio_Folder 100 // overloads by local scenario folder - each child folder has higher priority
# define C4GSPrio_Folder2 199 // highest priority a folder may have
# define C4GSPrio_Scenario 200 // overloads by scenario: highest priority
2009-05-08 13:28:41 +00:00
// group node contents
2011-03-13 15:16:45 +00:00
# define C4GSCnt_Graphics 1 // contains Graphics.ocg
2010-03-28 17:58:21 +00:00
# define C4GSCnt_Loaders 2 // contains loader files
2011-03-13 15:16:45 +00:00
# define C4GSCnt_Material 4 // contains Material.ocg
2010-03-28 17:58:21 +00:00
# define C4GSCnt_Music 8 // contains music
# define C4GSCnt_Definitions 16 // contains definition files
2009-05-08 13:28:41 +00:00
# define C4GSCnt_FontDefs 32 // contains font definitions
# define C4GSCnt_Language 64 // contains language files
# define C4GSCnt_Component 128 // other components
2010-03-28 17:58:21 +00:00
# define C4GSCnt_Folder (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
# define C4GSCnt_OriginFolder (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
2009-05-08 13:28:41 +00:00
# define C4GSCnt_Directory (C4GSCnt_Loaders | C4GSCnt_Music)
2010-03-28 17:58:21 +00:00
# define C4GSCnt_Scenario C4GSCnt_Folder
# define C4GSCnt_Root (C4GSCnt_Graphics | C4GSCnt_Material)
# define C4GSCnt_Extra (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
# define C4GSCnt_ExtraRoot (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
# define C4GSCnt_All ~0
2009-05-08 13:28:41 +00:00
// one node in the group set holds one group
class C4GroupSetNode
2010-03-28 17:58:21 +00:00
{
protected :
2012-03-13 16:06:49 +00:00
class C4GroupSet * pParent ; // owning set
2010-03-28 17:58:21 +00:00
C4GroupSetNode * pPrev , * pNext ; // linked list - always valid
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4Group * pGroup ; // ptr to group owned by this node
bool fGrpOwned ; // flag if group ptr is owned
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
int32_t id ; // group node ID
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
2012-03-13 16:06:49 +00:00
C4GroupSetNode ( class C4GroupSet & rParent , C4GroupSetNode * pPrev , C4Group & rGroup , bool fGrpOwned , int32_t id ) ; // ctor
2010-03-28 17:58:21 +00:00
~ C4GroupSetNode ( ) ; // dtor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
int32_t Priority ; // group priority
int32_t Contents ; // content held by this group
2009-05-08 13:28:41 +00:00
friend class C4GroupSet ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
// a group set manages file overloading within several groups
class C4GroupSet
2010-03-28 17:58:21 +00:00
{
protected :
C4GroupSetNode * pFirst , * pLast ; // linked list
int32_t iIndex ; // index to keep track of group node IDs
public :
bool UnregisterGroup ( int32_t iIndex ) ;
void Clear ( ) ;
void Default ( ) ;
C4GroupSet ( ) ; // ctor
2011-02-07 02:37:35 +00:00
C4GroupSet ( const C4GroupSet & rCopy ) ; // copy-constructor that registers all groups with all contents
2010-03-28 17:58:21 +00:00
~ C4GroupSet ( ) ; // dtor
bool RegisterGroup ( C4Group & rGroup , bool fOwnGrp , int32_t Priority , int32_t Contents , bool fCheckContent = true ) ; // add group to list
2011-02-07 02:37:35 +00:00
bool RegisterGroups ( const C4GroupSet & rCopy , int32_t Contents , const char * szFilename = NULL , int32_t iMaxSkipID = 0 ) ; // add all matching (child-)groups of the set
2010-03-28 17:58:21 +00:00
C4Group * FindGroup ( int32_t Contents , C4Group * pAfter = NULL , bool fSamePrio = false ) ; // search for suitable group in list
C4Group * FindEntry ( const char * szWildcard , int32_t * pPriority = NULL , int32_t * pID = NULL ) ; // find entry in groups; store priority of group if ptr is given
2010-06-27 00:30:47 +00:00
C4Group * FindSuitableFile ( const char * szName , const char * const extensions [ ] , char * szFileName , int32_t * pID = NULL ) ;
2010-03-28 17:58:21 +00:00
int32_t GetGroupCount ( ) ;
C4Group * GetGroup ( int32_t iIndex ) ;
bool LoadEntry ( const char * szEntryName , char * * lpbpBuf , size_t * ipSize = NULL , int32_t iAppendZeros = 0 ) ;
2011-03-05 01:44:26 +00:00
bool LoadEntryString ( const char * szEntryName , StdStrBuf * rBuf ) ;
bool LoadEntryString ( const StdStrBuf & name , StdStrBuf * Buf ) { return LoadEntryString ( name . getData ( ) , Buf ) ; }
2011-03-13 15:38:33 +00:00
C4Group * RegisterParentFolders ( const char * szScenFilename ) ; // register all parent .ocf groups to the given scenario filename and return an open group file of the innermost parent ocf
2015-02-07 12:59:45 +00:00
int32_t PreCacheEntries ( const char * szEntryMask ) ; // pre-cache all entries matching mask for packed files in all groups.
2010-03-28 17:58:21 +00:00
static int32_t CheckGroupContents ( C4Group & rGroup , int32_t Contents ) ;
int32_t GetLastID ( ) { return iIndex ; } // return ID assigned to the last added group
bool CloseFolders ( ) ; // remove all groups associated with scenario folders
2009-05-08 13:28:41 +00:00
friend class C4GroupSetNode ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
# endif