From 9ca70f44705d76ace9fcefe6809ca5ee240dffd5 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 13 Apr 2021 16:49:01 -0700 Subject: [PATCH] UI: Add obs_frontend_get_current_profile_path() Returns the path of the current profile's location on the filesystem. --- UI/api-interface.cpp | 10 ++++++++++ UI/obs-frontend-api/obs-frontend-api.cpp | 6 ++++++ UI/obs-frontend-api/obs-frontend-api.h | 1 + UI/obs-frontend-api/obs-frontend-internal.hpp | 1 + docs/sphinx/reference-frontend-api.rst | 7 +++++++ 5 files changed, 25 insertions(+) diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index 218ae8d69..50a144fcd 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -238,6 +238,16 @@ struct OBSStudioAPI : obs_frontend_callbacks { return bstrdup(name); } + char *obs_frontend_get_current_profile_path(void) override + { + char profilePath[512]; + int ret = GetProfilePath(profilePath, sizeof(profilePath), ""); + if (ret <= 0) + return nullptr; + + return bstrdup(profilePath); + } + void obs_frontend_set_current_profile(const char *profile) override { QList menuActions = main->ui->profileMenu->actions(); diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index 486d66654..a4bc770bc 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -204,6 +204,12 @@ char *obs_frontend_get_current_profile(void) : nullptr; } +char *obs_frontend_get_current_profile_path(void) +{ + return !!callbacks_valid() ? c->obs_frontend_get_current_profile_path() + : nullptr; +} + void obs_frontend_set_current_profile(const char *profile) { if (callbacks_valid()) diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index d153cffcf..0638dbd1c 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -117,6 +117,7 @@ EXPORT bool obs_frontend_add_scene_collection(const char *name); EXPORT char **obs_frontend_get_profiles(void); EXPORT char *obs_frontend_get_current_profile(void); +EXPORT char *obs_frontend_get_current_profile_path(void); EXPORT void obs_frontend_set_current_profile(const char *profile); typedef void (*obs_frontend_cb)(void *private_data); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index 6f29747e8..c925b8089 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -37,6 +37,7 @@ struct obs_frontend_callbacks { virtual void obs_frontend_get_profiles(std::vector &strings) = 0; virtual char *obs_frontend_get_current_profile(void) = 0; + virtual char *obs_frontend_get_current_profile_path(void) = 0; virtual void obs_frontend_set_current_profile(const char *profile) = 0; virtual void obs_frontend_streaming_start(void) = 0; diff --git a/docs/sphinx/reference-frontend-api.rst b/docs/sphinx/reference-frontend-api.rst index 031c13b36..a3a36ba28 100644 --- a/docs/sphinx/reference-frontend-api.rst +++ b/docs/sphinx/reference-frontend-api.rst @@ -314,6 +314,13 @@ Functions --------------------------------------- +.. function:: char *obs_frontend_get_current_profile_path(void) + + :return: A new pointer to the current profile's path on the filesystem. Free + with :c:func:`bfree()`. + +--------------------------------------- + .. function:: void obs_frontend_set_current_profile(const char *profile) :param profile: Name of the profile to activate.