fixed unicode support
This commit is contained in:
parent
82bb529bc2
commit
0e0737c53c
|
@ -4,6 +4,7 @@
|
|||
#include <winrt/windows.storage.streams.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <codecvt>
|
||||
|
||||
#include "../backend.hpp"
|
||||
#include "../utils.hpp"
|
||||
|
@ -11,11 +12,11 @@
|
|||
using namespace winrt;
|
||||
using namespace Windows::Media::Control;
|
||||
using namespace Windows::Storage::Streams;
|
||||
|
||||
// a winrt::hstring is just an extended std::wstring, so we can use std::strings built in conversion.
|
||||
#define EM_DASH "\xE2\x80\x94"
|
||||
// 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 converted = std::string(in.begin(), in.end());
|
||||
return converted;
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(in.c_str());
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||
|
@ -54,9 +55,9 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
|||
if (artist == "")
|
||||
artist = toStdString(mediaProperties.AlbumArtist()); // Needed for some apps
|
||||
|
||||
if (artist.find("\x14") != std::string::npos) {
|
||||
albumName = artist.substr(artist.find("\x14") + 1);
|
||||
artist = artist.substr(0, artist.find("\x14"));
|
||||
if (artist.find(EM_DASH) != std::string::npos) {
|
||||
albumName = artist.substr(artist.find(EM_DASH) + 3);
|
||||
artist = artist.substr(0, artist.find(EM_DASH));
|
||||
utils::trim(artist);
|
||||
utils::trim(albumName);
|
||||
}
|
||||
|
@ -66,5 +67,5 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
|||
toStdString(mediaProperties.Title()), artist, albumName, toStdString(currentSession.SourceAppUserModelId()),
|
||||
thumbnailData, endTime, elapsedTime);
|
||||
}
|
||||
|
||||
#undef EM_DASH
|
||||
#endif
|
|
@ -30,6 +30,7 @@ void handleRPCTasks() {
|
|||
break;
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -53,30 +53,18 @@ namespace utils {
|
|||
}
|
||||
|
||||
inline std::string urlEncode(std::string str) {
|
||||
std::string new_str = "";
|
||||
char c;
|
||||
int ic;
|
||||
const char* chars = str.c_str();
|
||||
char bufHex[10];
|
||||
int len = strlen(chars);
|
||||
std::ostringstream encoded;
|
||||
encoded << std::hex << std::uppercase;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = chars[i];
|
||||
ic = c;
|
||||
if (c == ' ')
|
||||
new_str += '+';
|
||||
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;
|
||||
for (unsigned char c : str) {
|
||||
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
|
||||
encoded << c;
|
||||
} else {
|
||||
encoded << '%' << std::setw(2) << std::setfill('0') << static_cast<int>(c);
|
||||
}
|
||||
}
|
||||
return new_str;
|
||||
|
||||
return encoded.str();
|
||||
}
|
||||
|
||||
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) {
|
||||
auto apps = getAllApps();
|
||||
for (auto app : apps) {
|
||||
for(auto procName : app.processNames) {
|
||||
if(procName == processName)
|
||||
for (auto procName : app.processNames) {
|
||||
if (procName == processName)
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue