2021-08-06 10:20:03 +08:00
|
|
|
|
#include "workerfactory.h"
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
2021-08-17 10:07:35 +08:00
|
|
|
|
Worker::Worker() :
|
2022-01-18 17:35:26 +08:00
|
|
|
|
QObject(nullptr),
|
|
|
|
|
m_bCancel(false)
|
2021-08-06 10:20:03 +08:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
Worker::~Worker()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
/**
|
|
|
|
|
* @brief 环境检测
|
|
|
|
|
*/
|
|
|
|
|
void Worker::checkEnv()
|
|
|
|
|
{
|
|
|
|
|
checkEnvEx();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 任务处理
|
|
|
|
|
*/
|
|
|
|
|
void Worker::doWork()
|
|
|
|
|
{
|
|
|
|
|
doWorkEx();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 环境检测,个性化部分派生类去实现
|
2021-08-24 18:08:18 +08:00
|
|
|
|
bool Worker::checkEnvEx()
|
2021-08-26 20:12:48 +08:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-08-06 10:20:03 +08:00
|
|
|
|
|
|
|
|
|
// 任务处理,个性化部分派生类去实现
|
|
|
|
|
void Worker::doWorkEx()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// 任务取消,个性化部分派生类去实现
|
|
|
|
|
void Worker::cancelEx()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 根据操作类型和位置创建相应的处理类
|
|
|
|
|
* @param type 操作类型,如:系统备份, 系统还原
|
|
|
|
|
* @param position 本地备份还是U盘备份: 0-本地备份;1-移动设备备份
|
|
|
|
|
* @return Worker派生类对象指针,需调用者释放此对象
|
|
|
|
|
*/
|
|
|
|
|
Worker * WorkerFactory::createWorker(int type, int position)
|
|
|
|
|
{
|
|
|
|
|
QString className;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case BackupType::BACKUP_SYSTEM:
|
|
|
|
|
case BackupType::INC_BACKUP_SYSTEM:
|
|
|
|
|
if (BackupPosition::UDISK == position) {
|
|
|
|
|
className = "UDiskSystemBackupProxy";
|
2022-04-19 16:13:38 +08:00
|
|
|
|
} else if (BackupPosition::CUSTOMIZE == position) {
|
|
|
|
|
className = "CustomizeSystemBackupProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
className = "SystemBackupProxy";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BackupType::RESTORE_SYSTEM:
|
|
|
|
|
case BackupType::RESTORE_SYSTEM_WITH_DATA:
|
2022-04-26 16:06:54 +08:00
|
|
|
|
if (BackupPosition::UDISK == position || BackupPosition::OTHER == position) {
|
2021-08-06 10:20:03 +08:00
|
|
|
|
className = "UDiskSystemRestoreProxy";
|
2022-04-19 16:13:38 +08:00
|
|
|
|
} else if (BackupPosition::CUSTOMIZE == position) {
|
|
|
|
|
className = "CustomizeSystemRestoreProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
className = "SystemRestoreProxy";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BackupType::BACKUP_DATA:
|
|
|
|
|
case BackupType::INC_BACKUP_DATA:
|
|
|
|
|
if (BackupPosition::UDISK == position) {
|
|
|
|
|
className = "UDiskDataBackupProxy";
|
2022-04-19 16:13:38 +08:00
|
|
|
|
} else if (BackupPosition::CUSTOMIZE == position) {
|
|
|
|
|
className = "CustomizeDataBackupProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
className = "DataBackupProxy";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BackupType::RESTORE_DATA:
|
|
|
|
|
if (BackupPosition::UDISK == position) {
|
|
|
|
|
className = "UDiskDataRestoreProxy";
|
|
|
|
|
} else {
|
|
|
|
|
className = "DataRestoreProxy";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BackupType::DELETE_BACKUP:
|
2021-12-06 14:55:00 +08:00
|
|
|
|
className = "DeleteBackupProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
break;
|
|
|
|
|
case BackupType::GHOST_IMAGE:
|
|
|
|
|
if (BackupPosition::UDISK == position) {
|
2022-01-13 14:06:40 +08:00
|
|
|
|
className = "UDiskGhostImageProxy";
|
2022-04-19 16:13:38 +08:00
|
|
|
|
} else if (BackupPosition::CUSTOMIZE == position) {
|
|
|
|
|
className = "CustomizeGhostImageProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
} else {
|
2022-01-13 14:06:40 +08:00
|
|
|
|
className = "GhostImageProxy";
|
2021-08-06 10:20:03 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (className.isEmpty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Worker * p = qobject_cast<Worker *>(Reflect::createObject(className));
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|