2007-11-10 14:39:45 +01:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : path.h
|
|
|
|
* Project : 0 A.D.
|
2007-11-20 19:51:07 +01:00
|
|
|
* Description : manage paths relative to a root directory
|
2007-11-10 14:39:45 +01:00
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// license: GPL; see lib/license.txt
|
|
|
|
|
2007-11-20 19:51:07 +01:00
|
|
|
// path types:
|
|
|
|
|
|
|
|
// tag type type separator
|
|
|
|
// portable relative /
|
|
|
|
// os native absolute SYS_DIR_SEP
|
|
|
|
// vfs vfs absolute /
|
|
|
|
|
|
|
|
// the vfs root directory is "". no ':', '\\', "." or ".." are allowed.
|
|
|
|
|
2007-11-10 14:39:45 +01:00
|
|
|
#ifndef INCLUDED_PATH
|
|
|
|
#define INCLUDED_PATH
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
struct PathTraits;
|
|
|
|
typedef fs::basic_path<std::string, PathTraits> Path;
|
|
|
|
|
2008-02-25 22:19:52 +01:00
|
|
|
struct LIB_API PathTraits
|
2007-12-20 21:14:21 +01:00
|
|
|
{
|
|
|
|
typedef std::string internal_string_type;
|
|
|
|
typedef std::string external_string_type;
|
|
|
|
|
2008-02-25 22:19:52 +01:00
|
|
|
static external_string_type to_external(const Path&, const internal_string_type& src);
|
|
|
|
static internal_string_type to_internal(const external_string_type& src);
|
2007-12-20 21:14:21 +01:00
|
|
|
};
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
namespace filesystem
|
|
|
|
{
|
|
|
|
template<> struct is_basic_path<Path>
|
|
|
|
{
|
|
|
|
BOOST_STATIC_CONSTANT(bool, value = true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 21:14:21 +01:00
|
|
|
|
2007-11-10 14:39:45 +01:00
|
|
|
namespace ERR
|
|
|
|
{
|
2007-11-20 19:51:07 +01:00
|
|
|
const LibError PATH_ROOT_DIR_ALREADY_SET = -110200;
|
|
|
|
const LibError PATH_NOT_IN_ROOT_DIR = -110201;
|
2007-11-10 14:39:45 +01:00
|
|
|
}
|
|
|
|
|
2007-11-20 19:51:07 +01:00
|
|
|
/**
|
|
|
|
* establish the root OS directory (portable paths are relative to it)
|
|
|
|
*
|
|
|
|
* @param argv0 the value of argv[0] (used to determine the location
|
|
|
|
* of the executable in case sys_get_executable_path fails). note that
|
|
|
|
* the current directory cannot be used because it's not set when
|
|
|
|
* starting via batch file.
|
2007-12-20 21:14:21 +01:00
|
|
|
* @param relativePath root directory relative to the executable's directory.
|
2007-11-20 19:51:07 +01:00
|
|
|
* the value is considered trusted since it will typically be hard-coded.
|
|
|
|
*
|
|
|
|
* example: executable in "$install_dir/system"; desired root dir is
|
|
|
|
* "$install_dir/data" => rel_path = "../data".
|
|
|
|
*
|
|
|
|
* can only be called once unless path_ResetRootDir is called.
|
|
|
|
**/
|
2007-12-20 21:14:21 +01:00
|
|
|
LIB_API LibError path_SetRoot(const char* argv0, const char* relativePath);
|
2007-11-10 14:39:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reset root directory that was previously established via path_SetRoot.
|
|
|
|
*
|
|
|
|
* this function avoids the security complaint that would be raised if
|
|
|
|
* path_SetRoot is called twice; it is provided for the
|
|
|
|
* legitimate application of a self-test setUp()/tearDown().
|
|
|
|
**/
|
2007-12-20 21:14:21 +01:00
|
|
|
LIB_API void path_ResetRootDir();
|
2007-11-20 19:51:07 +01:00
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
// note: path_MakeAbsolute has been replaced by Path::external_directory_string.
|
2007-11-20 19:51:07 +01:00
|
|
|
|
2007-11-10 14:39:45 +01:00
|
|
|
#endif // #ifndef INCLUDED_PATH
|