[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / pvr / guilib / PVRGUIChannelIconUpdater.cpp
blob11045c98d81266c4bda5a52dd4e6c1593fb774ad
1 /*
2 * Copyright (C) 2012-2019 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PVRGUIChannelIconUpdater.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "ServiceBroker.h"
14 #include "Util.h"
15 #include "filesystem/Directory.h"
16 #include "guilib/LocalizeStrings.h"
17 #include "pvr/channels/PVRChannel.h"
18 #include "pvr/channels/PVRChannelGroup.h"
19 #include "pvr/channels/PVRChannelGroupMember.h"
20 #include "pvr/guilib/PVRGUIProgressHandler.h"
21 #include "settings/AdvancedSettings.h"
22 #include "settings/Settings.h"
23 #include "settings/SettingsComponent.h"
24 #include "utils/FileUtils.h"
25 #include "utils/URIUtils.h"
26 #include "utils/log.h"
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <vector>
33 using namespace PVR;
35 void CPVRGUIChannelIconUpdater::SearchAndUpdateMissingChannelIcons() const
37 const std::string iconPath = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_PVRMENU_ICONPATH);
38 if (iconPath.empty())
39 return;
41 // fetch files in icon path for fast lookup
42 CFileItemList fileItemList;
43 XFILE::CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn", XFILE::DIR_FLAG_DEFAULTS);
45 if (fileItemList.IsEmpty())
46 return;
48 CLog::Log(LOGINFO, "Starting PVR channel icon search");
50 // create a map for fast lookup of normalized file base name
51 std::map<std::string, std::string> fileItemMap;
52 for (const auto& item : fileItemList)
54 std::string baseName = URIUtils::GetFileName(item->GetPath());
55 URIUtils::RemoveExtension(baseName);
56 StringUtils::ToLower(baseName);
57 fileItemMap.insert({baseName, item->GetPath()});
60 std::unique_ptr<CPVRGUIProgressHandler> progressHandler;
61 if (!m_groups.empty())
62 progressHandler = std::make_unique<CPVRGUIProgressHandler>(
63 g_localizeStrings.Get(19286)); // Searching for channel icons
65 for (const auto& group : m_groups)
67 const std::vector<std::shared_ptr<CPVRChannelGroupMember>> members = group->GetMembers();
68 int channelIndex = 0;
69 for (const auto& member : members)
71 const std::shared_ptr<CPVRChannel> channel = member->Channel();
73 progressHandler->UpdateProgress(channel->ChannelName(), channelIndex++, members.size());
75 // skip if an icon is already set and exists
76 if (CFileUtils::Exists(channel->IconPath()))
77 continue;
79 // reset icon before searching for a new one
80 channel->SetIconPath("");
82 const std::string strChannelUid = StringUtils::Format("{:08}", channel->UniqueID());
83 std::string strLegalClientChannelName =
84 CUtil::MakeLegalFileName(channel->ClientChannelName());
85 StringUtils::ToLower(strLegalClientChannelName);
86 std::string strLegalChannelName = CUtil::MakeLegalFileName(channel->ChannelName());
87 StringUtils::ToLower(strLegalChannelName);
89 std::map<std::string, std::string>::iterator itItem;
90 if ((itItem = fileItemMap.find(strLegalClientChannelName)) != fileItemMap.end() ||
91 (itItem = fileItemMap.find(strLegalChannelName)) != fileItemMap.end() ||
92 (itItem = fileItemMap.find(strChannelUid)) != fileItemMap.end())
94 channel->SetIconPath(itItem->second, CServiceBroker::GetSettingsComponent()
95 ->GetAdvancedSettings()
96 ->m_bPVRAutoScanIconsUserSet);
99 if (m_bUpdateDb)
100 channel->Persist();