Merge pull request #310 from andiabrudan/duplicate_profiles

Add option to duplicate profile
This commit is contained in:
Callow 2022-07-19 02:35:38 +03:00 committed by GitHub
commit ea771f19f3
3 changed files with 29 additions and 0 deletions

View File

@ -173,6 +173,13 @@ namespace cheat
config::RemoveProfile(profileName); config::RemoveProfile(profileName);
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
ImGui::SetTooltip("Delete"); ImGui::SetTooltip("Delete");
ImGui::SameLine();
if (ImGui::SmallButton("Dupe"))
config::DuplicateProfile(profileName);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Duplicate Profile");
} }
void CheatManagerBase::DrawProfileEntry(const std::string& profileName) void CheatManagerBase::DrawProfileEntry(const std::string& profileName)

View File

@ -371,6 +371,27 @@ namespace config
ProfileChanged(); ProfileChanged();
} }
void DuplicateProfile(const std::string& profileName)
{
// Find a unique name for the new profile
uint32_t counter = 0;
std::ostringstream buffer;
std::string newProfileName;
do
{
buffer.str(std::string());
buffer.clear();
counter++;
buffer << profileName << " (" << counter << ")";
newProfileName = buffer.str();
} while (s_Profiles->contains(newProfileName));
// nlohmann::json copy constructor will take care of duplicating
(*s_Profiles)[newProfileName] = (*s_Profiles)[profileName];
UpdateProfilesNames();
Save();
}
std::vector<std::string> const& GetProfiles() std::vector<std::string> const& GetProfiles()
{ {
return s_ProfilesNames; return s_ProfilesNames;

View File

@ -63,6 +63,7 @@ namespace config
void RemoveProfile(const std::string& profileName); void RemoveProfile(const std::string& profileName);
void RenameProfile(const std::string& oldProfileName, const std::string& newProfileName); void RenameProfile(const std::string& oldProfileName, const std::string& newProfileName);
void ChangeProfile(const std::string& profileName); void ChangeProfile(const std::string& profileName);
void DuplicateProfile(const std::string& profileName);
std::vector<std::string> const& GetProfiles(); std::vector<std::string> const& GetProfiles();
std::string const& CurrentProfileName(); std::string const& CurrentProfileName();