yhkylin-backup-tools/common/utils.h

340 lines
9.5 KiB
C
Raw Permalink Normal View History

2022-11-01 10:40:05 +08:00
#ifndef UTILS_H
#define UTILS_H
#include <QString>
#include <QtDebug>
#include "mydefine.h"
class SystemInfo
{
public:
// 操作系统
static QString m_os;
// 架构
static QString m_arch;
// 引导方式
static QString m_archDetect;
};
/**
* @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
* @return bool
*/
static bool isTablet();
/**
* @brief UUID
* @return UUID
*/
static QString getBackupPartitionUuid();
/**
* @brief UUID映射关系
* @param fstab文件路径
* @return -UUID
*/
static QHash<QString, QString> getPartUuidMap(const QString &fstab);
/**
* @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);
/**
* @brief
* @param excludes
*/
static void excludeSomeHomePath(QStringList &excludes);
/**
* @brief
* @param excludes
*/
static void excludeCustomizePath(QStringList &excludes);
/**
* @brief rsync --exclude-from排除路径规则文件
* @return
*/
static bool generateExcludePathsFile();
/**
* @brief
* @return
*/
static QStringList getFromExcludePathsFile();
/**
* @brief
* @param
* @return true,false,
*/
static bool isDirExist(const QString& fullDirName);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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();
/**
* @brief
* @return
*/
static QList<QString> getLocalDisks();
/**
* @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);
static QString executeCmd(const QString &cmd, const QStringList &args = QStringList());
/**
* @brief
* @return
*/
static QList<BackupWrapper> getBackupLogList();
/**
* @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();
/**
* @brief
* @return
*/
static QHash<QString, QString> getLeftSizeOfPartitions();
/**
* @brief //data分区
* @return
*/
static QHash<QString, qint64> getAvailableSizeOfPartitions();
/**
* @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);
/**
* @brief uuid记录
* @param backupName
*/
static void deleteBackupUniqueRecord(const QString& backupName);
/**
* @brief Uuid-BackupName键值对
* @return Uuid-BackupName键值对
*/
static QMap<QString, QString> getBackupUuidNameMap();
/**
* @brief
* @return
*/
static bool updateSyncFile();
/**
* @brief sleep便
* @param sec
* @author zhaominyong
* @since 2021/05/29
*/
static void wait(uint sec);
private:
// 系统根目录,默认"/"
static QString m_sysRootPath;
};
#endif // UTILS_H