OpenClonk
C4ScenarioListLoader::Entry Class Referenceabstract

#include <C4StartupScenSelDlg.h>

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

Public Member Functions

 Entry (class C4ScenarioListLoader *pLoader, class Folder *pParent)
 
virtual ~Entry ()
 
bool Load (C4Group *pFromGrp, const StdStrBuf *psFilename, bool fLoadEx)
 
virtual bool LoadCustom (C4Group &rGrp, bool fNameLoaded, bool fIconLoaded)
 
virtual bool LoadCustomPre (C4Group &rGrp)
 
virtual bool Start ()=0
 
virtual FolderGetIsFolder ()
 
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 CanOpen (StdStrBuf &sError, bool &CanHide)
 
virtual bool IsGrayed ()
 
virtual bool IsHidden ()
 
virtual bool HasMissionAccess () const
 
virtual bool HasUnregisteredAccess () const
 
virtual StdStrBuf GetOpenText ()=0
 
virtual StdStrBuf GetOpenTooltip ()=0
 
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 Attributes

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 Folder
 

Detailed Description

Definition at line 47 of file C4StartupScenSelDlg.h.

Constructor & Destructor Documentation

◆ Entry()

C4ScenarioListLoader::Entry::Entry ( class C4ScenarioListLoader pLoader,
class Folder pParent 
)

Definition at line 403 of file C4StartupScenSelDlg.cpp.

403  : pLoader(pLoader), pNext(nullptr), pParent(pParent), fBaseLoaded(false), fExLoaded(false)
404 {
405  // ctor: Put into parent tree node
406  if (pParent)
407  {
408  pNext = pParent->pFirst;
409  pParent->pFirst = this;
410  }
411  iIconIndex = -1;
412  iDifficulty = 0;
413  iFolderIndex = 0;
414 }
int iIconIndex
int iDifficulty
bool fExLoaded
class C4ScenarioListLoader * pLoader
int iFolderIndex
bool fBaseLoaded
Entry * pNext
class Folder * pParent

References iDifficulty, iFolderIndex, iIconIndex, C4ScenarioListLoader::Folder::pFirst, pNext, and pParent.

◆ ~Entry()

C4ScenarioListLoader::Entry::~Entry ( )
virtual

Definition at line 416 of file C4StartupScenSelDlg.cpp.

417 {
418  // dtor: unlink from parent list (MUST be in there)
419  if (pParent)
420  {
421  Entry **ppCheck = &(pParent->pFirst);
422  while (*ppCheck != this)
423  {
424  ppCheck = &(*ppCheck)->pNext;
425  }
426  *ppCheck = pNext;
427  }
428 }
Entry(class C4ScenarioListLoader *pLoader, class Folder *pParent)

References pNext.

Member Function Documentation

◆ CanOpen()

virtual bool C4ScenarioListLoader::Entry::CanOpen ( StdStrBuf sError,
bool &  CanHide 
)
inlinevirtual

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

Definition at line 91 of file C4StartupScenSelDlg.h.

91 { return true; } // whether item can be started/opened (e.g. mission access, unregistered)

Referenced by C4StartupScenSelDlg::DoOK(), and C4StartupScenSelDlg::ScenListItem::ScenListItem().

Here is the caller graph for this function:

◆ CreateEntryForFile()

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

Definition at line 549 of file C4StartupScenSelDlg.cpp.

