mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-21 07:25:39 -04:00
GameList: Add cover downloader
This commit is contained in:
@ -20,6 +20,8 @@ add_library(common
|
||||
hash_combine.h
|
||||
heap_array.h
|
||||
heterogeneous_containers.h
|
||||
http_downloader.cpp
|
||||
http_downloader.h
|
||||
layered_settings_interface.cpp
|
||||
layered_settings_interface.h
|
||||
log.cpp
|
||||
@ -86,6 +88,8 @@ if(WIN32)
|
||||
d3d11/stream_buffer.h
|
||||
d3d11/texture.cpp
|
||||
d3d11/texture.h
|
||||
http_downloader_winhttp.cpp
|
||||
http_downloader_winhttp.h
|
||||
thirdparty/StackWalker.cpp
|
||||
thirdparty/StackWalker.h
|
||||
win32_progress_callback.cpp
|
||||
@ -95,6 +99,16 @@ if(WIN32)
|
||||
target_link_libraries(common PRIVATE d3dcompiler.lib)
|
||||
endif()
|
||||
|
||||
if(NOT WIN32 AND NOT ANDROID)
|
||||
target_sources(common PRIVATE
|
||||
http_downloader_curl.cpp
|
||||
http_downloader_curl.h
|
||||
)
|
||||
target_link_libraries(common PRIVATE
|
||||
CURL::libcurl
|
||||
)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(common PRIVATE log)
|
||||
endif()
|
||||
@ -242,29 +256,6 @@ if(ENABLE_VULKAN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if(ENABLE_CHEEVOS)
|
||||
target_sources(common PRIVATE
|
||||
http_downloader.cpp
|
||||
http_downloader.h
|
||||
)
|
||||
if(WIN32)
|
||||
target_sources(common PRIVATE
|
||||
http_downloader_winhttp.cpp
|
||||
http_downloader_winhttp.h
|
||||
)
|
||||
elseif(NOT ANDROID)
|
||||
target_sources(common PRIVATE
|
||||
http_downloader_curl.cpp
|
||||
http_downloader_curl.h
|
||||
)
|
||||
target_link_libraries(common PRIVATE
|
||||
CURL::libcurl
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
# We need -lrt for shm_unlink
|
||||
target_link_libraries(common PRIVATE rt)
|
||||
|
@ -183,4 +183,74 @@ u32 HTTPDownloader::LockedGetActiveRequestCount()
|
||||
return count;
|
||||
}
|
||||
|
||||
} // namespace FrontendCommon
|
||||
std::string HTTPDownloader::URLEncode(const std::string_view& str)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(str.length() + ((str.length() + 3) / 4) * 3);
|
||||
|
||||
for (size_t i = 0, l = str.size(); i < l; i++)
|
||||
{
|
||||
const char c = str[i];
|
||||
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '-' || c == '_' ||
|
||||
c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')')
|
||||
{
|
||||
ret.push_back(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.push_back('%');
|
||||
|
||||
const unsigned char n1 = static_cast<unsigned char>(c) >> 4;
|
||||
const unsigned char n2 = static_cast<unsigned char>(c) & 0x0F;
|
||||
ret.push_back((n1 >= 10) ? ('a' + (n1 - 10)) : ('0' + n1));
|
||||
ret.push_back((n2 >= 10) ? ('a' + (n2 - 10)) : ('0' + n2));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string HTTPDownloader::URLDecode(const std::string_view& str)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(str.length());
|
||||
|
||||
for (size_t i = 0, l = str.size(); i < l; i++)
|
||||
{
|
||||
const char c = str[i];
|
||||
if (c == '+')
|
||||
{
|
||||
ret.push_back(c);
|
||||
}
|
||||
else if (c == '%')
|
||||
{
|
||||
if ((i + 2) >= str.length())
|
||||
break;
|
||||
|
||||
const char clower = str[i + 1];
|
||||
const char cupper = str[i + 2];
|
||||
const unsigned char lower =
|
||||
(clower >= '0' && clower <= '9') ?
|
||||
static_cast<unsigned char>(clower - '0') :
|
||||
((clower >= 'a' && clower <= 'f') ?
|
||||
static_cast<unsigned char>(clower - 'a') :
|
||||
((clower >= 'A' && clower <= 'F') ? static_cast<unsigned char>(clower - 'A') : 0));
|
||||
const unsigned char upper =
|
||||
(cupper >= '0' && cupper <= '9') ?
|
||||
static_cast<unsigned char>(cupper - '0') :
|
||||
((cupper >= 'a' && cupper <= 'f') ?
|
||||
static_cast<unsigned char>(cupper - 'a') :
|
||||
((cupper >= 'A' && cupper <= 'F') ? static_cast<unsigned char>(cupper - 'A') : 0));
|
||||
const char dch = static_cast<char>(lower | (upper << 4));
|
||||
ret.push_back(dch);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
return std::string(str);
|
||||
}
|
||||
|
||||
} // namespace Common
|
@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Common {
|
||||
@ -53,6 +54,8 @@ public:
|
||||
virtual ~HTTPDownloader();
|
||||
|
||||
static std::unique_ptr<HTTPDownloader> Create(const char* user_agent = DEFAULT_USER_AGENT);
|
||||
static std::string URLEncode(const std::string_view& str);
|
||||
static std::string URLDecode(const std::string_view& str);
|
||||
|
||||
void SetTimeout(float timeout);
|
||||
void SetMaxActiveRequests(u32 max_active_requests);
|
||||
|
Reference in New Issue
Block a user