Skip to content

Commit

Permalink
Added GetClipboardData + CrackWebUrl functions
Browse files Browse the repository at this point in the history
+ Some cleanup
  • Loading branch information
Aemony committed Jun 8, 2024
1 parent cd8794e commit c7b0224
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 49 deletions.
2 changes: 2 additions & 0 deletions include/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/stores/Epic/epic_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <comdef.h>
#include <process.h>

#include <gsl/gsl>

#include <utility/registry.h>

/*
Expand Down
1 change: 0 additions & 1 deletion src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include <utility/fsutil.h>
#include <atlimage.h>
#include <TlHelp32.h>
#include <gsl/gsl_util>

#include <utility/registry.h>
#include <utility/updater.h>
Expand Down
38 changes: 0 additions & 38 deletions src/utility/sk_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <utility/sk_utility.h>
#include <utility/utility.h>
#include <Windows.h>
#include <gsl/gsl>

#ifndef SECURITY_WIN32
#define SECURITY_WIN32
Expand All @@ -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 <int> (in.length ()),
out.data (),
gsl::narrow_cast <DWORD> (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 <int> (in.length()), NULL, 0, NULL, NULL);
Expand All @@ -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 <int> (in.length ()),
out.data (),
gsl::narrow_cast <DWORD> (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 <int> (in.length()), NULL, 0);
Expand Down
49 changes: 41 additions & 8 deletions src/utility/utility.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <utility/utility.h>
#include <utility/sk_utility.h>
#include <comdef.h>
#include <gsl/gsl_util>
#include <Psapi.h>
#include <cwctype>
#include <unordered_set>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand All @@ -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 <DWORD> (url.length ()),
0x00,
&urlcomps
)
)
if (InternetCrackUrl (url.c_str(), static_cast <DWORD> (url.length ()), 0x00, &urlcomps))
{
wcsncpy ( get->wszLocalPath,
destination.data (),
Expand All @@ -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 <DWORD> (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

Expand Down

0 comments on commit c7b0224

Please sign in to comment.