OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Reloc Class Reference

#include <C4Reloc.h>

Classes

struct  PathInfo
 

Public Types

enum  PathType { PATH_Regular, PATH_PreferredInstallationLocation }
 
typedef std::vector< PathInfoPathList
 
typedef PathList::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 &hGroup, const char *filename) const
 
bool LocateItem (const char *filename, StdStrBuf &str) const
 

Detailed Description

Definition at line 21 of file C4Reloc.h.

Member Typedef Documentation

typedef PathList::const_iterator C4Reloc::iterator

Definition at line 38 of file C4Reloc.h.

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

Definition at line 37 of file C4Reloc.h.

Member Enumeration Documentation

Enumerator
PATH_Regular 
PATH_PreferredInstallationLocation 

Definition at line 24 of file C4Reloc.h.

Member Function Documentation

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

Definition at line 47 of file C4Reloc.cpp.

References IsGlobalPath().

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

48 {
49  if(!IsGlobalPath(path))
50  return false;
51 
52  if(std::find(Paths.begin(), Paths.end(), path) != Paths.end())
53  return false;
54 
55  Paths.push_back(PathInfo(StdCopyStrBuf(path), pathType));
56  return true;
57 }
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:237

Here is the call graph for this function:

Here is the caller graph for this function:

C4Reloc::iterator C4Reloc::begin ( ) const

Definition at line 59 of file C4Reloc.cpp.

Referenced by C4Language::Init(), C4Extra::InitGroup(), C4AppDelegate::installAddOn, C4ScenarioListLoader::Load(), LocateItem(), and Open().

60 {
61  return Paths.begin();
62 }

Here is the caller graph for this function:

C4Reloc::iterator C4Reloc::end ( ) const

Definition at line 64 of file C4Reloc.cpp.

Referenced by C4Language::Init(), C4Extra::InitGroup(), C4AppDelegate::installAddOn, C4ScenarioListLoader::Load(), LocateItem(), and Open().

65 {
66  return Paths.end();
67 }

Here is the caller graph for this function:

void C4Reloc::Init ( )

Definition at line 24 of file C4Reloc.cpp.

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

Referenced by C4Application::DoInit().

25 {
26  Paths.clear();
27 
28  // The system folder (i.e. installation path) has higher priority than the user path
29  // Although this is counter-intuitive (the user may want to overload system files in the user path),
30  // people had trouble when they downloaded e.g. an Objects.ocd file in a network lobby and that copy permanently
31  // ruined their OpenClonk installation with no obvious way to fix it.
32  // Not even reinstalling would fix the problem because reinstallation does not overwrite user data.
33  // 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.
34 #ifndef __APPLE__
35  // Add planet subfolder with highest priority because it's used when starting directly from the repository with binaries in the root folder
37  planet.AppendBackslash();
38  planet.Append("planet");
39  AddPath(planet.getData());
40 #endif
41  // Add main system path
43  // Add user path for additional data (player files, user scenarios, etc.)
45 }
C4Config Config
Definition: C4Config.cpp:831
C4ConfigGeneral General
Definition: C4Config.h:252
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
bool AddPath(const char *path, PathType pathType=PATH_Regular)
Definition: C4Reloc.cpp:47
StdCopyStrBuf ExePath
Definition: C4Config.h:53

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 80 of file C4Reloc.cpp.

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

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

81 {
82  if(IsGlobalPath(filename))
83  {
84  str.Copy(filename);
85  return true;
86  }
87 
88  for(iterator iter = begin(); iter != end(); ++iter)
89  {
90  str.Copy((*iter).strBuf + DirSep + filename);
91  if(ItemExists(str.getData()))
92  return true;
93  }
94 
95  return false;
96 }
const char * getData() const
Definition: StdBuf.h:450
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:237
PathList::const_iterator iterator
Definition: C4Reloc.h:38
iterator begin() const
Definition: C4Reloc.cpp:59
iterator end() const
Definition: C4Reloc.cpp:64
#define DirSep
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 69 of file C4Reloc.cpp.

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

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

70 {
71  if(IsGlobalPath(filename)) return hGroup.Open(filename);
72 
73  for(iterator iter = begin(); iter != end(); ++iter)
74  if(hGroup.Open(((*iter).strBuf + DirSep + filename).getData()))
75  return true;
76 
77  return false;
78 }
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:237
PathList::const_iterator iterator
Definition: C4Reloc.h:38
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
iterator begin() const
Definition: C4Reloc.cpp:59
iterator end() const
Definition: C4Reloc.cpp:64
#define DirSep

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: