2008-09-18 03:15:49 +00:00
|
|
|
#pragma once
|
2021-04-12 06:34:26 +00:00
|
|
|
#include <stdint.h>
|
2022-10-03 08:04:42 +00:00
|
|
|
#include <string>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2016-01-12 06:52:59 +00:00
|
|
|
class CPath
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2021-03-16 23:04:56 +00:00
|
|
|
// Enums
|
2008-09-18 03:15:49 +00:00
|
|
|
public:
|
2022-10-03 08:04:42 +00:00
|
|
|
enum DIR_CURRENT_DIRECTORY
|
|
|
|
{
|
|
|
|
CURRENT_DIRECTORY = 1
|
|
|
|
};
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
enum DIR_MODULE_DIRECTORY
|
|
|
|
{
|
|
|
|
MODULE_DIRECTORY = 2
|
|
|
|
};
|
|
|
|
enum DIR_MODULE_FILE
|
|
|
|
{
|
|
|
|
MODULE_FILE = 3
|
|
|
|
};
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2022-10-03 08:04:42 +00:00
|
|
|
enum
|
2016-04-12 07:53:40 +00:00
|
|
|
{
|
2022-10-03 08:04:42 +00:00
|
|
|
FIND_ATTRIBUTE_ALLFILES = 0xFFFF, // Search include all files
|
|
|
|
FIND_ATTRIBUTE_FILES = 0x0000, // File can be read or written to without restriction
|
|
|
|
FIND_ATTRIBUTE_SUBDIR = 0x0010, // Subdirectories
|
|
|
|
};
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Attributes
|
2016-01-12 06:52:59 +00:00
|
|
|
private:
|
2022-10-03 08:04:42 +00:00
|
|
|
std::string m_strPath;
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
void * m_hFindFile;
|
2016-01-12 06:52:59 +00:00
|
|
|
static void * m_hInst;
|
2016-04-28 07:28:22 +00:00
|
|
|
#else
|
|
|
|
void * m_OpenedDir;
|
|
|
|
std::string m_FindWildcard;
|
|
|
|
#endif
|
|
|
|
uint32_t m_dwFindFileAttributes;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
public:
|
2021-03-16 23:04:56 +00:00
|
|
|
// Methods
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Construction / destruction
|
2016-01-12 06:52:59 +00:00
|
|
|
CPath();
|
2022-10-03 08:04:42 +00:00
|
|
|
CPath(const CPath & rPath);
|
2015-10-25 11:10:54 +00:00
|
|
|
CPath(const char * lpszPath);
|
2016-01-12 06:52:59 +00:00
|
|
|
CPath(const char * lpszPath, const char * NameExten);
|
2022-10-03 08:04:42 +00:00
|
|
|
CPath(const std::string & strPath);
|
|
|
|
CPath(const std::string & strPath, const char * NameExten);
|
|
|
|
CPath(const std::string & strPath, const std::string & NameExten);
|
2016-01-12 06:52:59 +00:00
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
CPath(DIR_CURRENT_DIRECTORY sdt, const char * NameExten = nullptr);
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2021-04-12 11:35:39 +00:00
|
|
|
CPath(DIR_MODULE_DIRECTORY sdt, const char * NameExten = nullptr);
|
2016-01-12 06:52:59 +00:00
|
|
|
CPath(DIR_MODULE_FILE sdt);
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2016-01-12 06:52:59 +00:00
|
|
|
virtual ~CPath();
|
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Operators
|
2022-10-03 08:04:42 +00:00
|
|
|
CPath & operator=(const CPath & rPath);
|
|
|
|
CPath & operator=(const char * lpszPath);
|
|
|
|
CPath & operator=(const std::string & strPath);
|
|
|
|
bool operator==(const CPath & rPath) const;
|
|
|
|
bool operator!=(const CPath & rPath) const;
|
2015-10-25 11:10:54 +00:00
|
|
|
operator const char *() const;
|
2022-10-03 08:04:42 +00:00
|
|
|
operator const std::string &()
|
|
|
|
{
|
|
|
|
return m_strPath;
|
|
|
|
}
|
2016-01-12 06:52:59 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Get path components
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetDriveDirectory(std::string & rDriveDirectory) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetDriveDirectory(void) const;
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetDirectory(std::string & rDirectory) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetDirectory(void) const;
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetName(std::string & rName) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetName(void) const;
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetNameExtension(std::string & rNameExtension) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetNameExtension(void) const;
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetExtension(std::string & rExtension) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetExtension(void) const;
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetLastDirectory(std::string & rDirectory) const;
|
2016-01-12 06:52:59 +00:00
|
|
|
std::string GetLastDirectory(void) const;
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetFullyQualified(std::string & rFullyQualified) const;
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetComponents(std::string * pDrive = nullptr, std::string * pDirectory = nullptr, std::string * pName = nullptr, std::string * pExtension = nullptr) const;
|
2016-04-28 07:28:22 +00:00
|
|
|
#else
|
2022-10-03 08:04:42 +00:00
|
|
|
void GetComponents(std::string * pDirectory = nullptr, std::string * pName = nullptr, std::string * pExtension = nullptr) const;
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2021-03-16 23:04:56 +00:00
|
|
|
// Get other state
|
2022-10-03 08:04:42 +00:00
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return m_strPath.empty();
|
|
|
|
}
|
2016-01-12 06:52:59 +00:00
|
|
|
bool IsRelative() const;
|
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Set path components
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-10-25 11:10:54 +00:00
|
|
|
void SetDrive(char chDrive);
|
|
|
|
void SetDriveDirectory(const char * lpszDriveDirectory);
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2015-10-25 11:10:54 +00:00
|
|
|
void SetDirectory(const char * lpszDirectory, bool bEnsureAbsolute = false);
|
|
|
|
void SetName(const char * lpszName);
|
2008-09-18 03:15:49 +00:00
|
|
|
void SetName(int iName);
|
2015-10-25 11:10:54 +00:00
|
|
|
void SetNameExtension(const char * lpszNameExtension);
|
|
|
|
void SetExtension(const char * lpszExtension);
|
2008-09-18 03:15:49 +00:00
|
|
|
void SetExtension(int iExtension);
|
2016-01-12 06:52:59 +00:00
|
|
|
void AppendDirectory(const char * lpszSubDirectory);
|
2022-10-03 08:04:42 +00:00
|
|
|
void UpDirectory(std::string * pLastDirectory = nullptr);
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
void SetComponents(const char * lpszDrive, const char * lpszDirectory, const char * lpszName, const char * lpszExtension);
|
2016-04-28 07:28:22 +00:00
|
|
|
#else
|
|
|
|
void SetComponents(const char * lpszDirectory, const char * lpszName, const char * lpszExtension);
|
|
|
|
#endif
|
2021-03-16 23:04:56 +00:00
|
|
|
// Set whole path
|
2022-10-03 08:04:42 +00:00
|
|
|
void Empty()
|
|
|
|
{
|
|
|
|
m_strPath.erase();
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
void CurrentDirectory();
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2008-09-18 03:15:49 +00:00
|
|
|
void Module();
|
2016-01-12 06:52:59 +00:00
|
|
|
void Module(void * hInstance);
|
2008-09-18 03:15:49 +00:00
|
|
|
void ModuleDirectory();
|
2016-01-12 06:52:59 +00:00
|
|
|
void ModuleDirectory(void * hInstance);
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Directory information
|
2015-10-25 11:10:54 +00:00
|
|
|
bool IsDirectory() const;
|
2016-01-12 06:52:59 +00:00
|
|
|
bool DirectoryExists() const;
|
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// File information
|
2022-10-03 08:04:42 +00:00
|
|
|
bool IsFile() const
|
|
|
|
{
|
|
|
|
return !IsDirectory();
|
|
|
|
}
|
2018-11-18 01:06:02 +00:00
|
|
|
bool Exists() const;
|
2017-01-20 23:31:09 +00:00
|
|
|
#ifdef _WIN32
|
2018-11-18 01:06:02 +00:00
|
|
|
bool SelectFile(void * hwndOwner, const char * InitialDir, const char * FileFilter, bool FileMustExist);
|
2017-01-20 23:31:09 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Directory operations
|
2016-01-12 06:52:59 +00:00
|
|
|
bool DirectoryCreate(bool bCreateIntermediates = true);
|
|
|
|
bool ChangeDirectory();
|
2022-10-03 08:04:42 +00:00
|
|
|
void NormalizePath(CPath BaseDir);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// File operations
|
2016-01-12 06:52:59 +00:00
|
|
|
bool Delete(bool bEvenIfReadOnly = true) const;
|
|
|
|
bool CopyTo(const char * lpcszTargetFile, bool bOverwrite = true);
|
|
|
|
bool MoveTo(const char * lpcszTargetFile, bool bOverwrite = true);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2021-03-16 23:04:56 +00:00
|
|
|
// Finders
|
2016-01-12 06:52:59 +00:00
|
|
|
bool FindFirst(uint32_t dwAttributes = 0);
|
|
|
|
bool FindNext();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2016-01-12 06:52:59 +00:00
|
|
|
// Helpers
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-12 06:52:59 +00:00
|
|
|
static void SethInst(void * hInst);
|
|
|
|
static void * GethInst();
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2009-12-28 22:22:50 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
private:
|
2021-03-16 23:04:56 +00:00
|
|
|
// Setup and cleanup
|
2018-02-19 06:43:42 +00:00
|
|
|
inline void Init();
|
|
|
|
inline void Exit();
|
|
|
|
|
2016-01-12 06:52:59 +00:00
|
|
|
bool AttributesMatch(uint32_t dwTargetAttributes, uint32_t dwFileAttributes);
|
|
|
|
|
2022-10-03 08:04:42 +00:00
|
|
|
void cleanPathString(std::string & rDirectory) const;
|
|
|
|
void StripLeadingChar(std::string & rText, char chLeading) const;
|
|
|
|
void StripLeadingBackslash(std::string & Directory) const;
|
|
|
|
void StripTrailingChar(std::string & rText, char chTrailing) const;
|
|
|
|
void StripTrailingBackslash(std::string & rDirectory) const;
|
|
|
|
void EnsureTrailingBackslash(std::string & Directory) const;
|
|
|
|
void EnsureLeadingBackslash(std::string & Directory) const;
|
2016-04-28 07:28:22 +00:00
|
|
|
#ifndef _WIN32
|
2022-10-03 08:04:42 +00:00
|
|
|
bool wildcmp(const char * wild, const char * string);
|
2016-04-28 07:28:22 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|