本文整理汇总了C++中ConfigFile::Swap方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigFile::Swap方法的具体用法?C++ ConfigFile::Swap怎么用?C++ ConfigFile::Swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigFile
的用法示例。
在下文中一共展示了ConfigFile::Swap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ChangeProfile
void OBSBasic::ChangeProfile()
{
QAction *action = reinterpret_cast<QAction*>(sender());
ConfigFile config;
std::string path;
if (!action)
return;
path = QT_TO_UTF8(action->property("file_name").value<QString>());
if (path.empty())
return;
const char *oldName = config_get_string(App()->GlobalConfig(),
"Basic", "Profile");
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'",
path.c_str());
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);
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
newDir);
config.Swap(basicConfig);
InitBasicConfigDefaults();
ResetProfileData();
RefreshProfiles();
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
UpdateTitleBar();
blog(LOG_INFO, "Switched to profile '%s' (%s)",
newName, newDir);
blog(LOG_INFO, "------------------------------------------------");
if (api)
api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
}
示例2: on_actionRemoveProfile_triggered
void OBSBasic::on_actionRemoveProfile_triggered()
{
std::string newName;
std::string newPath;
ConfigFile config;
std::string oldDir = config_get_string(App()->GlobalConfig(),
"Basic", "ProfileDir");
std::string oldName = config_get_string(App()->GlobalConfig(),
"Basic", "Profile");
auto cb = [&](const char *name, const char *filePath)
{
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()));
QMessageBox::StandardButton button = QMessageBox::question(this,
QTStr("ConfirmRemove.Title"), text);
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'",
newPath.c_str());
return;
}
newPath.resize(newPath_len);
const char *newDir = strrchr(newPath.c_str(), '/') + 1;
config_set_string(App()->GlobalConfig(), "Basic", "Profile",
newName.c_str());
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
newDir);
config.Swap(basicConfig);
InitBasicConfigDefaults();
ResetProfileData();
DeleteProfile(oldName.c_str(), oldDir.c_str());
RefreshProfiles();
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
blog(LOG_INFO, "Switched to profile '%s' (%s)",
newName.c_str(), newDir);
blog(LOG_INFO, "------------------------------------------------");
UpdateTitleBar();
}
示例3: AddProfile
bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
const char *init_text)
{
std::string newName;
std::string newDir;
ConfigFile config;
if (!GetProfileName(this, newName, newDir, title, text, init_text))
return false;
std::string curDir = config_get_string(App()->GlobalConfig(),
"Basic", "ProfileDir");
char newPath[512];
int ret = GetConfigPath(newPath, 512, "obs-studio/basic/profiles/");
if (ret <= 0) {
blog(LOG_WARNING, "Failed to get profiles config path");
return false;
}
strcat(newPath, newDir.c_str());
if (os_mkdir(newPath) < 0) {
blog(LOG_WARNING, "Failed to create profile directory '%s'",
newDir.c_str());
return false;
}
if (!create_new)
CopyProfile(curDir.c_str(), newPath);
strcat(newPath, "/basic.ini");
if (config.Open(newPath, CONFIG_OPEN_ALWAYS) != 0) {
blog(LOG_ERROR, "Failed to open new config file '%s'",
newDir.c_str());
return false;
}
config_set_string(App()->GlobalConfig(), "Basic", "Profile",
newName.c_str());
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
newDir.c_str());
config_set_string(config, "General", "Name", newName.c_str());
config.SaveSafe("tmp");
config.Swap(basicConfig);
InitBasicConfigDefaults();
RefreshProfiles();
if (create_new)
ResetProfileData();
blog(LOG_INFO, "Created profile '%s' (%s, %s)", newName.c_str(),
create_new ? "clean" : "duplicate", newDir.c_str());
blog(LOG_INFO, "------------------------------------------------");
config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
UpdateTitleBar();
return true;
}