[XAudio2] avoid leak + fix voice creation for closest match
[xbmc.git] / xbmc / imagefiles / ImageFileURL.cpp
blobd2d1cddfce335fbab32bc8c4f22ecec20db373e0
1 /*
2 * Copyright (C) 2024 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 "ImageFileURL.h"
11 #include "URL.h"
12 #include "utils/URIUtils.h"
14 #include <charconv>
16 namespace IMAGE_FILES
19 CImageFileURL::CImageFileURL(const std::string& imageFileURL)
21 if (!URIUtils::IsProtocol(imageFileURL, "image"))
23 m_filePath = imageFileURL;
24 return;
27 CURL url{imageFileURL};
28 m_filePath = url.GetHostName();
29 m_specialType = url.GetUserName();
31 url.GetOptions(m_options);
33 auto option = m_options.find("flipped");
34 if (option != m_options.end())
36 flipped = true;
37 m_options.erase(option);
41 CImageFileURL::CImageFileURL()
45 CImageFileURL CImageFileURL::FromFile(const std::string& filePath, std::string specialType)
47 if (URIUtils::IsProtocol(filePath, "image"))
49 // this function should not be called with an image file URL
50 return CImageFileURL(filePath);
53 CImageFileURL item;
54 item.m_filePath = filePath;
55 item.m_specialType = std::move(specialType);
57 return item;
60 void CImageFileURL::AddOption(std::string key, std::string value)
62 m_options[std::move(key)] = std::move(value);
65 std::string CImageFileURL::GetOption(const std::string& key) const
67 auto value = m_options.find(key);
68 if (value == m_options.end())
70 return {};
72 return value->second;
75 std::string CImageFileURL::ToString() const
77 CURL url;
78 url.SetProtocol("image");
79 url.SetUserName(m_specialType);
80 url.SetHostName(m_filePath);
81 if (flipped)
82 url.SetOption("flipped", "");
83 for (const auto& option : m_options)
84 url.SetOption(option.first, option.second);
86 return url.Get();
89 std::string CImageFileURL::ToCacheKey() const
91 if (!flipped && m_specialType.empty() && m_options.empty())
92 return m_filePath;
94 return ToString();
97 std::string URLFromFile(const std::string& filePath, std::string specialType)
99 return CImageFileURL::FromFile(filePath, std::move(specialType)).ToString();
102 std::string ToCacheKey(const std::string& imageFileURL)
104 return CImageFileURL(imageFileURL).ToCacheKey();
107 } // namespace IMAGE_FILES