mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
libobs: Add os_generate_uuid() to platform utils
This commit is contained in:
parent
11f88af880
commit
f72cc4498f
|
@ -496,3 +496,10 @@ Other Functions
|
||||||
being translated by Rosetta and running on Apple Silicon Macs. On Windows, it
|
being translated by Rosetta and running on Apple Silicon Macs. On Windows, it
|
||||||
returns true when an x64 binary is being emulated on Windows ARM64 PCs. On all other
|
returns true when an x64 binary is being emulated on Windows ARM64 PCs. On all other
|
||||||
platforms, it will always returns false.
|
platforms, it will always returns false.
|
||||||
|
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
.. function:: char *os_generate_uuid(void)
|
||||||
|
|
||||||
|
Creates a version 4 UUID and returns a NULL-terminated 36-character string.
|
||||||
|
Must be freed with :c:func:`bfree()`.
|
||||||
|
|
|
@ -307,7 +307,7 @@ if(OS_WINDOWS)
|
||||||
libobs PRIVATE UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS
|
libobs PRIVATE UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS
|
||||||
_CRT_NONSTDC_NO_WARNINGS)
|
_CRT_NONSTDC_NO_WARNINGS)
|
||||||
|
|
||||||
target_link_libraries(libobs PRIVATE dxgi Avrt Dwmapi winmm)
|
target_link_libraries(libobs PRIVATE dxgi Avrt Dwmapi winmm Rpcrt4)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_link_libraries(libobs PUBLIC OBS::w32-pthreads)
|
target_link_libraries(libobs PUBLIC OBS::w32-pthreads)
|
||||||
|
@ -374,6 +374,7 @@ elseif(OS_POSIX)
|
||||||
target_compile_definitions(libobs PRIVATE ENABLE_DARRAY_TYPE_TEST)
|
target_compile_definitions(libobs PRIVATE ENABLE_DARRAY_TYPE_TEST)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package(LibUUID REQUIRED)
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED)
|
||||||
find_package(
|
find_package(
|
||||||
XCB
|
XCB
|
||||||
|
@ -393,7 +394,7 @@ elseif(OS_POSIX)
|
||||||
util/pipe-posix.c
|
util/pipe-posix.c
|
||||||
util/platform-nix.c)
|
util/platform-nix.c)
|
||||||
|
|
||||||
target_link_libraries(libobs PRIVATE X11::X11_xcb XCB::XCB)
|
target_link_libraries(libobs PRIVATE X11::X11_xcb XCB::XCB LibUUID::LibUUID)
|
||||||
|
|
||||||
if(USE_XDG)
|
if(USE_XDG)
|
||||||
target_compile_definitions(libobs PRIVATE USE_XDG)
|
target_compile_definitions(libobs PRIVATE USE_XDG)
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
|
@ -1137,3 +1138,13 @@ uint64_t os_get_free_disk_space(const char *dir)
|
||||||
|
|
||||||
return (uint64_t)info.f_frsize * (uint64_t)info.f_bavail;
|
return (uint64_t)info.f_frsize * (uint64_t)info.f_bavail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *os_generate_uuid(void)
|
||||||
|
{
|
||||||
|
uuid_t uuid;
|
||||||
|
// 36 char UUID + NULL
|
||||||
|
char *out = bmalloc(37);
|
||||||
|
uuid_generate(uuid);
|
||||||
|
uuid_unparse_lower(uuid, out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <rpc.h>
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
@ -1479,3 +1480,21 @@ uint64_t os_get_free_disk_space(const char *dir)
|
||||||
|
|
||||||
return success ? free.QuadPart : 0;
|
return success ? free.QuadPart : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *os_generate_uuid(void)
|
||||||
|
{
|
||||||
|
UUID uuid;
|
||||||
|
|
||||||
|
RPC_STATUS res = UuidCreate(&uuid);
|
||||||
|
if (res != RPC_S_OK && res != RPC_S_UUID_LOCAL_ONLY)
|
||||||
|
bcrash("Failed to get UUID, RPC_STATUS: %l", res);
|
||||||
|
|
||||||
|
struct dstr uuid_str = {0};
|
||||||
|
dstr_printf(&uuid_str,
|
||||||
|
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||||
|
uuid.Data1, uuid.Data2, uuid.Data3, uuid.Data4[0],
|
||||||
|
uuid.Data4[1], uuid.Data4[2], uuid.Data4[3], uuid.Data4[4],
|
||||||
|
uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]);
|
||||||
|
|
||||||
|
return uuid_str.array;
|
||||||
|
}
|
||||||
|
|
|
@ -201,6 +201,10 @@ EXPORT bool os_get_proc_memory_usage(os_proc_memory_usage_t *usage);
|
||||||
EXPORT uint64_t os_get_proc_resident_size(void);
|
EXPORT uint64_t os_get_proc_resident_size(void);
|
||||||
EXPORT uint64_t os_get_proc_virtual_size(void);
|
EXPORT uint64_t os_get_proc_virtual_size(void);
|
||||||
|
|
||||||
|
#define UUID_STR_LENGTH 36
|
||||||
|
|
||||||
|
EXPORT char *os_generate_uuid(void);
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
# define ARCH_BITS 64
|
# define ARCH_BITS 64
|
||||||
|
|
Loading…
Reference in a new issue