2020-03-22 00:45:04 +01:00
|
|
|
#pragma once
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Common.hpp"
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-06-18 19:27:51 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the full path of file.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
Buffer GetRealFilePath(const SQChar * path);
|
2016-06-18 19:27:51 +02:00
|
|
|
|
2016-03-11 03:14:28 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* This class represents filesystem paths in a platform-independent manner.
|
|
|
|
*/
|
|
|
|
class SysPath
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef std::vector< String > StrVec; // Directory list.
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Styles of directories to expect when parsing or to export.
|
|
|
|
*/
|
|
|
|
enum struct Style
|
|
|
|
{
|
|
|
|
Unix = 0,
|
|
|
|
Windows,
|
|
|
|
Native,
|
|
|
|
Guess,
|
|
|
|
Dynamic
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates an empty relative path.
|
|
|
|
*/
|
|
|
|
SysPath();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates an empty absolute or relative path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
explicit SysPath(bool absolute);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in native format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
explicit SysPath(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(const SQChar * path, int32_t style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(const SQChar * path, Style style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in native format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
explicit SysPath(const Buffer & path, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(const Buffer & path, Style style, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in native format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
explicit SysPath(const String & path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a string.
|
|
|
|
*/
|
|
|
|
SysPath(const String & path, Style style);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a file name. The parent path is expected to reference
|
|
|
|
* a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(const SysPath & parent, const SQChar * name);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a file name. The parent path is expected to reference
|
|
|
|
* a directory.
|
|
|
|
*/
|
|
|
|
SysPath(const SysPath & parent, const String & name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a relative path. The parent path is expected
|
|
|
|
* to reference a directory. The relative path is appended to the parent path.
|
|
|
|
*/
|
|
|
|
SysPath(const SysPath & parent, const SysPath & relative);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(const SysPath & o) = default;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath(SysPath && o) noexcept = default;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
~SysPath() = default;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & operator = (const SysPath & o) = default;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & operator = (SysPath && o) noexcept = default;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path in native format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & operator = (const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path in native format.
|
|
|
|
*/
|
|
|
|
SysPath & operator = (const String & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Equality comparison.
|
|
|
|
*/
|
|
|
|
bool operator == (const SysPath & o) const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Inequality comparison.
|
|
|
|
*/
|
|
|
|
bool operator != (const SysPath & o) const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Implicit conversion to boolean operator.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
operator bool () const; // NOLINT(google-explicit-constructor)
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the n'th directory in the directory list. If n == depth(), returns the file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
const String & operator [] (uint32_t n) const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to compare two instances of this type.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD int32_t Cmp(const SysPath & o) const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Object ToString() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Swaps the path with another one.
|
|
|
|
*/
|
|
|
|
void Swap(SysPath & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Clears all components.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path in native format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const SQChar * path, int32_t style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const SQChar * path, Style style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path in native format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const Buffer & path, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const Buffer & path, Style style, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path in native format.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(const String & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(const String & path, Style style);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a file name. The parent path is expected to reference
|
|
|
|
* a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Assign(const SysPath & parent, const SQChar * name);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a file name. The parent path is expected to reference
|
|
|
|
* a directory.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(const SysPath & parent, const String & name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a relative path. The parent path is expected
|
|
|
|
* to reference a directory. The relative path is appended to the parent path.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(const SysPath & parent, const SysPath & relative);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy the components from another path.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(const SysPath & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move the components of another path into this instance.
|
|
|
|
*/
|
|
|
|
SysPath & Assign(SysPath && path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & AssignDir(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & AssignDir(const SQChar * path, int32_t style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & AssignDir(const SQChar * path, Style style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & AssignDir(const Buffer & path, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & AssignDir(const Buffer & path, Style style, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
|
|
|
SysPath & AssignDir(const String & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* The resulting path always refers to a directory and the filename part is empty.
|
|
|
|
*/
|
|
|
|
SysPath & AssignDir(const String & path, Style style);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns a string containing the path in native format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Buffer ToBuffer() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns a string containing the path in the given format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Buffer ToBuffer(Style style) const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns a string containing the path in the given format.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Object ToStr(int32_t style) const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Assigns a string containing a path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void FromString(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the path is absolute.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsAbsolute() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return m_Absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the path is relative.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsRelative() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return !m_Absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the path references a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsDirectory() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return m_Name.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the path references a file.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool IsFile() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return !m_Name.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the path Does not contain a drive, directories or file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD bool Empty() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
2016-03-11 19:52:00 +01:00
|
|
|
return (m_Dirs.empty() && m_Name.empty() && m_Drive == 0);
|
2016-03-11 03:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* If the path contains a file name, the file name is appended to the directory list and cleared.
|
|
|
|
*/
|
|
|
|
SysPath & MakeDirectory();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* If the path contains no file name, the last directory becomes the file name.
|
|
|
|
*/
|
|
|
|
SysPath & MakeFile();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Makes the path refer to its parent.
|
|
|
|
*/
|
|
|
|
SysPath & MakeParent();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Makes the path absolute if it is relative. The current working directory is taken
|
|
|
|
* as base directory.
|
|
|
|
*/
|
|
|
|
SysPath & MakeAbsolute();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Makes the path absolute if it is relative. The given path is taken as base.
|
|
|
|
*/
|
|
|
|
SysPath & MakeAbsolute(const SysPath & base);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Makes the path absolute if it is relative. The given path is taken as base.
|
|
|
|
*/
|
|
|
|
SysPath & MakeAbsolute(SysPath && base);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Appends the given path.
|
|
|
|
*/
|
|
|
|
SysPath & Append(const SysPath & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Appends the given path.
|
|
|
|
*/
|
|
|
|
SysPath & Append(SysPath && path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Append(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Append(const SQChar * path, int32_t style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Append(const SQChar * path, Style style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Append(const Buffer & path, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Append(const Buffer & path, Style style, int32_t size = -1);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
|
|
|
SysPath & Append(const String & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse the given string and append the resulted path.
|
|
|
|
*/
|
|
|
|
SysPath & Append(const String & path, Style style);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the drive letter.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD CharT GetDrive() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return m_Drive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modifies the drive letter.
|
|
|
|
*/
|
|
|
|
void SetDrive(CharT drive)
|
|
|
|
{
|
|
|
|
m_Drive = drive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the number of directories in the directory list.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD uint32_t Depth() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return static_cast< uint32_t >(m_Dirs.size());
|
2016-03-11 03:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the n'th directory in the directory list. If n == depth(), returns the file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD const String & Directory(uint32_t n) const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Adds a directory to the directory list.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & Push(const SQChar * dir);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Adds a directory to the directory list.
|
|
|
|
*/
|
|
|
|
SysPath & Push(const String & dir);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Adds a directory to the directory list.
|
|
|
|
*/
|
|
|
|
SysPath & Push(String && dir);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Removes the last directory from the directory list.
|
|
|
|
*/
|
|
|
|
SysPath & PopBack();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Removes the first directory from the directory list.
|
|
|
|
*/
|
|
|
|
SysPath & PopFront();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set the specified file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & SetFilename(const SQChar * name);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set the specified file name.
|
|
|
|
*/
|
|
|
|
SysPath & SetFilename(const String & name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set the specified file name.
|
|
|
|
*/
|
|
|
|
SysPath & SetFilename(String && name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieves the file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD const String & GetFilename() const
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
return m_Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Set the specified file name.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void SqSetFilename(const SQChar * name)
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
SetFilename(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the basename part of the file name and does not change the extension.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & SetBasename(const SQChar * name);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the basename part of the file name and does not change the extension.
|
|
|
|
*/
|
|
|
|
SysPath & SetBasename(const String & name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the basename part of the file name and does not change the extension.
|
|
|
|
*/
|
|
|
|
SysPath & SetBasename(String && name);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the basename (the file name without extension) of the path.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD String GetBasename() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the basename part of the file name and does not change the extension.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void SqSetBasename(const SQChar * name)
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
SetBasename(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the file name extension.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SysPath & SetExtension(const SQChar * ext);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the file name extension.
|
|
|
|
*/
|
|
|
|
SysPath & SetExtension(const String & ext);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the file name extension.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD String GetExtension() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Sets the file name extension.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void SqSetExtension(const SQChar * ext)
|
2016-03-11 03:14:28 +01:00
|
|
|
{
|
|
|
|
SetExtension(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns a pointer to the internal name string where the extension starts.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD const SQChar * GetExtensionC() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns a path referring to the path's directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD SysPath Parent() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Resolves the given path against the current one. If the given path is absolute, it replaces
|
|
|
|
* the current one. Otherwise, the relative path is appended to the current path.
|
|
|
|
*/
|
|
|
|
SysPath & Resolve(const SysPath & path);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse a path using the unix standards.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void ParseUnix(const SQChar * pos, const SQChar * end);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse a path using the windows standards.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void ParseWindows(const SQChar * pos, const SQChar * end);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse a path and expect combined windows and unix styles.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void ParseDynamic(const SQChar * pos, const SQChar * end);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Parse a path and try to detect it's type automatically.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
void ParseGuess(const SQChar * pos, const SQChar * end);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Build a path string using the Unix conventions.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Buffer BuildUnix() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Build a path string using the Windows conventions.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD Buffer BuildWindows() const;
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
StrVec m_Dirs; /* The list of directories that form the path. */
|
|
|
|
String m_Name; /* The file name if one was specified. */
|
|
|
|
CharT m_Drive; /* The drive letter if one was specified. */
|
|
|
|
bool m_Absolute; /* Whether this path is an absolute path. */
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the platform's path name separator, which separates the components (names) in a path.
|
|
|
|
*/
|
|
|
|
static CharT Separator()
|
|
|
|
{
|
2020-08-16 18:18:43 +02:00
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
2016-03-11 03:14:28 +01:00
|
|
|
return '\\';
|
|
|
|
#else
|
|
|
|
return '/';
|
2020-08-16 18:18:43 +02:00
|
|
|
#endif // SQMOD_OS_WINDOWS
|
2016-03-11 03:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the platform's path separator, which separates single paths in a list of paths.
|
|
|
|
*/
|
|
|
|
static CharT PathSeparator()
|
|
|
|
{
|
2020-08-16 18:18:43 +02:00
|
|
|
#ifdef SQMOD_OS_WINDOWS
|
2016-03-11 03:14:28 +01:00
|
|
|
return ';';
|
|
|
|
#else
|
|
|
|
return ':';
|
2020-08-16 18:18:43 +02:00
|
|
|
#endif // SQMOD_OS_WINDOWS
|
2016-03-11 03:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path referring to a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath ForDirectory(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path referring to a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath ForDirectory(const SQChar * path, int32_t style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path referring to a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath ForDirectory(const SQChar * path, Style style);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path referring to a directory.
|
|
|
|
*/
|
|
|
|
static SysPath ForDirectory(const String & path);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path referring to a directory.
|
|
|
|
*/
|
|
|
|
static SysPath ForDirectory(const String & path, Style style);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Expands all environment variables contained in the path. On Unix, a tilde as first character
|
|
|
|
* in the path is replaced with the path to user's home directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath Expand(const SQChar * path);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Expands all environment variables contained in the path.
|
|
|
|
*/
|
|
|
|
static SysPath Expand(const String & path)
|
|
|
|
{
|
|
|
|
return Expand(path.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the user's home directory.
|
|
|
|
*/
|
|
|
|
static SysPath Home();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the user's config directory.
|
|
|
|
*/
|
|
|
|
static SysPath ConfigHome();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the user's data directory.
|
|
|
|
*/
|
|
|
|
static SysPath DataHome();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the user's temp directory.
|
|
|
|
*/
|
|
|
|
static SysPath TempHome();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the user's temp directory.
|
|
|
|
*/
|
|
|
|
static SysPath CacheHome();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the current working directory.
|
|
|
|
*/
|
|
|
|
static SysPath Working();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the temporary directory.
|
|
|
|
*/
|
|
|
|
static SysPath Temp();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Returns the system-wide config directory.
|
2016-03-11 03:14:28 +01:00
|
|
|
*/
|
|
|
|
static SysPath Config();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the system directory.
|
|
|
|
*/
|
|
|
|
static SysPath System();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the name of the null device.
|
|
|
|
*/
|
|
|
|
static SysPath Null();
|
|
|
|
|
2016-09-03 23:49:32 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the real path to the specified file or directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath Real(const SQChar * path);
|
2016-09-03 23:49:32 +02:00
|
|
|
|
2016-03-11 03:14:28 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path from a parent path and a file name. The parent path is expected to reference
|
|
|
|
* a directory.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath With(const SysPath & parent, const SQChar * name);
|
2016-03-11 03:14:28 +01:00
|
|
|
|
2016-05-23 02:34:35 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in unix format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath MakeUnix(const SQChar * path);
|
2016-05-23 02:34:35 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in windows format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath MakeWindows(const SQChar * path);
|
2016-05-23 02:34:35 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in native format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath MakeNative(const SQChar * path);
|
2016-05-23 02:34:35 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in and guess the format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath MakeGuess(const SQChar * path);
|
2016-05-23 02:34:35 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Creates a path in dynamic format from a string.
|
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
static SysPath MakeDynamic(const SQChar * path);
|
2019-08-14 03:33:18 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Makes sure all separators from a path are the same.
|
|
|
|
*/
|
|
|
|
static String NormalizePath(SQInteger s, StackStrF & val);
|
2016-03-11 03:14:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|