Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Feb 24, 2025
1 parent 7231233 commit 3a0999d
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Docs/Developers/readme-developers.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ <h3><a name="Logging">Logging</a></h3>

<h4>Writing to log:</h4>
<p>Simplest way to write errormessage to log is using
<code>void LogErrorString(LPCTSTR sz)</code> defined in <code>stdafx.h</code>. Another
<code>void RootLogger::Error(LPCTSTR sz)</code> defined in <code>stdafx.h</code>. Another
way is to directly use <code>gLog</code> which is global instance of
<code>CLogFile</code>. Log is written to users temporary directory (<code>$temp</code>) with name
<code>WinMerge.log</code>.</p>
Expand Down
7 changes: 4 additions & 3 deletions Src/7zCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ DATE: BY: DESCRIPTION:
#include "paths.h"
#include "Environment.h"
#include "Merge7zFormatRegister.h"
#include "Logger.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -635,7 +636,7 @@ DecompressResult DecompressArchive(HWND hWnd, const PathContext& files)
}
if (res.files[0].find(path) == 0)
{
VERIFY(::DeleteFile(res.files[0].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[0])), false));
VERIFY(::DeleteFile(res.files[0].c_str()) || (RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), res.files[0])), false));
}
BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[0].c_str());
res.files[0] = ucr::toTString(pTmp);
Expand Down Expand Up @@ -667,7 +668,7 @@ DecompressResult DecompressArchive(HWND hWnd, const PathContext& files)
}
if (res.files[1].find(path) == 0)
{
VERIFY(::DeleteFile(res.files[1].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[1])), false));
VERIFY(::DeleteFile(res.files[1].c_str()) || (RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), res.files[1])), false));
}
BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[1].c_str());
res.files[1] = OLE2T(pTmp);
Expand Down Expand Up @@ -698,7 +699,7 @@ DecompressResult DecompressArchive(HWND hWnd, const PathContext& files)
}
if (res.files[2].find(path) == 0)
{
VERIFY(::DeleteFile(res.files[2].c_str()) || (LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), res.files[2])), false));
VERIFY(::DeleteFile(res.files[2].c_str()) || (RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), res.files[2])), false));
}
BSTR pTmp = piHandler->GetDefaultName(hWnd, res.files[2].c_str());
res.files[2] = OLE2T(pTmp);
Expand Down
8 changes: 4 additions & 4 deletions Src/Common/multiformatText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "codepage_detect.h"
#include "Environment.h"
#include "TFile.h"
#include "MergeApp.h"
#include "Logger.h"

