#ifndef GLOBAL_H
#define GLOBAL_H

#include <QObject>
#include <QList>
#include <QMutex>
#include <QFileInfo>
#include <QDir>

/**
* @brief 配置参数结构体
**/
struct ConfigParam
{
    QStringList inputPaths;
    QString outputPath;

    QString getInputStr()
    {
        QString inputPath;
        for(auto i : inputPaths)
        {
            inputPath = inputPath + i + ";";
        }
        return inputPath;
    }
};


class Global : public QObject
{
    Q_OBJECT
public:
    static Global *Instance();

    void setRootDirPath(const QString &path);
    QString rootDirPath();

    QString resourceDirPath();

    void setConfigParam(ConfigParam p);
    ConfigParam configParam();

    void setInput(QStringList list);
    void setOutput(const QString& output);

protected:
    Global();

private:
    /**
     *@brief 检查资源目录或者文件是否存在
     **/
    void checkResource();

    QString configFilePath();


private:
    static Global *mInstance;
    static QMutex mMutex;

    QString mRootPath;

    ConfigParam mConfigParam;

    // GC类
    // 程序退出后，该类的析构函数释放单例内存
    class GC
    {
    public:
        ~GC()
        {
            if (mInstance != nullptr)
            {
                delete mInstance;
                mInstance = nullptr;
            }
        }
    };

    static GC gc;
};

#endif // GLOBAL_H
