MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / UpdateProfileList

Method UpdateProfileList

ProfileManager.cpp:417–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417void ProfileManager::UpdateProfileList()
418{
419 profile_list.clear();
420
421 /*---------------------------------------------------------*\
422 | Load profiles by looking for .orp files in current dir |
423 \*---------------------------------------------------------*/
424 for(const auto & entry : filesystem::directory_iterator(configuration_directory))
425 {
426 std::string filename = entry.path().filename().string();
427
428 if(filename.find(".orp") != std::string::npos)
429 {
430 LOG_INFO("Found file: %s attempting to validate header", filename.c_str());
431
432 /*---------------------------------------------------------*\
433 | Open input file in binary mode |
434 \*---------------------------------------------------------*/
435 filesystem::path file_path = configuration_directory;
436 file_path.append(filename);
437 std::ifstream profile_file(file_path, std::ios::in | std::ios::binary);
438
439 /*---------------------------------------------------------*\
440 | Read and verify file header |
441 \*---------------------------------------------------------*/
442 char profile_string[16];
443 unsigned int profile_version;
444
445 profile_file.read(profile_string, 16);
446 profile_file.read((char *)&profile_version, sizeof(unsigned int));
447
448 if(strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0)
449 {
450 if(profile_version <= OPENRGB_PROFILE_VERSION)
451 {
452 /*---------------------------------------------------------*\
453 | Add this profile to the list |
454 \*---------------------------------------------------------*/
455 filename.erase(filename.length() - 4);
456 profile_list.push_back(filename);
457
458 LOG_INFO("Valid v%i profile found for %s", profile_version, filename.c_str());
459 }
460 else
461 {
462 LOG_WARNING("Profile %s isn't valid for current version (v%i, expected v%i at most)", filename.c_str(), profile_version, OPENRGB_PROFILE_VERSION);
463 }
464 }
465 else
466 {
467 LOG_WARNING("Profile %s isn't valid: header is missing", filename.c_str());
468 }
469
470 profile_file.close();
471 }
472 }
473}
474

Callers

nothing calls this directly

Calls 6

stringMethod · 0.45
findMethod · 0.45
appendMethod · 0.45
readMethod · 0.45
eraseMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected