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(); if (api) { api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED); api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED); } return true; }
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(App()->GlobalConfig()); blog(LOG_INFO, "Switched to profile '%s' (%s)", newName.c_str(), newDir); blog(LOG_INFO, "------------------------------------------------"); UpdateTitleBar(); }
static void upgrade_settings(void) { char path[512]; int pathlen = GetConfigPath(path, 512, "obs-studio/basic/profiles"); if (pathlen <= 0) return; if (!os_file_exists(path)) return; os_dir_t *dir = os_opendir(path); if (!dir) return; struct os_dirent *ent = os_readdir(dir); while (ent) { if (ent->directory && strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) { strcat(path, "/"); strcat(path, ent->d_name); strcat(path, "/basic.ini"); ConfigFile config; int ret; ret = config.Open(path, CONFIG_OPEN_EXISTING); if (ret == CONFIG_SUCCESS) { if (update_ffmpeg_output(config) || update_reconnect(config)) { config_save_safe(config, "tmp", nullptr); } } if (config) { const char *sEnc = config_get_string(config, "AdvOut", "Encoder"); const char *rEnc = config_get_string(config, "AdvOut", "RecEncoder"); /* replace "cbr" option with "rate_control" for * each profile's encoder data */ path[pathlen] = 0; strcat(path, "/"); strcat(path, ent->d_name); strcat(path, "/recordEncoder.json"); convert_14_2_encoder_setting(rEnc, path); path[pathlen] = 0; strcat(path, "/"); strcat(path, ent->d_name); strcat(path, "/streamEncoder.json"); convert_14_2_encoder_setting(sEnc, path); } path[pathlen] = 0; } ent = os_readdir(dir); } os_closedir(dir); }
BOOL Material::LoadFromFile(CTSTR lpFile) { traceIn(Material::LoadFromFile); String path; ConfigFile materialFile; if(!materialFile.Open(lpFile)) { AppWarning(TEXT("Couldn't load material file '%s'"), lpFile); return FALSE; } effect = ::GetEffect(materialFile.GetString(TEXT("Material"), TEXT("Effect"))); if(!effect) { AppWarning(TEXT("Invalid effect in material file '%s'"), lpFile); return FALSE; } String soundName = materialFile.GetString(TEXT("Material"), TEXT("SoftSound")); if(soundName.IsValid()) SetSoftHitSound(soundName); soundName = materialFile.GetString(TEXT("Material"), TEXT("HardSound")); if(soundName.IsValid()) SetHardHitSound(soundName); restitution = materialFile.GetFloat(TEXT("Material"), TEXT("Restitution")); friction = materialFile.GetFloat(TEXT("Material"), TEXT("Friction"), 0.5f); DWORD curParamID = 0; HANDLE hCurParam; while(hCurParam = effect->GetParameter(curParamID++)) { EffectParameterInfo paramInfo; effect->GetEffectParameterInfo(hCurParam, paramInfo); if(paramInfo.propertyType != EffectProperty_None) { if(paramInfo.propertyType == EffectProperty_Texture) { MaterialParameter *param = Params.CreateNew(); param->type = Parameter_Texture; param->handle = hCurParam; *(BaseTexture**)param->data = GetTexture(materialFile.GetString(TEXT("Parameters"), paramInfo.name)); } else if(paramInfo.propertyType == EffectProperty_Color) { MaterialParameter *param = Params.CreateNew(); param->type = Parameter_Vector3; param->handle = hCurParam; Vect chi = materialFile.GetColor3(TEXT("Parameters"), paramInfo.name); mcpy(param->data, &chi, sizeof(Vect)); } else if(paramInfo.propertyType == EffectProperty_Float) { MaterialParameter *param = Params.CreateNew(); param->type = Parameter_Float; param->handle = hCurParam; *(float*)param->data = materialFile.GetFloat(TEXT("Parameters"), paramInfo.name)*paramInfo.fMul; } } } return TRUE; traceOut; }