Skip to content

Commit

Permalink
Config: Save filters to plugin config
Browse files Browse the repository at this point in the history
  • Loading branch information
univrsal committed Mar 31, 2024
1 parent 73b112a commit e2ff51c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ void set_defaults()

void load()
{
/* Assure that ~/.config folder exists */
if (!QDir::home().exists(".config") && !QDir::home().mkdir(".config"))
berr("Couldn't create ~/.config, configuration files won't be saved");

enable_uiohook = CGET_BOOL(S_UIOHOOK);
enable_gamepad_hook = CGET_BOOL(S_GAMEPAD);
enable_websocket_server = CGET_BOOL(S_ENABLE_WSS);
Expand Down
18 changes: 14 additions & 4 deletions src/util/input_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ void input_filter::read_from_config()
m_regex = CGET_BOOL(S_REGEX);
m_whitelist = CGET_INT(S_FILTER_MODE) == 0;
QJsonDocument j;
if (!util_open_json(util_get_data_file("filters.json"), j)) {
berr("Couldn't load filters.json");
return;

char* path = obs_module_config_path("filters.json");

if (!util_open_json(utf8_to_qt(path), j)) {
berr("Couldn't load filters.json from plugin config, trying legacy location");
if (!util_open_json(util_get_data_file_legacy("filters.json"), j)) {
berr("Couldn't load filters.json from legacy location");
bfree(path);
return;
}
}
bfree(path);

if (j.isArray()) {
for (const auto &item : j.array()) {
Expand All @@ -57,8 +65,10 @@ void input_filter::write_to_config()
for (const auto &filter : m_filters)
arr.append(filter);
j.setArray(arr);
util_write_json(util_get_data_file("filters.json"), j);
char* path = obs_module_config_path("filters.json");
util_write_json(utf8_to_qt(path), j);
io_config::filter_mutex.unlock();
bfree(path);
}

void input_filter::add_filter(const char *filter)
Expand Down
4 changes: 2 additions & 2 deletions src/util/obs_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "lang.h"
#include <QDir>

QString util_get_data_file(const QString &file_name)
QString util_get_data_file_legacy(const QString &file_name)
{
QDir home = QDir::homePath();
#if UNIX
Expand Down Expand Up @@ -123,4 +123,4 @@ inline void os_set_thread_name(const char *name)
} __except (EXCEPTION_CONTINUE_EXECUTION) {
}
}
#endif
#endif
5 changes: 3 additions & 2 deletions src/util/obs_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ bool util_write_json(const QString &path, const QJsonDocument &doc);

/* Get file path to /home/user/.config/
* or C:\Users\user\*
* This is deprecated and only used to load old files
*/
QString util_get_data_file(const QString &file_name);
QString util_get_data_file_legacy(const QString &file_name);

/* Source:
* github.com/obsproject/obs-studio/blob/master/UI/frontend-plugins/frontend-tools/auto-scene-switcher-win.cpp
Expand All @@ -59,4 +60,4 @@ extern void GetCurrentWindowTitle(std::string &title);

#if _WIN32
extern void os_set_thread_name(const char *);
#endif
#endif

0 comments on commit e2ff51c

Please sign in to comment.