| 23 | } |
| 24 | |
| 25 | bool ProfileManager::SaveProfile(std::string profile_name, bool sizes) |
| 26 | { |
| 27 | /*---------------------------------------------------------*\ |
| 28 | | Get the list of controllers from the resource manager | |
| 29 | \*---------------------------------------------------------*/ |
| 30 | std::vector<RGBController *> controllers = ResourceManager::get()->GetRGBControllers(); |
| 31 | |
| 32 | /*---------------------------------------------------------*\ |
| 33 | | If a name was entered, save the profile file | |
| 34 | \*---------------------------------------------------------*/ |
| 35 | if(profile_name != "") |
| 36 | { |
| 37 | /*---------------------------------------------------------*\ |
| 38 | | Extension .orp - OpenRgb Profile | |
| 39 | \*---------------------------------------------------------*/ |
| 40 | std::string filename = profile_name; |
| 41 | |
| 42 | /*---------------------------------------------------------*\ |
| 43 | | Determine file extension | |
| 44 | \*---------------------------------------------------------*/ |
| 45 | if(sizes) |
| 46 | { |
| 47 | filename += ".ors"; |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | filename += ".orp"; |
| 52 | } |
| 53 | |
| 54 | /*---------------------------------------------------------*\ |
| 55 | | Open an output file in binary mode | |
| 56 | \*---------------------------------------------------------*/ |
| 57 | filesystem::path profile_path = configuration_directory / filesystem::u8path(filename); |
| 58 | std::ofstream controller_file(profile_path, std::ios::out | std::ios::binary | std::ios::trunc); |
| 59 | |
| 60 | /*---------------------------------------------------------*\ |
| 61 | | Write header | |
| 62 | | 16 bytes - "OPENRGB_PROFILE" | |
| 63 | | 4 bytes - Version, unsigned int | |
| 64 | \*---------------------------------------------------------*/ |
| 65 | unsigned int profile_version = OPENRGB_PROFILE_VERSION; |
| 66 | controller_file.write(OPENRGB_PROFILE_HEADER, 16); |
| 67 | controller_file.write((char *)&profile_version, sizeof(unsigned int)); |
| 68 | |
| 69 | /*---------------------------------------------------------*\ |
| 70 | | Write controller data for each controller | |
| 71 | \*---------------------------------------------------------*/ |
| 72 | for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++) |
| 73 | { |
| 74 | unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription(profile_version); |
| 75 | unsigned int controller_size; |
| 76 | |
| 77 | memcpy(&controller_size, controller_data, sizeof(controller_size)); |
| 78 | |
| 79 | controller_file.write((const char *)controller_data, controller_size); |
| 80 | |
| 81 | delete[] controller_data; |
| 82 | } |
no test coverage detected