Skip to content

Commit

Permalink
Remove WoC64 for x64 build; use the return value of WaitForSingleObject
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Oct 1, 2024
1 parent 8a44235 commit e6f4171
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 116 deletions.
110 changes: 94 additions & 16 deletions PowerEditor/src/MISC/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ bool Version::isCompatibleTo(const Version& from, const Version& to) const
return false;
}

//----------------------------------------------------
struct GetAttrParamResult {
std::wstring _filePath;
DWORD _fileAttr = INVALID_FILE_ATTRIBUTES;
Expand All @@ -1778,7 +1779,7 @@ DWORD WINAPI getFileAttributesWorker(void* data)
return TRUE;
};

DWORD getFileAttrWaitFewSec(const wchar_t* filePath, DWORD milleSec2wait, bool* isNetWorkProblem)
DWORD getFileAttrWaitSec(const wchar_t* filePath, DWORD milleSec2wait, bool* isNetWorkProblem)
{
GetAttrParamResult data;
data._fileAttr = INVALID_FILE_ATTRIBUTES;
Expand All @@ -1788,15 +1789,25 @@ DWORD getFileAttrWaitFewSec(const wchar_t* filePath, DWORD milleSec2wait, bool*
HANDLE hThread = ::CreateThread(NULL, 0, getFileAttributesWorker, &data, 0, NULL);
if (!hThread)
{
return false;
return INVALID_FILE_ATTRIBUTES;
}

// Wait for few sec
::WaitForSingleObject(hThread, milleSec2wait == 0 ? 1000 : milleSec2wait);
TerminateThread(hThread, 2);
// wait for our worker thread to complete or terminate it when the required timeout has elapsed
DWORD dwWaitStatus = ::WaitForSingleObject(hThread, milleSec2wait == 0 ? 1000 : milleSec2wait);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0: // Ok, the state of our worker thread is signaled, so it finished itself in the timeout given
// - nothing else to do here, except the thread handle closing later
break;

case WAIT_TIMEOUT: // the timeout interval elapsed, but the worker's state is still non-signaled
default: // any other dwWaitStatus is a BAD one here
// WAIT_FAILED or WAIT_ABANDONED
::TerminateThread(hThread, dwWaitStatus);
break;
}
CloseHandle(hThread);

if (isNetWorkProblem != nullptr)
*isNetWorkProblem = data._isNetworkFailure;

Expand All @@ -1805,22 +1816,23 @@ DWORD getFileAttrWaitFewSec(const wchar_t* filePath, DWORD milleSec2wait, bool*

bool doesFileExist(const wchar_t* filePath, DWORD milleSec2wait, bool* isNetWorkProblem)
{
DWORD attr = getFileAttrWaitFewSec(filePath, milleSec2wait, isNetWorkProblem);
DWORD attr = getFileAttrWaitSec(filePath, milleSec2wait, isNetWorkProblem);
return (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY));
}

bool doesDirectoryExist(const wchar_t* dirPath, DWORD milleSec2wait, bool* isNetWorkProblem)
{
DWORD attr = getFileAttrWaitFewSec(dirPath, milleSec2wait, isNetWorkProblem);
DWORD attr = getFileAttrWaitSec(dirPath, milleSec2wait, isNetWorkProblem);
return (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY));
}

bool doesPathExist(const wchar_t* path, DWORD milleSec2wait, bool* isNetWorkProblem)
{
DWORD attr = getFileAttrWaitFewSec(path, milleSec2wait, isNetWorkProblem);
DWORD attr = getFileAttrWaitSec(path, milleSec2wait, isNetWorkProblem);
return (attr != INVALID_FILE_ATTRIBUTES);
}

//----------------------------------------------------

struct GetDiskFreeSpaceParamResult
{
Expand All @@ -1838,8 +1850,7 @@ DWORD WINAPI getDiskFreeSpaceExWorker(void* data)
return TRUE;
};


DWORD getDiskFreeSpaceWaitFewSec(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milleSec2wait, bool* isNetWorkProblem)
DWORD getDiskFreeSpaceWaitSec(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milleSec2wait, bool* isNetWorkProblem)
{
GetDiskFreeSpaceParamResult data;
data._dirPath = dirPath;
Expand All @@ -1850,13 +1861,23 @@ DWORD getDiskFreeSpaceWaitFewSec(const wchar_t* dirPath, ULARGE_INTEGER* freeByt
HANDLE hThread = ::CreateThread(NULL, 0, getDiskFreeSpaceExWorker, &data, 0, NULL);
if (!hThread)
{
return false;
return FALSE;
}

// Wait for 1 sec
::WaitForSingleObject(hThread, milleSec2wait == 0 ? 1000 : milleSec2wait);
TerminateThread(hThread, 2);
// wait for our worker thread to complete or terminate it when the required timeout has elapsed
DWORD dwWaitStatus = ::WaitForSingleObject(hThread, milleSec2wait == 0 ? 1000 : milleSec2wait);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0: // Ok, the state of our worker thread is signaled, so it finished itself in the timeout given
// - nothing else to do here, except the thread handle closing later
break;

case WAIT_TIMEOUT: // the timeout interval elapsed, but the worker's state is still non-signaled
default: // any other dwWaitStatus is a BAD one here
// WAIT_FAILED or WAIT_ABANDONED
::TerminateThread(hThread, dwWaitStatus);
break;
}
CloseHandle(hThread);

*freeBytesForUser = data._freeBytesForUser;
Expand All @@ -1865,4 +1886,61 @@ DWORD getDiskFreeSpaceWaitFewSec(const wchar_t* dirPath, ULARGE_INTEGER* freeByt
*isNetWorkProblem = data._isNetworkFailure;

return data._result;
};
}


