diff --git a/CMakeLists.txt b/CMakeLists.txt index c804877..3b91323 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,4 +56,6 @@ if(UNAME_OUT MATCHES "alpine" OR UNAME_OUT MATCHES "Alpine") message(STATUS "ofen on musl static link") target_link_libraries(ofen -static;-static-libstdc++) endif() +else() +target_link_libraries(ofen PRIVATE Rpcrt4) endif() diff --git a/include/of_util.h b/include/of_util.h index cba2a0e..2427828 100644 --- a/include/of_util.h +++ b/include/of_util.h @@ -47,6 +47,7 @@ public: public: static ofString now_time(); static ofString get_file_size(long long bytes); + static ofString get_uuid(); }; class CMutBuffer diff --git a/src/of_util.cpp b/src/of_util.cpp index d96a8fa..c4ac551 100644 --- a/src/of_util.cpp +++ b/src/of_util.cpp @@ -7,6 +7,12 @@ #ifdef _WIN32 #include #endif +// 这里这样写是为了处理头文件排序问题 +#ifdef _WIN32 +#include +#else +#include +#endif namespace ofen { void CMutBuffer::push(const char* data, int len) @@ -117,6 +123,33 @@ ofString OfUtil::get_file_size(long long bytes) return oss.str(); } +ofString OfUtil::get_uuid() +{ +#ifdef _WIN32 + UUID uuid; + UuidCreate(&uuid); + ofChar* pUuid = nullptr; +#ifdef UNICODE_OFSTR + UuidToStringW(&uuid, (RPC_CSTR*)&pUuid); +#else + UuidToStringA(&uuid, (RPC_CSTR*)&pUuid); +#endif + ofString ret(pUuid); +#ifdef UNICODE_OFSTR + RpcStringFreeW((RPC_CSTR*)&pUuid); +#else + RpcStringFreeA((RPC_CSTR*)&pUuid); +#endif + return ret; +#else + uuid_t uuid; + uuid_generate(uuid); + char uuid_str[37]; + uuid_unparse(uuid, uuid_str); + return ofString(uuid_str); +#endif +} + #ifdef _WIN32 std::string CCodec::u8_to_ansi(const std::string& str) {