Repository: xbmc/xbmc
File: xbmc/Autorun.cpp (C++)

Code before:
bool CAutorun::ExecuteAutorun(const std::string& path)
{
  if (CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_LOGIN_SCREEN)
    return false;

  CCdInfo* pInfo = CServiceBroker::GetMediaManager().GetCdInfo(path);

  if ( pInfo == NULL )
    return false;

  auto& components = CServiceBroker::GetAppComponents();
  const auto appPower = components.GetComponent<CApplicationPowerHandling>();
  appPower->ResetScreenSaver();
  appPower->WakeUpScreenSaverAndDPMS(); // turn off the screensaver if it's active

  bool success = false;

#ifdef HAS_CDDA_RIPPER
  const auto& settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const AutoCDAction action =
      static_cast<AutoCDAction>(settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION));
  if (action == AutoCDAction::RIP && pInfo->IsAudio(1) &&
      !CServiceBroker::GetSettingsComponent()
           ->GetProfileManager()
           ->GetCurrentProfile()
           .musicLocked())
  {
    success = KODI::CDRIP::CCDDARipper::GetInstance().RipCD();
  }
  else
#endif

    success = PlayDisc(path, false, false);
  return success;
}

bool CAutorun::PlayDisc(const std::string& path, bool bypassSettings, bool startFromBeginning)
{
  const auto& settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const AutoCDAction action =
      static_cast<AutoCDAction>(settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION));
  if (!bypassSettings && action != AutoCDAction::PLAY &&
      !settings->GetBool(CSettings::SETTING_DVDS_AUTORUN))
    return false;

  int nSize = CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::Id::TYPE_MUSIC).size();
  int nAddedToPlaylist = 0;

  std::string mediaPath;

  CCdInfo* pInfo = CServiceBroker::GetMediaManager().GetCdInfo(path);

Review comment (suggestion):
How about

```c++
  const auto& settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const auto& profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
```

```c++
  const AutoCDAction action =
      static_cast<AutoCDAction>(settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION));
  if (action == AutoCDAction::RIP && pInfo->IsAudio(1) &&
      !profileManager->GetCurrentProfile().musicLocked())
```
           

Code after:
bool CAutorun::ExecuteAutorun(const std::string& path)
{
  if (CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_LOGIN_SCREEN)
    return false;

  CCdInfo* pInfo = CServiceBroker::GetMediaManager().GetCdInfo(path);

  if ( pInfo == NULL )
    return false;

  auto& components = CServiceBroker::GetAppComponents();
  const auto appPower = components.GetComponent<CApplicationPowerHandling>();
  appPower->ResetScreenSaver();
  appPower->WakeUpScreenSaverAndDPMS(); // turn off the screensaver if it's active

  bool success = false;

#ifdef HAS_CDDA_RIPPER
  const auto& settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const auto& profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
  const AutoCDAction action =
      static_cast<AutoCDAction>(settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION));
  if (action == AutoCDAction::RIP && pInfo->IsAudio(1) &&
      !profileManager->GetCurrentProfile().musicLocked())
  {
    success = KODI::CDRIP::CCDDARipper::GetInstance().RipCD();
  }
  else
#endif

    success = PlayDisc(path, false, false);
  return success;
}

bool CAutorun::PlayDisc(const std::string& path, bool bypassSettings, bool startFromBeginning)
{
  const auto& settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  const AutoCDAction action =
      static_cast<AutoCDAction>(settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION));
  if (!bypassSettings && action != AutoCDAction::PLAY &&
      !settings->GetBool(CSettings::SETTING_DVDS_AUTORUN))
    return false;

  int nSize = CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::Id::TYPE_MUSIC).size();
  int nAddedToPlaylist = 0;

  std::string mediaPath;

  CCdInfo* pInfo = CServiceBroker::GetMediaManager().GetCdInfo(path);
  if (pInfo == NULL)
    return false;