550 {
551  // determine entry type by file type
552  const char *szFilename = sFilename.getData();
553  if (!szFilename || !*szFilename) return nullptr;
554  if (WildcardMatch(C4CFN_ScenarioFiles, sFilename.getData())) return new Scenario(pLoader, pParent);
555  if (WildcardMatch(C4CFN_FolderFiles, sFilename.getData())) return new SubFolder(pLoader, pParent);
556  // regular, open folder (C4Group-packed folders without extensions are not regarded, because they could contain anything!)
557  const char *szExt = GetExtension(szFilename);
558  if ((!szExt || !*szExt) && DirectoryExists(sFilename.getData()))
559  {
560  // do not open folders in the mod directory (and the dir itself - thus match minus the separator),
561  // as contained files will be discovered anyway
562  const char * modsDirectoryPrefix = Config.General.ModsDataPath;
563  if (std::strncmp(szFilename, modsDirectoryPrefix, std::strlen(modsDirectoryPrefix) - 1) == 0)
564  return nullptr;
565  // open folders only if they contain a scenario or folder
566  if (DirContainsScenarios(szFilename))
567  return new RegularFolder(pLoader, pParent);
568  }
569  // type not recognized
570  return nullptr;
571 }
#define C4CFN_ScenarioFiles
Definition: C4Components.h:175
#define C4CFN_FolderFiles
Definition: C4Components.h:176
C4Config Config
Definition: C4Config.cpp:930
bool DirContainsScenarios(const char *szDir)
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:708
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:118
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:396
char ModsDataPath[CFG_MaxString+1]
Definition: C4Config.h:57
C4ConfigGeneral General
Definition: C4Config.h:255
StdCopyStrBuf sFilename
const char * getData() const
Definition: StdBuf.h:442

References C4CFN_FolderFiles, C4CFN_ScenarioFiles, Config, DirContainsScenarios(), DirectoryExists(), C4Config::General, StdStrBuf::getData(), GetExtension(), C4ConfigGeneral::ModsDataPath, and WildcardMatch().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAchievement()

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

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 87 of file C4StartupScenSelDlg.h.

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

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

Here is the caller graph for this function:

◆ GetAuthor()

const StdStrBuf& C4ScenarioListLoader::Entry::GetAuthor ( ) const
inline

Definition at line 77 of file C4StartupScenSelDlg.h.

77 { return sAuthor; }
StdCopyStrBuf sAuthor

References sAuthor.

◆ GetDefaultExtension()

virtual const char* C4ScenarioListLoader::Entry::GetDefaultExtension ( )
inlinevirtual

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

Definition at line 99 of file C4StartupScenSelDlg.h.

99 { return nullptr; } // extension to be added when item is renamed

◆ GetDesc()

const StdStrBuf& C4ScenarioListLoader::Entry::GetDesc ( ) const
inline

Definition at line 80 of file C4StartupScenSelDlg.h.

80 { return sDesc; }
StdCopyStrBuf sDesc

References sDesc.

◆ GetDifficulty()

int C4ScenarioListLoader::Entry::GetDifficulty ( )
inline

Definition at line 82 of file C4StartupScenSelDlg.h.

82 { return iDifficulty; }

References iDifficulty.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

◆ GetEntryFilename()

const StdStrBuf& C4ScenarioListLoader::Entry::GetEntryFilename ( ) const
inline

Definition at line 75 of file C4StartupScenSelDlg.h.

75 { return sFilename; }

References sFilename.

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

Here is the caller graph for this function:

◆ GetFolderIndex()

int C4ScenarioListLoader::Entry::GetFolderIndex ( )
inline

Definition at line 83 of file C4StartupScenSelDlg.h.

83 { return iFolderIndex; }

References iFolderIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

◆ GetIconFacet()

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

Definition at line 78 of file C4StartupScenSelDlg.h.

78 { return fctIcon; }
C4FacetSurface fctIcon

References fctIcon.

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

Here is the caller graph for this function:

◆ GetIconIndex()

int C4ScenarioListLoader::Entry::GetIconIndex ( )
inline

Definition at line 81 of file C4StartupScenSelDlg.h.

81 { return iIconIndex; }

References iIconIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

◆ GetIsFolder()

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

Reimplemented in C4ScenarioListLoader::Folder.

Definition at line 72 of file C4StartupScenSelDlg.h.

72 { return nullptr; } // return this if this is a folder

