Added option to duplicate profile

This commit is contained in:
Andrei Abrudan 2022-07-17 21:41:13 +01:00
parent bc06e0abc5
commit f8a8131bb6
3 changed files with 27 additions and 0 deletions

View File

@ -173,6 +173,11 @@ namespace cheat
config::RemoveProfile(profileName); config::RemoveProfile(profileName);
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
ImGui::SetTooltip("Delete"); ImGui::SetTooltip("Delete");
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();