yhkylin-backup-tools/backup-daemon/parsebackuplist.h

139 lines
3.8 KiB
C
Raw Normal View History

2022-11-01 10:40:05 +08:00
#ifndef PARSEBACKUPLIST_H
#define PARSEBACKUPLIST_H
#include <QString>
#include <QDomDocument>
#include <QDomElement>
#include <QList>
#include "../common/mydefine.h"
class ParseBackupList {
public:
enum ParseResult {
// xml解析错误
XML_PARSE_ERR,
// 失败
FAIL,
// 成功
SUCCESS,
};
struct BackupPoint {
// 备份或还原指定的UUID
QString m_uuid;
// 备份名称用来替换m_comment
QString m_backupName;
// 备份时间
QString m_time;
// 本地备份还是U盘备份: 0-本地备份1-移动设备备份2-异机备份仅用于业务场景标记不用于持久化记录3-自定义路径备份
int m_iPosition = -1;
// 操作类型,如:系统备份, 系统还原
int m_type = -1;
// 备份大小
QString m_size;
// 备份状态,如是否完成
QString m_state;
// 备份用户id
QString m_userId;
// 备份机器操作系统
QString m_os;
// 备份机器架构
QString m_arch;
// 备份机器引导方式
QString m_archdetect;
// 备份点所在设备挂载路径(这个暂只在查询中界面展示选择中使用)或自定义的备份路径
QString m_path;
bool isNull() { return m_uuid.isEmpty(); }
bool operator< (const BackupPoint &other);
};
ParseBackupList(const QString& xmlPath);
/**
* @brief backuplist.xml
* @param factoryBackupUuiduuid
* @return ParseResult枚举类型
* @author zhaominyong
* @since 2021/06/27
*/
ParseResult updateForFactoryRestore(const QString &factoryBackupUuid);
/**
* @brief comment查找uuid
* @param comment
* @return uuid
*/
QString findUuidByComment(const QString& comment);
/**
* @brief Uuid查找备份点信息
* @param Uuid
* @return
*/
BackupPoint findBackupPointByUuid(const QString& Uuid);
/**
* @brief xml文件中备份点uuid和backupname的映射
* @param uuid_namexml文件中备份点uuid和backupname的映射
* @return
*/
void getXmlUuidNameMap(QMap<QString, QString> &uuid_name);
/**
* @brief
* @return
*/
BackupPoint getLastSysBackupPoint();
/**
* @brief
* @param customizePaths
*/
void getCustomizePaths(QStringList &customizePaths);
/**
* @brief
* @param backupPoint,
* @return SUCCESS成功 XML_PARSE_ERR失败
*/
ParseResult addItem(const BackupPoint& backupPoint);
/**
* @brief
* @param backupPoint
* @return SUCCESS成功 XML_PARSE_ERR失败
*/
ParseResult updateItem(const BackupPoint & backupPoint);
/**
* @brief
* @param uuid
* @return SUCCESS成功 XML_PARSE_ERR失败
*/
ParseResult deleteItem(const QString& uuid);
/**
* @brief
* @return
*/
QList<BackupPoint> getBackupPointList();
inline QString getXmlPath() { return m_xmlPath; }
private:
bool InitXml();
bool isXmlCorrect();
bool Doc_setContent(QDomDocument& doc);
void elementNodeToBackupPoint(const QDomElement& eleNode, BackupPoint& backupPoint);
void backupPointToElementNode(const BackupPoint& backupPoint, QDomDocument& doc, QDomNode& eleNode);
QDomElement createTextElement(QDomDocument& doc, const QString& tagName, const QString& text);
private:
QString m_xmlPath;
};
#endif // PARSEBACKUPLIST_H