OpenClonk
C4Reloc Class Reference

#include <C4Reloc.h>

Classes

class  const_iterator
 
struct  PathInfo
 

Public Types

enum  PathType { PATH_Regular , PATH_PreferredInstallationLocation , PATH_IncludingSubdirectories }
 
typedef std::vector< PathInfoPathList
 
typedef const_iterator iterator
 

Public Member Functions

void Init ()
 
bool AddPath (const char *path, PathType pathType=PATH_Regular)
 
iterator begin () const
 
iterator end () const
 
bool Open (C4Group &group, const char *filename) const
 
bool LocateItem (const char *filename, StdStrBuf &str) const
 

Detailed Description

Definition at line 22 of file C4Reloc.h.

Member Typedef Documentation

◆ iterator

Definition at line 73 of file C4Reloc.h.

◆ PathList

typedef std::vector<PathInfo> C4Reloc::PathList

Definition at line 39 of file C4Reloc.h.

Member Enumeration Documentation

◆ PathType

Enumerator
PATH_Regular 
PATH_PreferredInstallationLocation 
PATH_IncludingSubdirectories 

Definition at line 25 of file C4Reloc.h.

26  {
30  };
@ PATH_Regular
Definition: C4Reloc.h:27
@ PATH_PreferredInstallationLocation
Definition: C4Reloc.h:28
@ PATH_IncludingSubdirectories
Definition: C4Reloc.h:29

Member Function Documentation

◆ AddPath()

bool C4Reloc::AddPath ( const char *  path,
PathType  pathType = PATH_Regular 
)

Definition at line 62 of file C4Reloc.cpp.

63 {
64  if (!IsGlobalPath(path))
65  {
66  return false;
67  }
68 
69  if (std::find(Paths.begin(), Paths.end(), path) != Paths.end())
70  {
71  return false;
72  }
73 
74  Paths.emplace_back(StdCopyStrBuf(path), pathType);
75  return true;
76 }
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:224

References IsGlobalPath().

Referenced by Init(), and C4Application::ParseCommandLine().

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

◆ begin()

C4Reloc::iterator C4Reloc::begin ( ) const

Definition at line 142 of file C4Reloc.cpp.

143 {
144  C4Reloc::iterator iter;
145  iter.pathListIter = Paths.begin();
146  return std::move(iter);
147 }
PathList::const_iterator pathListIter
Definition: C4Reloc.h:68

References C4Reloc::const_iterator::pathListIter.

Referenced by C4Language::Init().

Here is the caller graph for this function:

◆ end()

C4Reloc::iterator C4Reloc::end ( ) const

Definition at line 149 of file C4Reloc.cpp.

150 {
151  C4Reloc::iterator iter;
152  iter.pathListIter = Paths.end();
153  return std::move(iter);
154 }

References C4Reloc::const_iterator::pathListIter.

Referenced by C4Language::Init().

Here is the caller graph for this function:

◆ Init()

void C4Reloc::Init ( )

Definition at line 23 of file C4Reloc.cpp.

24 {
25  Paths.clear();
26 
27  // The system folder (i.e. installation path) has higher priority than the user path
28  // Although this is counter-intuitive (the user may want to overload system files in the user path),
29  // people had trouble when they downloaded e.g. an Objects.ocd file in a network lobby and that copy permanently
30  // ruined their OpenClonk installation with no obvious way to fix it.
31  // Not even reinstalling would fix the problem because reinstallation does not overwrite user data.
32  // We currently don't have any valid case where overloading system files would make sense so just give higher priority to the system path for now.
33 #ifndef __APPLE__
34  // Add planet subfolder with highest priority because it's used when starting directly from the repository with binaries in the root folder
36  planet.AppendBackslash();
37  planet.Append("planet");
38  if (DirectoryExists(planet.getData()))
39  {
40  // Only add planet if it's a valid contents folder.
41  // Because users may create a folder "planet" in their source repos.
42  StdCopyStrBuf planet_system_check(planet);
43  planet_system_check.AppendBackslash();
44  planet_system_check.Append(C4CFN_System);
45  if (ItemExists(planet_system_check.getData()))
46  {
47  AddPath(planet.getData());
48  }
49  }
50 #endif
51  // Add main system path (unless it's using planet/ anyway, in which we would just slow down scenario enumeration by looking throug hthe whole source folder)
52  if (!Paths.size())
53  {
55  }
56  // Add mods directory before the user path.
58  // Add user path for additional data (player files, user scenarios, etc.)
60 }
#define C4CFN_System
Definition: C4Components.h:29
C4Config Config
Definition: C4Config.cpp:930
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:708
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
StdCopyStrBuf ExePath
Definition: C4Config.h:54
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:58
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
char ModsDataPath[CFG_MaxString+1]
Definition: C4Config.h:57
C4ConfigGeneral General
Definition: C4Config.h:255
bool AddPath(const char *path, PathType pathType=PATH_Regular)
Definition: C4Reloc.cpp:62

References AddPath(), StdStrBuf::Append(), StdStrBuf::AppendBackslash(), C4CFN_System, Config, DirectoryExists(), C4ConfigGeneral::ExePath, C4Config::General, StdStrBuf::getData(), ItemExists(), C4ConfigGeneral::ModsDataPath, PATH_IncludingSubdirectories, PATH_PreferredInstallationLocation, C4ConfigGeneral::SystemDataPath, and C4ConfigGeneral::UserDataPath.

Referenced by C4Application::DoInit().

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

◆ LocateItem()

bool C4Reloc::LocateItem ( const char *  filename,
StdStrBuf str 
) const

Definition at line 174 of file C4Reloc.cpp.

175 {
176  if (IsGlobalPath(filename))
177  {
178  str.Copy(filename);
179  return true;
180  }
181 
182  for(const auto & iter : *this)
183  {
184  str.Copy(iter.strBuf + DirSep + filename);
185  if (ItemExists(str.getData()))
186  {
187  return true;
188  }
189  }
190 
191  return false;
192 }
#define DirSep
const char * getData() const
Definition: StdBuf.h:442
void Copy()
Definition: StdBuf.h:467

References StdStrBuf::Copy(), DirSep, StdStrBuf::getData(), IsGlobalPath(), and ItemExists().

Referenced by C4ControlJoinPlayer::C4ControlJoinPlayer(), and C4Network2Res::SetByFile().

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

◆ Open()

bool C4Reloc::Open ( C4Group group,
const char *  filename 
) const

Definition at line 156 of file C4Reloc.cpp.

157 {
158  if (IsGlobalPath(filename))
159  {
160  return group.Open(filename);
161  }
162 
163  for (const auto & iter : *this)
164  {
165  if (group.Open((iter.strBuf + DirSep + filename).getData()))
166  {
167  return true;
168  }
169  }
170 
171  return false;
172 }
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660

References DirSep, IsGlobalPath(), and C4Group::Open().

Referenced by C4Application::DoInit(), C4SoundSystem::Init(), C4LoaderScreen::Init(), C4Game::InitMaterialTexture(), C4Player::Load(), C4DefList::Load(), C4GameResList::LoadFoldersWithLocalDefs(), C4PlayerInfo::LoadFromLocalFile(), C4Game::OpenScenario(), C4GraphicsResource::RegisterGlobalGraphics(), C4GroupSet::RegisterParentFolders(), and C4Network2Res::SetByFile().

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

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