Remove null terminating chars from profile names before using them in ProfileManager
This commit is contained in:
parent
6d562d8d37
commit
2eb43fa445
3 changed files with 21 additions and 1 deletions
|
|
@ -7,7 +7,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue