diff --git a/cmake/common/buildspec_common.cmake b/cmake/common/buildspec_common.cmake
index b2c24144..d0f43c7c 100644
--- a/cmake/common/buildspec_common.cmake
+++ b/cmake/common/buildspec_common.cmake
@@ -73,6 +73,13 @@ function(_setup_obs_studio)
set(_cmake_version "3.0.0")
endif()
+ message(STATUS "Patch libobs")
+ execute_process(
+ COMMAND patch --forward "libobs/CMakeLists.txt" "${CMAKE_CURRENT_SOURCE_DIR}/patch_libobs.diff"
+ RESULT_VARIABLE _process_result
+ WORKING_DIRECTORY "${dependencies_dir}/${_obs_destination}")
+ message(STATUS "Patch - done")
+
message(STATUS "Configure ${label} (${arch})")
execute_process(
COMMAND
diff --git a/patch_libobs.diff b/patch_libobs.diff
new file mode 100644
index 00000000..980b79c2
--- /dev/null
+++ b/patch_libobs.diff
@@ -0,0 +1,12 @@
+diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt
+index d2e2671..a08d948 100644
+--- a/libobs/CMakeLists.txt
++++ b/libobs/CMakeLists.txt
+@@ -287,6 +287,7 @@ set(public_headers
+ util/base.h
+ util/bmem.h
+ util/c99defs.h
++ util/config-file.h
+ util/darray.h
+ util/profiler.h
+ util/sse-intrin.h
diff --git a/src/obs-utils/obs-config-utils.cpp b/src/obs-utils/obs-config-utils.cpp
index 40726026..91fdce6d 100644
--- a/src/obs-utils/obs-config-utils.cpp
+++ b/src/obs-utils/obs-config-utils.cpp
@@ -2,49 +2,77 @@
#include "plugin-support.h"
#include
+#include
+#include
-int getFlagFromConfig(const char *name, bool *returnValue)
+void create_config_folder()
{
- // Check configuration to see if update checks are disabled
- char *config_file = obs_module_file("config.json");
- if (!config_file) {
- obs_log(LOG_INFO, "Unable to find config file");
- return OBS_BGREMOVAL_CONFIG_FAIL;
+ char *config_folder_path = obs_module_config_path("");
+ if (config_folder_path == nullptr) {
+ obs_log(LOG_ERROR, "Failed to get config folder path");
+ return;
+ }
+ std::filesystem::path config_folder_std_path(config_folder_path);
+ bfree(config_folder_path);
+
+ // create the folder if it doesn't exist
+ if (!std::filesystem::exists(config_folder_std_path)) {
+#ifdef _WIN32
+ obs_log(LOG_INFO, "Config folder does not exist, creating: %S",
+ config_folder_std_path.c_str());
+#else
+ obs_log(LOG_INFO, "Config folder does not exist, creating: %s",
+ config_folder_std_path.c_str());
+#endif
+ // Create the config folder
+ std::filesystem::create_directories(config_folder_std_path);
}
+}
+
+int getFlagFromConfig(const char *name, bool *returnValue, bool defaultValue)
+{
+ create_config_folder(); // ensure the config folder exists
- obs_data_t *data = obs_data_create_from_json_file(config_file);
- if (!data) {
- obs_log(LOG_INFO, "Failed to parse config file");
+ // Get the config file
+ char *config_file_path = obs_module_config_path("config.ini");
+
+ config_t *config;
+ int ret = config_open(&config, config_file_path, CONFIG_OPEN_EXISTING);
+ if (ret != CONFIG_SUCCESS) {
+ obs_log(LOG_INFO, "Failed to open config file %s",
+ config_file_path);
+ *returnValue = defaultValue;
return OBS_BGREMOVAL_CONFIG_FAIL;
}
- *returnValue = obs_data_get_bool(data, name);
- obs_data_release(data);
+ *returnValue = config_get_bool(config, "config", name);
+ config_close(config);
+
+ bfree(config_file_path);
return OBS_BGREMOVAL_CONFIG_SUCCESS;
}
int setFlagFromConfig(const char *name, const bool value)
{
+ create_config_folder(); // ensure the config folder exists
+
// Get the config file
- char *config_file = obs_module_file("config.json");
- if (!config_file) {
- obs_log(LOG_INFO, "Unable to find config file");
- return OBS_BGREMOVAL_CONFIG_FAIL;
- }
+ char *config_file_path = obs_module_config_path("config.ini");
- // Parse the config file
- obs_data_t *json_data = obs_data_create_from_json_file(config_file);
- if (!json_data) {
- obs_log(LOG_INFO, "Failed to parse config file");
+ config_t *config;
+ int ret = config_open(&config, config_file_path, CONFIG_OPEN_ALWAYS);
+ if (ret != CONFIG_SUCCESS) {
+ obs_log(LOG_INFO, "Failed to open config file %s",
+ config_file_path);
return OBS_BGREMOVAL_CONFIG_FAIL;
}
- // Update the config
- obs_data_set_bool(json_data, name, value);
- obs_data_save_json(json_data, config_file);
+ config_set_bool(config, "config", name, value);
+ config_save(config);
+ config_close(config);
- obs_data_release(json_data);
+ bfree(config_file_path);
return OBS_BGREMOVAL_CONFIG_SUCCESS;
}
diff --git a/src/obs-utils/obs-config-utils.h b/src/obs-utils/obs-config-utils.h
index afcc0df6..00166611 100644
--- a/src/obs-utils/obs-config-utils.h
+++ b/src/obs-utils/obs-config-utils.h
@@ -11,10 +11,11 @@ enum {
*
* @param name The name of the config item.
* @param returnValue The value of the config item.
+ * @param defaultValue The default value of the config item.
* @return OBS_BGREMOVAL_CONFIG_SUCCESS if the config item was found,
* OBS_BGREMOVAL_CONFIG_FAIL otherwise.
*/
-int getFlagFromConfig(const char *name, bool *returnValue);
+int getFlagFromConfig(const char *name, bool *returnValue, bool defaultValue);
/**
* Set a boolean flag in the module configuration file.
diff --git a/src/update-checker/UpdateDialog.cpp b/src/update-checker/UpdateDialog.cpp
index bf0983bd..1b459862 100644
--- a/src/update-checker/UpdateDialog.cpp
+++ b/src/update-checker/UpdateDialog.cpp
@@ -1,5 +1,6 @@
#include "UpdateDialog.hpp"
#include "obs-utils/obs-config-utils.h"
+#include "plugin-support.h"
#include
#include
@@ -11,15 +12,15 @@
static QString dialogContent =
"Background Removal - Update available! 🚀
"
"A new version of the Background Removal plugin (v{version}) is "
+ "href=\"https://github.com/obs-ai/obs-backgroundremoval/releases\">v{version}) is "
"now available for download. We've made some exciting updates and improvements that we think "
"you'll love. To get the latest features and enhancements, please follow the link below:
"
"Download the latest version from GitHub: v{version}
"
+ "href=\"https://github.com/obs-ai/obs-backgroundremoval/releases\">v{version}
"
"Once you've downloaded the new version, install the update as usual, there's no need to "
"uninstall the previous version.
"
"If you have any questions or need assistance during the update process, feel free to reach out"
- " to our support team.
"
+ " to our support team."
"Thank you for using our plugin and we hope you enjoy the latest release! 🙏
"
"Changelog
";
@@ -30,7 +31,8 @@ UpdateDialog::UpdateDialog(
setWindowTitle("Background Removal - Update available! 🚀");
setLayout(layout);
QLabel *label = new QLabel(dialogContent.replace(
- QString("{version}"), QString(latestVersion.version)));
+ QString("{version}"),
+ QString::fromStdString(latestVersion.version)));
label->setOpenExternalLinks(true);
label->setTextInteractionFlags(Qt::TextBrowserInteraction);
label->setTextFormat(Qt::RichText);
@@ -39,7 +41,7 @@ UpdateDialog::UpdateDialog(
QScrollArea *scrollArea = new QScrollArea;
QLabel *scrollAreaLabel =
- new QLabel(QString(latestVersion.responseBody));
+ new QLabel(QString::fromStdString(latestVersion.responseBody));
scrollAreaLabel->setOpenExternalLinks(true);
scrollAreaLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
scrollAreaLabel->setTextFormat(Qt::MarkdownText);
diff --git a/src/update-checker/github-utils.cpp b/src/update-checker/github-utils.cpp
index 09f9f56e..18e26e6b 100644
--- a/src/update-checker/github-utils.cpp
+++ b/src/update-checker/github-utils.cpp
@@ -8,7 +8,7 @@
#include "plugin-support.h"
static const std::string GITHUB_LATEST_RELEASE_URL =
- "https://api.github.com/repos/royshil/obs-backgroundremoval/releases/latest";
+ "https://api.github.com/repos/obs-ai/obs-backgroundremoval/releases/latest";
void github_utils_get_release_information(
std::function callback)
@@ -25,34 +25,20 @@ void github_utils_get_release_information(
if (!data) {
obs_log(LOG_INFO,
"Failed to parse latest release info");
- callback(
- {OBS_BGREMOVAL_GITHUB_UTILS_ERROR, NULL, NULL});
+ callback({OBS_BGREMOVAL_GITHUB_UTILS_ERROR, "", ""});
return;
}
// The version is in the "tag_name" property
- char *version = strdup(obs_data_get_string(data, "tag_name"));
- char *body = strdup(obs_data_get_string(data, "body"));
+ std::string version = obs_data_get_string(data, "tag_name");
+ std::string body = obs_data_get_string(data, "body");
obs_data_release(data);
// remove the "v" prefix in version, if it exists
if (version[0] == 'v') {
- char *newVersion = (char *)malloc(strlen(version) - 1);
- strcpy(newVersion, version + 1);
- free(version);
- version = newVersion;
+ version = version.substr(1);
}
callback({OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS, body, version});
});
}
-
-void github_utils_release_information_free(
- struct github_utils_release_information info)
-{
- if (info.responseBody != NULL)
- free(info.responseBody);
- if (info.version != NULL)
- free(info.version);
- info.responseCode = OBS_BGREMOVAL_GITHUB_UTILS_ERROR;
-}
diff --git a/src/update-checker/github-utils.h b/src/update-checker/github-utils.h
index 804db4bd..986c640d 100644
--- a/src/update-checker/github-utils.h
+++ b/src/update-checker/github-utils.h
@@ -1,6 +1,7 @@
#pragma once
#include
+#include
enum {
OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS = 0,
@@ -9,12 +10,9 @@ enum {
struct github_utils_release_information {
int responseCode;
- char *responseBody;
- char *version;
+ std::string responseBody;
+ std::string version;
};
void github_utils_get_release_information(
std::function callback);
-
-void github_utils_release_information_free(
- struct github_utils_release_information info);
diff --git a/src/update-checker/update-checker.cpp b/src/update-checker/update-checker.cpp
index 4e3ca310..f8568594 100644
--- a/src/update-checker/update-checker.cpp
+++ b/src/update-checker/update-checker.cpp
@@ -10,49 +10,56 @@
#include
-UpdateDialog *update_dialog;
-
extern "C" const char *PLUGIN_VERSION;
+UpdateDialog *update_dialog = nullptr;
+
void check_update(void)
{
- github_utils_get_release_information([](github_utils_release_information
- info) {
- if (info.responseCode == OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS) {
- obs_log(LOG_INFO, "Latest release is %s", info.version);
- bool shouldCheckForUpdates = false;
- if (getFlagFromConfig("check_for_updates",
- &shouldCheckForUpdates) !=
- OBS_BGREMOVAL_CONFIG_SUCCESS) {
- // Failed to get the config value, assume it's enabled
- shouldCheckForUpdates = true;
- }
-
- if (!shouldCheckForUpdates) {
- // Update checks are disabled
- return;
- }
-
- if (strcmp(info.version, PLUGIN_VERSION) == 0) {
- // No update available, latest version is the same as the current version
- return;
- }
-
- try {
- update_dialog = new UpdateDialog(
- info,
- (QWidget *)
- obs_frontend_get_main_window());
- QTimer::singleShot(2000, update_dialog,
- &UpdateDialog::exec);
- } catch (...) {
- obs_log(LOG_ERROR,
- "Failed to construct UpdateDialog");
- }
- } else {
+ bool shouldCheckForUpdates = false;
+ if (getFlagFromConfig("check_for_updates", &shouldCheckForUpdates,
+ true) != OBS_BGREMOVAL_CONFIG_SUCCESS) {
+ // Failed to get the config value, assume it's enabled
+ shouldCheckForUpdates = true;
+ // store the default value
+ setFlagFromConfig("check_for_updates", shouldCheckForUpdates);
+ }
+
+ if (!shouldCheckForUpdates) {
+ // Update checks are disabled
+ return;
+ }
+
+ const auto callback = [](github_utils_release_information info) {
+ if (info.responseCode != OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS) {
obs_log(LOG_INFO,
"failed to get latest release information");
+ return;
}
- github_utils_release_information_free(info);
- });
+ obs_log(LOG_INFO, "Latest release is %s", info.version.c_str());
+
+ if (info.version == PLUGIN_VERSION) {
+ // No update available, latest version is the same as the current version
+ return;
+ }
+
+ try {
+ QTimer::singleShot(2000, [=]() {
+ QWidget *main_window = (QWidget *)
+ obs_frontend_get_main_window();
+ if (main_window == nullptr) {
+ obs_log(LOG_ERROR,
+ "Update Checker failed to get main window");
+ return;
+ }
+ update_dialog =
+ new UpdateDialog(info, main_window);
+ update_dialog->exec();
+ });
+ } catch (...) {
+ obs_log(LOG_ERROR, "Failed to construct UpdateDialog");
+ }
+ };
+
+ github_utils_get_release_information(callback);
}