Skip to content

Commit

Permalink
Remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Oct 9, 2024
1 parent 5f8f4ae commit e111514
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 94 deletions.
103 changes: 51 additions & 52 deletions PowerEditor/src/MISC/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,57 +1838,6 @@ bool doesPathExist(const wchar_t* path, DWORD milliSec2wait, bool* isNetWorkProb
}


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

struct wfopenParamResult
{
std::wstring _filePath;
FILE* _pFile = nullptr;
bool _isNetworkFailure = true;
wfopenParamResult(wstring filePath) : _filePath(filePath) {};
};

DWORD WINAPI wfopenWorker(void* data)
{
wfopenParamResult* inAndOut = static_cast<wfopenParamResult*>(data);
inAndOut->_pFile = _wfopen(inAndOut->_filePath.c_str(), L"rb");
inAndOut->_isNetworkFailure = false;
return ERROR_SUCCESS;
};

FILE* wfopenWaitSec(const wchar_t* filePath, DWORD milliSec2wait, bool* isNetWorkProblem)
{
wfopenParamResult data(filePath);

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

// wait for our worker thread to complete or terminate it when the required timeout has elapsed
DWORD dwWaitStatus = ::WaitForSingleObject(hThread, milliSec2wait == 0 ? DEFAULT_MILLISEC : milliSec2wait);
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;

return data._pFile;
}


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

struct GetDiskFreeSpaceParamResult
Expand Down Expand Up @@ -2053,4 +2002,54 @@ HANDLE createFileWaitSec(const wchar_t* filePath, DWORD accessParam, DWORD share
*isNetWorkProblem = data._isNetworkFailure;

return data._hFile;
}
}

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

struct wfopenParamResult
{
std::wstring _filePath;
FILE* _pFile = nullptr;
bool _isNetworkFailure = true;
wfopenParamResult(wstring filePath) : _filePath(filePath) {};
};

DWORD WINAPI wfopenWorker(void* data)
{
wfopenParamResult* inAndOut = static_cast<wfopenParamResult*>(data);
inAndOut->_pFile = _wfopen(inAndOut->_filePath.c_str(), L"rb");
inAndOut->_isNetworkFailure = false;
return ERROR_SUCCESS;
};

FILE* wfopenWithTimeout(const wchar_t* filePath, DWORD milliSec2wait, bool* isNetWorkProblem)
{
wfopenParamResult data(filePath);

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

// wait for our worker thread to complete or terminate it when the required timeout has elapsed
DWORD dwWaitStatus = ::WaitForSingleObject(hThread, milliSec2wait == 0 ? DEFAULT_MILLISEC : milliSec2wait);
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;

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

FILE* wfopenWaitSec(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getDiskFreeSpaceWaitSec(const wchar_t* dirPath, ULARGE_INTEGER* freeBytesForUser, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
DWORD getFileAttributesExWaitSec(const wchar_t* filePath, WIN32_FILE_ATTRIBUTE_DATA* fileAttr, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
HANDLE createFileWaitSec(const wchar_t* filePath, DWORD accessParam, DWORD shareParam, DWORD dispParam, DWORD attribParam, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);
FILE* wfopenWithTimeout(const wchar_t* filePath, DWORD milliSec2wait = 0, bool* isNetWorkProblem = nullptr);

46 changes: 5 additions & 41 deletions PowerEditor/src/ScintillaComponent/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,42 +702,22 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi
//Get file size
int64_t fileSize = -1;
const wchar_t* pPath = filename;
std::wstring msg = pPath;
msg += L"\t BEFORE doesFileExist";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());
if (!doesFileExist(pPath))
{
pPath = backupFileName;
}
msg = pPath;
msg += L"\t AFTER doesFileExist";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());



if (pPath)
{
msg = pPath;
msg += L"\t BEFORE getFileAttributesExWaitSec";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());

WIN32_FILE_ATTRIBUTE_DATA attributes{};
if (getFileAttributesExWaitSec(pPath, &attributes) != FALSE)
{
msg = pPath;
msg += L"\t getFileAttributesExWaitSec OK - let's retrieve file length";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());

LARGE_INTEGER size{};
size.LowPart = attributes.nFileSizeLow;
size.HighPart = attributes.nFileSizeHigh;

fileSize = size.QuadPart;
}

msg = pPath;
msg += L"\t AFTER getFileAttributesExWaitSec";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());
}

// * the auto-completion feature will be disabled for large files
Expand Down Expand Up @@ -797,16 +777,8 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi
loadedFileFormat._eolFormat = EolType::unknown;
loadedFileFormat._language = L_TEXT;

msg = pPath;
msg += L"\t BEFORE loadFileData";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());

bool loadRes = loadFileData(doc, fileSize, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, loadedFileFormat);

msg = pPath;
msg += L"\t AFTER loadFileData";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());

delete[] data;

if (loadRes)
Expand Down Expand Up @@ -1642,15 +1614,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
}
}

wstring msg = filename;
msg += L"\t BEFORE _wfopen";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());

FILE* fp = wfopenWaitSec(filename, 5000);

msg = filename;
msg += L"\t AFTER _wfopen";
writeLog(L"c:\\tmp\\QQQ", msg.c_str());
FILE* fp = wfopenWithTimeout(filename);

if (!fp)
return false;
Expand Down Expand Up @@ -1687,8 +1651,8 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
bool success = true;
EolType format = EolType::unknown;
int sciStatus = SC_STATUS_OK;
/*wchar_t szException[64] = {'\0'};
__try*/
wchar_t szException[64] = {'\0'};
__try
{
// First allocate enough memory for the whole file (this will reduce memory copy during loading)
_pscratchTilla->execute(SCI_ALLOCATE, WPARAM(bufferSizeRequested));
Expand Down Expand Up @@ -1776,7 +1740,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
}
while (lenFile > 0);
}
/*__except (EXCEPTION_EXECUTE_HANDLER)
__except (EXCEPTION_EXECUTE_HANDLER)
{
switch (sciStatus)
{
Expand Down Expand Up @@ -1815,7 +1779,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
szException);
}
success = false;
}*/
}

fclose(fp);

Expand Down

0 comments on commit e111514

Please sign in to comment.