[BUG_FIXED] Fix opening file problem from the network drive.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1090 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2013-07-30 18:31:33 +00:00
parent 512cc2db65
commit 774a9fab3d

View File

@ -893,68 +893,17 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea
return success;
}
BufferID FileManager::getBufferFromName(const TCHAR * name)
BufferID FileManager::getBufferFromName(const TCHAR * name)
{
// Attempt to match by name first.
TCHAR fullpath[MAX_PATH];
::GetFullPathName(name, MAX_PATH, fullpath, NULL);
::GetLongPathName(fullpath, fullpath, MAX_PATH);
for(size_t i = 0; i < _buffers.size(); ++i)
for(size_t i = 0; i < _buffers.size(); i++)
{
if (!lstrcmpi(name, _buffers.at(i)->getFullPathName()))
return _buffers.at(i)->getID();
}
// If no buffer matches exactly by name, try another method.
HANDLE givenFile = ::CreateFile(name,
GENERIC_READ,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
BY_HANDLE_FILE_INFORMATION givenFileInfo, currentFileInfo;
if(givenFile == INVALID_HANDLE_VALUE)
return BUFFER_INVALID;
if(! ::GetFileInformationByHandle(givenFile, &givenFileInfo))
{
::CloseHandle(givenFile);
return BUFFER_INVALID;
}
::CloseHandle(givenFile);
const unsigned int bufferSize = _buffers.size();
for(size_t i = 0; i < bufferSize; ++i)
{
HANDLE currentFile = ::CreateFile(_buffers.at(i)->getFullPathName(),
GENERIC_READ,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(currentFile != INVALID_HANDLE_VALUE)
{
if(::GetFileInformationByHandle(currentFile, &currentFileInfo))
{
if(currentFileInfo.dwVolumeSerialNumber == givenFileInfo.dwVolumeSerialNumber &&
currentFileInfo.nFileIndexLow == givenFileInfo.nFileIndexLow &&
currentFileInfo.nFileIndexHigh == givenFileInfo.nFileIndexHigh)
{
::CloseHandle(currentFile);
return _buffers.at(i)->getID();
}
}
::CloseHandle(currentFile);
}
}
return BUFFER_INVALID;
return BUFFER_INVALID;
}
BufferID FileManager::getBufferFromDocument(Document doc) {