yhkylin-backup-tools/common/utils.h

322 lines
9.1 KiB
C
Raw Normal View History

2021-08-06 10:20:03 +08:00
#ifndef UTILS_H
#define UTILS_H
#include <QString>
#include <QtDebug>
#include "mydefine.h"
2021-11-11 16:03:58 +08:00
class SystemInfo
{
public:
// 操作系统
static QString m_os;
// 架构
static QString m_arch;
// 引导方式
static QString m_archDetect;
};
2021-08-06 10:20:03 +08:00
/**
* @brief
* @author zhaominyong
* @since 2021/07/22
*/
class Utils
{
public:
/**
* @brief initSysRootPath,
* @param qsAppPath
*/
static void initSysRootPath(const QString& qsAppPath);
/**
* @brief getSysRootPath
* @return const QString&
* @note
* initSysRootPath/
*/
static const QString& getSysRootPath() { return m_sysRootPath; }
/**
* @brief customMessageHandler
* @param type debug等
* @param context
* @param msg
*/
static void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
/**
* @brief
* @param frontUidid
* @return
*/
static int lockProgram(int frontUid);
/**
* @brief
* @param lock_file_fd
* @return 01
*/
static int unLockProgram(int lock_file_fd);
/**
* @brief
* @return bool
*/
static bool rmLockFile();
/**
* @brief /etc/.bootinfo是否存在并可读UUID等信息
* @return bool
*/
static bool checkBootInfoExists();
/**
* @brief UUID
* @return UUID
*/
static QString getBackupPartitionUuid();
2021-11-08 09:52:01 +08:00
/**
* @brief UUID映射关系
* @param fstab文件路径
* @return -UUID
*/
static QHash<QString, QString> getPartUuidMap(const QString &fstab);
2021-08-06 10:20:03 +08:00
/**
* @brief
* @param path
*/
static void mkdir(const QString& path);
/**
* @brief
* @param path
* @return bool
*/
static bool mkpath(const QString& path);
/**
* @brief
* @param excludes
*/
static void excludeFstabBindPath(QStringList &excludes);
2021-12-06 14:55:00 +08:00
/**
* @brief
* @param excludes
*/
static void excludeSomeHomePath(QStringList &excludes);
2021-08-06 10:20:03 +08:00
/**
2021-08-17 10:07:35 +08:00
* @brief rsync --exclude-from排除路径规则文件
2021-08-06 10:20:03 +08:00
* @return
*/
static bool generateExcludePathsFile();
2021-08-17 10:07:35 +08:00
/**
* @brief
* @return
*/
static QStringList getFromExcludePathsFile();
/**
* @brief
* @param
* @return true,false,
*/
static bool isDirExist(const QString& fullDirName);
2021-08-24 18:08:18 +08:00
/**
* @brief Uuid
* @return UUID
*/
static QString createUuid();
/**
* @brief
* @param fileName
* @param lines
* @return truefalse
*/
static bool writeFileByLines(const QString& fileName, const QStringList& lines);
/**
* @brief
* @param fileName
* @return booltrue-false-
* @author zhaominyong
* @since 2021/05/29
*/
static bool filsExists(const QString &fileName);
2021-12-09 10:00:07 +08:00
/**
* @brief
* @param fullDirName
* @return true-; false-
*/
static bool isDirEmpty(const QString& fullDirName);
/**
* @brief
* @param line
* @return bool, true-false-
* @author zhaominyong
* @since 2021/05/29
* @note
* rebootfdatasync确保缓存落盘
*/
static bool writeBackupLog(QString line);
2021-09-23 11:21:58 +08:00
/**
* @brief
* @param fileName
* @param content
* @return bool
*/
static bool syncWriteFile(const QString &fileName, const QString& content);
/**
* @brief GB等表示的字符串
* @param sizeqint64
* @return GB/MB/KB等表示的字符串型大小
*/
static QString StringBySize(qint64 size);
2021-10-13 16:31:58 +08:00
/**
* @brief
* @return MOUNTPOINT,PATH键值对列表(path中如果含有空格时显示不对)
* @author zhaominyong
* @since 2021/06/07
* @note
* for bug 59636 cpmHUAWEIKOSL0V3试制dev/sdc的路径(++)
* QStorageInfo::mountedVolumes获取的磁盘列表区分不出来是否移动设备
*/
static QHash<QString, QString> getRemovableStorages();
2021-10-26 09:24:05 +08:00
/**
* @brief
* @param enabletruefalse
*/
static void setKysecStatus(bool enable);
/**
* @brief kysec-sync-daemon服务
* @param enabletruefalse
*/
static void setKysecDaemon(bool enable);
/**
* @brief
* @param processName
* @return true-false-
*/
static bool isRunning(const QString &processName);
/**
* @brief 9909006C处理器
* @return bool
*/
static bool isHuawei990();
/**
* @brief popen()fork()shell以运行命令来开启一个进程
* @param cmd NULL shell bin/sh 使 -c shell
* @param result
* @note 使
*/
static void executeCMD(const char* cmd, QString &result);
2021-11-08 09:52:01 +08:00
static QString executeCmd(const QString &cmd, const QStringList &args = QStringList());
2021-10-26 09:24:05 +08:00
/**
* @brief
* @return
*/
static QList<BackupWrapper> getBackupLogList();
2021-11-11 16:03:58 +08:00
/**
* @brief
*/
static void initSystemInfo();
/**
* @brief getOs
* @return ,
* Kylin-Desktop V10-SP1
* Build 20210407
*/
static QString getOs();
/**
* @brief getArch
* @return arch命令的结果x86_64
*/
static QString getArch();
/**
* @brief getArchDetect
* @return archdetect命令的结果amd64/efi
*/
static QString getArchDetect();
2021-11-20 12:09:26 +08:00
/**
* @brief
* @return
*/
static QHash<QString, QString> getLeftSizeOfPartitions();
2022-01-13 14:06:40 +08:00
/**
* @brief //data分区
* @return
*/
static QHash<QString, qint64> getAvailableSizeOfPartitions();
2021-11-20 17:50:17 +08:00
/**
* @brief
* @param path
* @return
*/
static qint64 getDirOrFileSize(const QString &path);
/**
* @brief uuid及其名称
* @param uuid
* @param backupName
*/
static void update_backup_unique_settings(const QString &uuid, const QString &backupName);
2021-12-06 14:55:00 +08:00
/**
* @brief uuid记录
* @param backupName
*/
static void deleteBackupUniqueRecord(const QString& backupName);
2022-03-09 10:27:29 +08:00
/**
* @brief Uuid-BackupName键值对
* @return Uuid-BackupName键值对
*/
static QMap<QString, QString> getBackupUuidNameMap();
2021-12-09 10:00:07 +08:00
/**
* @brief
* @return
*/
static bool updateSyncFile();
/**
* @brief sleep便
* @param sec
* @author zhaominyong
* @since 2021/05/29
*/
static void wait(uint sec);
2021-08-06 10:20:03 +08:00
private:
// 系统根目录,默认"/"
static QString m_sysRootPath;
};
#endif // UTILS_H