2008-09-18 03:15:49 +00:00
|
|
|
#pragma once
|
2015-10-25 11:10:54 +00:00
|
|
|
#include <string>
|
|
|
|
#include "stdtypes.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
class CPathException
|
|
|
|
{
|
|
|
|
public:
|
2015-10-25 11:10:54 +00:00
|
|
|
uint32_t m_dwErrorCode;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
public:
|
2015-10-25 11:10:54 +00:00
|
|
|
CPathException(uint32_t code =0): m_dwErrorCode(code) {}
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CPath
|
|
|
|
{
|
|
|
|
//Enums
|
|
|
|
public:
|
|
|
|
|
2009-12-28 22:22:50 +00:00
|
|
|
enum DIR_CURRENT_DIRECTORY { CURRENT_DIRECTORY = 1 };
|
2015-02-16 06:13:37 +00:00
|
|
|
enum DIR_MODULE_DIRECTORY { MODULE_DIRECTORY = 2 };
|
|
|
|
enum DIR_MODULE_FILE { MODULE_FILE = 3 };
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
enum { _A_ALLFILES = 0xFFFF }; /* Search Include all files */
|
|
|
|
|
|
|
|
//Attributes
|
|
|
|
private:
|
|
|
|
|
2015-10-25 11:10:54 +00:00
|
|
|
std::string m_strPath;
|
|
|
|
uint32_t m_dwFindFileAttributes;
|
|
|
|
void * m_hFindFile;
|
|
|
|
static void * m_hInst;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
//Methods
|
|
|
|
|
|
|
|
//Construction / destruction
|
|
|
|
CPath();
|
|
|
|
CPath(const CPath& rPath);
|
2015-10-25 11:10:54 +00:00
|
|
|
CPath(const char * lpszPath);
|
|
|
|
CPath(const char * lpszPath, const char * NameExten);
|
|
|
|
CPath(const char * lpszPath, const std::string & NameExten);
|
|
|
|
CPath(const std::string& strPath);
|
|
|
|
CPath(const std::string& strPath, const char * NameExten);
|
|
|
|
CPath(const std::string& strPath, const std::string& NameExten);
|
|
|
|
|
|
|
|
CPath(DIR_CURRENT_DIRECTORY sdt, const char * NameExten = NULL);
|
|
|
|
CPath(DIR_MODULE_DIRECTORY sdt, const char * NameExten = NULL);
|
2009-12-28 22:22:50 +00:00
|
|
|
CPath(DIR_MODULE_FILE sdt);
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
virtual ~CPath();
|
|
|
|
|
|
|
|
//Setup & Cleanup
|
|
|
|
inline void Init();
|
|
|
|
inline void Exit();
|
|
|
|
|
|
|
|
//Operators
|
|
|
|
CPath& operator = (const CPath& rPath);
|
2015-10-25 11:10:54 +00:00
|
|
|
CPath& operator = (const char * lpszPath);
|
|
|
|
CPath& operator = (const std::string & strPath);
|
|
|
|
bool operator == (const CPath& rPath) const;
|
|
|
|
bool operator != (const CPath& rPath) const;
|
|
|
|
operator const char *() const;
|
|
|
|
operator std::string &() { return m_strPath; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Get path components
|
2015-10-25 11:10:54 +00:00
|
|
|
void GetDriveDirectory(std::string & rDriveDirectory) const;
|
|
|
|
std::string GetDriveDirectory(void) const;
|
|
|
|
void GetDirectory(std::string& rDirectory) const;
|
|
|
|
std::string GetDirectory(void) const;
|
|
|
|
void GetName(std::string& rName) const;
|
|
|
|
std::string GetName(void) const;
|
|
|
|
void GetNameExtension(std::string& rNameExtension) const;
|
|
|
|
std::string GetNameExtension(void) const;
|
|
|
|
void GetExtension(std::string& rExtension) const;
|
|
|
|
std::string GetExtension(void) const;
|
|
|
|
void GetCurrentDirectory(std::string& rDrive) const;
|
|
|
|
std::string GetCurrentDirectory(void) const;
|
|
|
|
void GetFullyQualified(std::string& rFullyQualified) const;
|
|
|
|
void GetComponents(std::string* pDrive = NULL,
|
|
|
|
std::string* pDirectory =NULL,
|
|
|
|
std::string* pName = NULL,
|
|
|
|
std::string* pExtension = NULL) const;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Get other state
|
2015-10-25 11:10:54 +00:00
|
|
|
bool IsEmpty() const { return m_strPath.empty(); }
|
|
|
|
bool IsRelative() const;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Set path components
|
2015-10-25 11:10:54 +00:00
|
|
|
void SetDrive(char chDrive);
|
|
|
|
void SetDriveDirectory(const char * lpszDriveDirectory);
|
|
|
|
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);
|
2015-10-25 11:10:54 +00:00
|
|
|
void AppendDirectory(const char * lpszSubDirectory);
|
|
|
|
void UpDirectory(std::string* pLastDirectory = NULL);
|
|
|
|
void SetComponents(const char * lpszDrive,
|
|
|
|
const char * lpszDirectory,
|
|
|
|
const char * lpszName,
|
|
|
|
const char * lpszExtension);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Set whole path
|
|
|
|
void Empty() { m_strPath.erase(); }
|
|
|
|
void CurrentDirectory();
|
|
|
|
void Module();
|
2015-10-25 11:10:54 +00:00
|
|
|
void Module(void * hInstance);
|
2008-09-18 03:15:49 +00:00
|
|
|
void ModuleDirectory();
|
2015-10-25 11:10:54 +00:00
|
|
|
void ModuleDirectory(void * hInstance);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Directory information
|
2015-10-25 11:10:54 +00:00
|
|
|
bool IsDirectory() const;
|
|
|
|
bool DirectoryExists() const;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//File Information
|
2015-10-25 11:10:54 +00:00
|
|
|
bool IsFile() const { return !IsDirectory(); }
|
|
|
|
bool Exists() const;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Directory operations
|
2015-10-25 11:10:54 +00:00
|
|
|
bool DirectoryCreate(bool bCreateIntermediates = true);
|
|
|
|
bool ChangeDirectory();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//File operations
|
2015-10-25 11:10:54 +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
|
|
|
|
|
|
|
//Finders
|
2015-10-25 11:10:54 +00:00
|
|
|
bool FindFirst(uint32_t dwAttributes = 0);
|
|
|
|
bool FindNext();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
// Helpers
|
2015-10-25 11:10:54 +00:00
|
|
|
static void SethInst(void * hInst);
|
|
|
|
static void * GethInst();
|
2009-12-28 22:22:50 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
private:
|
2015-10-25 11:10:54 +00:00
|
|
|
bool AttributesMatch(uint32_t dwTargetAttributes, uint32_t dwFileAttributes);
|
|
|
|
|
|
|
|
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;
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|