yolobs-studio/UI/window-basic-main-profiles.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

697 lines
18 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
/******************************************************************************
Copyright (C) 2015 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <obs.hpp>
#include <util/platform.h>
#include <util/util.hpp>
#include <QMessageBox>
#include <QVariant>
2017-04-19 19:54:15 +00:00
#include <QFileDialog>
2016-02-23 23:16:51 +00:00
#include "window-basic-main.hpp"
#include "window-namedialog.hpp"
#include "qt-wrappers.hpp"
2019-07-27 12:47:10 +00:00
extern void DestroyPanelCookieManager();
extern void DuplicateCurrentCookieProfile(ConfigFile &config);
extern void CheckExistingCookieId();
extern void DeleteCookies();
2019-09-22 21:19:10 +00:00
void EnumProfiles(std::function<bool(const char *, const char *)> &&cb)
2016-02-23 23:16:51 +00:00
{
char path[512];
os_glob_t *glob;
int ret = GetConfigPath(path, sizeof(path),
2019-09-22 21:19:10 +00:00
"obs-studio/basic/profiles/*");
2016-02-23 23:16:51 +00:00
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return;
}
if (os_glob(path, 0, &glob) != 0) {
blog(LOG_WARNING, "Failed to glob profiles");
return;
}
for (size_t i = 0; i < glob->gl_pathc; i++) {
const char *filePath = glob->gl_pathv[i].path;
const char *dirName = strrchr(filePath, '/') + 1;
if (!glob->gl_pathv[i].directory)
continue;
2019-09-22 21:19:10 +00:00
if (strcmp(dirName, ".") == 0 || strcmp(dirName, "..") == 0)
2016-02-23 23:16:51 +00:00
continue;
std::string file = filePath;
file += "/basic.ini";
ConfigFile config;
int ret = config.Open(file.c_str(), CONFIG_OPEN_EXISTING);
if (ret != CONFIG_SUCCESS)
continue;
const char *name = config_get_string(config, "General", "Name");
if (!name)
name = strrchr(filePath, '/') + 1;
if (!cb(name, filePath))
break;
}
os_globfree(glob);
}
static bool ProfileExists(const char *findName)
{
bool found = false;
2019-09-22 21:19:10 +00:00
auto func = [&](const char *name, const char *) {
2016-02-23 23:16:51 +00:00
if (strcmp(name, findName) == 0) {
found = true;
return false;
}
return true;
};
EnumProfiles(func);
return found;
}
static bool GetProfileName(QWidget *parent, std::string &name,
2019-09-22 21:19:10 +00:00
std::string &file, const char *title,
const char *text, const char *oldName = nullptr)
2016-02-23 23:16:51 +00:00
{
char path[512];
int ret;
for (;;) {
2019-09-22 21:19:10 +00:00
bool success = NameDialog::AskForName(parent, title, text, name,
QT_UTF8(oldName));
2016-02-23 23:16:51 +00:00
if (!success) {
return false;
}
if (name.empty()) {
2019-07-27 12:47:10 +00:00
OBSMessageBox::warning(parent,
2019-09-22 21:19:10 +00:00
QTStr("NoNameEntered.Title"),
QTStr("NoNameEntered.Text"));
2016-02-23 23:16:51 +00:00
continue;
}
if (ProfileExists(name.c_str())) {
2019-07-27 12:47:10 +00:00
OBSMessageBox::warning(parent,
2019-09-22 21:19:10 +00:00
QTStr("NameExists.Title"),
QTStr("NameExists.Text"));
2016-02-23 23:16:51 +00:00
continue;
}
break;
}
if (!GetFileSafeName(name.c_str(), file)) {
blog(LOG_WARNING, "Failed to create safe file name for '%s'",
2019-09-22 21:19:10 +00:00
name.c_str());
2016-02-23 23:16:51 +00:00
return false;
}
ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/profiles/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return false;
}
file.insert(0, path);
if (!GetClosestUnusedFileName(file, nullptr)) {
blog(LOG_WARNING, "Failed to get closest file name for %s",
2019-09-22 21:19:10 +00:00
file.c_str());
2016-02-23 23:16:51 +00:00
return false;
}
file.erase(0, ret);
return true;
}
static bool CopyProfile(const char *fromPartial, const char *to)
{
os_glob_t *glob;
2019-07-27 12:47:10 +00:00
char path[514];
2018-02-19 19:54:37 +00:00
char dir[512];
2016-02-23 23:16:51 +00:00
int ret;
2018-02-19 19:54:37 +00:00
ret = GetConfigPath(dir, sizeof(dir), "obs-studio/basic/profiles/");
2016-02-23 23:16:51 +00:00
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return false;
}
2018-02-19 19:54:37 +00:00
snprintf(path, sizeof(path), "%s%s/*", dir, fromPartial);
2016-02-23 23:16:51 +00:00
if (os_glob(path, 0, &glob) != 0) {
blog(LOG_WARNING, "Failed to glob profile '%s'", fromPartial);
return false;
}
for (size_t i = 0; i < glob->gl_pathc; i++) {
const char *filePath = glob->gl_pathv[i].path;
if (glob->gl_pathv[i].directory)
continue;
2019-09-22 21:19:10 +00:00
ret = snprintf(path, sizeof(path), "%s/%s", to,
strrchr(filePath, '/') + 1);
2016-02-23 23:16:51 +00:00
if (ret > 0) {
if (os_copyfile(filePath, path) != 0) {
2019-09-22 21:19:10 +00:00
blog(LOG_WARNING,
"CopyProfile: Failed to "
"copy file %s to %s",
filePath, path);
2016-02-23 23:16:51 +00:00
}
}
}
os_globfree(glob);
return true;
}
bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
2019-09-22 21:19:10 +00:00
const char *init_text, bool rename)
2016-02-23 23:16:51 +00:00
{
std::string newName;
std::string newDir;
2018-02-19 19:54:37 +00:00
std::string newPath;
2016-02-23 23:16:51 +00:00
ConfigFile config;
if (!GetProfileName(this, newName, newDir, title, text, init_text))
return false;
2019-09-22 21:19:10 +00:00
std::string curDir =
config_get_string(App()->GlobalConfig(), "Basic", "ProfileDir");
2016-02-23 23:16:51 +00:00
2018-02-19 19:54:37 +00:00
char baseDir[512];
int ret = GetConfigPath(baseDir, sizeof(baseDir),
2019-09-22 21:19:10 +00:00
"obs-studio/basic/profiles/");
2016-02-23 23:16:51 +00:00
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return false;
}
2018-02-19 19:54:37 +00:00
newPath = baseDir;
newPath += newDir;
2016-02-23 23:16:51 +00:00
2018-02-19 19:54:37 +00:00
if (os_mkdir(newPath.c_str()) < 0) {
2016-02-23 23:16:51 +00:00
blog(LOG_WARNING, "Failed to create profile directory '%s'",
2019-09-22 21:19:10 +00:00
newDir.c_str());
2016-02-23 23:16:51 +00:00
return false;
}
if (!create_new)
2018-02-19 19:54:37 +00:00
CopyProfile(curDir.c_str(), newPath.c_str());
2016-02-23 23:16:51 +00:00
2018-02-19 19:54:37 +00:00
newPath += "/basic.ini";
2016-02-23 23:16:51 +00:00
2018-02-19 19:54:37 +00:00
if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
2016-02-23 23:16:51 +00:00
blog(LOG_ERROR, "Failed to open new config file '%s'",
2019-09-22 21:19:10 +00:00
newDir.c_str());
2016-02-23 23:16:51 +00:00
return false;
}
config_set_string(App()->GlobalConfig(), "Basic", "Profile",
2019-09-22 21:19:10 +00:00
newName.c_str());
2016-02-23 23:16:51 +00:00
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
2019-09-22 21:19:10 +00:00
newDir.c_str());
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
Auth::Save();
if (create_new) {
auth.reset();
DestroyPanelCookieManager();
} else if (!rename) {
DuplicateCurrentCookieProfile(config);
}
2016-02-23 23:16:51 +00:00
config_set_string(config, "General", "Name", newName.c_str());
2019-07-27 12:47:10 +00:00
basicConfig.SaveSafe("tmp");
2016-02-23 23:16:51 +00:00
config.SaveSafe("tmp");
config.Swap(basicConfig);
InitBasicConfigDefaults();
2019-07-27 12:47:10 +00:00
InitBasicConfigDefaults2();
2016-02-23 23:16:51 +00:00
RefreshProfiles();
if (create_new)
ResetProfileData();
blog(LOG_INFO, "Created profile '%s' (%s, %s)", newName.c_str(),
2019-09-22 21:19:10 +00:00
create_new ? "clean" : "duplicate", newDir.c_str());
2016-02-23 23:16:51 +00:00
blog(LOG_INFO, "------------------------------------------------");
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
UpdateTitleBar();
2016-10-10 19:01:40 +00:00
if (api) {
api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
}
2016-02-23 23:16:51 +00:00
return true;
}
void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir)
{
char profilePath[512];
char basePath[512];
int ret = GetConfigPath(basePath, 512, "obs-studio/basic/profiles");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return;
}
ret = snprintf(profilePath, 512, "%s/%s/*", basePath, profileDir);
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get path for profile dir '%s'",
2019-09-22 21:19:10 +00:00
profileDir);
2016-02-23 23:16:51 +00:00
return;
}
os_glob_t *glob;
if (os_glob(profilePath, 0, &glob) != 0) {
blog(LOG_WARNING, "Failed to glob profile dir '%s'",
2019-09-22 21:19:10 +00:00
profileDir);
2016-02-23 23:16:51 +00:00
return;
}
for (size_t i = 0; i < glob->gl_pathc; i++) {
const char *filePath = glob->gl_pathv[i].path;
if (glob->gl_pathv[i].directory)
continue;
os_unlink(filePath);
}
os_globfree(glob);
ret = snprintf(profilePath, 512, "%s/%s", basePath, profileDir);
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get path for profile dir '%s'",
2019-09-22 21:19:10 +00:00
profileDir);
2016-02-23 23:16:51 +00:00
return;
}
os_rmdir(profilePath);
blog(LOG_INFO, "------------------------------------------------");
2019-09-22 21:19:10 +00:00
blog(LOG_INFO, "Removed profile '%s' (%s)", profileName, profileDir);
2016-02-23 23:16:51 +00:00
blog(LOG_INFO, "------------------------------------------------");
}
void OBSBasic::RefreshProfiles()
{
2019-09-22 21:19:10 +00:00
QList<QAction *> menuActions = ui->profileMenu->actions();
2016-02-23 23:16:51 +00:00
int count = 0;
for (int i = 0; i < menuActions.count(); i++) {
QVariant v = menuActions[i]->property("file_name");
if (v.typeName() != nullptr)
delete menuActions[i];
}
2019-09-22 21:19:10 +00:00
const char *curName =
config_get_string(App()->GlobalConfig(), "Basic", "Profile");
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
auto addProfile = [&](const char *name, const char *path) {
2016-02-23 23:16:51 +00:00
std::string file = strrchr(path, '/') + 1;
QAction *action = new QAction(QT_UTF8(name), this);
action->setProperty("file_name", QT_UTF8(path));
2019-09-22 21:19:10 +00:00
connect(action, &QAction::triggered, this,
&OBSBasic::ChangeProfile);
2016-02-23 23:16:51 +00:00
action->setCheckable(true);
action->setChecked(strcmp(name, curName) == 0);
ui->profileMenu->addAction(action);
count++;
return true;
};
EnumProfiles(addProfile);
ui->actionRemoveProfile->setEnabled(count > 1);
}
void OBSBasic::ResetProfileData()
{
ResetVideo();
service = nullptr;
InitService();
ResetOutputs();
ClearHotkeys();
CreateHotkeys();
2018-12-16 16:14:58 +00:00
/* load audio monitoring */
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
2019-09-22 21:19:10 +00:00
const char *device_name =
config_get_string(basicConfig, "Audio", "MonitoringDeviceName");
const char *device_id =
config_get_string(basicConfig, "Audio", "MonitoringDeviceId");
2018-12-16 16:14:58 +00:00
obs_set_audio_monitoring_device(device_name, device_id);
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
2019-09-22 21:19:10 +00:00
device_name, device_id);
2018-12-16 16:14:58 +00:00
#endif
2016-02-23 23:16:51 +00:00
}
void OBSBasic::on_actionNewProfile_triggered()
{
AddProfile(true, Str("AddProfile.Title"), Str("AddProfile.Text"));
}
void OBSBasic::on_actionDupProfile_triggered()
{
AddProfile(false, Str("AddProfile.Title"), Str("AddProfile.Text"));
}
void OBSBasic::on_actionRenameProfile_triggered()
{
2019-09-22 21:19:10 +00:00
std::string curDir =
config_get_string(App()->GlobalConfig(), "Basic", "ProfileDir");
std::string curName =
config_get_string(App()->GlobalConfig(), "Basic", "Profile");
2016-02-23 23:16:51 +00:00
/* Duplicate and delete in case there are any issues in the process */
bool success = AddProfile(false, Str("RenameProfile.Title"),
2019-09-22 21:19:10 +00:00
Str("AddProfile.Text"), curName.c_str(),
true);
2016-02-23 23:16:51 +00:00
if (success) {
DeleteProfile(curName.c_str(), curDir.c_str());
RefreshProfiles();
}
2016-10-10 19:01:40 +00:00
if (api) {
api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
}
2016-02-23 23:16:51 +00:00
}
void OBSBasic::on_actionRemoveProfile_triggered()
{
std::string newName;
std::string newPath;
ConfigFile config;
2019-09-22 21:19:10 +00:00
std::string oldDir =
config_get_string(App()->GlobalConfig(), "Basic", "ProfileDir");
std::string oldName =
config_get_string(App()->GlobalConfig(), "Basic", "Profile");
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
auto cb = [&](const char *name, const char *filePath) {
2016-02-23 23:16:51 +00:00
if (strcmp(oldName.c_str(), name) != 0) {
newName = name;
newPath = filePath;
return false;
}
return true;
};
EnumProfiles(cb);
/* this should never be true due to menu item being grayed out */
if (newPath.empty())
return;
QString text = QTStr("ConfirmRemove.Text");
text.replace("$1", QT_UTF8(oldName.c_str()));
2019-09-22 21:19:10 +00:00
QMessageBox::StandardButton button = OBSMessageBox::question(
this, QTStr("ConfirmRemove.Title"), text);
2016-02-23 23:16:51 +00:00
if (button == QMessageBox::No)
return;
size_t newPath_len = newPath.size();
newPath += "/basic.ini";
if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
2019-09-22 21:19:10 +00:00
newPath.c_str());
2016-02-23 23:16:51 +00:00
return;
}
newPath.resize(newPath_len);
const char *newDir = strrchr(newPath.c_str(), '/') + 1;
config_set_string(App()->GlobalConfig(), "Basic", "Profile",
2019-09-22 21:19:10 +00:00
newName.c_str());
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
Auth::Save();
auth.reset();
DeleteCookies();
DestroyPanelCookieManager();
2016-02-23 23:16:51 +00:00
config.Swap(basicConfig);
InitBasicConfigDefaults();
2019-07-27 12:47:10 +00:00
InitBasicConfigDefaults2();
2016-02-23 23:16:51 +00:00
ResetProfileData();
DeleteProfile(oldName.c_str(), oldDir.c_str());
RefreshProfiles();
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
2019-09-22 21:19:10 +00:00
blog(LOG_INFO, "Switched to profile '%s' (%s)", newName.c_str(),
newDir);
2016-02-23 23:16:51 +00:00
blog(LOG_INFO, "------------------------------------------------");
UpdateTitleBar();
2016-10-10 19:01:40 +00:00
2019-07-27 12:47:10 +00:00
Auth::Load();
2016-10-10 19:01:40 +00:00
if (api) {
api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
}
2016-02-23 23:16:51 +00:00
}
2017-04-19 19:54:15 +00:00
void OBSBasic::on_actionImportProfile_triggered()
{
char path[512];
QString home = QDir::homePath();
int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profile config path");
return;
}
2020-10-01 20:15:25 +00:00
QString dir = SelectDirectory(
this, QTStr("Basic.MainMenu.Profile.Import"), home);
2017-04-19 19:54:15 +00:00
if (!dir.isEmpty() && !dir.isNull()) {
QString inputPath = QString::fromUtf8(path);
QFileInfo finfo(dir);
QString directory = finfo.fileName();
QString profileDir = inputPath + directory;
2020-03-25 08:07:22 +00:00
if (ProfileExists(directory.toStdString().c_str())) {
OBSMessageBox::warning(
this, QTStr("Basic.MainMenu.Profile.Import"),
QTStr("Basic.MainMenu.Profile.Exists"));
} else if (os_mkdir(profileDir.toStdString().c_str()) < 0) {
blog(LOG_WARNING,
"Failed to create profile directory '%s'",
directory.toStdString().c_str());
} else {
2017-04-19 19:54:15 +00:00
QFile::copy(dir + "/basic.ini",
2019-09-22 21:19:10 +00:00
profileDir + "/basic.ini");
2017-04-19 19:54:15 +00:00
QFile::copy(dir + "/service.json",
2019-09-22 21:19:10 +00:00
profileDir + "/service.json");
2017-04-19 19:54:15 +00:00
QFile::copy(dir + "/streamEncoder.json",
2019-09-22 21:19:10 +00:00
profileDir + "/streamEncoder.json");
2017-04-19 19:54:15 +00:00
QFile::copy(dir + "/recordEncoder.json",
2019-09-22 21:19:10 +00:00
profileDir + "/recordEncoder.json");
2017-04-19 19:54:15 +00:00
RefreshProfiles();
}
}
}
void OBSBasic::on_actionExportProfile_triggered()
{
char path[512];
QString home = QDir::homePath();
2019-09-22 21:19:10 +00:00
QString currentProfile = QString::fromUtf8(config_get_string(
App()->GlobalConfig(), "Basic", "ProfileDir"));
2017-04-19 19:54:15 +00:00
int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profile config path");
return;
}
2020-10-01 20:15:25 +00:00
QString dir = SelectDirectory(
this, QTStr("Basic.MainMenu.Profile.Export"), home);
2017-04-19 19:54:15 +00:00
if (!dir.isEmpty() && !dir.isNull()) {
QString outputDir = dir + "/" + currentProfile;
QString inputPath = QString::fromUtf8(path);
QDir folder(outputDir);
if (!folder.exists()) {
folder.mkpath(outputDir);
2018-02-19 19:54:37 +00:00
} else {
if (QFile::exists(outputDir + "/basic.ini"))
QFile::remove(outputDir + "/basic.ini");
if (QFile::exists(outputDir + "/service.json"))
QFile::remove(outputDir + "/service.json");
if (QFile::exists(outputDir + "/streamEncoder.json"))
2019-09-22 21:19:10 +00:00
QFile::remove(outputDir +
"/streamEncoder.json");
2018-02-19 19:54:37 +00:00
if (QFile::exists(outputDir + "/recordEncoder.json"))
2019-09-22 21:19:10 +00:00
QFile::remove(outputDir +
"/recordEncoder.json");
2017-04-19 19:54:15 +00:00
}
2018-02-19 19:54:37 +00:00
QFile::copy(inputPath + currentProfile + "/basic.ini",
2019-09-22 21:19:10 +00:00
outputDir + "/basic.ini");
2018-02-19 19:54:37 +00:00
QFile::copy(inputPath + currentProfile + "/service.json",
2019-09-22 21:19:10 +00:00
outputDir + "/service.json");
2018-02-19 19:54:37 +00:00
QFile::copy(inputPath + currentProfile + "/streamEncoder.json",
2019-09-22 21:19:10 +00:00
outputDir + "/streamEncoder.json");
2018-02-19 19:54:37 +00:00
QFile::copy(inputPath + currentProfile + "/recordEncoder.json",
2019-09-22 21:19:10 +00:00
outputDir + "/recordEncoder.json");
2017-04-19 19:54:15 +00:00
}
}
2016-02-23 23:16:51 +00:00
void OBSBasic::ChangeProfile()
{
2019-09-22 21:19:10 +00:00
QAction *action = reinterpret_cast<QAction *>(sender());
2016-02-23 23:16:51 +00:00
ConfigFile config;
std::string path;
if (!action)
return;
path = QT_TO_UTF8(action->property("file_name").value<QString>());
if (path.empty())
return;
2019-09-22 21:19:10 +00:00
const char *oldName =
config_get_string(App()->GlobalConfig(), "Basic", "Profile");
2016-02-23 23:16:51 +00:00
if (action->text().compare(QT_UTF8(oldName)) == 0) {
action->setChecked(true);
return;
}
size_t path_len = path.size();
path += "/basic.ini";
if (config.Open(path.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
2019-09-22 21:19:10 +00:00
path.c_str());
2016-02-23 23:16:51 +00:00
return;
}
path.resize(path_len);
const char *newName = config_get_string(config, "General", "Name");
const char *newDir = strrchr(path.c_str(), '/') + 1;
config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName);
2019-09-22 21:19:10 +00:00
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
2016-02-23 23:16:51 +00:00
2019-07-27 12:47:10 +00:00
Auth::Save();
auth.reset();
DestroyPanelCookieManager();
2016-02-23 23:16:51 +00:00
config.Swap(basicConfig);
InitBasicConfigDefaults();
2019-07-27 12:47:10 +00:00
InitBasicConfigDefaults2();
2016-02-23 23:16:51 +00:00
ResetProfileData();
RefreshProfiles();
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
UpdateTitleBar();
2019-07-27 12:47:10 +00:00
Auth::Load();
2018-02-19 19:54:37 +00:00
CheckForSimpleModeX264Fallback();
2019-09-22 21:19:10 +00:00
blog(LOG_INFO, "Switched to profile '%s' (%s)", newName, newDir);
2016-02-23 23:16:51 +00:00
blog(LOG_INFO, "------------------------------------------------");
2016-10-10 19:01:40 +00:00
if (api)
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
2016-02-23 23:16:51 +00:00
}
2018-02-19 19:54:37 +00:00
void OBSBasic::CheckForSimpleModeX264Fallback()
{
2019-09-22 21:19:10 +00:00
const char *curStreamEncoder =
config_get_string(basicConfig, "SimpleOutput", "StreamEncoder");
const char *curRecEncoder =
config_get_string(basicConfig, "SimpleOutput", "RecEncoder");
2018-02-19 19:54:37 +00:00
bool qsv_supported = false;
bool amd_supported = false;
bool nve_supported = false;
bool changed = false;
size_t idx = 0;
const char *id;
while (obs_enum_encoder_types(idx++, &id)) {
if (strcmp(id, "amd_amf_h264") == 0)
amd_supported = true;
else if (strcmp(id, "obs_qsv11") == 0)
qsv_supported = true;
else if (strcmp(id, "ffmpeg_nvenc") == 0)
nve_supported = true;
}
2019-09-22 21:19:10 +00:00
auto CheckEncoder = [&](const char *&name) {
2018-02-19 19:54:37 +00:00
if (strcmp(name, SIMPLE_ENCODER_QSV) == 0) {
if (!qsv_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
} else if (strcmp(name, SIMPLE_ENCODER_NVENC) == 0) {
if (!nve_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
} else if (strcmp(name, SIMPLE_ENCODER_AMD) == 0) {
if (!amd_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
}
return true;
};
if (!CheckEncoder(curStreamEncoder))
2019-09-22 21:19:10 +00:00
config_set_string(basicConfig, "SimpleOutput", "StreamEncoder",
curStreamEncoder);
2018-02-19 19:54:37 +00:00
if (!CheckEncoder(curRecEncoder))
2019-09-22 21:19:10 +00:00
config_set_string(basicConfig, "SimpleOutput", "RecEncoder",
curRecEncoder);
2018-02-19 19:54:37 +00:00
if (changed)
config_save_safe(basicConfig, "tmp", nullptr);
}