fixed unicode support
This commit is contained in:
parent
82bb529bc2
commit
0e0737c53c
|
@ -4,6 +4,7 @@
|
||||||
#include <winrt/windows.storage.streams.h>
|
#include <winrt/windows.storage.streams.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
#include "../backend.hpp"
|
#include "../backend.hpp"
|
||||||
#include "../utils.hpp"
|
#include "../utils.hpp"
|
||||||
|
@ -11,11 +12,11 @@
|
||||||
using namespace winrt;
|
using namespace winrt;
|
||||||
using namespace Windows::Media::Control;
|
using namespace Windows::Media::Control;
|
||||||
using namespace Windows::Storage::Streams;
|
using namespace Windows::Storage::Streams;
|
||||||
|
#define EM_DASH "\xE2\x80\x94"
|
||||||
// a winrt::hstring is just an extended std::wstring, so we can use std::strings built in conversion.
|
// codecvt is deprecated, but there is no good portable way to do this, I could technically use the winapi as this is the windows backend tho
|
||||||
std::string toStdString(winrt::hstring in) {
|
std::string toStdString(winrt::hstring in) {
|
||||||
std::string converted = std::string(in.begin(), in.end());
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||||
return converted;
|
return converter.to_bytes(in.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||||
|
@ -54,9 +55,9 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||||
if (artist == "")
|
if (artist == "")
|
||||||
artist = toStdString(mediaProperties.AlbumArtist()); // Needed for some apps
|
artist = toStdString(mediaProperties.AlbumArtist()); // Needed for some apps
|
||||||
|
|
||||||
if (artist.find("\x14") != std::string::npos) {
|
if (artist.find(EM_DASH) != std::string::npos) {
|
||||||
albumName = artist.substr(artist.find("\x14") + 1);
|
albumName = artist.substr(artist.find(EM_DASH) + 3);
|
||||||
artist = artist.substr(0, artist.find("\x14"));
|
artist = artist.substr(0, artist.find(EM_DASH));
|
||||||
utils::trim(artist);
|
utils::trim(artist);
|
||||||
utils::trim(albumName);
|
utils::trim(albumName);
|
||||||
}
|
}
|
||||||
|
@ -66,5 +67,5 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||||
toStdString(mediaProperties.Title()), artist, albumName, toStdString(currentSession.SourceAppUserModelId()),
|
toStdString(mediaProperties.Title()), artist, albumName, toStdString(currentSession.SourceAppUserModelId()),
|
||||||
thumbnailData, endTime, elapsedTime);
|
thumbnailData, endTime, elapsedTime);
|
||||||
}
|
}
|
||||||
|
#undef EM_DASH
|
||||||
#endif
|
#endif
|
|
@ -30,6 +30,7 @@ void handleRPCTasks() {
|
||||||
break;
|
break;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
Discord_Shutdown();
|
||||||
handleRPCTasks(); // this could theoretically cause a stack overflow if discord is restarted often enough
|
handleRPCTasks(); // this could theoretically cause a stack overflow if discord is restarted often enough
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,30 +53,18 @@ namespace utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string urlEncode(std::string str) {
|
inline std::string urlEncode(std::string str) {
|
||||||
std::string new_str = "";
|
std::ostringstream encoded;
|
||||||
char c;
|
encoded << std::hex << std::uppercase;
|
||||||
int ic;
|
|
||||||
const char* chars = str.c_str();
|
|
||||||
char bufHex[10];
|
|
||||||
int len = strlen(chars);
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (unsigned char c : str) {
|
||||||
c = chars[i];
|
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
|
||||||
ic = c;
|
encoded << c;
|
||||||
if (c == ' ')
|
} else {
|
||||||
new_str += '+';
|
encoded << '%' << std::setw(2) << std::setfill('0') << static_cast<int>(c);
|
||||||
else if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
|
|
||||||
new_str += c;
|
|
||||||
else {
|
|
||||||
snprintf(bufHex, sizeof(bufHex), "%X", c);
|
|
||||||
if (ic < 16)
|
|
||||||
new_str += "%0";
|
|
||||||
else
|
|
||||||
new_str += "%";
|
|
||||||
new_str += bufHex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new_str;
|
|
||||||
|
return encoded.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t curlWriteCallback(char* contents, size_t size, size_t nmemb, void* userp) {
|
inline size_t curlWriteCallback(char* contents, size_t size, size_t nmemb, void* userp) {
|
||||||
|
@ -144,8 +132,8 @@ namespace utils {
|
||||||
inline App getApp(std::string processName) {
|
inline App getApp(std::string processName) {
|
||||||
auto apps = getAllApps();
|
auto apps = getAllApps();
|
||||||
for (auto app : apps) {
|
for (auto app : apps) {
|
||||||
for(auto procName : app.processNames) {
|
for (auto procName : app.processNames) {
|
||||||
if(procName == processName)
|
if (procName == processName)
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue