mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
improvements messages:
- save msgId in configuration file - enable previous improvements read/unread state and tags new function for creating backups of a file bool createBackup (std::string sFilename, unsigned int nCount = 5); currently its only available for windows compile. maybe there is a linux developer who change it for linux. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3064 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
fe98568329
commit
342768e626
8 changed files with 123 additions and 111 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
@ -428,6 +429,60 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool RsDirUtil::createBackup (std::string sFilename, unsigned int nCount)
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
if (GetFileAttributes (sFilename.c_str ()) == -1) {
|
||||
// file doesn't exist
|
||||
return true;
|
||||
}
|
||||
|
||||
// search last backup
|
||||
int nLast;
|
||||
for (nLast = nCount; nLast >= 1; nLast--) {
|
||||
std::ostringstream sStream;
|
||||
sStream << sFilename << nLast << ".bak";
|
||||
|
||||
if (GetFileAttributes (sStream.str ().c_str ()) != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// delete max backup
|
||||
if (nLast == nCount) {
|
||||
std::ostringstream sStream;
|
||||
sStream << sFilename << nCount << ".bak";
|
||||
if (DeleteFile (sStream.str ().c_str ()) == FALSE) {
|
||||
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File delete error", "Error while deleting file " + sStream.str ());
|
||||
return false;
|
||||
}
|
||||
nLast--;
|
||||
}
|
||||
|
||||
// rename backups
|
||||
for (int nIndex = nLast; nIndex >= 1; nIndex--) {
|
||||
std::ostringstream sStream;
|
||||
sStream << sFilename << nIndex << ".bak";
|
||||
std::ostringstream sStream1;
|
||||
sStream1 << sFilename << nIndex + 1 << ".bak";
|
||||
|
||||
if (renameFile (sStream.str (), sStream1.str ()) == false) {
|
||||
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + sStream.str () + " to " + sStream1.str ());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// copy backup
|
||||
std::ostringstream sStream;
|
||||
sStream << sFilename << 1 << ".bak";
|
||||
if (CopyFile (sFilename.c_str (), sStream.str ().c_str (), FALSE) == FALSE) {
|
||||
getPqiNotify()->AddSysMessage (0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + sFilename + " to " + sStream.str ());
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0 // NOT ENABLED YET!
|
||||
/************************* WIDE STRING ***************************/
|
||||
/************************* WIDE STRING ***************************/
|
||||
|
|
|
@ -44,6 +44,7 @@ std::string removeRootDirs(std::string path, std::string root);
|
|||
// Renames file from to file to. Files should be on the same file system.
|
||||
// returns true if succeed, false otherwise.
|
||||
bool renameFile(const std::string& from,const std::string& to) ;
|
||||
bool createBackup (std::string sFilename, unsigned int nCount = 5);
|
||||
|
||||
int breakupDirList(std::string path,
|
||||
std::list<std::string> &subdirs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue