[NEW_FEATURE] Automatic Backup System (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1218 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2014-04-10 18:16:11 +00:00
parent 7ec6d51d8f
commit b30c3246d4
11 changed files with 68 additions and 35 deletions

View File

@ -3209,9 +3209,12 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
{ {
//scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED //scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
if (isBackupMode)
{
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
}
Buffer * pBuf = MainFileManager->getBufferByID(id); Buffer * pBuf = MainFileManager->getBufferByID(id);
bool reload = pBuf->getNeedReload(); bool reload = pBuf->getNeedReload();
if (reload) if (reload)
@ -4471,8 +4474,9 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
if (doCloseOrNot(buffer->getFullPathName()) == IDNO) if (doCloseOrNot(buffer->getFullPathName()) == IDNO)
{ {
//close in both views, doing current view last since that has to remain opened //close in both views, doing current view last since that has to remain opened
doClose(buffer->getID(), otherView(), true); bool isBackupMode = nppGUI._isBackupMode;
doClose(buffer->getID(), currentView(), true); doClose(buffer->getID(), otherView(), isBackupMode);
doClose(buffer->getID(), currentView(), isBackupMode);
} }
break; break;
} }
@ -5750,19 +5754,17 @@ void Notepad_plus::showQuoteFromIndex(int index) const
void Notepad_plus::launchDocumentBackupTask() void Notepad_plus::launchDocumentBackupTask()
{ {
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, this, 0, NULL); size_t timer = NppParameters::getInstance()->getNppGUI()._backupTiming;
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, &timer, 0, NULL);
::CloseHandle(hThread); ::CloseHandle(hThread);
} }
DWORD WINAPI Notepad_plus::backupDocument(void *param) DWORD WINAPI Notepad_plus::backupDocument(void *param)
{ {
Notepad_plus *notepad_plus = static_cast<Notepad_plus *>(param); size_t *timer = (size_t *)param;
//static int i = 0; while (*timer)
while (notepad_plus)
{ {
::Sleep(7000); ::Sleep(*timer);
//printInt(i++);
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
} }
return TRUE; return TRUE;

View File

@ -290,7 +290,8 @@ public:
void loadLastSession(){ void loadLastSession(){
Session lastSession = (NppParameters::getInstance())->getSession(); Session lastSession = (NppParameters::getInstance())->getSession();
loadSession(lastSession, true); bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
loadSession(lastSession, isBackupMode);
}; };
bool loadSession(Session & session, bool isBackupMode = false); bool loadSession(Session & session, bool isBackupMode = false);

View File

@ -223,8 +223,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
::MessageBoxA(NULL, dest, "", MB_OK); ::MessageBoxA(NULL, dest, "", MB_OK);
} }
bool doBackup = true; bool isBackupMode = nppGUI._isBackupMode;
if (doBackup) if (isBackupMode)
{ {
_notepad_plus_plus_core.checkModifiedDocument(); _notepad_plus_plus_core.checkModifiedDocument();
// Lauch backup task // Lauch backup task

View File

@ -1398,6 +1398,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (_pTrayIco) if (_pTrayIco)
_pTrayIco->doTrayIcon(REMOVE); _pTrayIco->doTrayIcon(REMOVE);
bool isBackupMode = pNppParam->getNppGUI()._isBackupMode;
if (isBackupMode)
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
const NppGUI & nppgui = pNppParam->getNppGUI(); const NppGUI & nppgui = pNppParam->getNppGUI();
@ -1409,7 +1411,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
//Causing them to show on restart even though they are loaded by session //Causing them to show on restart even though they are loaded by session
_lastRecentFileList.setLock(true); //only lock when the session is remembered _lastRecentFileList.setLock(true); //only lock when the session is remembered
} }
bool allClosed = fileCloseAll(false, true); //try closing files before doing anything else bool allClosed = fileCloseAll(false, isBackupMode); //try closing files before doing anything else
if (nppgui._rememberLastSession) if (nppgui._rememberLastSession)
{ {

View File

@ -117,9 +117,12 @@ void Notepad_plus::command(int id)
break; break;
case IDM_FILE_CLOSEALL: case IDM_FILE_CLOSEALL:
fileCloseAll(true, false); {
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
fileCloseAll(isBackupMode, false);
checkDocState(); checkDocState();
break; break;
}
case IDM_FILE_CLOSEALL_BUT_CURRENT : case IDM_FILE_CLOSEALL_BUT_CURRENT :
fileCloseAllButCurrent(); fileCloseAllButCurrent();

View File

@ -597,7 +597,8 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
viewToClose = curView; viewToClose = curView;
//first check amount of documents, we dont want the view to hide if we closed a secondary doc with primary being empty //first check amount of documents, we dont want the view to hide if we closed a secondary doc with primary being empty
//int nrDocs = _pDocTab->nbItem(); //int nrDocs = _pDocTab->nbItem();
doClose(bufferID, viewToClose, true); bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
doClose(bufferID, viewToClose, isBackupMode);
return true; return true;
} }
@ -732,8 +733,9 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
} }
// Now we close. // Now we close.
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) { for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), true); doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isBackupMode);
} }
return true; return true;
@ -824,13 +826,15 @@ bool Notepad_plus::fileCloseAllButCurrent()
} }
} }
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
//Then start closing, inactive view first so the active is left open //Then start closing, inactive view first so the active is left open
if (bothActive()) if (bothActive())
{ //first close all docs in non-current view, which gets closed automatically { //first close all docs in non-current view, which gets closed automatically
//Set active tab to the last one closed. //Set active tab to the last one closed.
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView()); activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
doClose(_pNonDocTab->getBufferByIndex(i), otherView(), true); doClose(_pNonDocTab->getBufferByIndex(i), otherView(), isBackupMode);
} }
//hideView(otherView()); //hideView(otherView());
} }
@ -840,7 +844,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
if (i == active) { //dont close active index if (i == active) { //dont close active index
continue; continue;
} }
doClose(_pDocTab->getBufferByIndex(i), currentView(), true); doClose(_pDocTab->getBufferByIndex(i), currentView(), isBackupMode);
} }
return true; return true;
} }
@ -1055,8 +1059,9 @@ bool Notepad_plus::fileDelete(BufferID id)
MB_OK); MB_OK);
return false; return false;
} }
doClose(bufferID, MAIN_VIEW, true); bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
doClose(bufferID, SUB_VIEW, true); doClose(bufferID, MAIN_VIEW, isBackupMode);
doClose(bufferID, SUB_VIEW, isBackupMode);
return true; return true;
} }
return false; return false;

