2011-01-06 20:18:13 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 2011-2013, The OpenClonk Team and contributors
|
2011-01-06 20:18:13 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2011-01-06 20:18:13 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2011-01-06 20:18:13 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2011-01-06 20:18:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4Reloc.h>
|
|
|
|
|
2011-01-24 00:15:58 +00:00
|
|
|
#include <C4Config.h>
|
2011-10-09 16:09:48 +00:00
|
|
|
#include <C4Application.h>
|
2011-01-24 00:15:58 +00:00
|
|
|
|
2011-01-06 20:18:13 +00:00
|
|
|
C4Reloc Reloc; // singleton
|
|
|
|
|
|
|
|
void C4Reloc::Init()
|
|
|
|
{
|
|
|
|
Paths.clear();
|
|
|
|
|
2011-11-10 01:17:00 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
StdCopyStrBuf planet(Config.General.ExePath);
|
|
|
|
planet.AppendBackslash();
|
|
|
|
planet.Append("planet");
|
|
|
|
AddPath(planet.getData());
|
|
|
|
#endif
|
2011-10-09 16:36:25 +00:00
|
|
|
|
2011-10-16 14:07:13 +00:00
|
|
|
AddPath(Config.General.UserDataPath, PATH_PreferredInstallationLocation);
|
2011-01-06 20:18:13 +00:00
|
|
|
AddPath(Config.General.SystemDataPath);
|
|
|
|
}
|
|
|
|
|
2011-10-16 14:25:23 +00:00
|
|
|
bool C4Reloc::AddPath(const char* path, PathType pathType)
|
2011-01-06 20:18:13 +00:00
|
|
|
{
|
|
|
|
if(!IsGlobalPath(path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(std::find(Paths.begin(), Paths.end(), path) != Paths.end())
|
|
|
|
return false;
|
|
|
|
|
2011-10-16 14:07:13 +00:00
|
|
|
Paths.push_back(PathInfo(StdCopyStrBuf(path), pathType));
|
2011-01-06 20:18:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
C4Reloc::iterator C4Reloc::begin() const
|
|
|
|
{
|
|
|
|
return Paths.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
C4Reloc::iterator C4Reloc::end() const
|
|
|
|
{
|
|
|
|
return Paths.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Reloc::Open(C4Group& hGroup, const char* filename) const
|
|
|
|
{
|
|
|
|
if(IsGlobalPath(filename)) return hGroup.Open(filename);
|
|
|
|
|
|
|
|
for(iterator iter = begin(); iter != end(); ++iter)
|
2011-10-16 14:07:13 +00:00
|
|
|
if(hGroup.Open(((*iter).strBuf + DirSep + filename).getData()))
|
2011-01-06 20:18:13 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool C4Reloc::LocateItem(const char* filename, StdStrBuf& str) const
|
|
|
|
{
|
|
|
|
if(IsGlobalPath(filename))
|
|
|
|
{
|
|
|
|
str.Copy(filename);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(iterator iter = begin(); iter != end(); ++iter)
|
|
|
|
{
|
2011-10-16 14:07:13 +00:00
|
|
|
str.Copy((*iter).strBuf + DirSep + filename);
|
2011-01-06 20:18:13 +00:00
|
|
|
if(ItemExists(str.getData()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-01-09 23:23:06 +00:00
|
|
|
}
|