#ifndef DEVICE_CTRL_PROCESS_UTIL_H
#define DEVICE_CTRL_PROCESS_UTIL_H
#include <QCoreApplication>
#include <string>

namespace zsy::ProcessUtil
{
    inline std::string workDir()
    {
        static std::string workDir = []
        {
            return QCoreApplication::applicationDirPath().toStdString();
        }();
        return workDir;
    }

    inline std::string homeDir()
    {
        static std::string homeDir = []
        {
            auto workDir = ProcessUtil::workDir();
            if (workDir.ends_with("bin"))
            {
                const size_t lastSlash = workDir.find_last_of("\\/");
                return lastSlash == std::string::npos ? workDir : workDir.substr(0, lastSlash);
            }
            return workDir;
        }();
        return homeDir;
    }

    inline int64_t processId()
    {
        return QCoreApplication::applicationPid();
    }
} // zsy

#endif // DEVICE_CTRL_PROCESS_UTIL_H
