[Project64] Remove tchar from path

This commit is contained in:
zilmar 2016-01-12 23:19:50 +11:00
parent 7b747cb5e0
commit 0a45420b4b
2 changed files with 110 additions and 95 deletions

View File

@ -9,18 +9,11 @@
// Constants // Constants
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
const char * const DLL_EXTENSION = "dll"; const char DRIVE_DELIMITER = ':';
const char * const INI_EXTENSION = "ini";
const char * const EXE_EXTENSION = "exe";
const char * const WILD_NAME_EXTENSION = "*.*";
const TCHAR WILD_ONE = '?';
const TCHAR WILD_ANY = '*';
const char * const WILD_SET = "?*";
const char * const DIR_DOUBLEDELIM = "\\\\"; const char * const DIR_DOUBLEDELIM = "\\\\";
const TCHAR DRIVE_DELIMITER = ':'; const char DIRECTORY_DELIMITER = '\\';
const TCHAR DIRECTORY_DELIMITER = '\\'; const char DIRECTORY_DELIMITER2 = '/';
const TCHAR EXTENSION_DELIMITER = '.'; const char EXTENSION_DELIMITER = '.';
const TCHAR DIRECTORY_DELIMITER2 = '/';
void * CPath::m_hInst = NULL; void * CPath::m_hInst = NULL;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -174,7 +167,9 @@ bool CPath::operator !=(const CPath& rPath) const
CPath& CPath::operator =(const CPath& rPath) CPath& CPath::operator =(const CPath& rPath)
{ {
if (this != &rPath) if (this != &rPath)
{
m_strPath = rPath.m_strPath; m_strPath = rPath.m_strPath;
}
return *this; return *this;
} }
@ -248,46 +243,55 @@ CPath::CPath(DIR_MODULE_FILE /*sdt*/)
// Do not rely on pNames being <= 8 characters, extensions // Do not rely on pNames being <= 8 characters, extensions
// being <= 3 characters, or drives being 1 character // being <= 3 characters, or drives being 1 character
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::GetComponents(std::string* pDrive, void CPath::GetComponents(std::string* pDrive, std::string* pDirectory, std::string* pName, std::string* pExtension) const
std::string* pDirectory,
std::string* pName,
std::string* pExtension) const
{ {
TCHAR buff_drive[_MAX_DRIVE + 1]; char buff_drive[_MAX_DRIVE + 1];
TCHAR buff_dir[_MAX_DIR + 1]; char buff_dir[_MAX_DIR + 1];
TCHAR buff_name[_MAX_FNAME + 1]; char buff_name[_MAX_FNAME + 1];
TCHAR buff_ext[_MAX_EXT + 1]; char buff_ext[_MAX_EXT + 1];
ZeroMemory(buff_drive, sizeof(buff_drive)); ZeroMemory(buff_drive, sizeof(buff_drive));
ZeroMemory(buff_dir, sizeof(buff_dir)); ZeroMemory(buff_dir, sizeof(buff_dir));
ZeroMemory(buff_name, sizeof(buff_name)); ZeroMemory(buff_name, sizeof(buff_name));
ZeroMemory(buff_ext, sizeof(buff_ext)); ZeroMemory(buff_ext, sizeof(buff_ext));
_splitpath(m_strPath.c_str(), _splitpath(m_strPath.c_str(), pDrive ? buff_drive : NULL, pDirectory ? buff_dir : NULL, pName ? buff_name : NULL, pExtension ? buff_ext : NULL);
pDrive ? buff_drive : NULL,
pDirectory ? buff_dir : NULL,
pName ? buff_name : NULL,
pExtension ? buff_ext : NULL);
if (pDrive) if (pDrive)
{
*pDrive = buff_drive; *pDrive = buff_drive;
}
if (pDirectory) if (pDirectory)
{
*pDirectory = buff_dir; *pDirectory = buff_dir;
}
if (pName) if (pName)
{
*pName = buff_name; *pName = buff_name;
}
if (pExtension) if (pExtension)
{
*pExtension = buff_ext; *pExtension = buff_ext;
}
// DOS's _splitpath returns "d:", we return "d" // DOS's _splitpath returns "d:", we return "d"
if (pDrive) if (pDrive)
{
StripTrailingChar(*pDrive, DRIVE_DELIMITER); StripTrailingChar(*pDrive, DRIVE_DELIMITER);
}
// DOS's _splitpath returns "\dir\subdir\", we return "\dir\subdir" // DOS's _splitpath returns "\dir\subdir\", we return "\dir\subdir"
if (pDirectory) if (pDirectory)
{
StripTrailingBackslash(*pDirectory); StripTrailingBackslash(*pDirectory);
}
// DOS's _splitpath returns ".ext", we return "ext" // DOS's _splitpath returns ".ext", we return "ext"
if (pExtension) if (pExtension)
{
StripLeadingChar(*pExtension, EXTENSION_DELIMITER); StripLeadingChar(*pExtension, EXTENSION_DELIMITER);
} }
}
//------------------------------------------------------------- //-------------------------------------------------------------
// Task : Get drive and directory from path // Task : Get drive and directory from path
@ -323,7 +327,7 @@ void CPath::GetDirectory(std::string& rDirectory) const
std::string CPath::GetDirectory(void) const std::string CPath::GetDirectory(void) const
{ {
std::string rDirectory; std::string rDirectory;
GetComponents(NULL, &rDirectory); GetDirectory(rDirectory);
return rDirectory; return rDirectory;
} }
@ -362,7 +366,7 @@ void CPath::GetName(std::string& rName) const
std::string CPath::GetName(void) const std::string CPath::GetName(void) const
{ {
std::string rName; std::string rName;
GetComponents(NULL, NULL, &rName); GetName(rName);
return rName; return rName;
} }
@ -377,7 +381,7 @@ void CPath::GetExtension(std::string& rExtension) const
std::string CPath::GetExtension(void) const std::string CPath::GetExtension(void) const
{ {
std::string rExtension; std::string rExtension;
GetComponents(NULL, NULL, NULL, &rExtension); GetExtension(rExtension);
return rExtension; return rExtension;
} }
@ -414,7 +418,7 @@ std::string CPath::GetLastDirectory(void) const
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::GetFullyQualified(std::string& rFullyQualified) const void CPath::GetFullyQualified(std::string& rFullyQualified) const
{ {
TCHAR buff_fullname[MAX_PATH]; char buff_fullname[MAX_PATH];
memset(buff_fullname, 0, sizeof(buff_fullname)); memset(buff_fullname, 0, sizeof(buff_fullname));
@ -442,12 +446,9 @@ bool CPath::IsRelative() const
//------------------------------------------------------------- //-------------------------------------------------------------
// Task : Set path components // Task : Set path components
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetComponents(const char * lpszDrive, void CPath::SetComponents(const char * lpszDrive, const char * lpszDirectory, const char * lpszName, const char * lpszExtension)
const char * lpszDirectory,
const char * lpszName,
const char * lpszExtension)
{ {
TCHAR buff_fullname[MAX_PATH]; char buff_fullname[MAX_PATH];
memset(buff_fullname, 0, sizeof(buff_fullname)); memset(buff_fullname, 0, sizeof(buff_fullname));
@ -460,7 +461,7 @@ void CPath::SetComponents(const char * lpszDrive,
//------------------------------------------------------------- //-------------------------------------------------------------
// Task : Set path's drive // Task : Set path's drive
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetDrive(TCHAR chDrive) void CPath::SetDrive(char chDrive)
{ {
stdstr_f Drive("%c", chDrive); stdstr_f Drive("%c", chDrive);
std::string Directory; std::string Directory;
@ -474,17 +475,22 @@ void CPath::SetDrive(TCHAR chDrive)
//------------------------------------------------------------- //-------------------------------------------------------------
// Task : Set path's directory // Task : Set path's directory
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetDirectory(const char * lpszDirectory, bool bEnsureAbsolute /*= FALSE*/) void CPath::SetDirectory(const char * lpszDirectory, bool bEnsureAbsolute /*= false*/)
{ {
std::string Drive;
std::string Directory = lpszDirectory; std::string Directory = lpszDirectory;
std::string Name; std::string Name;
std::string Extension; std::string Extension;
if (bEnsureAbsolute) if (bEnsureAbsolute)
{
EnsureLeadingBackslash(Directory); EnsureLeadingBackslash(Directory);
}
if (Directory.length() > 0)
{
EnsureTrailingBackslash(Directory); EnsureTrailingBackslash(Directory);
}
std::string Drive;
GetComponents(&Drive, NULL, &Name, &Extension); GetComponents(&Drive, NULL, &Name, &Extension);
SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), Extension.c_str()); SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), Extension.c_str());
} }
@ -498,8 +504,11 @@ void CPath::SetDriveDirectory(const char * lpszDriveDirectory)
std::string Name; std::string Name;
std::string Extension; std::string Extension;
if (DriveDirectory.length() > 0)
{
EnsureTrailingBackslash(DriveDirectory); EnsureTrailingBackslash(DriveDirectory);
cleanPathString(DriveDirectory); cleanPathString(DriveDirectory);
}
GetComponents(NULL, NULL, &Name, &Extension); GetComponents(NULL, NULL, &Name, &Extension);
SetComponents(NULL, DriveDirectory.c_str(), Name.c_str(), Extension.c_str()); SetComponents(NULL, DriveDirectory.c_str(), Name.c_str(), Extension.c_str());
@ -510,10 +519,10 @@ void CPath::SetDriveDirectory(const char * lpszDriveDirectory)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetName(const char * lpszName) void CPath::SetName(const char * lpszName)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string Extension; std::string Extension;
std::string Drive;
GetComponents(&Drive, &Directory, NULL, &Extension); GetComponents(&Drive, &Directory, NULL, &Extension);
SetComponents(Drive.c_str(), Directory.c_str(), lpszName, Extension.c_str()); SetComponents(Drive.c_str(), Directory.c_str(), lpszName, Extension.c_str());
} }
@ -523,15 +532,15 @@ void CPath::SetName(const char * lpszName)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetName(int iName) void CPath::SetName(int iName)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string Extension; std::string Extension;
TCHAR sName[33]; char sName[33];
memset(sName, 0, sizeof(sName)); memset(sName, 0, sizeof(sName));
_itoa(iName, sName, 10); _snprintf(sName, sizeof(sName), "%d", iName);
std::string Drive;
GetComponents(&Drive, &Directory, NULL, &Extension); GetComponents(&Drive, &Directory, NULL, &Extension);
SetComponents(Drive.c_str(), Directory.c_str(), sName, Extension.c_str()); SetComponents(Drive.c_str(), Directory.c_str(), sName, Extension.c_str());
} }
@ -541,10 +550,10 @@ void CPath::SetName(int iName)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetExtension(const char * lpszExtension) void CPath::SetExtension(const char * lpszExtension)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string Name; std::string Name;
std::string Drive;
GetComponents(&Drive, &Directory, &Name); GetComponents(&Drive, &Directory, &Name);
SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), lpszExtension); SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), lpszExtension);
} }
@ -554,15 +563,15 @@ void CPath::SetExtension(const char * lpszExtension)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetExtension(int iExtension) void CPath::SetExtension(int iExtension)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string Name; std::string Name;
TCHAR sExtension[20]; char sExtension[20];
memset(sExtension, 0, sizeof(sExtension)); memset(sExtension, 0, sizeof(sExtension));
_itoa(iExtension, sExtension, 10); _snprintf(sExtension, sizeof(sExtension), "%d", iExtension);
std::string Drive;
GetComponents(&Drive, &Directory, &Name); GetComponents(&Drive, &Directory, &Name);
SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), sExtension); SetComponents(Drive.c_str(), Directory.c_str(), Name.c_str(), sExtension);
} }
@ -572,9 +581,9 @@ void CPath::SetExtension(int iExtension)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::SetNameExtension(const char * lpszNameExtension) void CPath::SetNameExtension(const char * lpszNameExtension)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string Drive;
GetComponents(&Drive, &Directory); GetComponents(&Drive, &Directory);
SetComponents(Drive.c_str(), Directory.c_str(), lpszNameExtension, NULL); SetComponents(Drive.c_str(), Directory.c_str(), lpszNameExtension, NULL);
} }
@ -584,19 +593,21 @@ void CPath::SetNameExtension(const char * lpszNameExtension)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::AppendDirectory(const char * lpszSubDirectory) void CPath::AppendDirectory(const char * lpszSubDirectory)
{ {
std::string Drive;
std::string Directory; std::string Directory;
std::string SubDirectory = lpszSubDirectory; std::string SubDirectory = lpszSubDirectory;
std::string Name; std::string Name;
std::string Extension; std::string Extension;
if (SubDirectory.empty()) if (SubDirectory.empty())
{
return; return;
}
// Strip out any preceeding backslash // Strip out any preceeding backslash
StripLeadingBackslash(SubDirectory); StripLeadingBackslash(SubDirectory);
EnsureTrailingBackslash(SubDirectory); EnsureTrailingBackslash(SubDirectory);
std::string Drive;
GetComponents(&Drive, &Directory, &Name, &Extension); GetComponents(&Drive, &Directory, &Name, &Extension);
EnsureTrailingBackslash(Directory); EnsureTrailingBackslash(Directory);
Directory += SubDirectory; Directory += SubDirectory;
@ -627,7 +638,9 @@ void CPath::UpDirectory(std::string *pLastDirectory /*= NULL*/)
} }
if (nDelimiter != std::string::npos) if (nDelimiter != std::string::npos)
{
Directory = Directory.substr(0, nDelimiter); Directory = Directory.substr(0, nDelimiter);
}
SetDirectory(Directory.c_str()); SetDirectory(Directory.c_str());
} }
@ -637,7 +650,7 @@ void CPath::UpDirectory(std::string *pLastDirectory /*= NULL*/)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::CurrentDirectory() void CPath::CurrentDirectory()
{ {
TCHAR buff_path[MAX_PATH]; char buff_path[MAX_PATH];
memset(buff_path, 0, sizeof(buff_path)); memset(buff_path, 0, sizeof(buff_path));
@ -652,7 +665,7 @@ void CPath::CurrentDirectory()
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::Module(void * hInstance) void CPath::Module(void * hInstance)
{ {
TCHAR buff_path[MAX_PATH]; char buff_path[MAX_PATH];
memset(buff_path, 0, sizeof(buff_path)); memset(buff_path, 0, sizeof(buff_path));
@ -665,11 +678,7 @@ void CPath::Module(void * hInstance)
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::Module() void CPath::Module()
{ {
TCHAR buff_path[MAX_PATH]; Module(m_hInst);
memset(buff_path, 0, sizeof(buff_path));
GetModuleFileName((HMODULE)m_hInst, buff_path, MAX_PATH);
m_strPath = buff_path;
} }
//------------------------------------------------------------- //-------------------------------------------------------------
@ -677,7 +686,7 @@ void CPath::Module()
//------------------------------------------------------------- //-------------------------------------------------------------
void CPath::ModuleDirectory(void * hInstance) void CPath::ModuleDirectory(void * hInstance)
{ {
Module((HINSTANCE)hInstance); Module(hInstance);
SetNameExtension(""); SetNameExtension("");
} }
@ -725,7 +734,9 @@ bool CPath::DirectoryExists() const
bool bGotFile = (hFindFile != INVALID_HANDLE_VALUE); bool bGotFile = (hFindFile != INVALID_HANDLE_VALUE);
if (hFindFile != NULL) // Make sure we close the search if (hFindFile != NULL) // Make sure we close the search
{
FindClose(hFindFile); FindClose(hFindFile);
}
return bGotFile; return bGotFile;
} }
@ -741,7 +752,9 @@ bool CPath::Exists() const
bool bSuccess = (hFindFile != INVALID_HANDLE_VALUE); bool bSuccess = (hFindFile != INVALID_HANDLE_VALUE);
if (hFindFile != NULL) // Make sure we close the search if (hFindFile != NULL) // Make sure we close the search
{
FindClose(hFindFile); FindClose(hFindFile);
}
return bSuccess; return bSuccess;
} }
@ -754,19 +767,23 @@ bool CPath::Delete(bool bEvenIfReadOnly) const
{ {
uint32_t dwAttr = ::GetFileAttributes(m_strPath.c_str()); uint32_t dwAttr = ::GetFileAttributes(m_strPath.c_str());
if (dwAttr == (uint32_t)-1) if (dwAttr == (uint32_t)-1)
{
// File does not exists // File does not exists
return FALSE; return false;
}
if (((dwAttr & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) && !bEvenIfReadOnly) if (((dwAttr & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) && !bEvenIfReadOnly)
{
// File is read-only, and we're not allowed 2 delete it // File is read-only, and we're not allowed 2 delete it
return FALSE; return false;
}
SetFileAttributes(m_strPath.c_str(), FILE_ATTRIBUTE_NORMAL); SetFileAttributes(m_strPath.c_str(), FILE_ATTRIBUTE_NORMAL);
return DeleteFile(m_strPath.c_str()) != 0; return DeleteFile(m_strPath.c_str()) != 0;
} }
//------------------------------------------------------------- //-------------------------------------------------------------
// Post : Return TRUE on success, FALSE if there is such a target file // Post : Return TRUE on success, false if there is such a target file
// and we weren't granted permission 2 overwrite file or some error // and we weren't granted permission 2 overwrite file or some error
// Task : Copy file // Task : Copy file
// Since ::CopyFile will not overwrite read only files // Since ::CopyFile will not overwrite read only files
@ -781,11 +798,15 @@ bool CPath::CopyTo(const char * lpcszTargetFile, bool bOverwrite)
// Yeah there is already such a target file // Yeah there is already such a target file
// Decide if we should overwrite // Decide if we should overwrite
if (!bOverwrite) if (!bOverwrite)
return FALSE; {
return false;
}
// Delete any previous target // Delete any previous target
if (!TargetFile.Delete(TRUE)) if (!TargetFile.Delete(true))
return FALSE; {
return false;
}
} }
// CopyFile will set the target's attributes 2 the same as // CopyFile will set the target's attributes 2 the same as
@ -794,7 +815,7 @@ bool CPath::CopyTo(const char * lpcszTargetFile, bool bOverwrite)
} }
//------------------------------------------------------------- //-------------------------------------------------------------
// Post : Return TRUE on success, FALSE if there is such a target file // Post : Return TRUE on success, false if there is such a target file
// and we weren't granted permission 2 overwrite file or some error // and we weren't granted permission 2 overwrite file or some error
// Task : Move file // Task : Move file
//------------------------------------------------------------- //-------------------------------------------------------------
@ -807,11 +828,15 @@ bool CPath::MoveTo(const char * lpcszTargetFile, bool bOverwrite)
// Yeah there is already such a target file // Yeah there is already such a target file
// Decide if we should overwrite // Decide if we should overwrite
if (!bOverwrite) if (!bOverwrite)
return FALSE; {
return false;
}
// Delete any previous target // Delete any previous target
if (!TargetFile.Delete(TRUE)) if (!TargetFile.Delete(TRUE))
return FALSE; {
return false;
}
} }
return MoveFile(m_strPath.c_str(), lpcszTargetFile) != 0; return MoveFile(m_strPath.c_str(), lpcszTargetFile) != 0;
@ -899,7 +924,7 @@ bool CPath::FindFirst(uint32_t dwAttributes /*= _A_NORMAL*/)
bGotFile = FindNextFile(m_hFindFile, &FindData); bGotFile = FindNextFile(m_hFindFile, &FindData);
} }
return FALSE; return false;
} }
//------------------------------------------------------------- //-------------------------------------------------------------
@ -910,10 +935,12 @@ bool CPath::FindFirst(uint32_t dwAttributes /*= _A_NORMAL*/)
bool CPath::FindNext() bool CPath::FindNext()
{ {
if (m_hFindFile == NULL) if (m_hFindFile == NULL)
return FALSE; {
return false;
}
WIN32_FIND_DATA FindData; WIN32_FIND_DATA FindData;
while (FindNextFile(m_hFindFile, &FindData) != FALSE) while (FindNextFile(m_hFindFile, &FindData) != false)
{ // while(FindNext(...)) { // while(FindNext(...))
if (AttributesMatch(m_dwFindFileAttributes, FindData.dwFileAttributes)) if (AttributesMatch(m_dwFindFileAttributes, FindData.dwFileAttributes))
{ // if(AttributesMatch(...) { // if(AttributesMatch(...)
@ -946,7 +973,7 @@ bool CPath::FindNext()
} }
} }
return FALSE; return false;
} }
//------------------------------------------------------------- //-------------------------------------------------------------
@ -986,17 +1013,15 @@ bool CPath::DirectoryCreate(bool bCreateIntermediates /*= TRUE*/)
{ {
std::string::size_type nDelimiter = PathText.rfind(DIRECTORY_DELIMITER); std::string::size_type nDelimiter = PathText.rfind(DIRECTORY_DELIMITER);
if (nDelimiter == std::string::npos) if (nDelimiter == std::string::npos)
return FALSE; {
return false;
}
PathText.resize(nDelimiter + 1); PathText.resize(nDelimiter + 1);
CPath SubPath(PathText); CPath SubPath(PathText);
if (SubPath.DirectoryCreate()) return SubPath.DirectoryCreate() ? DirectoryCreate(false) : false;
return DirectoryCreate(false);
else
return FALSE;
} }
return bSuccess; return bSuccess;
} }
@ -1007,8 +1032,6 @@ bool CPath::DirectoryCreate(bool bCreateIntermediates /*= TRUE*/)
//------------------------------------------------------------------------ //------------------------------------------------------------------------
void CPath::cleanPathString(std::string& rDirectory) const void CPath::cleanPathString(std::string& rDirectory) const
{ {
LPCSTR const DIR_DOUBLEDELIM = "\\\\";
std::string::size_type pos = rDirectory.find(DIRECTORY_DELIMITER2); std::string::size_type pos = rDirectory.find(DIRECTORY_DELIMITER2);
while (pos != std::string::npos) while (pos != std::string::npos)
{ {
@ -1016,7 +1039,7 @@ void CPath::cleanPathString(std::string& rDirectory) const
pos = rDirectory.find(DIRECTORY_DELIMITER2, pos + 1); pos = rDirectory.find(DIRECTORY_DELIMITER2, pos + 1);
} }
bool AppendEnd = !_strnicmp(rDirectory.c_str(), "\\\\", 2); bool AppendEnd = !_strnicmp(rDirectory.c_str(), DIR_DOUBLEDELIM, 2);
pos = rDirectory.find(DIR_DOUBLEDELIM); pos = rDirectory.find(DIR_DOUBLEDELIM);
while (pos != std::string::npos) while (pos != std::string::npos)
{ {
@ -1025,11 +1048,11 @@ void CPath::cleanPathString(std::string& rDirectory) const
} }
if (AppendEnd) if (AppendEnd)
{ {
rDirectory.insert(0, "\\"); rDirectory.insert(0, stdstr_f("%c",DIRECTORY_DELIMITER).c_str());
} }
} }
void CPath::StripLeadingChar(std::string& rText, TCHAR chLeading) const void CPath::StripLeadingChar(std::string& rText, char chLeading) const
{ {
std::string::size_type nLength = rText.length(); std::string::size_type nLength = rText.length();
if (nLength == 0) if (nLength == 0)
@ -1057,7 +1080,7 @@ void CPath::StripLeadingBackslash(std::string& Directory) const
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Task : Remove last character (if any) if it's chTrailing // Task : Remove last character (if any) if it's chTrailing
//------------------------------------------------------------------------ //------------------------------------------------------------------------
void CPath::StripTrailingChar(std::string& rText, TCHAR chTrailing) const void CPath::StripTrailingChar(std::string& rText, char chTrailing) const
{ {
std::string::size_type nLength = rText.length(); std::string::size_type nLength = rText.length();
if (nLength == 0) if (nLength == 0)

View File

@ -60,7 +60,7 @@ public:
bool operator == (const CPath& rPath) const; bool operator == (const CPath& rPath) const;
bool operator != (const CPath& rPath) const; bool operator != (const CPath& rPath) const;
operator const char *() const; operator const char *() const;
operator std::string &() { return m_strPath; } operator const std::string &() { return m_strPath; }
//Get path components //Get path components
void GetDriveDirectory(std::string & rDriveDirectory) const; void GetDriveDirectory(std::string & rDriveDirectory) const;
@ -73,14 +73,10 @@ public:
std::string GetNameExtension(void) const; std::string GetNameExtension(void) const;
void GetExtension(std::string& rExtension) const; void GetExtension(std::string& rExtension) const;
std::string GetExtension(void) const; std::string GetExtension(void) const;
void GetLastDirectory(std::string& rDrive) const; void GetLastDirectory(std::string& rDirectory) const;
std::string GetLastDirectory(void) const; std::string GetLastDirectory(void) const;
void GetFullyQualified(std::string& rFullyQualified) const; void GetFullyQualified(std::string& rFullyQualified) const;
void GetComponents(std::string* pDrive = NULL, void GetComponents(std::string* pDrive = NULL, std::string* pDirectory = NULL, std::string* pName = NULL, std::string* pExtension = NULL) const;
std::string* pDirectory = NULL,
std::string* pName = NULL,
std::string* pExtension = NULL) const;
//Get other state //Get other state
bool IsEmpty() const { return m_strPath.empty(); } bool IsEmpty() const { return m_strPath.empty(); }
bool IsRelative() const; bool IsRelative() const;
@ -96,11 +92,7 @@ public:
void SetExtension(int iExtension); void SetExtension(int iExtension);
void AppendDirectory(const char * lpszSubDirectory); void AppendDirectory(const char * lpszSubDirectory);
void UpDirectory(std::string* pLastDirectory = NULL); void UpDirectory(std::string* pLastDirectory = NULL);
void SetComponents(const char * lpszDrive, void SetComponents(const char * lpszDrive, const char * lpszDirectory, const char * lpszName, const char * lpszExtension);
const char * lpszDirectory,
const char * lpszName,
const char * lpszExtension);
//Set whole path //Set whole path
void Empty() { m_strPath.erase(); } void Empty() { m_strPath.erase(); }
void CurrentDirectory(); void CurrentDirectory();