Referenced by C4ScenarioListLoader::Folder::ClearChildren(), and EntrySortFunc().

Here is the caller graph for this function:

◆ GetName()

const StdStrBuf& C4ScenarioListLoader::Entry::GetName ( ) const
inline

Definition at line 74 of file C4StartupScenSelDlg.h.

74 { return sName; }
StdCopyStrBuf sName

References sName.

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

Here is the caller graph for this function:

◆ GetNext()

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

Definition at line 84 of file C4StartupScenSelDlg.h.

84 { return pNext; }

References pNext.

Referenced by C4ScenarioListLoader::Folder::FindEntryByName().

Here is the caller graph for this function:

◆ GetOpenText()

virtual StdStrBuf C4ScenarioListLoader::Entry::GetOpenText ( )
pure virtual

◆ GetOpenTooltip()

virtual StdStrBuf C4ScenarioListLoader::Entry::GetOpenTooltip ( )
pure virtual

◆ GetParameterDefs()

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

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 104 of file C4StartupScenSelDlg.h.

104 { return nullptr; }

◆ GetParameters()

virtual C4ScenarioParameters* C4ScenarioListLoader::Entry::GetParameters ( )
inlinevirtual

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 105 of file C4StartupScenSelDlg.h.

105 { return nullptr; }

◆ GetParent()

class Folder* C4ScenarioListLoader::Entry::GetParent ( ) const
inline

Definition at line 85 of file C4StartupScenSelDlg.h.

85 { return pParent; }

References pParent.

Referenced by C4ScenarioListLoader::FolderBack().

Here is the caller graph for this function:

◆ GetTitlePicture()

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

Definition at line 79 of file C4StartupScenSelDlg.h.

79 { return fctTitle; }
C4FacetSurface fctTitle

References fctTitle.

◆ GetTypeName()

virtual StdStrBuf C4ScenarioListLoader::Entry::GetTypeName ( )
pure virtual

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

Referenced by C4StartupScenSelDlg::KeyDelete().

Here is the caller graph for this function:

◆ GetVersion()

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

Definition at line 76 of file C4StartupScenSelDlg.h.

76 { return sVersion; }
StdCopyStrBuf sVersion

References sVersion.

◆ HasMissionAccess()

virtual bool C4ScenarioListLoader::Entry::HasMissionAccess ( ) const
inlinevirtual

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 94 of file C4StartupScenSelDlg.h.

94 { return true; }

◆ HasUnregisteredAccess()

virtual bool C4ScenarioListLoader::Entry::HasUnregisteredAccess ( ) const
inlinevirtual

Definition at line 95 of file C4StartupScenSelDlg.h.

95 { return false; }

◆ IsGrayed()

virtual bool C4ScenarioListLoader::Entry::IsGrayed ( )
inlinevirtual

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

Definition at line 92 of file C4StartupScenSelDlg.h.

92 { return false; } // additional condition for graying out - notice unreg folders are grayed but can still be opened

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

Here is the caller graph for this function:

◆ IsHidden()

virtual bool C4ScenarioListLoader::Entry::IsHidden ( )
inlinevirtual

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 93 of file C4StartupScenSelDlg.h.

93 { return false; } // condition for hiding element completely

◆ IsScenario()

virtual bool C4ScenarioListLoader::Entry::IsScenario ( )
inlinevirtual

Reimplemented in C4ScenarioListLoader::Scenario.

Definition at line 102 of file C4StartupScenSelDlg.h.

102 { return false; }

◆ Load()

bool C4ScenarioListLoader::Entry::Load ( C4Group pFromGrp,
const StdStrBuf psFilename,
bool  fLoadEx 
)

Definition at line 431 of file C4StartupScenSelDlg.cpp.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadCustom()

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

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

Definition at line 69 of file C4StartupScenSelDlg.h.

69 { return true; } // load custom data for entry type (e.g. scenario title fallback in Scenario.txt)

◆ LoadCustomPre()