using Poco::SharedMemory;
using Poco::FileOutputStream;
Expand Down Expand Up @@ -103,7 +103,7 @@ const tchar_t *storageForPlugins::GetDestFileName()
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}
}
Expand All @@ -125,7 +125,7 @@ void storageForPlugins::ValidateNewFile()
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
// we may reuse the temp filename
// tempFilenameDst.Empty();
Expand All @@ -142,7 +142,7 @@ void storageForPlugins::ValidateNewFile()
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}
else
Expand Down
9 changes: 5 additions & 4 deletions Src/DiffTextBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ccrystaltextview.h"
#include "UniFile.h"
#include "FileLoadResult.h"
#include "Logger.h"
#include "locality.h"
#include "paths.h"
#include "OptionsDef.h"
Expand Down Expand Up @@ -366,7 +367,7 @@ int CDiffTextBuffer::LoadFromFile(const tchar_t* pszFileNameInit,
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}
return nRetVal;
Expand Down Expand Up @@ -436,10 +437,10 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
{
sError = uniErr.GetError();
if (bTempFile)
LogErrorString(strutils::format(_T("Opening file %s failed: %s"),
RootLogger::Error(strutils::format(_T("Opening file %s failed: %s"),
pszFileName, sError));
else
LogErrorString(strutils::format(_T("Opening file %s failed: %s"),
RootLogger::Error(strutils::format(_T("Opening file %s failed: %s"),
sIntermediateFilename, sError));
}
return SAVE_FAILED;
Expand Down Expand Up @@ -525,7 +526,7 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
if (!bSaveSuccess)
{
Expand Down
3 changes: 2 additions & 1 deletion Src/DiffWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Exceptions.h"
#include "parsers/crystallineparser.h"
#include "SyntaxColors.h"
#include "Logger.h"
#include "MergeApp.h"
#include "SubstitutionList.h"
#include "codepage_detect.h"
Expand Down Expand Up @@ -953,7 +954,7 @@ bool CDiffWrapper::RunFileDiff()
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
strFileTemp[file].erase();
}
Expand Down
5 changes: 3 additions & 2 deletions Src/DirActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "DirActions.h"
#include "MergeApp.h"
#include "UnicodeString.h"
#include "Logger.h"
#include "7zCommon.h"
#include "ShellFileOperations.h"
#include "DiffItem.h"
Expand Down Expand Up @@ -228,7 +229,7 @@ void ConfirmActionList(const CDiffContext& ctxt, const FileActionScript & action

// Invalid operation
default:
LogErrorString(_T("Unknown fileoperation in CDirView::ConfirmActionList()"));
RootLogger::Error(_T("Unknown fileoperation in CDirView::ConfirmActionList()"));
throw "Unknown fileoperation in ConfirmActionList()";
break;
}
Expand Down Expand Up @@ -1221,7 +1222,7 @@ int UpdateCompareFlagsAfterSync(DIFFITEM& di, bool bRecursive)
/**
* @brief Update the paths of the diff items recursively.
* @param[in] nDirs Number of directories to compare.
* @param[in,out] di@Item to update the path.
* @param[in,out] di Item to update the path.
*/
void UpdatePaths(int nDirs, DIFFITEM& di)
{
Expand Down
7 changes: 4 additions & 3 deletions Src/FileTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Environment.h"
#include "TFile.h"
#include "paths.h"
#include "Logger.h"
#include "MergeApp.h"

using Poco::Exception;
Expand Down Expand Up @@ -537,7 +538,7 @@ bool PackingInfo::Packing(int target, const String& srcFilepath, const String& d
catch (Poco::Exception& e)
{
DWORD dwErrCode = GetLastError();
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
SetLastError(dwErrCode);
return false;
}
Expand Down Expand Up @@ -954,7 +955,7 @@ bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite)
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}
// and change the filepath if everything works
Expand All @@ -968,7 +969,7 @@ bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite)
}
catch (Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}

Expand Down
13 changes: 7 additions & 6 deletions Src/FolderCmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "TFile.h"
#include "FileFilterHelper.h"
#include "PropertySystem.h"
#include "Logger.h"
#include "MergeApp.h"
#include "DebugNew.h"

Expand Down Expand Up @@ -388,17 +389,17 @@ int FolderCmp::prepAndCompareFiles(DIFFITEM &di)

// delete the temp files after comparison
if (filepathTransformed[0] != filepathUnpacked[0] && !filepathTransformed[0].empty())
try { TFile(filepathTransformed[0]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[0])); }
try { TFile(filepathTransformed[0]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[0])); }
if (filepathTransformed[1] != filepathUnpacked[1] && !filepathTransformed[1].empty())
try { TFile(filepathTransformed[1]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[1])); }
try { TFile(filepathTransformed[1]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[1])); }
if (nDirs > 2 && filepathTransformed[2] != filepathUnpacked[2] && !filepathTransformed[2].empty())
try { TFile(filepathTransformed[2]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[2])); }
try { TFile(filepathTransformed[2]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathTransformed[2])); }
if (filepathUnpacked[0] != tFiles[0] && !filepathUnpacked[0].empty())
try { TFile(filepathUnpacked[0]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[0])); }
try { TFile(filepathUnpacked[0]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[0])); }
if (filepathUnpacked[1] != tFiles[1] && !filepathUnpacked[1].empty())
try { TFile(filepathUnpacked[1]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[1])); }
try { TFile(filepathUnpacked[1]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[1])); }
if (nDirs > 2 && filepathUnpacked[2] != tFiles[2] && !filepathUnpacked[2].empty())
try { TFile(filepathUnpacked[2]).remove(); } catch (...) { LogErrorString(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[2])); }
try { TFile(filepathUnpacked[2]).remove(); } catch (...) { RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed"), filepathUnpacked[2])); }

// When comparing empty file and nonexistent file, `DIFFCODE::SAME` flag is set to the variable `code`, so change the flag to `DIFFCODE::DIFF`
// Also when disabling ignore codepage option and the encodings of files are not equal, change the flag to `DIFFCODE::DIFF even if `DIFFCODE::SAME` flag is set to the variable `code`
Expand Down
3 changes: 2 additions & 1 deletion Src/HexMergeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "OptionsMgr.h"
#include "Environment.h"
#include "Constants.h"
#include "Logger.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -374,7 +375,7 @@ HRESULT CHexMergeView::SaveFile(const tchar_t* path, bool packing)
hr = SE(DeleteFile(sIntermediateFilename.c_str()));
if (hr != S_OK)
{
LogErrorString(strutils::format(_T("DeleteFile(%s) failed: %s"),
RootLogger::Error(strutils::format(_T("DeleteFile(%s) failed: %s"),
sIntermediateFilename, GetSysError(hr)));
}
return S_OK;
Expand Down
4 changes: 2 additions & 2 deletions Src/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Logger
{
public:
enum class LogLevel : int { ERROR, WARN, INFO };
enum class LogLevel : int { ERR, WARN, INFO };

static Logger& Get() { static Logger logger; return logger; }
template<class T> void Info(const T& msg) { if (m_level >= LogLevel::INFO) Log(LogLevel::INFO, msg); }
template<class T> void Warn(const T& msg) { if (m_level >= LogLevel::WARN) Log(LogLevel::WARN, msg); }
template<class T> void Error(const T& msg) { if (m_level >= LogLevel::ERROR) Log(LogLevel::ERROR, msg); }
template<class T> void Error(const T& msg) { if (m_level >= LogLevel::ERR) Log(LogLevel::ERR, msg); }
void Log(LogLevel level, const String& msg);
void Log(LogLevel level, const std::string& msg);
void SetOutputFunction(std::function<void(LogLevel level, const String& msg)> func) { m_func = func; }
Expand Down
9 changes: 5 additions & 4 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "HexMergeView.h"
#include "ImgMergeFrm.h"
#include "WebPageDiffFrm.h"
#include "OutputDoc.h"
#include "OutputBar.h"
#include "OutputView.h"
#include "Logger.h"
#include "LineFiltersList.h"
#include "SubstitutionFiltersList.h"
#include "ConflictFileParser.h"
Expand Down Expand Up @@ -70,9 +74,6 @@
#include "locality.h"
#include "DirWatcher.h"
#include "Win_VersionHelper.h"
#include "OutputDoc.h"
#include "OutputBar.h"
#include "OutputView.h"

#if !defined(SM_CXPADDEDBORDER)
#define SM_CXPADDEDBORDER 92
Expand Down Expand Up @@ -3029,7 +3030,7 @@ bool CMainFrame::DoSelfCompare(UINT nID, const String& file, const String strDes
}
catch (Poco::Exception& e)
{
LogErrorStringUTF8(e.displayText());
RootLogger::Error(e.displayText());
}
}
m_tempFiles.push_back(wTemp);
Expand Down
17 changes: 0 additions & 17 deletions Src/MergeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@ COptionsMgr * GetOptionsMgr()
return pApp->GetMergeOptionsMgr();
}

// Send message to log and debug window
void LogErrorString(const String& sz)
{
if (sz.empty()) return;
CString now = COleDateTime::GetCurrentTime().Format();
TRACE(_T("%s: %s\n"), (const tchar_t*)now, sz.c_str());
}

// Send message to log and debug window
void LogErrorStringUTF8(const std::string& sz)
{
if (sz.empty()) return;
String str = ucr::toTString(sz);
CString now = COleDateTime::GetCurrentTime().Format();
TRACE(_T("%s: %s\n"), (const tchar_t*)now, str.c_str());
}

/**
* @brief Load string resource and return as CString.
* @param [in] id Resource string ID.
Expand Down
2 changes: 0 additions & 2 deletions Src/MergeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ struct AboutInfo
String GetSysError(int nerr = -1);

COptionsMgr * GetOptionsMgr();
void LogErrorString(const String& sz);
void LogErrorStringUTF8(const std::string& sz);
void AppErrorMessageBox(const String& msg);
void* AppGetMainHWND();

Expand Down
3 changes: 2 additions & 1 deletion Src/MergeAppCOMClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "MergeAppCOMClass.h"
#include "OptionsMgr.h"
#include "MergeApp.h"
#include "Logger.h"
#include "resource.h"

MergeAppCOMClass::MergeAppCOMClass()
Expand Down Expand Up @@ -207,7 +208,7 @@ HRESULT STDMETHODCALLTYPE MergeAppCOMClass::InputBox(BSTR prompt, VARIANT varTit

HRESULT STDMETHODCALLTYPE MergeAppCOMClass::LogError(BSTR text)
{
LogErrorString(text);
RootLogger::Error(text);
return S_OK;
}

5 changes: 3 additions & 2 deletions Src/MergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "charsets.h"
#include "markdown.h"
#include "stringdiffs.h"
#include "Logger.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -780,15 +781,15 @@ void CMergeDoc::ShowRescanError(int nRescanResult, IDENTLEVEL identical)
if (nRescanResult == RESCAN_FILE_ERR)
{
s = _("An error occurred while comparing the files.");
LogErrorString(s);
RootLogger::Error(s);
ShowMessageBox(s, MB_ICONSTOP);
return;
}

if (nRescanResult == RESCAN_TEMP_ERR)
{
s = _("Temporary files could not be created. Check your temporary path settings.");
LogErrorString(s);
RootLogger::Error(s);
ShowMessageBox(s, MB_ICONSTOP);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion Src/OpenView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "OpenView.h"
#include <vector>
#include "UnicodeString.h"
#include "Logger.h"
#include "Merge.h"
#include "OpenDoc.h"
#include "ProjectFile.h"
Expand Down Expand Up @@ -292,7 +293,7 @@ void COpenView::OnInitialUpdate()
if (ind != CB_ERR)
m_ctlExt.SetCurSel(ind);
else
LogErrorString(_T("Failed to add string to filters combo list!"));
RootLogger::Error(_T("Failed to add string to filters combo list!"));
}

if (!GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS))
Expand Down
Loading

0 comments on commit 3a0999d

Please sign in to comment.