OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScenarioListLoader::Folder Class Referenceabstract

#include <C4StartupScenSelDlg.h>

Inheritance diagram for C4ScenarioListLoader::Folder:
[legend]
Collaboration diagram for C4ScenarioListLoader::Folder:
[legend]

Public Member Functions

 Folder (class C4ScenarioListLoader *pLoader, Folder *pParent)
 
virtual ~Folder ()
 
virtual bool LoadCustomPre (C4Group &rGrp)
 
bool LoadContents (C4ScenarioListLoader *pLoader, C4Group *pFromGrp, const StdStrBuf *psFilename, bool fLoadEx, bool fReload)
 
uint32_t GetEntryCount () const
 
virtual bool Start ()
 
virtual FolderGetIsFolder ()
 
EntryGetFirstEntry () const
 
void Resort ()
 
EntryFindEntryByName (const char *szFilename) const
 
virtual bool CanOpen (StdStrBuf &sError)
 
virtual bool IsGrayed ()
 
virtual StdStrBuf GetOpenText ()
 
virtual StdStrBuf GetOpenTooltip ()
 
C4MapFolderDataGetMapData () const
 
virtual const
C4ScenarioParameterDefs
GetAchievementDefs () const
 
virtual const
C4AchievementGraphics
GetAchievementGfx () const
 
bool Load (C4Group *pFromGrp, const StdStrBuf *psFilename, bool fLoadEx)
 
virtual bool LoadCustom (C4Group &rGrp, bool fNameLoaded, bool fIconLoaded)
 
const StdStrBufGetName () const
 
const StdStrBufGetEntryFilename () const
 
const StdStrBufGetVersion () const
 
const StdStrBufGetAuthor () const
 
const C4FacetGetIconFacet () const
 
const C4FacetGetTitlePicture () const
 
const StdStrBufGetDesc () const
 
int GetIconIndex ()
 
int GetDifficulty ()
 
int GetFolderIndex ()
 
EntryGetNext () const
 
class FolderGetParent () const
 
virtual StdStrBuf GetTypeName ()=0
 
virtual bool GetAchievement (int32_t idx, C4Facet *out_facet, const char **out_description)
 
virtual bool IsHidden ()
 
virtual bool HasMissionAccess () const
 
virtual bool HasUnregisteredAccess () const
 
virtual const char * GetDefaultExtension ()
 
virtual bool SetTitleInGroup (C4Group &rGrp, const char *szNewTitle)
 
bool RenameTo (const char *szNewName)
 
virtual bool IsScenario ()
 
virtual C4ScenarioParameterDefsGetParameterDefs ()
 
virtual C4ScenarioParametersGetParameters ()
 

Static Public Member Functions

static EntryCreateEntryForFile (const StdStrBuf &sFilename, C4ScenarioListLoader *pLoader, Folder *pParent)
 

Protected Member Functions

void ClearChildren ()
 
void Sort ()
 
virtual bool DoLoadContents (C4ScenarioListLoader *pLoader, C4Group *pFromGrp, const StdStrBuf &sFilename, bool fLoadEx)=0
 

Protected Attributes

C4Folder C4F
 
bool fContentsLoaded
 
EntrypFirst
 
class C4MapFolderDatapMapData
 
class C4ScenarioListLoaderpLoader
 
EntrypNext
 
class FolderpParent
 
StdCopyStrBuf sName
 
StdCopyStrBuf sFilename
 
StdCopyStrBuf sDesc
 
StdCopyStrBuf sVersion
 
StdCopyStrBuf sAuthor
 
C4FacetSurface fctIcon
 
C4FacetSurface fctTitle
 
bool fBaseLoaded
 
bool fExLoaded
 
int iIconIndex
 
int iDifficulty
 
int iFolderIndex
 

Friends

class Entry
 

Detailed Description

Definition at line 152 of file C4StartupScenSelDlg.h.

Constructor & Destructor Documentation

C4ScenarioListLoader::Folder::Folder ( class C4ScenarioListLoader pLoader,
Folder pParent 
)
inline
C4ScenarioListLoader::Folder::~Folder ( )
virtual

Definition at line 839 of file C4StartupScenSelDlg.cpp.

840 {
841  if (pMapData) delete pMapData;
842  ClearChildren();
843 }
class C4MapFolderData * pMapData

Member Function Documentation

virtual bool C4ScenarioListLoader::Folder::CanOpen ( StdStrBuf sError)
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 182 of file C4StartupScenSelDlg.h.

