mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-11-23 20:25:42 +01:00
Apply formatting (#178)
This commit is contained in:
parent
566076e3d8
commit
7e0480e2ef
@ -12,19 +12,26 @@ void FDiscordRpcModule::StartupModule()
|
|||||||
#if defined(DISCORD_DYNAMIC_LIB)
|
#if defined(DISCORD_DYNAMIC_LIB)
|
||||||
// Get the base directory of this plugin
|
// Get the base directory of this plugin
|
||||||
FString BaseDir = IPluginManager::Get().FindPlugin("DiscordRpc")->GetBaseDir();
|
FString BaseDir = IPluginManager::Get().FindPlugin("DiscordRpc")->GetBaseDir();
|
||||||
const FString SDKDir = FPaths::Combine(*BaseDir, TEXT("Source"), TEXT("ThirdParty"), TEXT("DiscordRpcLibrary"));
|
const FString SDKDir =
|
||||||
|
FPaths::Combine(*BaseDir, TEXT("Source"), TEXT("ThirdParty"), TEXT("DiscordRpcLibrary"));
|
||||||
#if PLATFORM_WINDOWS
|
#if PLATFORM_WINDOWS
|
||||||
const FString LibName = TEXT("discord-rpc");
|
const FString LibName = TEXT("discord-rpc");
|
||||||
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Win64"));
|
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Win64"));
|
||||||
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
|
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
|
||||||
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT(LOCTEXT_NAMESPACE, "Failed to load DiscordRpc plugin. Plug-in will not be functional."));
|
FMessageDialog::Open(
|
||||||
|
EAppMsgType::Ok,
|
||||||
|
LOCTEXT(LOCTEXT_NAMESPACE,
|
||||||
|
"Failed to load DiscordRpc plugin. Plug-in will not be functional."));
|
||||||
FreeDependency(DiscordRpcLibraryHandle);
|
FreeDependency(DiscordRpcLibraryHandle);
|
||||||
}
|
}
|
||||||
#elif PLATFORM_MAC
|
#elif PLATFORM_MAC
|
||||||
const FString LibName = TEXT("libdiscord-rpc");
|
const FString LibName = TEXT("libdiscord-rpc");
|
||||||
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Mac"));
|
const FString LibDir = FPaths::Combine(*SDKDir, TEXT("Mac"));
|
||||||
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
|
if (!LoadDependency(LibDir, LibName, DiscordRpcLibraryHandle)) {
|
||||||
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT(LOCTEXT_NAMESPACE, "Failed to load DiscordRpc plugin. Plug-in will not be functional."));
|
FMessageDialog::Open(
|
||||||
|
EAppMsgType::Ok,
|
||||||
|
LOCTEXT(LOCTEXT_NAMESPACE,
|
||||||
|
"Failed to load DiscordRpc plugin. Plug-in will not be functional."));
|
||||||
FreeDependency(DiscordRpcLibraryHandle);
|
FreeDependency(DiscordRpcLibraryHandle);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -49,8 +56,7 @@ bool FDiscordRpcModule::LoadDependency(const FString& Dir, const FString& Name,
|
|||||||
|
|
||||||
Handle = FPlatformProcess::GetDllHandle(*Path);
|
Handle = FPlatformProcess::GetDllHandle(*Path);
|
||||||
|
|
||||||
if (Handle == nullptr)
|
if (Handle == nullptr) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +65,7 @@ bool FDiscordRpcModule::LoadDependency(const FString& Dir, const FString& Name,
|
|||||||
|
|
||||||
void FDiscordRpcModule::FreeDependency(void*& Handle)
|
void FDiscordRpcModule::FreeDependency(void*& Handle)
|
||||||
{
|
{
|
||||||
if (Handle != nullptr)
|
if (Handle != nullptr) {
|
||||||
{
|
|
||||||
FPlatformProcess::FreeDllHandle(Handle);
|
FPlatformProcess::FreeDllHandle(Handle);
|
||||||
Handle = nullptr;
|
Handle = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(DISCORD_DYNAMIC_LIB)
|
#if defined(DISCORD_DYNAMIC_LIB)
|
||||||
# if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# if defined(DISCORD_BUILDING_SDK)
|
#if defined(DISCORD_BUILDING_SDK)
|
||||||
# define DISCORD_EXPORT __declspec(dllexport)
|
#define DISCORD_EXPORT __declspec(dllexport)
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __attribute__((visibility("default")))
|
|
||||||
# endif
|
|
||||||
#else
|
#else
|
||||||
# define DISCORD_EXPORT
|
#define DISCORD_EXPORT __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DISCORD_EXPORT __attribute__((visibility("default")))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DISCORD_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -91,7 +91,8 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId)
|
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId,
|
||||||
|
const char* steamId)
|
||||||
{
|
{
|
||||||
char command[256];
|
char command[256];
|
||||||
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
||||||
|
@ -26,7 +26,8 @@ static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat,
|
|||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, pszFormat);
|
va_start(va, pszFormat);
|
||||||
cbDest /= 2; // Size is divided by 2 to convert from bytes to wide characters - causes segfault othervise
|
cbDest /= 2; // Size is divided by 2 to convert from bytes to wide characters - causes segfault
|
||||||
|
// othervise
|
||||||
ret = vsnwprintf(pszDest, cbDest, pszFormat, va);
|
ret = vsnwprintf(pszDest, cbDest, pszFormat, va);
|
||||||
pszDest[cbDest - 1] = 0; // Terminate the string in case a buffer overflow; -1 will be returned
|
pszDest[cbDest - 1] = 0; // Terminate the string in case a buffer overflow; -1 will be returned
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -44,17 +45,24 @@ static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat,
|
|||||||
#undefine RegSetKeyValueW
|
#undefine RegSetKeyValueW
|
||||||
#endif
|
#endif
|
||||||
#define RegSetKeyValueW regset
|
#define RegSetKeyValueW regset
|
||||||
static LSTATUS regset(HKEY hkey, LPCWSTR subkey, LPCWSTR name, DWORD type, const void *data, DWORD len)
|
static LSTATUS regset(HKEY hkey,
|
||||||
|
LPCWSTR subkey,
|
||||||
|
LPCWSTR name,
|
||||||
|
DWORD type,
|
||||||
|
const void* data,
|
||||||
|
DWORD len)
|
||||||
{
|
{
|
||||||
HKEY htkey = hkey, hsubkey = nullptr;
|
HKEY htkey = hkey, hsubkey = nullptr;
|
||||||
LSTATUS ret;
|
LSTATUS ret;
|
||||||
if (subkey && subkey[0])
|
if (subkey && subkey[0]) {
|
||||||
{
|
if ((ret = RegCreateKeyExW(hkey, subkey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hsubkey, 0)) !=
|
||||||
if((ret = RegCreateKeyExW(hkey, subkey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hsubkey, 0)) != ERROR_SUCCESS) return ret;
|
ERROR_SUCCESS)
|
||||||
|
return ret;
|
||||||
htkey = hsubkey;
|
htkey = hsubkey;
|
||||||
}
|
}
|
||||||
ret = RegSetValueExW(htkey, name, 0, type, (const BYTE*)data, len);
|
ret = RegSetValueExW(htkey, name, 0, type, (const BYTE*)data, len);
|
||||||
if (hsubkey && hsubkey != hkey) RegCloseKey(hsubkey);
|
if (hsubkey && hsubkey != hkey)
|
||||||
|
RegCloseKey(hsubkey);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +80,7 @@ static void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* comma
|
|||||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command);
|
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//StringCbCopyW(openCommand, sizeof(openCommand), exeFilePath);
|
// StringCbCopyW(openCommand, sizeof(openCommand), exeFilePath);
|
||||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", exeFilePath);
|
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", exeFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +146,8 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const
|
|||||||
Discord_RegisterW(appId, wcommand);
|
Discord_RegisterW(appId, wcommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId)
|
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId,
|
||||||
|
const char* steamId)
|
||||||
{
|
{
|
||||||
wchar_t appId[32];
|
wchar_t appId[32];
|
||||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||||
|
@ -102,8 +102,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
|
|||||||
WriteKey(writer, "pid");
|
WriteKey(writer, "pid");
|
||||||
writer.Int(pid);
|
writer.Int(pid);
|
||||||
|
|
||||||
if (presence != nullptr)
|
if (presence != nullptr) {
|
||||||
{
|
|
||||||
WriteObject activity(writer, "activity");
|
WriteObject activity(writer, "activity");
|
||||||
|
|
||||||
WriteOptionalString(writer, "state", presence->state);
|
WriteOptionalString(writer, "state", presence->state);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#pragma warning(disable : 4464) // relative include path contains
|
#pragma warning(disable : 4464) // relative include path contains
|
||||||
#pragma warning(disable : 4668) // is not defined as a preprocessor macro
|
#pragma warning(disable : 4668) // is not defined as a preprocessor macro
|
||||||
#pragma warning(disable : 6313) // Incorrect operator
|
#pragma warning(disable : 6313) // Incorrect operator
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
|
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user