[Common] Make sure we always have a path in CPath::SetComponents
This commit is contained in:
parent
3a1fc904c6
commit
4203cbd2ef
|
@ -167,9 +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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +451,11 @@ void CPath::SetComponents(const char * lpszDrive, const char * lpszDirectory, co
|
||||||
char buff_fullname[MAX_PATH];
|
char buff_fullname[MAX_PATH];
|
||||||
|
|
||||||
memset(buff_fullname, 0, sizeof(buff_fullname));
|
memset(buff_fullname, 0, sizeof(buff_fullname));
|
||||||
|
if (lpszDirectory == NULL || strlen(lpszDirectory) == 0)
|
||||||
|
{
|
||||||
|
static char empty_dir[] = { DIRECTORY_DELIMITER, '\0' };
|
||||||
|
lpszDirectory = empty_dir;
|
||||||
|
}
|
||||||
_makepath(buff_fullname, lpszDrive, lpszDirectory, lpszName, lpszExtension);
|
_makepath(buff_fullname, lpszDrive, lpszDirectory, lpszName, lpszExtension);
|
||||||
|
|
||||||
m_strPath.erase();
|
m_strPath.erase();
|
||||||
|
@ -482,13 +486,13 @@ void CPath::SetDirectory(const char * lpszDirectory, bool bEnsureAbsolute /*= fa
|
||||||
std::string Extension;
|
std::string Extension;
|
||||||
|
|
||||||
if (bEnsureAbsolute)
|
if (bEnsureAbsolute)
|
||||||
{
|
{
|
||||||
EnsureLeadingBackslash(Directory);
|
EnsureLeadingBackslash(Directory);
|
||||||
}
|
}
|
||||||
if (Directory.length() > 0)
|
if (Directory.length() > 0)
|
||||||
{
|
{
|
||||||
EnsureTrailingBackslash(Directory);
|
EnsureTrailingBackslash(Directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Drive;
|
std::string Drive;
|
||||||
GetComponents(&Drive, NULL, &Name, &Extension);
|
GetComponents(&Drive, NULL, &Name, &Extension);
|
||||||
|
@ -504,11 +508,11 @@ void CPath::SetDriveDirectory(const char * lpszDriveDirectory)
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::string Extension;
|
std::string Extension;
|
||||||
|
|
||||||
if (DriveDirectory.length() > 0)
|
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());
|
||||||
|
@ -731,14 +735,14 @@ bool CPath::DirectoryExists() const
|
||||||
|
|
||||||
WIN32_FIND_DATA FindData;
|
WIN32_FIND_DATA FindData;
|
||||||
HANDLE hFindFile = FindFirstFile((const char *)TestPath, &FindData); // Find anything
|
HANDLE hFindFile = FindFirstFile((const char *)TestPath, &FindData); // Find anything
|
||||||
bool bGotFile = (hFindFile != INVALID_HANDLE_VALUE);
|
bool bGotDirectory = (hFindFile != INVALID_HANDLE_VALUE) && (FindData.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY != 0);
|
||||||
|
|
||||||
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 bGotDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
//-------------------------------------------------------------
|
||||||
|
@ -1048,7 +1052,7 @@ void CPath::cleanPathString(std::string& rDirectory) const
|
||||||
}
|
}
|
||||||
if (AppendEnd)
|
if (AppendEnd)
|
||||||
{
|
{
|
||||||
rDirectory.insert(0, stdstr_f("%c",DIRECTORY_DELIMITER).c_str());
|
rDirectory.insert(0, stdstr_f("%c", DIRECTORY_DELIMITER).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue