From c7b02247bc94503941859d03e6f074f14645ee1e Mon Sep 17 00:00:00 2001 From: aemony Date: Sat, 8 Jun 2024 21:30:50 +0200 Subject: [PATCH] Added GetClipboardData + CrackWebUrl functions + Some cleanup --- include/utility/utility.h | 2 ++ src/stores/Epic/epic_library.cpp | 2 -- src/tabs/library.cpp | 1 - src/utility/sk_utility.cpp | 38 ------------------------- src/utility/utility.cpp | 49 ++++++++++++++++++++++++++------ 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/include/utility/utility.h b/include/utility/utility.h index 99feb3d7..d874166a 100644 --- a/include/utility/utility.h +++ b/include/utility/utility.h @@ -202,6 +202,7 @@ bool SKIF_Util_GetHotKeyStateSVCTemp (void); struct skif_get_web_uri_t { wchar_t wszHostName [INTERNET_MAX_HOST_NAME_LENGTH] = { }; wchar_t wszHostPath [INTERNET_MAX_PATH_LENGTH] = { }; + wchar_t wszExtraInfo[INTERNET_MAX_PATH_LENGTH] = { }; wchar_t wszLocalPath[MAX_PATH + 2] = { }; LPCWSTR method = L"GET"; bool https = false; @@ -211,6 +212,7 @@ struct skif_get_web_uri_t { DWORD WINAPI SKIF_Util_GetWebUri (skif_get_web_uri_t* get); DWORD SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination, std::wstring method = L"GET", std::wstring header = L"", std::string body = ""); +skif_get_web_uri_t SKIF_Util_CrackWebUrl (const std::wstring url); // Shortcuts (*.lnk) diff --git a/src/stores/Epic/epic_library.cpp b/src/stores/Epic/epic_library.cpp index 8ed360f7..3e13f2f7 100644 --- a/src/stores/Epic/epic_library.cpp +++ b/src/stores/Epic/epic_library.cpp @@ -7,8 +7,6 @@ #include #include -#include - #include /* diff --git a/src/tabs/library.cpp b/src/tabs/library.cpp index 15ecc6a6..8e5c0c35 100644 --- a/src/tabs/library.cpp +++ b/src/tabs/library.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include #include diff --git a/src/utility/sk_utility.cpp b/src/utility/sk_utility.cpp index e332a551..4e23e918 100644 --- a/src/utility/sk_utility.cpp +++ b/src/utility/sk_utility.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #ifndef SECURITY_WIN32 #define SECURITY_WIN32 @@ -39,25 +38,6 @@ std::string SK_WideCharToUTF8 (const std::wstring& in) { - /* - size_t len = - WideCharToMultiByte ( CP_UTF8, 0x00, in.c_str (), -1, - nullptr, 0, nullptr, FALSE ); - - std::string out ( - len * 2 + 2, - '\0' - ); - - WideCharToMultiByte ( CP_UTF8, 0x00, in.c_str (), - gsl::narrow_cast (in.length ()), - out.data (), - gsl::narrow_cast (len), - nullptr, FALSE ); - - out.resize(len); - */ - // CC BY-SA 4.0: https://stackoverflow.com/a/59617138 int count = WideCharToMultiByte (CP_UTF8, 0, in.c_str(), static_cast (in.length()), NULL, 0, NULL, NULL); @@ -71,24 +51,6 @@ SK_WideCharToUTF8 (const std::wstring& in) std::wstring SK_UTF8ToWideChar (const std::string& in) { - /* - size_t len = - MultiByteToWideChar ( CP_UTF8, 0x00, in.c_str (), -1, - nullptr, 0 ); - - std::wstring out ( - len * 2 + 2, - L'\0' - ); - - MultiByteToWideChar ( CP_UTF8, 0x00, in.c_str (), - gsl::narrow_cast (in.length ()), - out.data (), - gsl::narrow_cast (len) ); - - out.resize(len); - */ - // CC BY-SA 4.0: https://stackoverflow.com/a/59617138 int count = MultiByteToWideChar (CP_UTF8, 0, in.c_str(), static_cast (in.length()), NULL, 0); diff --git a/src/utility/utility.cpp b/src/utility/utility.cpp index ac4a3aab..367644a2 100644 --- a/src/utility/utility.cpp +++ b/src/utility/utility.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -3349,10 +3348,14 @@ SKIF_Util_GetWebUri (skif_get_web_uri_t* get) else flags |= INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE; + std::wstring full_path = std::wstring (get->wszHostPath); + if (get->wszExtraInfo[0] != L'\0') + full_path += std::wstring (get->wszExtraInfo); + hInetHTTPGetReq = HttpOpenRequest ( hInetHost, get->method, - get->wszHostPath, + full_path.c_str(), L"HTTP/1.1", nullptr, rgpszAcceptTypes, @@ -3472,6 +3475,9 @@ SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination, std:: urlcomps.lpszUrlPath = get->wszHostPath; urlcomps.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH; + urlcomps.lpszExtraInfo = get->wszExtraInfo; + urlcomps.dwExtraInfoLength = INTERNET_MAX_PATH_LENGTH; + if (! method.empty()) get->method = method.c_str(); @@ -3481,12 +3487,7 @@ SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination, std:: if (! body.empty()) get->body = body; - if ( InternetCrackUrl ( url.c_str (), - gsl::narrow_cast (url.length ()), - 0x00, - &urlcomps - ) - ) + if (InternetCrackUrl (url.c_str(), static_cast (url.length ()), 0x00, &urlcomps)) { wcsncpy ( get->wszLocalPath, destination.data (), @@ -3508,6 +3509,38 @@ SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination, std:: return 0; } +skif_get_web_uri_t +SKIF_Util_CrackWebUrl (const std::wstring url) +{ + skif_get_web_uri_t cracked = { }; + URL_COMPONENTSW urlcomps = { }; + + urlcomps.dwStructSize = sizeof (URL_COMPONENTSW); + + urlcomps.lpszHostName = cracked.wszHostName; + urlcomps.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH; + + urlcomps.lpszUrlPath = cracked.wszHostPath; + urlcomps.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH; + + urlcomps.lpszExtraInfo = cracked.wszExtraInfo; + urlcomps.dwExtraInfoLength = INTERNET_MAX_PATH_LENGTH; + + if (! InternetCrackUrl (url.c_str(), static_cast (url.length ()), 0x00, &urlcomps)) + PLOG_ERROR << "Failed to cracks a URL into its component parts! URL: " << url; + +#ifdef _DEBUG + else { + PLOG_VERBOSE << "Cracked URL:\n" + << "wszHostName : " << std::wstring (cracked.wszHostName) << "\n" + << "wszHostPath : " << std::wstring (cracked.wszHostPath) << "\n" + << "wszExtraInfo: " << std::wstring (cracked.wszExtraInfo); + } +#endif + + return cracked; +} + // Directory Watch