Skip to content

Commit

Permalink
Fix issue #229: Program is crashed!
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 1, 2019
1 parent 3864427 commit 9c16ef8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Src/HexMergeDoc.cpp
Expand Up @@ -550,7 +550,7 @@ void CHexMergeDoc::CheckFileChanged(void)
{
for (int pane = 0; pane < m_nBuffers; ++pane)
{
if (m_pView[pane]->IsFileChangedOnDisk(m_filePaths[pane].c_str()))
if (m_pView[pane]->IsFileChangedOnDisk(m_filePaths[pane].c_str()) == FileChanged)
{
String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge scanned it last time.\n\nDo you want to reload the file?"), m_filePaths[pane]);
if (AfxMessageBox(msg.c_str(), MB_YESNO | MB_ICONWARNING) == IDYES)
Expand Down Expand Up @@ -732,7 +732,8 @@ void CHexMergeDoc::OnFileReload()
fileloc[pane].setPath(m_filePaths[pane]);
bRO[pane] = m_pView[pane]->GetReadOnly();
}
OpenDocs(m_nBuffers, fileloc, bRO, m_strDesc);
if (!OpenDocs(m_nBuffers, fileloc, bRO, m_strDesc))
return;
MoveOnLoad(GetActiveMergeView()->m_nThisPane);
}

Expand Down
11 changes: 6 additions & 5 deletions Src/HexMergeView.cpp
Expand Up @@ -246,18 +246,19 @@ int CHexMergeView::GetLength()
* @param [in] path File to check
* @return `true` if file is changed.
*/
bool CHexMergeView::IsFileChangedOnDisk(LPCTSTR path)
IMergeDoc::FileChange CHexMergeView::IsFileChangedOnDisk(LPCTSTR path)
{
DiffFileInfo dfi;
dfi.Update(path);
if (!dfi.Update(path))
return IMergeDoc::FileRemoved;
int tolerance = 0;
if (GetOptionsMgr()->GetBool(OPT_IGNORE_SMALL_FILETIME))
tolerance = SmallTimeDiff; // From MainFrm.h
int64_t timeDiff = dfi.mtime - m_fileInfo.mtime;
if (timeDiff < 0) timeDiff = -timeDiff;
if ((timeDiff > tolerance * Poco::Timestamp::resolution()) || (dfi.size != m_fileInfo.size))
return true;
return false;
return IMergeDoc::FileChanged;
return IMergeDoc::FileNoChange;
}

/**
Expand Down Expand Up @@ -298,7 +299,7 @@ HRESULT CHexMergeView::LoadFile(LPCTSTR path)
HRESULT CHexMergeView::SaveFile(LPCTSTR path)
{
// Warn user in case file has been changed by someone else
if (IsFileChangedOnDisk(path))
if (IsFileChangedOnDisk(path) == IMergeDoc::FileChanged)
{
String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge loaded it.\n\nOverwrite changed file?"), path);
if (AfxMessageBox(msg.c_str(), MB_ICONWARNING | MB_YESNO) == IDNO)
Expand Down
3 changes: 2 additions & 1 deletion Src/HexMergeView.h
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include "DiffFileInfo.h"
#include "IMergeDoc.h"

class CHexMergeDoc;
class IHexEditorWindow;
Expand Down Expand Up @@ -55,7 +56,7 @@ class CHexMergeView : public CView
bool GetReadOnly();
void SetReadOnly(bool);
void ResizeWindow();
bool IsFileChangedOnDisk(LPCTSTR);
IMergeDoc::FileChange IsFileChangedOnDisk(LPCTSTR);
void ZoomText(int amount);
static void CopySel(const CHexMergeView *src, CHexMergeView *dst);
static void CopyAll(const CHexMergeView *src, CHexMergeView *dst);
Expand Down
7 changes: 7 additions & 0 deletions Src/IMergeDoc.h
Expand Up @@ -6,6 +6,13 @@ class CDirDoc;

struct IMergeDoc
{
enum FileChange
{
FileNoChange,
FileChanged,
FileRemoved,
};

virtual void SetDirDoc(CDirDoc *pDirDoc) = 0;
virtual bool CloseNow(void) = 0;
virtual bool GenerateReport(const String &path) const = 0;
Expand Down
11 changes: 6 additions & 5 deletions Src/ImgMergeFrm.cpp
Expand Up @@ -304,25 +304,26 @@ void CImgMergeFrame::SetDirDoc(CDirDoc * pDirDoc)
m_pDirDoc = pDirDoc;
}

bool CImgMergeFrame::IsFileChangedOnDisk(int pane) const
IMergeDoc::FileChange CImgMergeFrame::IsFileChangedOnDisk(int pane) const
{
DiffFileInfo dfi;
dfi.Update(m_filePaths[pane]);
if (!dfi.Update(m_filePaths[pane]))
return FileRemoved;
int tolerance = 0;
if (GetOptionsMgr()->GetBool(OPT_IGNORE_SMALL_FILETIME))
tolerance = SmallTimeDiff; // From MainFrm.h
int64_t timeDiff = dfi.mtime - m_fileInfo[pane].mtime;
if (timeDiff < 0) timeDiff = -timeDiff;
if ((timeDiff > tolerance * Poco::Timestamp::resolution()) || (dfi.size != m_fileInfo[pane].size))
return true;
return false;
return FileChanged;
return FileNoChange;
}

void CImgMergeFrame::CheckFileChanged(void)
{
for (int pane = 0; pane < m_pImgMergeWindow->GetPaneCount(); ++pane)
{
if (IsFileChangedOnDisk(pane))
if (IsFileChangedOnDisk(pane) == FileChanged)
{
String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge scanned it last time.\n\nDo you want to reload the file?"), m_filePaths[pane]);
if (AfxMessageBox(msg.c_str(), MB_YESNO | MB_ICONWARNING) == IDYES)
Expand Down
2 changes: 1 addition & 1 deletion Src/ImgMergeFrm.h
Expand Up @@ -72,7 +72,7 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc
bool GenerateReport(const String& sFileName) const override;
void DoAutoMerge(int dstPane);
bool IsModified() const;
bool IsFileChangedOnDisk(int pane) const;
IMergeDoc::FileChange IsFileChangedOnDisk(int pane) const;
void CheckFileChanged(void) override;
String GetDescription(int pane) const { return m_strDesc[pane]; }
static bool IsLoadable();
Expand Down
7 changes: 0 additions & 7 deletions Src/MergeDoc.h
Expand Up @@ -140,13 +140,6 @@ class CLocationView;
class CMergeDoc : public CDocument, public IMergeDoc
{
public:
enum FileChange
{
FileNoChange,
FileChanged,
FileRemoved,
};

// Attributes
public:
static int m_nBuffersTemp;
Expand Down

0 comments on commit 9c16ef8

Please sign in to comment.