OpenClonk
C4StartupScenSelDlg.cpp File Reference
Include dependency graph for C4StartupScenSelDlg.cpp:

Go to the source code of this file.

Functions

bool DirContainsScenarios (const char *szDir)
 
int EntrySortFunc (const void *pEl1, const void *pEl2)
 

Variables

const uint32_t ClrScenarioItem = 0xff000000
 
const uint32_t ClrScenarioItemXtra = 0x7f000000
 
const uint32_t ClrScenarioItemDisabled = 0x7f000000
 

Function Documentation

◆ DirContainsScenarios()

bool DirContainsScenarios ( const char *  szDir)

Definition at line 525 of file C4StartupScenSelDlg.cpp.

526 {
527  // Ignore object and group folders to avoid descending e.g. deep into unpacked Objects.ocd
529  {
530  return false;
531  }
532  // create iterator on free store to avoid stack overflow with deeply recursed folders
533  DirectoryIterator *pIter = new DirectoryIterator(szDir);
534  const char *szChildFilename;
535  for (; (szChildFilename = **pIter); ++*pIter)
536  {
537  // Ignore directory navigation entries and CVS folders
538  if (C4Group_TestIgnore(szChildFilename)) continue;
539  if (WildcardMatch(C4CFN_ScenarioFiles, szChildFilename) || WildcardMatch(C4CFN_FolderFiles, szChildFilename)) break;
540  if (DirectoryExists(szChildFilename))
541  if (DirContainsScenarios(szChildFilename))
542  break;
543  }
544  delete pIter;
545  // return true if loop was broken, in which case a matching entry was found
546  return !!szChildFilename;
547 }
#define C4CFN_GenericGroupFiles
Definition: C4Components.h:167
#define C4CFN_ScenarioFiles
Definition: C4Components.h:175
#define C4CFN_DefFiles
Definition: C4Components.h:166
#define C4CFN_FolderFiles
Definition: C4Components.h:176
bool C4Group_TestIgnore(const char *filename)
Definition: C4Group.cpp:92
bool DirContainsScenarios(const char *szDir)
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:708
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:396

References C4CFN_DefFiles, C4CFN_FolderFiles, C4CFN_GenericGroupFiles, C4CFN_ScenarioFiles, C4Group_TestIgnore(), DirectoryExists(), and WildcardMatch().

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

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

◆ EntrySortFunc()

int EntrySortFunc ( const void *  pEl1,
const void *  pEl2 
)

Definition at line 869 of file C4StartupScenSelDlg.cpp.

870 {
871  C4ScenarioListLoader::Entry *pEntry1 = *(C4ScenarioListLoader::Entry * const *) pEl1, *pEntry2 = *(C4ScenarioListLoader::Entry * const *) pEl2;
872  // sort folders before scenarios
873  bool fS1 = !pEntry1->GetIsFolder(), fS2 = !pEntry2->GetIsFolder();
874  if (fS1 != fS2) return fS1-fS2;
875  // sort by folder index (undefined index 0 goes to the end)
876  if (!Config.Startup.AlphabeticalSorting) if (pEntry1->GetFolderIndex() || pEntry2->GetFolderIndex())
877  {
878  if (!pEntry1->GetFolderIndex()) return +1;
879  if (!pEntry2->GetFolderIndex()) return -1;
880  int32_t iDiff = pEntry1->GetFolderIndex() - pEntry2->GetFolderIndex();
881  if (iDiff) return iDiff;
882  }
883  // sort by numbered standard scenario icons
884  if (Inside(pEntry1->GetIconIndex(), 2, 11))
885  {
886  int32_t iDiff = pEntry1->GetIconIndex() - pEntry2->GetIconIndex();
887  if (iDiff) return iDiff;
888  }
889  // sort by difficulty (undefined difficulty goes to the end)
890  if (!Config.Startup.AlphabeticalSorting) if (pEntry1->GetDifficulty() || pEntry2->GetDifficulty())
891  {
892  if (!pEntry1->GetDifficulty()) return +1;
893  if (!pEntry2->GetDifficulty()) return -1;
894  int32_t iDiff = pEntry1->GetDifficulty() - pEntry2->GetDifficulty();
895  if (iDiff) return iDiff;
896  }
897  // otherwise, sort by name
898  return stricmp(pEntry1->GetName().getData(), pEntry2->GetName().getData());
899 }
C4Config Config
Definition: C4Config.cpp:930
int stricmp(const char *s1, const char *s2)
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
C4ConfigStartup Startup
Definition: C4Config.h:264
int32_t AlphabeticalSorting
Definition: C4Config.h:193
virtual Folder * GetIsFolder()
int GetFolderIndex()
const StdStrBuf & GetName() const
int GetDifficulty()
int GetIconIndex()
const char * getData() const
Definition: StdBuf.h:442

References C4ConfigStartup::AlphabeticalSorting, Config, StdStrBuf::getData(), C4ScenarioListLoader::Entry::GetDifficulty(), C4ScenarioListLoader::Entry::GetFolderIndex(), C4ScenarioListLoader::Entry::GetIconIndex(), C4ScenarioListLoader::Entry::GetIsFolder(), C4ScenarioListLoader::Folder::GetIsFolder(), C4ScenarioListLoader::Entry::GetName(), Inside(), C4Config::Startup, and stricmp().

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

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

Variable Documentation

◆ ClrScenarioItem

const uint32_t ClrScenarioItem = 0xff000000

◆ ClrScenarioItemDisabled

const uint32_t ClrScenarioItemDisabled = 0x7f000000

◆ ClrScenarioItemXtra

const uint32_t ClrScenarioItemXtra = 0x7f000000

Definition at line 1305 of file C4StartupScenSelDlg.cpp.

Referenced by C4StartupScenSelDlg::C4StartupScenSelDlg().