Search through controller list for each controller when loading profile, allows controller order to change without breaking the profile

This commit is contained in:
Adam Honse 2020-03-03 12:11:21 -06:00
parent 9deb0f8fff
commit 3cf855bd10

View file

@ -77,6 +77,7 @@ bool ProfileManager::SaveProfile(std::string profile_name)
bool ProfileManager::LoadProfile(std::string profile_name)
{
std::vector<RGBController*> temp_controllers;
std::vector<bool> temp_controller_used;
unsigned int controller_size;
unsigned int controller_offset = 0;
bool ret_val = false;
@ -122,6 +123,7 @@ bool ProfileManager::LoadProfile(std::string profile_name)
temp_controller->ReadDeviceDescription(controller_data);
temp_controllers.push_back(temp_controller);
temp_controller_used.push_back(false);
delete[] controller_data;
@ -131,15 +133,23 @@ bool ProfileManager::LoadProfile(std::string profile_name)
ret_val = true;
}
/*---------------------------------------------------------*\
| Loop through all controllers. For each controller, search|
| all saved controllers until a match is found |
\*---------------------------------------------------------*/
for(int controller_index = 0; controller_index < controllers.size(); controller_index++)
{
RGBController *temp_controller = temp_controllers[controller_index];
RGBController *controller_ptr = controllers[controller_index];
for(int temp_index = 0; temp_index < temp_controllers.size(); temp_index++)
{
RGBController *temp_controller = temp_controllers[controller_index];
/*---------------------------------------------------------*\
| Test if saved controller data matches this controller |
\*---------------------------------------------------------*/
if((temp_controller->type == controller_ptr->type )
if((temp_controller_used[temp_index] == false )
&&(temp_controller->type == controller_ptr->type )
&&(temp_controller->name == controller_ptr->name )
&&(temp_controller->description == controller_ptr->description)
&&(temp_controller->version == controller_ptr->version )
@ -188,6 +198,11 @@ bool ProfileManager::LoadProfile(std::string profile_name)
controller_ptr->colors[color_index] = temp_controller->colors[color_index];
}
}
temp_controller_used[temp_index] = true;
break;
}
}
}
}