add:uuid

This commit is contained in:
taynpg 2025-04-07 16:42:09 +08:00
parent a667080d96
commit f6bc83b0de
3 changed files with 36 additions and 0 deletions

View File

@ -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()

View File

@ -47,6 +47,7 @@ public:
public:
static ofString now_time();
static ofString get_file_size(long long bytes);
static ofString get_uuid();
};
class CMutBuffer

View File

@ -7,6 +7,12 @@
#ifdef _WIN32
#include <windows.h>
#endif
// 这里这样写是为了处理头文件排序问题
#ifdef _WIN32
#include <rpcdce.h>
#else
#include <uuid/uuid.h>
#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)
{