Merge pull request #120 from andreas-jonsson/tempfix_corruption

[BUG_FIXED] Prevent big file corruption on some long period operations.
pull/140/head
Don HO 10 years ago
commit 17e8ca3c15

@ -0,0 +1,42 @@
// This file is part of Notepad++ project
// Copyright (C)2003 Don HO <don.h@free.fr>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "LongRunningOperation.h"
#include <mutex>
static std::recursive_mutex _operationMutex;
LongRunningOperation::LongRunningOperation()
{
_operationMutex.lock();
}
LongRunningOperation::~LongRunningOperation()
{
_operationMutex.unlock();
}

@ -0,0 +1,39 @@
// This file is part of Notepad++ project
// Copyright (C)2003 Don HO <don.h@free.fr>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef M30_IDE_LONGRUNNINGOPERATION_h
#define M30_IDE_LONGRUNNINGOPERATION_h
class LongRunningOperation
{
public:
LongRunningOperation();
~LongRunningOperation();
};
#endif //M30_IDE_LONGRUNNINGOPERATION_h

@ -36,6 +36,7 @@
#include "documentMap.h" #include "documentMap.h"
#include "functionListPanel.h" #include "functionListPanel.h"
#include "Sorters.h" #include "Sorters.h"
#include "LongRunningOperation.h"
void Notepad_plus::macroPlayback(Macro macro) void Notepad_plus::macroPlayback(Macro macro)
@ -178,16 +179,22 @@ void Notepad_plus::command(int id)
break; break;
case IDM_EDIT_UNDO: case IDM_EDIT_UNDO:
{
LongRunningOperation op;
_pEditView->execute(WM_UNDO); _pEditView->execute(WM_UNDO);
checkClipboard(); checkClipboard();
checkUndoState(); checkUndoState();
break; break;
}
case IDM_EDIT_REDO: case IDM_EDIT_REDO:
{
LongRunningOperation op;
_pEditView->execute(SCI_REDO); _pEditView->execute(SCI_REDO);
checkClipboard(); checkClipboard();
checkUndoState(); checkUndoState();
break; break;
}
case IDM_EDIT_CUT: case IDM_EDIT_CUT:
_pEditView->execute(WM_CUT); _pEditView->execute(WM_CUT);
@ -260,6 +267,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_PASTE: case IDM_EDIT_PASTE:
{ {
LongRunningOperation op;
int eolMode = int(_pEditView->execute(SCI_GETEOLMODE)); int eolMode = int(_pEditView->execute(SCI_GETEOLMODE));
_pEditView->execute(SCI_PASTE); _pEditView->execute(SCI_PASTE);
_pEditView->execute(SCI_CONVERTEOLS, eolMode); _pEditView->execute(SCI_CONVERTEOLS, eolMode);
@ -268,6 +276,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_PASTE_BINARY: case IDM_EDIT_PASTE_BINARY:
{ {
LongRunningOperation op;
if (!IsClipboardFormatAvailable(CF_TEXT)) if (!IsClipboardFormatAvailable(CF_TEXT))
return; return;
@ -312,6 +321,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_PASTE_AS_RTF: case IDM_EDIT_PASTE_AS_RTF:
case IDM_EDIT_PASTE_AS_HTML: case IDM_EDIT_PASTE_AS_HTML:
{ {
LongRunningOperation op;
UINT f = RegisterClipboardFormat(id==IDM_EDIT_PASTE_AS_HTML?CF_HTML:CF_RTF); UINT f = RegisterClipboardFormat(id==IDM_EDIT_PASTE_AS_HTML?CF_HTML:CF_RTF);
if (!IsClipboardFormatAvailable(f)) if (!IsClipboardFormatAvailable(f))
@ -354,6 +364,8 @@ void Notepad_plus::command(int id)
case IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING: case IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING:
case IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING: case IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING:
{ {
LongRunningOperation op;
size_t fromLine = 0, toLine = 0; size_t fromLine = 0, toLine = 0;
size_t fromColumn = 0, toColumn = 0; size_t fromColumn = 0, toColumn = 0;

@ -34,6 +34,7 @@
#include "ScintillaEditView.h" #include "ScintillaEditView.h"
#include "EncodingMapper.h" #include "EncodingMapper.h"
#include "uchardet.h" #include "uchardet.h"
#include "LongRunningOperation.h"
FileManager * FileManager::_pSelf = new FileManager(); FileManager * FileManager::_pSelf = new FileManager();
@ -675,6 +676,8 @@ For untitled document (new 4)
*/ */
bool FileManager::backupCurrentBuffer() bool FileManager::backupCurrentBuffer()
{ {
LongRunningOperation op;
Buffer * buffer = _pNotepadPlus->getCurrentBuffer(); Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
bool result = false; bool result = false;
bool hasModifForSession = false; bool hasModifForSession = false;

@ -31,6 +31,7 @@
#include "ScintillaEditView.h" #include "ScintillaEditView.h"
#include "Notepad_plus_msgs.h" #include "Notepad_plus_msgs.h"
#include "UniConversion.h" #include "UniConversion.h"
#include "LongRunningOperation.h"
FindOption * FindReplaceDlg::_env; FindOption * FindReplaceDlg::_env;
FindOption FindReplaceDlg::_options; FindOption FindReplaceDlg::_options;
@ -725,6 +726,7 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
case IDREPLACE : case IDREPLACE :
{ {
LongRunningOperation op;
if (_currentStatus == REPLACE_DLG) if (_currentStatus == REPLACE_DLG)
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(TEXT(""), FSNoMessage);
@ -811,6 +813,7 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
case IDD_FINDINFILES_REPLACEINFILES : case IDD_FINDINFILES_REPLACEINFILES :
{ {
LongRunningOperation op;
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(TEXT(""), FSNoMessage);
const int filterSize = 256; const int filterSize = 256;
TCHAR filters[filterSize]; TCHAR filters[filterSize];
@ -851,6 +854,7 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
case IDC_REPLACE_OPENEDFILES : case IDC_REPLACE_OPENEDFILES :
{ {
LongRunningOperation op;
if (_currentStatus == REPLACE_DLG) if (_currentStatus == REPLACE_DLG)
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(TEXT(""), FSNoMessage);
@ -871,6 +875,7 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
case IDREPLACEALL : case IDREPLACEALL :
{ {
LongRunningOperation op;
if (_currentStatus == REPLACE_DLG) if (_currentStatus == REPLACE_DLG)
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(TEXT(""), FSNoMessage);

@ -138,6 +138,7 @@ copy ..\src\contextMenu.xml ..\bin\contextMenu.xml
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\MISC\Common\LongRunningOperation.cpp" />
<ClCompile Include="..\src\WinControls\AboutDlg\AboutDlg.cpp" /> <ClCompile Include="..\src\WinControls\AboutDlg\AboutDlg.cpp" />
<ClCompile Include="..\src\WinControls\AnsiCharPanel\ansiCharPanel.cpp" /> <ClCompile Include="..\src\WinControls\AnsiCharPanel\ansiCharPanel.cpp" />
<ClCompile Include="..\src\ScitillaComponent\AutoCompletion.cpp" /> <ClCompile Include="..\src\ScitillaComponent\AutoCompletion.cpp" />

Loading…
Cancel
Save