diff --git a/ProfileManager.cpp b/ProfileManager.cpp index 6bd2630f..14aecb95 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -7,7 +7,7 @@ #include #include #include - +#include "StringUtils.h" #define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE" #define OPENRGB_PROFILE_VERSION OPENRGB_SDK_PROTOCOL_VERSION @@ -25,6 +25,8 @@ ProfileManager::~ProfileManager() bool ProfileManager::SaveProfile(std::string profile_name, bool sizes) { + profile_name = StringUtils::remove_null_terminating_chars(profile_name); + /*---------------------------------------------------------*\ | Get the list of controllers from the resource manager | \*---------------------------------------------------------*/ @@ -108,11 +110,13 @@ void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory bool ProfileManager::LoadProfile(std::string profile_name) { + profile_name = StringUtils::remove_null_terminating_chars(profile_name); return(LoadProfileWithOptions(profile_name, false, true)); } bool ProfileManager::LoadSizeFromProfile(std::string profile_name) { + profile_name = StringUtils::remove_null_terminating_chars(profile_name); return(LoadProfileWithOptions(profile_name, true, false)); } @@ -407,6 +411,8 @@ bool ProfileManager::LoadProfileWithOptions void ProfileManager::DeleteProfile(std::string profile_name) { + profile_name = StringUtils::remove_null_terminating_chars(profile_name); + filesystem::path filename = configuration_directory / profile_name; filename.concat(".orp"); diff --git a/StringUtils.cpp b/StringUtils.cpp index 614679c1..3957abbc 100644 --- a/StringUtils.cpp +++ b/StringUtils.cpp @@ -38,3 +38,14 @@ const char* StringUtils::wchar_to_char(const wchar_t* pwchar) return filePathC; } + +const std::string StringUtils::remove_null_terminating_chars(std::string input) +{ + while (!input.empty() && input.back() == 0) + { + input.pop_back(); + } + + return input; +} + diff --git a/StringUtils.h b/StringUtils.h index 7b52f46b..ea8ea613 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -1,10 +1,13 @@ #ifndef STRING_UTILS_H #define STRING_UTILS_H +#include + class StringUtils { public: static const char* wchar_to_char(const wchar_t* pwchar); + static const std::string remove_null_terminating_chars(std::string input); }; #endif // STRING_UTILS_H