Browse Source

Rename variable & enhance the code

pull/15701/head
Don Ho 1 month ago
parent
commit
5e3ee3e0e4
  1. 34
      PowerEditor/src/MISC/Common/Common.cpp
  2. 10
      PowerEditor/src/MISC/Common/Common.h
  3. 6
      PowerEditor/src/MISC/Common/FileInterface.cpp
  4. 1
      PowerEditor/src/Notepad_plus.cpp
  5. 2
      PowerEditor/src/ScintillaComponent/Buffer.cpp

34
PowerEditor/src/MISC/Common/Common.cpp

@ -1779,7 +1779,8 @@ struct GetDiskFreeSpaceParamResult
std::wstring _dirPath;
ULARGE_INTEGER _freeBytesForUser {};
DWORD _result = FALSE;
bool _isNetworkFailure = true;
bool _isTimeoutReached = true;
GetDiskFreeSpaceParamResult(wstring dirPath) : _dirPath(dirPath) {};
};
@ -1787,11 +1788,11 @@ DWORD WINAPI getDiskFreeSpaceExWorker(void* data)
{
GetDiskFreeSpaceParamResult* inAndOut = static_cast<GetDiskFreeSpaceParamResult*>(data);
inAndOut->_result = ::GetDiskFreeSpaceExW(inAndOut->_dirPath.c_str(), &(inAndOut->_freeBytesForUser), nullptr, nullptr);
inAndOut->_isNetworkFailure = false;
inAndOut->_isTimeoutReached = false;
return ERROR_SUCCESS;
};
DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milliSec2wait, bool* isNetWorkProblem)
DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milliSec2wait, bool* isTimeoutReached)
{
GetDiskFreeSpaceParamResult data(dirPath);
@ -1819,8 +1820,8 @@ DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBy
*freeBytesForUser = data._freeBytesForUser;
if (isNetWorkProblem != nullptr)
*isNetWorkProblem = data._isNetworkFailure;
if (isTimeoutReached != nullptr)
*isTimeoutReached = data._isTimeoutReached;
return data._result;
}
@ -1833,7 +1834,8 @@ struct GetAttrExParamResult
wstring _filePath;
WIN32_FILE_ATTRIBUTE_DATA _attributes{};
DWORD _result = FALSE;
bool _isNetworkFailure = true;
bool _isTimeoutReached = true;
GetAttrExParamResult(wstring filePath): _filePath(filePath) {
_attributes.dwFileAttributes = INVALID_FILE_ATTRIBUTES;
}
@ -1843,11 +1845,11 @@ DWORD WINAPI getFileAttributesExWorker(void* data)
{
GetAttrExParamResult* inAndOut = static_cast<GetAttrExParamResult*>(data);
inAndOut->_result = ::GetFileAttributesEx(inAndOut->_filePath.c_str(), GetFileExInfoStandard, &(inAndOut->_attributes));
inAndOut->_isNetworkFailure = false;
inAndOut->_isTimeoutReached = false;
return ERROR_SUCCESS;
};
DWORD getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milliSec2wait, bool* isNetWorkProblem)
DWORD getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milliSec2wait, bool* isTimeoutReached)
{
GetAttrExParamResult data(filePath);
@ -1875,29 +1877,29 @@ DWORD getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBU
*fileAttr = data._attributes;
if (isNetWorkProblem != nullptr)
*isNetWorkProblem = data._isNetworkFailure;
if (isTimeoutReached != nullptr)
*isTimeoutReached = data._isTimeoutReached;
return data._result;
}
bool doesFileExist(const wchar_t* filePath, DWORD milliSec2wait, bool* isNetWorkProblem)
bool doesFileExist(const wchar_t* filePath, DWORD milliSec2wait, bool* isTimeoutReached)
{
WIN32_FILE_ATTRIBUTE_DATA attributes{};
getFileAttributesExWithTimeout(filePath, &attributes, milliSec2wait, isNetWorkProblem);
getFileAttributesExWithTimeout(filePath, &attributes, milliSec2wait, isTimeoutReached);
return (attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES && !(attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait, bool* isNetWorkProblem)
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait, bool* isTimeoutReached)
{
WIN32_FILE_ATTRIBUTE_DATA attributes{};
getFileAttributesExWithTimeout(dirPath, &attributes, milliSec2wait, isNetWorkProblem);
getFileAttributesExWithTimeout(dirPath, &attributes, milliSec2wait, isTimeoutReached);
return (attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES && (attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
bool doesPathExist(const wchar_t* path, DWORD milliSec2wait, bool* isNetWorkProblem)
bool doesPathExist(const wchar_t* path, DWORD milliSec2wait, bool* isTimeoutReached)
{
WIN32_FILE_ATTRIBUTE_DATA attributes{};
getFileAttributesExWithTimeout(path, &attributes, milliSec2wait, isNetWorkProblem);
getFileAttributesExWithTimeout(path, &attributes, milliSec2wait, isTimeoutReached);
return (attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES);
}

10
PowerEditor/src/MISC/Common/Common.h

@ -283,9 +283,9 @@ private:
};
DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
DWORD getFileAttributesExWithTimeout(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
bool doesFileExist(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
bool doesPathExist(const wchar_t* path, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
bool doesFileExist(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
bool doesPathExist(const wchar_t* path, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);

6
PowerEditor/src/MISC/Common/FileInterface.cpp

@ -33,9 +33,9 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
WIN32_FILE_ATTRIBUTE_DATA attributes_original{};
DWORD dispParam = CREATE_ALWAYS;
bool fileExists = false;
bool hasNetworkProblem = false;
bool isTimeoutReached = false;
// Store the file creation date & attributes for a possible use later...
if (getFileAttributesExWithTimeout(fname, &attributes_original, 0, &hasNetworkProblem))
if (getFileAttributesExWithTimeout(fname, &attributes_original, 0, &isTimeoutReached))
{
fileExists = (attributes_original.dwFileAttributes != INVALID_FILE_ATTRIBUTES);
}
@ -54,7 +54,7 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
else
{
bool isFromNetwork = PathIsNetworkPath(fname);
if (isFromNetwork && hasNetworkProblem) // The file doesn't exist, and the file is a network file, plus the network problem has been detected due to timeout
if (isFromNetwork && isTimeoutReached) // The file doesn't exist, and the file is a network file, plus the network problem has been detected due to timeout
return; // In this case, we don't call createFile to prevent hanging
}

1
PowerEditor/src/Notepad_plus.cpp

@ -7762,6 +7762,7 @@ static const QuoteParams quotes[] =
{L"Notepad++ #1", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"I hate reading other people's code.\nSo I wrote mine, made it as open source project, and watch others suffer."},
{L"Notepad++ #2", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"Good programmers use Notepad++ to code.\nExtreme programmers use MS Word to code, in Comic Sans, center aligned."},
{L"Notepad++ #3", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"The best things in life are free.\nNotepad++ is free.\nSo Notepad++ is the best.\n"},
{L"Notepad++ #4", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"Whatever you do, always give 100%.\nUnless you're donating to Notepad++, then 50% is OK.\nhttps://notepad-plus-plus.org/donate/\n"},
{L"Richard Stallman", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"If I'm the Father of Open Source, it was conceived through artificial insemination using stolen sperm without my knowledge or consent."},
{L"Martin Golding", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."},
{L"L. Peter Deutsch", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"To iterate is human, to recurse divine."},

2
PowerEditor/src/ScintillaComponent/Buffer.cpp

@ -1210,7 +1210,7 @@ SavingStatus FileManager::saveBuffer(BufferID id, const wchar_t* filename, bool
WIN32_FILE_ATTRIBUTE_DATA attributes{};
getFileAttributesExWithTimeout(fullpath, &attributes);
if (attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES)
if (attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES && !(attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
isHiddenOrSys = (attributes.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
if (isHiddenOrSys)

Loading…
Cancel
Save