//----------------------------------------------------

struct GetAttrExParamResult
{
std::wstring _filePath;
WIN32_FILE_ATTRIBUTE_DATA _attributes{};
DWORD _result = FALSE;
bool _isNetworkFailure = true;
};

DWORD WINAPI getFileAttributesExWorker(void* data)
{
GetAttrExParamResult* inAndOut = static_cast<GetAttrExParamResult*>(data);
inAndOut->_result = ::GetFileAttributesEx(inAndOut->_filePath.c_str(), GetFileExInfoStandard, &(inAndOut->_attributes));
inAndOut->_isNetworkFailure = false;
return TRUE;
};

DWORD getFileAttributesExWaitSec(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milleSec2wait, bool* isNetWorkProblem)
{
GetAttrExParamResult data;
data._filePath = filePath;
data._attributes = {};
data._result = FALSE;
data._isNetworkFailure = true;

HANDLE hThread = ::CreateThread(NULL, 0, getFileAttributesExWorker, &data, 0, NULL);
if (!hThread)
{
return FALSE;
}

// wait for our worker thread to complete or terminate it when the required timeout has elapsed
DWORD dwWaitStatus = ::WaitForSingleObject(hThread, milleSec2wait == 0 ? 1000 : milleSec2wait);
switch (dwWaitStatus)
{
case WAIT_OBJECT_0: // Ok, the state of our worker thread is signaled, so it finished itself in the timeout given
// - nothing else to do here, except the thread handle closing later
break;

case WAIT_TIMEOUT: // the timeout interval elapsed, but the worker's state is still non-signaled
default: // any other dwWaitStatus is a BAD one here
// WAIT_FAILED or WAIT_ABANDONED
::TerminateThread(hThread, dwWaitStatus);
break;
}
CloseHandle(hThread);

*fileAttr = data._attributes;

if (isNetWorkProblem != nullptr)
*isNetWorkProblem = data._isNetworkFailure;

return data._result;
}
3 changes: 2 additions & 1 deletion PowerEditor/src/MISC/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,5 @@ bool doesFileExist(const wchar_t* filePath, DWORD milleSec2wait = 0, bool* isNet
bool doesDirectoryExist(const wchar_t* dirPath, DWORD milleSec2wait = 0, bool* isNetWorkProblem = nullptr);
bool doesPathExist(const wchar_t* path, DWORD milleSec2wait = 0, bool* isNetWorkProblem = nullptr);

DWORD getDiskFreeSpaceWaitFewSec(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milleSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getDiskFreeSpaceWaitSec(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milleSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getFileAttributesExWaitSec(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milleSec2wait = 0, bool* isNetWorkProblem = nullptr);
3 changes: 2 additions & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7796,6 +7796,7 @@ static const QuoteParams quotes[] =
{L"Don Ho #3", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"The smartphone is the best invention of the 21st century for avoiding eye contact with people you know while crossing the street."},
{L"Don Ho #4", QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, L"Poor countries' museums vs. rich countries' museums:\nThe first show what they have left.\nThe second show what they have stolen."},
{L"Don Ho #5", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"With great refactoring comes great regressions."},
{L"Don Ho #6", QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, L"Naming a variable always reminds me the effort I put into my existence,\nfor giving some sense to my meaningless life."},
{L"Anonymous #1", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"An opinion without 3.14 is just an onion."},
{L"Anonymous #2", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"Before sex, you help each other get naked, after sex you only dress yourself.\nMoral of the story: in life no one helps you once you're fucked."},
{L"Anonymous #3", QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, L"I'm not totally useless. I can be used as a bad example."},
Expand All @@ -7818,7 +7819,7 @@ static const QuoteParams quotes[] =
{L"Anonymous #20", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"Never make eye contact while eating a banana."},
{L"Anonymous #21", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"I love my sixpack so much, I protect it with a layer of fat."},
{L"Anonymous #22", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"\"It's impossible.\" said pride.\n\"It's risky.\" said experience.\n\"It's pointless.\" said reason.\n\"Give it a try.\" whispered the heart.\n...\n\"What the hell was that?!?!?!?!?!\" shouted the anus two minutes later."},
{L"Anonymous #23", QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, L"A programmer is told to \"go to hell\".\nHe finds the worst part of that statement is the \"go to\"."},
{L"Anonymous #23", QuoteParams::rapid, false, SC_CP_UTF8, L_TEXT, L"A C++ programmer is told to \"go to hell\".\nHe finds the most offensive part of that statement is the \"go to\"."},
{L"Anonymous #24", QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, L"An Architect's dream is an Engineer's nightmare."},
{L"Anonymous #25", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"In a way, I feel sorry for the kids of this generation.\nThey'll have parents who know how to check browser history."},
{L"Anonymous #26", QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, L"Q: What's the difference between git and github?\nA: It's the difference between porn and pornhub.\n"},
Expand Down
Loading

0 comments on commit e6f4171

Please sign in to comment.