#include "my_utility.h"

namespace MyUtility
{
    std::string GenerateUUID()
    {
        std::random_device rd;
        std::mt19937_64 gen(rd());
        std::uniform_int_distribution<uint64_t> dis;

        uint64_t part1 = dis(gen);
        uint64_t part2 = dis(gen);

        std::ostringstream oss;
        oss << std::hex << part1 << part2;

        std::string uuidStr = oss.str();
        return uuidStr.substr(0, 32); // 截取32位作为简化的UUID
    }

    std::string GetCacheDirectory()
    {
        const char* env_tmp = std::getenv("TMPDIR");
        if (env_tmp != nullptr) {
            return env_tmp;
        }

#ifdef _WIN32
        env_tmp = std::getenv("TEMP");
        if (env_tmp == nullptr) {
            env_tmp = std::getenv("TMP");
        }
#else
        env_tmp = "/tmp";
#endif

        return env_tmp ? env_tmp : "";
    }
}


