Rename variable & enhance the code

This commit is contained in:
Don Ho 2024-10-12 19:32:37 +02:00
parent 3b6f22b357
commit 5e3ee3e0e4
5 changed files with 28 additions and 25 deletions

View File

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

View File

@ -283,9 +283,9 @@ private:
}; };
DWORD getDiskFreeSpaceWithTimeout(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, 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* isNetWorkProblem = 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 doesFileExist(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr); bool doesDirectoryExist(const wchar_t* dirPath, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);
bool doesPathExist(const wchar_t* path, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr); bool doesPathExist(const wchar_t* path, DWORD milliSec2wait = 0, bool* isTimeoutReached = nullptr);

View File

@ -33,9 +33,9 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
WIN32_FILE_ATTRIBUTE_DATA attributes_original{}; WIN32_FILE_ATTRIBUTE_DATA attributes_original{};
DWORD dispParam = CREATE_ALWAYS; DWORD dispParam = CREATE_ALWAYS;
bool fileExists = false; bool fileExists = false;
bool hasNetworkProblem = false; bool isTimeoutReached = false;
// Store the file creation date & attributes for a possible use later... // 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); fileExists = (attributes_original.dwFileAttributes != INVALID_FILE_ATTRIBUTES);
} }
@ -54,7 +54,7 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
else else
{ {
bool isFromNetwork = PathIsNetworkPath(fname); 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 return; // In this case, we don't call createFile to prevent hanging
} }

View File

@ -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++ #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++ #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++ #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"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"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."}, {L"L. Peter Deutsch", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"To iterate is human, to recurse divine."},

View File

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