View File

@ -111,9 +111,13 @@ BOOL Notepad_plus::notify(SCNotification *notification)
buf->setDirty(isDirty); buf->setDirty(isDirty);
if (notification->nmhdr.code == SCN_SAVEPOINTREACHED) if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
{
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
if (isBackupMode)
{ {
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
} }
}
break; break;
} }
@ -271,16 +275,24 @@ BOOL Notepad_plus::notify(SCNotification *notification)
} }
} }
else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf() && _activeView == SUB_VIEW) else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf() && _activeView == SUB_VIEW)
{
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
if (isBackupMode)
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
}
// Switch off // Switch off
switchEditViewTo(MAIN_VIEW); switchEditViewTo(MAIN_VIEW);
} }
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf() && _activeView == MAIN_VIEW) else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf() && _activeView == MAIN_VIEW)
{
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
if (isBackupMode)
{ {
// Before switching off, synchronize backup file // Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
}
// Switch off // Switch off
switchEditViewTo(SUB_VIEW); switchEditViewTo(SUB_VIEW);
} }

View File

@ -648,7 +648,7 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
_pXmlSessionDoc(NULL), _pXmlBlacklistDoc(NULL), _nbUserLang(0), _nbExternalLang(0),\ _pXmlSessionDoc(NULL), _pXmlBlacklistDoc(NULL), _nbUserLang(0), _nbExternalLang(0),\
_hUser32(NULL), _hUXTheme(NULL), _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\ _hUser32(NULL), _hUXTheme(NULL), _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\
_pNativeLangSpeaker(NULL), _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1),\ _pNativeLangSpeaker(NULL), _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1),\
_asNotepadStyle(false), _isFindReplacing(false)/*, _forceLoadingSession(false)*/ _asNotepadStyle(false), _isFindReplacing(false)
{ {
// init import UDL array // init import UDL array
_nbImportedULD = 0; _nbImportedULD = 0;
@ -3859,6 +3859,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
const TCHAR *pDir = element->Attribute(TEXT("dir")); const TCHAR *pDir = element->Attribute(TEXT("dir"));
if (pDir) if (pDir)
_nppGUI._backupDir = pDir; _nppGUI._backupDir = pDir;
} }
else if (!lstrcmp(nm, TEXT("DockingManager"))) else if (!lstrcmp(nm, TEXT("DockingManager")))
{ {

View File

@ -714,7 +714,7 @@ struct NppGUI
_autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")),\ _autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")),\
_doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _enableMultiSelection(false), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false),\ _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _enableMultiSelection(false), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false),\
_smartHiliteCaseSensitive(false), _leftmostDelimiter('('), _rightmostDelimiter(')'), _delimiterSelectionOnEntireDocument(false), _multiInstSetting(monoInst),\ _smartHiliteCaseSensitive(false), _leftmostDelimiter('('), _rightmostDelimiter(')'), _delimiterSelectionOnEntireDocument(false), _multiInstSetting(monoInst),\
_fileSwitcherWithoutExtColumn(false) { _fileSwitcherWithoutExtColumn(false), _isBackupMode(false), _backupTiming(7000) {
_appPos.left = 0; _appPos.left = 0;
_appPos.top = 0; _appPos.top = 0;
_appPos.right = 700; _appPos.right = 700;
@ -814,6 +814,15 @@ struct NppGUI
generic_string _themeName; generic_string _themeName;
MultiInstSetting _multiInstSetting; MultiInstSetting _multiInstSetting;
bool _fileSwitcherWithoutExtColumn; bool _fileSwitcherWithoutExtColumn;
/*
bool isBackupMode() const {return _isBackupMode;};
void setBackupMode(bool doBackup) {_isBackupMode = doBackup;};
size_t getBackupTiming() const {return _backupTiming;};
void setBackupTiming(size_t timing) {_backupTiming = timing;};
*/
bool _isBackupMode;
size_t _backupTiming;
}; };
struct ScintillaViewParams struct ScintillaViewParams
@ -1492,6 +1501,7 @@ public:
bool _isFindReplacing; // an on the fly variable for find/replace functions bool _isFindReplacing; // an on the fly variable for find/replace functions
void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection); void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection);
#ifdef UNICODE #ifdef UNICODE
LocalizationSwitcher & getLocalizationSwitcher() { LocalizationSwitcher & getLocalizationSwitcher() {
return _localizationSwitcher; return _localizationSwitcher;

View File

@ -774,7 +774,6 @@ bool FileManager::deleteCurrentBufferBackup()
buffer->setBackupFileName(TEXT("")); buffer->setBackupFileName(TEXT(""));
result = (::DeleteFile(file2Delete.c_str()) != 0); result = (::DeleteFile(file2Delete.c_str()) != 0);
} }
//printStr(TEXT("backup deleted in deleteCurrentBufferBackup"));
::ReleaseMutex(mutex); ::ReleaseMutex(mutex);
return result; return result;
} }

View File

@ -321,8 +321,6 @@ public :
Lang * getCurrentLang() const; Lang * getCurrentLang() const;
//time_t getBackupModifiedTimeStamp() const {return _backupModifiedTimeStamp;};
//void setBackupModifiedTimeStamp(time_t timestamp2Set) {_backupModifiedTimeStamp = timestamp2Set;};
bool isModified() const {return _isModified;}; bool isModified() const {return _isModified;};
void setModifiedStatus(bool isModified) {_isModified = isModified;}; void setModifiedStatus(bool isModified) {_isModified = isModified;};
generic_string getBackupFileName() const {return _backupFileName;}; generic_string getBackupFileName() const {return _backupFileName;};