Avoid GetLongPathName() call for files with long name
Fixes #1148; Closes #1150
This commit is contained in:
parent
51cc22fb3d
commit
86ab42031f
@ -163,18 +163,21 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
|
|||||||
TCHAR longFileName[longFileNameBufferSize];
|
TCHAR longFileName[longFileNameBufferSize];
|
||||||
|
|
||||||
const DWORD getFullPathNameResult = ::GetFullPathName(fileName.c_str(), longFileNameBufferSize, longFileName, NULL);
|
const DWORD getFullPathNameResult = ::GetFullPathName(fileName.c_str(), longFileNameBufferSize, longFileName, NULL);
|
||||||
if ( getFullPathNameResult == 0 )
|
if (getFullPathNameResult == 0)
|
||||||
{
|
{
|
||||||
return BUFFER_INVALID;
|
return BUFFER_INVALID;
|
||||||
}
|
}
|
||||||
if ( getFullPathNameResult > longFileNameBufferSize )
|
if (getFullPathNameResult > longFileNameBufferSize)
|
||||||
{
|
{
|
||||||
return BUFFER_INVALID;
|
return BUFFER_INVALID;
|
||||||
}
|
}
|
||||||
assert( _tcslen( longFileName ) == getFullPathNameResult );
|
assert(_tcslen(longFileName) == getFullPathNameResult);
|
||||||
|
|
||||||
|
if (_tcschr(longFileName, '~'))
|
||||||
|
{
|
||||||
// ignore the returned value of function due to win64 redirection system
|
// ignore the returned value of function due to win64 redirection system
|
||||||
::GetLongPathName(longFileName, longFileName, longFileNameBufferSize);
|
::GetLongPathName(longFileName, longFileName, longFileNameBufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName);
|
bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName);
|
||||||
if (isSnapshotMode && !PathFileExists(longFileName)) // UNTITLED
|
if (isSnapshotMode && !PathFileExists(longFileName)) // UNTITLED
|
||||||
|
@ -581,7 +581,10 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
|
|||||||
|
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
|
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
|
||||||
|
if (_tcschr(fullpath, '~'))
|
||||||
|
{
|
||||||
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName);
|
bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName);
|
||||||
if (isSnapshotMode && !PathFileExists(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED
|
if (isSnapshotMode && !PathFileExists(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED
|
||||||
@ -850,7 +853,10 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
|
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
::GetFullPathName(backupFilePath.c_str(), MAX_PATH, fullpath, NULL);
|
::GetFullPathName(backupFilePath.c_str(), MAX_PATH, fullpath, NULL);
|
||||||
|
if (_tcschr(fullpath, '~'))
|
||||||
|
{
|
||||||
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the backup file is not read only
|
// Make sure the backup file is not read only
|
||||||
DWORD dwFileAttribs = ::GetFileAttributes(fullpath);
|
DWORD dwFileAttribs = ::GetFileAttributes(fullpath);
|
||||||
@ -1024,7 +1030,11 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
|
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
|
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
|
||||||
|
if (_tcschr(fullpath, '~'))
|
||||||
|
{
|
||||||
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
if (PathFileExists(fullpath))
|
if (PathFileExists(fullpath))
|
||||||
{
|
{
|
||||||
attrib = ::GetFileAttributes(fullpath);
|
attrib = ::GetFileAttributes(fullpath);
|
||||||
@ -1501,7 +1511,10 @@ BufferID FileManager::getBufferFromName(const TCHAR* name)
|
|||||||
{
|
{
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
::GetFullPathName(name, MAX_PATH, fullpath, NULL);
|
::GetFullPathName(name, MAX_PATH, fullpath, NULL);
|
||||||
|
if (_tcschr(fullpath, '~'))
|
||||||
|
{
|
||||||
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
::GetLongPathName(fullpath, fullpath, MAX_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i < _buffers.size(); i++)
|
for(size_t i = 0; i < _buffers.size(); i++)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user