Fixing profile loading #1135

This commit is contained in:
jath03 2021-02-24 14:39:08 -08:00 committed by Adam Honse
parent ea6e961a13
commit 84861ef989
5 changed files with 51 additions and 12 deletions

View file

@ -20,7 +20,7 @@ ProfileManager::~ProfileManager()
} }
bool ProfileManager::SaveProfile(std::string profile_name) bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
{ {
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Get the list of controllers from the resource manager | | Get the list of controllers from the resource manager |
@ -35,7 +35,19 @@ bool ProfileManager::SaveProfile(std::string profile_name)
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Extension .orp - OpenRgb Profile | | Extension .orp - OpenRgb Profile |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
std::string filename = profile_name + ".orp"; std::string filename = profile_name;
/*---------------------------------------------------------*\
| Determine file extension |
\*---------------------------------------------------------*/
if(sizes)
{
filename += ".ors";
}
else
{
filename += ".orp";
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Open an output file in binary mode | | Open an output file in binary mode |
@ -100,7 +112,8 @@ bool ProfileManager::LoadSizeFromProfile(std::string profile_name)
std::vector<RGBController*> ProfileManager::LoadProfileToList std::vector<RGBController*> ProfileManager::LoadProfileToList
( (
std::string profile_name std::string profile_name,
bool sizes
) )
{ {
std::vector<RGBController*> temp_controllers; std::vector<RGBController*> temp_controllers;
@ -108,8 +121,21 @@ std::vector<RGBController*> ProfileManager::LoadProfileToList
unsigned int controller_offset = 0; unsigned int controller_offset = 0;
bool ret_val = false; bool ret_val = false;
std::string filename = configuration_directory + profile_name; std::string filename = configuration_directory + profile_name;
/*---------------------------------------------------------*\
| Determine file extension |
\*---------------------------------------------------------*/
if(sizes)
{
filename += ".ors";
}
else
{
filename += ".orp";
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Open input file in binary mode | | Open input file in binary mode |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
@ -292,7 +318,7 @@ bool ProfileManager::LoadProfileWithOptions
std::vector<bool> temp_controller_used; std::vector<bool> temp_controller_used;
bool ret_val = false; bool ret_val = false;
std::string filename = configuration_directory + profile_name; std::string filename = configuration_directory + profile_name + ".orp";
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Get the list of controllers from the resource manager | | Get the list of controllers from the resource manager |

View file

@ -5,7 +5,11 @@
class ProfileManagerInterface class ProfileManagerInterface
{ {
public: public:
virtual bool SaveProfile(std::string profile_name) = 0; virtual bool SaveProfile
(
std::string profile_name,
bool sizes = false
) = 0;
virtual bool LoadProfile(std::string profile_name) = 0; virtual bool LoadProfile(std::string profile_name) = 0;
virtual bool LoadSizeFromProfile(std::string profile_name) = 0; virtual bool LoadSizeFromProfile(std::string profile_name) = 0;
virtual void DeleteProfile(std::string profile_name) = 0; virtual void DeleteProfile(std::string profile_name) = 0;
@ -22,7 +26,11 @@ public:
bool load_settings bool load_settings
) = 0; ) = 0;
virtual std::vector<RGBController*> LoadProfileToList (std::string profile_name) = 0; virtual std::vector<RGBController*> LoadProfileToList
(
std::string profile_name,
bool sizes = false
) = 0;
virtual void SetConfigurationDirectory(std::string directory) = 0; virtual void SetConfigurationDirectory(std::string directory) = 0;
protected: protected:
@ -35,7 +43,11 @@ public:
ProfileManager(std::string config_dir); ProfileManager(std::string config_dir);
~ProfileManager(); ~ProfileManager();
bool SaveProfile(std::string profile_name); bool SaveProfile
(
std::string profile_name,
bool sizes = false
);
bool LoadProfile(std::string profile_name); bool LoadProfile(std::string profile_name);
bool LoadSizeFromProfile(std::string profile_name); bool LoadSizeFromProfile(std::string profile_name);
void DeleteProfile(std::string profile_name); void DeleteProfile(std::string profile_name);
@ -54,7 +66,8 @@ public:
std::vector<RGBController*> LoadProfileToList std::vector<RGBController*> LoadProfileToList
( (
std::string profile_name std::string profile_name,
bool sizes = false
); );
void SetConfigurationDirectory(std::string directory); void SetConfigurationDirectory(std::string directory);

View file

@ -52,7 +52,7 @@ ResourceManager::ResourceManager()
| Load sizes list from file | | Load sizes list from file |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
profile_manager = new ProfileManager(GetConfigurationDirectory()); profile_manager = new ProfileManager(GetConfigurationDirectory());
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors"); rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true);
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
| Load settings from file | | Load settings from file |
@ -313,7 +313,7 @@ void ResourceManager::SetConfigurationDirectory(std::string directory)
profile_manager->SetConfigurationDirectory(directory); profile_manager->SetConfigurationDirectory(directory);
rgb_controllers_sizes.clear(); rgb_controllers_sizes.clear();
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors"); rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true);
} }
void ResourceManager::Cleanup() void ResourceManager::Cleanup()

View file

@ -623,7 +623,7 @@ bool OptionSize(int *current_device, int *current_zone, std::string argument, Op
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Save the profile | | Save the profile |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
ResourceManager::get()->GetProfileManager()->SaveProfile("sizes.ors"); ResourceManager::get()->GetProfileManager()->SaveProfile("sizes", true);
return true; return true;
} }

View file

@ -902,7 +902,7 @@ void OpenRGBDialog2::on_SaveSizeProfile()
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Save the profile | | Save the profile |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
profile_manager->SaveProfile("sizes.ors"); profile_manager->SaveProfile("sizes", true);
} }
} }