Skip to content

Commit

Permalink
[NEW_FEATURE] Automatic Backup System (in progress).
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1204 f5eea248-9336-0410-98b8-ebc06183d4e3
  • Loading branch information
donho committed Mar 28, 2014
1 parent 9c9fa8c commit 7cbcc1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 43 deletions.
21 changes: 1 addition & 20 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5760,26 +5760,7 @@ int Notepad_plus::getQuoteIndexFrom(const char *quoter) const

void Notepad_plus::showAllQuotes() const
{
/*
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppTextWriter"));
for (int i = 0; i < nbQuote; i++)
{
static bool firstTime = true;
if (firstTime)
{
firstTime = false;
}
else
{
WaitForSingleObject(mutex, INFINITE);
}
ReleaseMutex(mutex);
Sleep(1000);
showQuoteFromIndex(i);
WaitForSingleObject(mutex, INFINITE);
}
*/

}

void Notepad_plus::showQuoteFromIndex(int index) const
Expand Down
54 changes: 31 additions & 23 deletions PowerEditor/src/ScitillaComponent/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,18 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName)

bool FileManager::backupBuffer(BufferID id, const TCHAR * filename)
{
// This method is called from 2 differents place, so synchronization is important
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem"));
::WaitForSingleObject(mutex, INFINITE);

Buffer * buffer = getBufferByID(id);

TCHAR fullpath[MAX_PATH];
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
::GetLongPathName(fullpath, fullpath, MAX_PATH);

bool result = false;

/*
time_t currentBakModifTimestamp = buffer->getBackupModifiedTimeStamp();
time_t lastBakModifTimestamp = 0;
Expand Down Expand Up @@ -687,33 +693,33 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename)

// Error, we didn't write the entire document to disk.
// Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS.
if(items_written != 1)
{
return false;
}

_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
/*
if (lastBakModifTimestamp != 0)
buffer->setBackupModifiedTimeStamp(lastBakModifTimestamp);
else
if(items_written == 1)
{
struct _stat statBuf;
if (!generic_stat(fullpath, &statBuf))

_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
/*
if (lastBakModifTimestamp != 0)
buffer->setBackupModifiedTimeStamp(lastBakModifTimestamp);
else
{
buffer->setBackupModifiedTimeStamp(statBuf.st_mtime);
struct _stat statBuf;
if (!generic_stat(fullpath, &statBuf))
{
buffer->setBackupModifiedTimeStamp(statBuf.st_mtime);
}
}
}
*/

buffer->setModifiedStatus(false);
*/

buffer->setModifiedStatus(false);

return true; //all done
result = true; //all done
}
}
return false; // fopen failed
}

return true; // buffer dirty nut unmodified
else // buffer dirty but unmodified
{
result = true;
}
}
else // buffer not dirty, sync: delete the backup file
{
Expand All @@ -722,10 +728,12 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename)
{
// delete backup file

return true; // backup file deleted
}
return true; // no backup file to delete
result = true; // no backup file to delete
}

::ReleaseMutex(mutex);
return result;
}

bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg)
Expand Down

0 comments on commit 7cbcc1f

Please sign in to comment.