Added option to duplicate profile

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

View File

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

View File

@ -371,6 +371,27 @@ namespace config
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()
{
return s_ProfilesNames;

View File

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