diff options
Diffstat (limited to 'helper.cpp')
| -rw-r--r-- | helper.cpp | 38 | 
1 files changed, 38 insertions, 0 deletions
| @@ -9,6 +9,7 @@  #include <QByteArray>  #include <QFileInfo>  #include <QFile> +#include <QSettings>  #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1  #include <md5.h> @@ -75,5 +76,42 @@ namespace Helper {  		}  		return retval;  	} + +	bool moveToArchive(const QString &path, const QString &md5){ +		QFileInfo info(path); +		if(!info.exists()){ +			return false; +		} +		QFileInfo destFile = QFileInfo(createArchivePath(path, md5)); +		if(destFile.exists()){ +			destFile = QFileInfo(createArchivePath(path, md5, true)); +			if(destFile.exists()){ +				return false; +			} +		} +		return QFile::rename(path, destFile.absoluteFilePath());	 +	} + +	bool removeFromArchive(const QString &fileName, const QString &md5){ +		QString file = createArchivePath(fileName, md5); +		QFileInfo info(file); +		if(!info.exists()){ +			return false; +		} +		return QFile::remove(file); +	} + +	const QString createArchivePath(const QString &path, const QString &md5, bool withMd5){ +		QSettings s; +		QString archiveDir = s.value("paths/archivedir").toString(); +		QFileInfo info(path); +		QString retval; +		if(withMd5){ +			retval = QString("%1/%2/%3/%4_%5.%6").arg(archiveDir).arg(md5[0]).arg(md5[1]).arg(info.completeBaseName()).arg(md5).arg(info.suffix()); +		}else{ +			retval = QString("%1/%2/%3/%4").arg(archiveDir).arg(md5[0]).arg(md5[1]).arg(info.fileName()); +		} +		return retval; +	}  } | 