virtual bool C4ScenarioListLoader::Entry::LoadCustomPre ( C4Group rGrp)
inlinevirtual

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

Definition at line 70 of file C4StartupScenSelDlg.h.

70 { return true; } // preload stuff that's early in the group (Scenario.txt)

◆ RenameTo()

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

Definition at line 573 of file C4StartupScenSelDlg.cpp.

574 {
575  // change name+filename
576  // some name sanity validation
577  if (!szNewName || !*szNewName) return false;
578  if (SEqual(szNewName, sName.getData())) return true;
579  char fn[_MAX_PATH_LEN];
580  SCopy(szNewName, fn, _MAX_PATH);
581  // generate new file name
583  if (!*fn) return false;
584  const char *szExt = GetDefaultExtension();
585  if (szExt) { SAppend(".", fn, _MAX_PATH); SAppend(szExt, fn, _MAX_PATH); }
586  char fullfn[_MAX_PATH_LEN];
587  SCopy(sFilename.getData(), fullfn, _MAX_PATH);
588  char *fullfn_fn = GetFilename(fullfn);
589  SCopy(fn, fullfn_fn, _MAX_PATH - (fullfn_fn - fullfn));
590  StdCopyStrBuf strErr(LoadResStr("IDS_FAIL_RENAME"));
591  // check if a rename is due
592  if (!ItemIdentical(sFilename.getData(), fullfn))
593  {
594  // check for duplicate filename
595  if (ItemExists(fullfn))
596  {
597  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_FILEEXISTS"), fullfn);
599  return false;
600  }
601  // OK; then rename
602  if (!C4Group_MoveItem(sFilename.getData(), fullfn, true))
603  {
604  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_RENAMEFILE"), sFilename.getData(), fullfn);
606  return false;
607  }
608  sFilename.Copy(fullfn);
609  }
610  // update real name in group, if this is a group
611  if (C4Group_IsGroup(fullfn))
612  {
613  C4Group Grp;
614  if (!Grp.Open(fullfn))
615  {
616  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_OPENFILE"), sFilename.getData(), Grp.GetError());
618  return false;
619  }
620  if (!Grp.Delete(C4CFN_Title))
621  {
622  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_DELOLDTITLE"), sFilename.getData(), Grp.GetError());
624  return false;
625  }
626  if (!SetTitleInGroup(Grp, szNewName)) return false;
627  if (!Grp.Close())
628  {
629  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_WRITENEWTITLE"), sFilename.getData(), Grp.GetError());
631  return false;
632  }
633  }
634  // update title
635  sName.Copy(szNewName);
636  // done
637  return true;
638 }
bool C4Group_MoveItem(const char *source, const char *target, bool no_sorting)
Definition: C4Group.cpp:182
bool C4Group_IsGroup(const char *filename)
Definition: C4Group.cpp:104
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
#define _MAX_PATH
#define _MAX_PATH_LEN
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:879
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:426
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
const char * GetError()
Definition: C4Group.cpp:650
bool Close()
Definition: C4Group.cpp:971
bool Delete(const char *files, bool recursive=false)
Definition: C4Group.cpp:1645
virtual const char * GetDefaultExtension()
virtual bool SetTitleInGroup(C4Group &rGrp, const char *szNewTitle)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
@ Ico_Error
Definition: C4Gui.h:652

References _MAX_PATH, _MAX_PATH_LEN, 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().

Here is the call graph for this function:

◆ SetTitleInGroup()

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

Definition at line 640 of file C4StartupScenSelDlg.cpp.

641 {
642  // default for group files: Create a title text file and set the title in there
643  // no title needed if filename is sufficient - except for scenarios, where a Scenario.txt could overwrite the title
644  if (!IsScenario())
645  {
646  StdStrBuf sNameByFile; sNameByFile.Copy(GetFilename(sFilename.getData()));
647  char *szBuf = sNameByFile.GrabPointer();
648  RemoveExtension(szBuf);
649  sNameByFile.Take(szBuf);
650  if (SEqual(szNewTitle, sNameByFile.getData())) return true;
651  }
652  // okay, make a title
653  StdStrBuf sTitle; sTitle.Format("%s:%s", Config.General.Language, szNewTitle);
654  if (!rGrp.Add(C4CFN_WriteTitle, sTitle, false, true))
655  {
656  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_ERRORADDINGNEWTITLEFORFIL"), sFilename.getData(), rGrp.GetError());
658  return false;
659  }
660  return true;
661 }
#define C4CFN_WriteTitle
Definition: C4Components.h:83
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621
virtual bool IsScenario()

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().

Here is the call graph for this function:

◆ Start()

virtual bool C4ScenarioListLoader::Entry::Start ( )
pure virtual

Implemented in C4ScenarioListLoader::Folder, and C4ScenarioListLoader::Scenario.

Referenced by C4StartupScenSelDlg::DoOK().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Folder

friend class Folder
friend

Definition at line 54 of file C4StartupScenSelDlg.h.

Member Data Documentation

◆ fBaseLoaded

bool C4ScenarioListLoader::Entry::fBaseLoaded
protected

Definition at line 59 of file C4StartupScenSelDlg.h.

◆ fctIcon

C4FacetSurface C4ScenarioListLoader::Entry::fctIcon
protected

Definition at line 58 of file C4StartupScenSelDlg.h.

Referenced by GetIconFacet().

◆ fctTitle

C4FacetSurface C4ScenarioListLoader::Entry::fctTitle
protected

Definition at line 58 of file C4StartupScenSelDlg.h.

Referenced by GetTitlePicture().

◆ fExLoaded

bool C4ScenarioListLoader::Entry::fExLoaded
protected

Definition at line 59 of file C4StartupScenSelDlg.h.

◆ iDifficulty

int C4ScenarioListLoader::Entry::iDifficulty
protected

Definition at line 61 of file C4StartupScenSelDlg.h.

Referenced by Entry(), and GetDifficulty().

◆ iFolderIndex

int C4ScenarioListLoader::Entry::iFolderIndex
protected

Definition at line 62 of file C4StartupScenSelDlg.h.

Referenced by Entry(), and GetFolderIndex().

◆ iIconIndex

int C4ScenarioListLoader::Entry::iIconIndex
protected

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by Entry(), and GetIconIndex().

◆ pLoader

class C4ScenarioListLoader* C4ScenarioListLoader::Entry::pLoader
protected

Definition at line 50 of file C4StartupScenSelDlg.h.

◆ pNext

Entry* C4ScenarioListLoader::Entry::pNext
protected

◆ pParent

class Folder* C4ScenarioListLoader::Entry::pParent
protected

Definition at line 52 of file C4StartupScenSelDlg.h.

Referenced by Entry(), and GetParent().

◆ sAuthor

StdCopyStrBuf C4ScenarioListLoader::Entry::sAuthor
protected

Definition at line 57 of file C4StartupScenSelDlg.h.

Referenced by GetAuthor().

◆ sDesc

StdCopyStrBuf C4ScenarioListLoader::Entry::sDesc
protected

Definition at line 57 of file C4StartupScenSelDlg.h.

Referenced by GetDesc().

◆ sFilename

StdCopyStrBuf C4ScenarioListLoader::Entry::sFilename
protected

Definition at line 57 of file C4StartupScenSelDlg.h.

Referenced by GetEntryFilename().

◆ sName

StdCopyStrBuf C4ScenarioListLoader::Entry::sName
protected

Definition at line 57 of file C4StartupScenSelDlg.h.

Referenced by GetName().

◆ sVersion

StdCopyStrBuf C4ScenarioListLoader::Entry::sVersion
protected

Definition at line 57 of file C4StartupScenSelDlg.h.

Referenced by GetVersion().


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