182 { return true; } // can always open folders
void C4ScenarioListLoader::Folder::ClearChildren ( )
protected

Definition at line 908 of file C4StartupScenSelDlg.cpp.

References C4ScenarioListLoader::Entry::GetIsFolder(), and pFirst.

909 {
910  // folder deletion: del all the tree non-recursively
911  Folder *pDelFolder = this, *pCheckFolder;
912  for (;;)
913  {
914  // delete all children as long as they are not folders
915  Entry *pChild;
916  while ((pChild = pDelFolder->pFirst))
917  if ((pCheckFolder = pChild->GetIsFolder()))
918  // child entry if folder: Continue delete in there
919  pDelFolder = pCheckFolder;
920  else
921  // regular child entry: del it
922  // destructor of child will remove it from list
923  delete pChild;
924  // this emptied: Done!
925  if (pDelFolder == this) break;
926  // deepest child recursion reached: Travel up folders
927  pDelFolder = (pCheckFolder = pDelFolder)->pParent;
928  assert(pDelFolder);
929  delete pCheckFolder;
930  }
931 }
Folder(class C4ScenarioListLoader *pLoader, Folder *pParent)
class Folder * pParent

Here is the call graph for this function:

C4ScenarioListLoader::Entry * C4ScenarioListLoader::Entry::CreateEntryForFile ( const StdStrBuf sFilename,
C4ScenarioListLoader pLoader,
Folder pParent 
)
staticinherited

Definition at line 548 of file C4StartupScenSelDlg.cpp.

References C4CFN_FolderFiles, C4CFN_ScenarioFiles, DirContainsScenarios(), DirectoryExists(), StdStrBuf::getData(), GetExtension(), and WildcardMatch().

Referenced by C4ScenarioListLoader::SubFolder::DoLoadContents(), and C4ScenarioListLoader::RegularFolder::DoLoadContents().

549 {
550  // determine entry type by file type
551  const char *szFilename = sFilename.getData();
552  if (!szFilename || !*szFilename) return nullptr;
553  if (WildcardMatch(C4CFN_ScenarioFiles, sFilename.getData())) return new Scenario(pLoader, pParent);
554  if (WildcardMatch(C4CFN_FolderFiles, sFilename.getData())) return new SubFolder(pLoader, pParent);
555  // regular, open folder (C4Group-packed folders without extensions are not regarded, because they could contain anything!)
556  const char *szExt = GetExtension(szFilename);
557  if ((!szExt || !*szExt) && DirectoryExists(sFilename.getData()))
558  {
559  // open folders only if they contain a scenario or folder
560  if (DirContainsScenarios(szFilename))
561  return new RegularFolder(pLoader, pParent);
562  }
563  // type not recognized
564  return nullptr;
565 }
const char * getData() const
Definition: StdBuf.h:450
#define C4CFN_FolderFiles
Definition: C4Components.h:175
bool DirContainsScenarios(const char *szDir)
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384
#define C4CFN_ScenarioFiles
Definition: C4Components.h:174
class Folder * pParent

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4ScenarioListLoader::Folder::DoLoadContents ( C4ScenarioListLoader pLoader,
C4Group pFromGrp,
const StdStrBuf sFilename,
bool  fLoadEx 
)
protectedpure virtual
C4ScenarioListLoader::Entry * C4ScenarioListLoader::Folder::FindEntryByName ( const char *  szFilename) const

Definition at line 948 of file C4StartupScenSelDlg.cpp.

References GetFilename(), C4ScenarioListLoader::Entry::GetNext(), and SEqualNoCase().

Referenced by C4MapFolderData::Load().

949 {
950  // do a case-insensitive filename comparison
951  for (Entry *pEntry = pFirst; pEntry; pEntry = pEntry->GetNext())
952  if (SEqualNoCase(szFilename, GetFilename(pEntry->GetEntryFilename().getData())))
953  return pEntry;
954  // nothing found
955  return nullptr;
956 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
Entry * GetNext() const

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4ScenarioListLoader::Entry::GetAchievement ( int32_t  idx,
C4Facet out_facet,
const char **  out_description 
)
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 90 of file C4StartupScenSelDlg.h.

Referenced by C4StartupScenSelDlg::ScenListItem::ScenListItem().

90 { return false; } // return true and fill output parameters if player got the indexed achievement

Here is the caller graph for this function:

virtual const C4ScenarioParameterDefs* C4ScenarioListLoader::Folder::GetAchievementDefs ( ) const
inlinevirtual

Reimplemented in C4ScenarioListLoader::SubFolder.

Definition at line 188 of file C4StartupScenSelDlg.h.

188 { return nullptr; }
virtual const C4AchievementGraphics* C4ScenarioListLoader::Folder::GetAchievementGfx ( ) const
inlinevirtual

Reimplemented in C4ScenarioListLoader::SubFolder.

Definition at line 189 of file C4StartupScenSelDlg.h.

189 { return nullptr; }
const StdStrBuf& C4ScenarioListLoader::Entry::GetAuthor ( ) const
inlineinherited

Definition at line 80 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sAuthor.

80 { return sAuthor; }
StdCopyStrBuf sAuthor
virtual const char* C4ScenarioListLoader::Entry::GetDefaultExtension ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::SubFolder, and C4ScenarioListLoader::Scenario.

Definition at line 102 of file C4StartupScenSelDlg.h.

102 { return nullptr; } // extension to be added when item is renamed
const StdStrBuf& C4ScenarioListLoader::Entry::GetDesc ( ) const
inlineinherited

Definition at line 83 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sDesc.

83 { return sDesc; }
StdCopyStrBuf sDesc
int C4ScenarioListLoader::Entry::GetDifficulty ( )
inlineinherited

Definition at line 85 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iDifficulty.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

uint32_t C4ScenarioListLoader::Folder::GetEntryCount ( ) const

Definition at line 887 of file C4StartupScenSelDlg.cpp.

References C4ScenarioListLoader::Entry::pNext.

888 {
889  uint32_t iCount = 0;
890  for (Entry *i = pFirst; i; i = i->pNext) ++iCount;
891  return iCount;
892 }
Entry * pNext
const StdStrBuf& C4ScenarioListLoader::Entry::GetEntryFilename ( ) const
inlineinherited

Definition at line 78 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sFilename.

Referenced by C4StartupScenSelDlg::DeleteConfirm(), C4StartupScenSelDlg::KeyDelete(), and C4StartupScenSelDlg::StartScenario().

78 { return sFilename; }
StdCopyStrBuf sFilename

Here is the caller graph for this function:

Entry* C4ScenarioListLoader::Folder::GetFirstEntry ( ) const
inline

Definition at line 178 of file C4StartupScenSelDlg.h.

References pFirst.

Referenced by C4ScenarioListLoader::GetFirstEntry().

178 { return pFirst; }

Here is the caller graph for this function:

int C4ScenarioListLoader::Entry::GetFolderIndex ( )
inlineinherited

Definition at line 86 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iFolderIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

const C4Facet& C4ScenarioListLoader::Entry::GetIconFacet ( ) const
inlineinherited

Definition at line 81 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::fctIcon.

Referenced by C4StartupScenSelDlg::ScenListItem::ScenListItem().

81 { return fctIcon; }
C4FacetSurface fctIcon

Here is the caller graph for this function:

int C4ScenarioListLoader::Entry::GetIconIndex ( )
inlineinherited

Definition at line 84 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iIconIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

virtual Folder* C4ScenarioListLoader::Folder::GetIsFolder ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 177 of file C4StartupScenSelDlg.h.

Referenced by EntrySortFunc().

177 { return this; } // this is a folder

Here is the caller graph for this function:

C4MapFolderData* C4ScenarioListLoader::Folder::GetMapData ( ) const
inline

Definition at line 186 of file C4StartupScenSelDlg.h.

References pMapData.

186 { return pMapData; }
class C4MapFolderData * pMapData
const StdStrBuf& C4ScenarioListLoader::Entry::GetName ( ) const
inlineinherited

Definition at line 77 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sName.

Referenced by EntrySortFunc(), C4StartupScenSelDlg::KeyDelete(), and C4StartupScenSelDlg::ScenListItem::ScenListItem().

77 { return sName; }
StdCopyStrBuf sName

Here is the caller graph for this function:

Entry* C4ScenarioListLoader::Entry::GetNext ( ) const
inlineinherited

Definition at line 87 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::pNext.

Referenced by FindEntryByName().

87 { return pNext; }
Entry * pNext

Here is the caller graph for this function:

StdStrBuf C4ScenarioListLoader::Folder::GetOpenText ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 958 of file C4StartupScenSelDlg.cpp.

References LoadResStr().

959 {
960  return StdCopyStrBuf(LoadResStr("IDS_BTN_OPEN"));
961 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

Here is the call graph for this function:

StdStrBuf C4ScenarioListLoader::Folder::GetOpenTooltip ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 963 of file C4StartupScenSelDlg.cpp.

References LoadResStr().

964 {
965  return StdCopyStrBuf(LoadResStr("IDS_DLGTIP_SCENSELNEXT"));
966 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

Here is the call graph for this function:

virtual C4ScenarioParameterDefs* C4ScenarioListLoader::Entry::GetParameterDefs ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 107 of file C4StartupScenSelDlg.h.

107 { return nullptr; }
virtual C4ScenarioParameters* C4ScenarioListLoader::Entry::GetParameters ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 108 of file C4StartupScenSelDlg.h.

108 { return nullptr; }
class Folder* C4ScenarioListLoader::Entry::GetParent ( ) const
inlineinherited

Definition at line 88 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::pParent.

Referenced by C4ScenarioListLoader::FolderBack().

88 { return pParent; }
class Folder * pParent

Here is the caller graph for this function:

const C4Facet& C4ScenarioListLoader::Entry::GetTitlePicture ( ) const
inlineinherited

Definition at line 82 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::fctTitle.

82 { return fctTitle; }
C4FacetSurface fctTitle
virtual StdStrBuf C4ScenarioListLoader::Entry::GetTypeName ( )
pure virtualinherited

Implemented in C4ScenarioListLoader::RegularFolder, C4ScenarioListLoader::SubFolder, and C4ScenarioListLoader::Scenario.

Referenced by C4StartupScenSelDlg::KeyDelete().

Here is the caller graph for this function:

const StdStrBuf& C4ScenarioListLoader::Entry::GetVersion ( ) const
inlineinherited

Definition at line 79 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sVersion.

79 { return sVersion; }
StdCopyStrBuf sVersion
virtual bool C4ScenarioListLoader::Entry::HasMissionAccess ( ) const
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 97 of file C4StartupScenSelDlg.h.

97 { return true; }
virtual bool C4ScenarioListLoader::Entry::HasUnregisteredAccess ( ) const
inlinevirtualinherited

Definition at line 98 of file C4StartupScenSelDlg.h.

98 { return false; }
bool C4ScenarioListLoader::Folder::IsGrayed ( )
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 968 of file C4StartupScenSelDlg.cpp.

969 {
970  return false;
971 }
virtual bool C4ScenarioListLoader::Entry::IsHidden ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 96 of file C4StartupScenSelDlg.h.

96 { return false; } // condition for hiding element completely
virtual bool C4ScenarioListLoader::Entry::IsScenario ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 105 of file C4StartupScenSelDlg.h.

105 { return false; }
bool C4ScenarioListLoader::Entry::Load ( C4Group pFromGrp,
const StdStrBuf psFilename,
bool  fLoadEx 
)
inherited

Definition at line 435 of file C4StartupScenSelDlg.cpp.

References C4CFN_IconPNG, C4CFN_ScenarioDesc, C4CFN_ScenarioIcon, C4CFN_ScenarioTitle, C4CFN_Title, C4CFN_Version, C4FCT_Full, C4StartupScenSel_DefaultIcon_OldIconBG, C4FacetSurface::Clear(), Config, C4Facet::Draw(), C4StartupGraphics::fctScenSelIcons, C4Group::FindEntry(), C4Config::General, C4Startup::Get(), C4ComponentHost::GetData(), StdStrBuf::getData(), GetFilename(), C4Group::GetFullName(), C4ComponentHost::GetLanguageString(), C4Facet::GetPhase(), C4Surface::GetPixDw(), C4Startup::Graphics, C4Facet::Hgt, C4ConfigGeneral::LanguageEx, C4ComponentHost::Load(), C4FacetSurface::Load(), C4Language::LoadComponentHost(), C4Group::LoadEntryString(), C4Surface::Lock(), C4Group::Open(), C4Group::OpenAsChild(), RemoveExtension(), C4Surface::SetPixDw(), C4Facet::Surface, C4Surface::Unlock(), and C4Facet::Wdt.

Referenced by C4ScenarioListLoader::SubFolder::DoLoadContents(), C4ScenarioListLoader::RegularFolder::DoLoadContents(), and C4ScenarioListLoader::LoadExtended().

436 {
437  // nothing to do if already loaded
438  if (fBaseLoaded && (fExLoaded || !fLoadEx)) return true;
439  C4Group Group;
440  // group specified: Load as child
441  if (pFromGrp)
442  {
443  assert(psFilename);
444  if (!Group.OpenAsChild(pFromGrp, psFilename->getData())) return false;
445  // set FN by complete entry name
446  this->sFilename.Take(Group.GetFullName());
447  }
448  else
449  {
450  // set FN by complete entry name
451  if (psFilename) this->sFilename.Copy(*psFilename);
452  // no parent group: Direct load from filename
453  if (!Group.Open(sFilename.getData())) return false;
454  }
455  // okay; load standard stuff from group
456  bool fNameLoaded=false, fIconLoaded=false;
457  if (fBaseLoaded)
458  {
459  fNameLoaded = fIconLoaded = true;
460  }
461  else
462  {
463  // Set default name as filename without extension
465  char *szBuf = sName.GrabPointer();
466  RemoveExtension(szBuf);
467  sName.Take(szBuf);
468  // load entry specific stuff that's in the front of the group
469  if (!LoadCustomPre(Group))
470  return false;
471  // Load entry name
472  C4ComponentHost DefNames;
475  fNameLoaded = true;
476  // load entry icon
477  if (Group.FindEntry(C4CFN_IconPNG) && fctIcon.Load(Group, C4CFN_IconPNG, C4FCT_Full, C4FCT_Full, false, 0))
478  fIconLoaded = true;
479  else
480  {
481  C4FacetSurface fctTemp;
482  if (Group.FindEntry(C4CFN_ScenarioIcon) && fctTemp.Load(Group, C4CFN_ScenarioIcon, C4FCT_Full, C4FCT_Full, true, 0))
483  {
484  // old style icon: Blit it on a pieace of paper
485  fctTemp.Surface->Lock();
486  for (int y=0; y<fctTemp.Hgt; ++y)
487  for (int x=0; x<fctTemp.Wdt; ++x)
488  {
489  uint32_t dwPix = fctTemp.Surface->GetPixDw(x,y, false);
490  // transparency has some tolerance...
491  if (Inside<uint8_t>(dwPix & 0xff, 0xb8, 0xff))
492  if (Inside<uint8_t>((dwPix>>0x08) & 0xff, 0x00, 0x0f))
493  if (Inside<uint8_t>((dwPix>>0x10) & 0xff, 0xb8, 0xff))
494  fctTemp.Surface->SetPixDw(x,y,0x00ffffff);
495  }
496  fctTemp.Surface->Unlock();
497  int iIconSize = C4Startup::Get()->Graphics.fctScenSelIcons.Hgt;
498  fctIcon.Create(iIconSize, iIconSize, C4FCT_Full, C4FCT_Full);
500  fctTemp.Draw(fctIcon.Surface, (fctIcon.Wdt-fctTemp.Wdt)/2, (fctIcon.Hgt-fctTemp.Hgt)/2);
501  fctTemp.Clear();
502  fIconLoaded = true;
503  }
504  }
505  // load any entryx-type-specific custom data (e.g. fallbacks for scenario title, and icon)
506  if (!LoadCustom(Group, fNameLoaded, fIconLoaded)) return false;
507  fBaseLoaded = true;
508  }
509  // load extended stuff: title picture
510  if (fLoadEx && !fExLoaded)
511  {
512  // load desc
513  C4ComponentHost DefDesc;
515  {
516  sDesc.Copy(DefDesc.GetData());
517  }
518  // load title
520  fExLoaded = true;
521  // load version
523  }
524  // done, success
525  return true;
526 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
const int32_t C4StartupScenSel_DefaultIcon_OldIconBG
C4ConfigGeneral General
Definition: C4Config.h:252
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
Definition: C4FacetEx.cpp:78
const char * GetData() const
bool Lock()
Definition: C4Surface.cpp:463
bool Unlock()
Definition: C4Surface.cpp:474
#define C4CFN_Version
Definition: C4Components.h:72
StdCopyStrBuf sDesc
C4FacetID fctScenSelIcons
Definition: C4Startup.h:61
StdCopyStrBuf sName
StdCopyStrBuf sFilename
bool GetLanguageString(const char *szLanguage, StdStrBuf &rTarget)
static bool LoadComponentHost(C4ComponentHost *host, C4Group &hGroup, const char *szFilename, const char *szLanguage)
Definition: C4Language.cpp:235
#define C4CFN_Title
Definition: C4Components.h:82
StdCopyStrBuf sVersion
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
virtual bool LoadCustom(C4Group &rGrp, bool fNameLoaded, bool fIconLoaded)
void Take(char *pnData)
Definition: StdBuf.h:465
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:501
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
C4FacetSurface fctIcon
bool fBaseLoaded
bool fExLoaded
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
#define C4CFN_IconPNG
Definition: C4Components.h:86
float Hgt
Definition: C4Facet.h:120
#define C4CFN_ScenarioDesc
Definition: C4Components.h:88
bool Create(int iWdt, int iHgt, int iWdt2=C4FCT_Full, int iHgt2=C4FCT_Full)
Definition: C4FacetEx.cpp:54
static C4Startup * Get()
Definition: C4Startup.h:133
C4Surface * Surface
Definition: C4Facet.h:119
const int C4FCT_Full
Definition: C4FacetEx.h:26
#define C4CFN_ScenarioIcon
Definition: C4Components.h:85
void Copy()
Definition: StdBuf.h:475
float Wdt
Definition: C4Facet.h:120
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
C4StartupGraphics Graphics
Definition: C4Startup.h:100
void Clear()
Definition: C4FacetEx.h:44
#define C4CFN_ScenarioTitle
Definition: C4Components.h:84
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
virtual bool LoadCustomPre(C4Group &rGrp)
C4FacetSurface fctTitle

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScenarioListLoader::Folder::LoadContents ( C4ScenarioListLoader pLoader,
C4Group pFromGrp,
const StdStrBuf psFilename,
bool  fLoadEx,
bool  fReload 
)

Definition at line 933 of file C4StartupScenSelDlg.cpp.

Referenced by C4ScenarioListLoader::Load().

934 {
935  // contents already loaded?
936  if (fContentsLoaded && !fReload) return true;
937  // clear previous
938  if (pMapData) { delete pMapData; pMapData = nullptr; }
939  // if filename is not given, assume it's been loaded in this entry
940  if (!psFilename) psFilename = &this->sFilename; else this->sFilename = *psFilename;
941  // nothing loaded: Load now
942  if (!DoLoadContents(pLoader, pFromGrp, *psFilename, fLoadEx)) return false;
943  // sort loaded stuff by name
944  Sort();
945  return true;
946 }
virtual bool DoLoadContents(C4ScenarioListLoader *pLoader, C4Group *pFromGrp, const StdStrBuf &sFilename, bool fLoadEx)=0
StdCopyStrBuf sFilename
class C4MapFolderData * pMapData

Here is the caller graph for this function:

virtual bool C4ScenarioListLoader::Entry::LoadCustom ( C4Group rGrp,
bool  fNameLoaded,
bool  fIconLoaded 
)
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::RegularFolder, C4ScenarioListLoader::SubFolder, and C4ScenarioListLoader::Scenario.

Definition at line 72 of file C4StartupScenSelDlg.h.

72 { return true; } // load custom data for entry type (e.g. scenario title fallback in Scenario.txt)
bool C4ScenarioListLoader::Folder::LoadCustomPre ( C4Group rGrp)
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 973 of file C4StartupScenSelDlg.cpp.

References C4CFN_FolderCore, DirSep, C4Group::GetFullName(), and C4Group::LoadEntryString().

974 {
975  // load folder core if available
976  StdStrBuf sFileContents;
977  if (rGrp.LoadEntryString(C4CFN_FolderCore, &sFileContents))
978  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(C4F, sFileContents, (rGrp.GetFullName() + DirSep C4CFN_FolderCore).getData()))
979  return false;
980  return true;
981 }
#define C4CFN_FolderCore
Definition: C4Components.h:44
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
#define DirSep

Here is the call graph for this function:

bool C4ScenarioListLoader::Entry::RenameTo ( const char *  szNewName)
inherited

Definition at line 567 of file C4StartupScenSelDlg.cpp.

References _MAX_PATH, C4GUI::MessageDialog::btnOK, C4CFN_Title, C4Group_IsGroup(), C4Group_MoveItem(), C4Group::Close(), C4Group::Delete(), StdStrBuf::Format(), StdStrBuf::getData(), C4Group::GetError(), GetFilename(), C4GUI::Ico_Error, ItemExists(), ItemIdentical(), LoadResStr(), MakeFilenameFromTitle(), C4Group::Open(), pGUI, SAppend(), SCopy(), SEqual(), and C4GUI::Screen::ShowMessageModal().

568 {
569  // change name+filename
570  // some name sanity validation
571  if (!szNewName || !*szNewName) return false;
572  if (SEqual(szNewName, sName.getData())) return true;
573  char fn[_MAX_PATH+1];
574  SCopy(szNewName, fn, _MAX_PATH);
575  // generate new file name
577  if (!*fn) return false;
578  const char *szExt = GetDefaultExtension();
579  if (szExt) { SAppend(".", fn, _MAX_PATH); SAppend(szExt, fn, _MAX_PATH); }
580  char fullfn[_MAX_PATH+1];
581  SCopy(sFilename.getData(), fullfn, _MAX_PATH);
582  char *fullfn_fn = GetFilename(fullfn);
583  SCopy(fn, fullfn_fn, _MAX_PATH - (fullfn_fn - fullfn));
584  StdCopyStrBuf strErr(LoadResStr("IDS_FAIL_RENAME"));
585  // check if a rename is due
586  if (!ItemIdentical(sFilename.getData(), fullfn))
587  {
588  // check for duplicate filename
589  if (ItemExists(fullfn))
590  {
591  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_FILEEXISTS"), fullfn);
593  return false;
594  }
595  // OK; then rename
596  if (!C4Group_MoveItem(sFilename.getData(), fullfn, true))
597  {
598  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_RENAMEFILE"), sFilename.getData(), fullfn);
600  return false;
601  }
602  sFilename.Copy(fullfn);
603  }
604  // update real name in group, if this is a group
605  if (C4Group_IsGroup(fullfn))
606  {
607  C4Group Grp;
608  if (!Grp.Open(fullfn))
609  {
610  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_OPENFILE"), sFilename.getData(), Grp.GetError());
612  return false;
613  }
614  if (!Grp.Delete(C4CFN_Title))
615  {
616  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_DELOLDTITLE"), sFilename.getData(), Grp.GetError());
618  return false;
619  }
620  if (!SetTitleInGroup(Grp, szNewName)) return false;
621  if (!Grp.Close())
622  {
623  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_WRITENEWTITLE"), sFilename.getData(), Grp.GetError());
625  return false;
626  }
627  }
628  // update title
629  sName.Copy(szNewName);
630  // done
631  return true;
632 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:234
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
virtual const char * GetDefaultExtension()
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
#define _MAX_PATH
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
StdCopyStrBuf sName
StdCopyStrBuf sFilename
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:412
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
#define C4CFN_Title
Definition: C4Components.h:82
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool C4Group_IsGroup(const char *szFilename)
Definition: C4Group.cpp:94
bool Close()
Definition: C4Group.cpp:755
virtual bool SetTitleInGroup(C4Group &rGrp, const char *szNewTitle)
const char * GetError()
Definition: C4Group.cpp:504
bool C4Group_MoveItem(const char *szSource, const char *szTarget1, bool fNoSort)
Definition: C4Group.cpp:144
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

void C4ScenarioListLoader::Folder::Resort ( )
inline

Definition at line 179 of file C4StartupScenSelDlg.h.

References Sort().

Here is the call graph for this function:

bool C4ScenarioListLoader::Entry::SetTitleInGroup ( C4Group rGrp,
const char *  szNewTitle 
)
virtualinherited

Definition at line 634 of file C4StartupScenSelDlg.cpp.

References C4Group::Add(), C4GUI::MessageDialog::btnOK, C4CFN_WriteTitle, Config, StdStrBuf::Copy(), StdStrBuf::Format(), C4Config::General, StdStrBuf::getData(), C4Group::GetError(), GetFilename(), StdStrBuf::GrabPointer(), C4GUI::Ico_Error, C4ConfigGeneral::Language, LoadResStr(), pGUI, RemoveExtension(), SEqual(), C4GUI::Screen::ShowMessageModal(), and StdStrBuf::Take().

635 {
636  // default for group files: Create a title text file and set the title in there
637  // no title needed if filename is sufficient - except for scenarios, where a Scenario.txt could overwrite the title
638  if (!IsScenario())
639  {
640  StdStrBuf sNameByFile; sNameByFile.Copy(GetFilename(sFilename.getData()));
641  char *szBuf = sNameByFile.GrabPointer();
642  RemoveExtension(szBuf);
643  sNameByFile.Take(szBuf);
644  if (SEqual(szNewTitle, sNameByFile.getData())) return true;
645  }
646  // okay, make a title
647  StdStrBuf sTitle; sTitle.Format("%s:%s", Config.General.Language, szNewTitle);
648  if (!rGrp.Add(C4CFN_WriteTitle, sTitle, false, true))
649  {
650  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_ERRORADDINGNEWTITLEFORFIL"), sFilename.getData(), rGrp.GetError());
652  return false;
653  }
654  return true;
655 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
#define C4CFN_WriteTitle
Definition: C4Components.h:83
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
C4ConfigGeneral General
Definition: C4Config.h:252
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
virtual bool IsScenario()
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
StdCopyStrBuf sFilename
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
void Take(char *pnData)
Definition: StdBuf.h:465
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
const char * GetError()
Definition: C4Group.cpp:504
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

void C4ScenarioListLoader::Folder::Sort ( )
protected

Definition at line 894 of file C4StartupScenSelDlg.cpp.

References EntrySortFunc(), and C4ScenarioListLoader::Entry::pNext.

Referenced by Resort().

895 {
896  // use C-Library-QSort on a buffer of entry pointers; then re-link list
897  if (!pFirst) return;
898  uint32_t iCount,i;
899  Entry **ppEntries = new Entry *[i = iCount = GetEntryCount()], **ppI, *pI=pFirst, **ppIThis;
900  for (ppI = ppEntries; i--; pI = pI->pNext) *ppI++ = pI;
901  qsort(ppEntries, iCount, sizeof(Entry *), &EntrySortFunc);
902  ppIThis = &pFirst;
903  for (ppI = ppEntries; iCount--; ppIThis = &((*ppIThis)->pNext)) *ppIThis = *ppI++;
904  *ppIThis = nullptr;
905  delete [] ppEntries;
906 }
int EntrySortFunc(const void *pEl1, const void *pEl2)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScenarioListLoader::Folder::Start ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 845 of file C4StartupScenSelDlg.cpp.

References C4StartupScenSelDlg::OpenFolder().

846 {
847  // open as subfolder
848  if (!C4StartupScenSelDlg::pInstance) return false;
850 }
bool OpenFolder(C4ScenarioListLoader::Folder *pNewFolder)
static C4StartupScenSelDlg * pInstance

Here is the call graph for this function:

Friends And Related Function Documentation

friend class Entry
friend

Definition at line 159 of file C4StartupScenSelDlg.h.

Member Data Documentation

C4Folder C4ScenarioListLoader::Folder::C4F
protected

Definition at line 155 of file C4StartupScenSelDlg.h.

bool C4ScenarioListLoader::Entry::fBaseLoaded
protectedinherited

Definition at line 62 of file C4StartupScenSelDlg.h.

bool C4ScenarioListLoader::Folder::fContentsLoaded
protected

Definition at line 156 of file C4StartupScenSelDlg.h.

C4FacetSurface C4ScenarioListLoader::Entry::fctIcon
protectedinherited

Definition at line 61 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetIconFacet().

C4FacetSurface C4ScenarioListLoader::Entry::fctTitle
protectedinherited

Definition at line 61 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetTitlePicture().

bool C4ScenarioListLoader::Entry::fExLoaded
protectedinherited

Definition at line 62 of file C4StartupScenSelDlg.h.

int C4ScenarioListLoader::Entry::iDifficulty
protectedinherited
int C4ScenarioListLoader::Entry::iFolderIndex
protectedinherited
int C4ScenarioListLoader::Entry::iIconIndex
protectedinherited
Entry* C4ScenarioListLoader::Folder::pFirst
protected
class C4ScenarioListLoader* C4ScenarioListLoader::Entry::pLoader
protectedinherited

Definition at line 53 of file C4StartupScenSelDlg.h.

class C4MapFolderData* C4ScenarioListLoader::Folder::pMapData
protected

Definition at line 158 of file C4StartupScenSelDlg.h.

Referenced by GetMapData().

Entry* C4ScenarioListLoader::Entry::pNext
protectedinherited
class Folder* C4ScenarioListLoader::Entry::pParent
protectedinherited

Definition at line 55 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetParent().

StdCopyStrBuf C4ScenarioListLoader::Entry::sAuthor
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetAuthor().

StdCopyStrBuf C4ScenarioListLoader::Entry::sDesc
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetDesc().

StdCopyStrBuf C4ScenarioListLoader::Entry::sFilename
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetEntryFilename().

StdCopyStrBuf C4ScenarioListLoader::Entry::sName
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetName().

StdCopyStrBuf C4ScenarioListLoader::Entry::sVersion
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetVersion().


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