mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
(Discord) Cleanups - get rid of discord_register.h header
This commit is contained in:
parent
03ea12d334
commit
3387170d62
14
deps/discord-rpc/include/discord_register.h
vendored
14
deps/discord-rpc/include/discord_register.h
vendored
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define DISCORD_EXPORT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command);
|
||||
DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
6
deps/discord-rpc/include/discord_rpc.h
vendored
6
deps/discord-rpc/include/discord_rpc.h
vendored
@ -53,9 +53,9 @@ typedef struct DiscordEventHandlers
|
||||
#define DISCORD_REPLY_IGNORE 2
|
||||
|
||||
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||
DiscordEventHandlers* handlers,
|
||||
int autoRegister,
|
||||
const char* optionalSteamId);
|
||||
DiscordEventHandlers* handlers,
|
||||
int autoRegister,
|
||||
const char* optionalSteamId);
|
||||
DISCORD_EXPORT void Discord_Shutdown(void);
|
||||
|
||||
/* checks for incoming messages, dispatches callbacks */
|
||||
|
55
deps/discord-rpc/src/backoff.h
vendored
55
deps/discord-rpc/src/backoff.h
vendored
@ -5,36 +5,37 @@
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
struct Backoff {
|
||||
int64_t minAmount;
|
||||
int64_t maxAmount;
|
||||
int64_t current;
|
||||
int fails;
|
||||
std::mt19937_64 randGenerator;
|
||||
std::uniform_real_distribution<> randDistribution;
|
||||
struct Backoff
|
||||
{
|
||||
int64_t minAmount;
|
||||
int64_t maxAmount;
|
||||
int64_t current;
|
||||
int fails;
|
||||
std::mt19937_64 randGenerator;
|
||||
std::uniform_real_distribution<> randDistribution;
|
||||
|
||||
double rand01() { return randDistribution(randGenerator); }
|
||||
double rand01() { return randDistribution(randGenerator); }
|
||||
|
||||
Backoff(int64_t min, int64_t max)
|
||||
Backoff(int64_t min, int64_t max)
|
||||
: minAmount(min)
|
||||
, maxAmount(max)
|
||||
, current(min)
|
||||
, fails(0)
|
||||
, randGenerator((uint64_t)time(0))
|
||||
{
|
||||
}
|
||||
, maxAmount(max)
|
||||
, current(min)
|
||||
, fails(0)
|
||||
, randGenerator((uint64_t)time(0))
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
fails = 0;
|
||||
current = minAmount;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
fails = 0;
|
||||
current = minAmount;
|
||||
}
|
||||
|
||||
int64_t nextDelay()
|
||||
{
|
||||
++fails;
|
||||
int64_t delay = (int64_t)((double)current * 2.0 * rand01());
|
||||
current = std::min(current + delay, maxAmount);
|
||||
return current;
|
||||
}
|
||||
int64_t nextDelay()
|
||||
{
|
||||
++fails;
|
||||
int64_t delay = (int64_t)((double)current * 2.0 * rand01());
|
||||
current = std::min(current + delay, maxAmount);
|
||||
return current;
|
||||
}
|
||||
};
|
||||
|
19
deps/discord-rpc/src/connection.h
vendored
19
deps/discord-rpc/src/connection.h
vendored
@ -6,14 +6,15 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/* not really connectiony, but need per-platform */
|
||||
int GetProcessId();
|
||||
int GetProcessId(void);
|
||||
|
||||
struct BaseConnection {
|
||||
static BaseConnection* Create();
|
||||
static void Destroy(BaseConnection*&);
|
||||
bool isOpen{false};
|
||||
bool Open();
|
||||
bool Close();
|
||||
bool Write(const void* data, size_t length);
|
||||
bool Read(void* data, size_t length);
|
||||
struct BaseConnection
|
||||
{
|
||||
static BaseConnection* Create();
|
||||
static void Destroy(BaseConnection*&);
|
||||
bool isOpen{false};
|
||||
bool Open();
|
||||
bool Close();
|
||||
bool Write(const void* data, size_t length);
|
||||
bool Read(void* data, size_t length);
|
||||
};
|
||||
|
10
deps/discord-rpc/src/discord_register_linux.c
vendored
10
deps/discord-rpc/src/discord_register_linux.c
vendored
@ -1,5 +1,3 @@
|
||||
#include "discord_rpc.h"
|
||||
#include "discord_register.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
@ -13,9 +11,11 @@
|
||||
#include <file/file_path.h>
|
||||
#include <compat/strl.h>
|
||||
|
||||
#include <discord_rpc.h>
|
||||
|
||||
/* we want to register games so we can run them from
|
||||
* Discord client as discord-<appid>:// */
|
||||
void Discord_Register(const char* applicationId, const char* command)
|
||||
void Discord_Register(const char *applicationId, const char *command)
|
||||
{
|
||||
FILE* fp;
|
||||
int fileLen;
|
||||
@ -82,9 +82,7 @@ void Discord_Register(const char* applicationId, const char* command)
|
||||
fprintf(stderr, "Failed to register mime handler\n");
|
||||
}
|
||||
|
||||
void Discord_RegisterSteamGame(
|
||||
const char* applicationId,
|
||||
const char* steamId)
|
||||
void Discord_RegisterSteamGame(const char *applicationId, const char *steamId)
|
||||
{
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "xdg-open steam://rungameid/%s", steamId);
|
||||
|
76
deps/discord-rpc/src/discord_register_osx.m
vendored
76
deps/discord-rpc/src/discord_register_osx.m
vendored
@ -3,8 +3,6 @@
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#include "../include/discord_register.h"
|
||||
|
||||
static void RegisterCommand(const char* applicationId, const char* command)
|
||||
{
|
||||
/* There does not appear to be a way to register arbitrary commands on OSX, so instead we'll save the command
|
||||
@ -31,54 +29,52 @@ static void RegisterCommand(const char* applicationId, const char* command)
|
||||
|
||||
static void RegisterURL(const char* applicationId)
|
||||
{
|
||||
char url[256];
|
||||
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
||||
CFStringRef cfURL = CFStringCreateWithCString(NULL, url, kCFStringEncodingUTF8);
|
||||
NSString* myBundleId = [[NSBundle mainBundle] bundleIdentifier];
|
||||
char url[256];
|
||||
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
||||
CFStringRef cfURL = CFStringCreateWithCString(NULL, url, kCFStringEncodingUTF8);
|
||||
NSString* myBundleId = [[NSBundle mainBundle] bundleIdentifier];
|
||||
|
||||
if (!myBundleId)
|
||||
{
|
||||
fprintf(stderr, "No bundle id found\n");
|
||||
return;
|
||||
}
|
||||
if (!myBundleId)
|
||||
{
|
||||
fprintf(stderr, "No bundle id found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
NSURL* myURL = [[NSBundle mainBundle] bundleURL];
|
||||
if (!myURL)
|
||||
{
|
||||
fprintf(stderr, "No bundle url found\n");
|
||||
return;
|
||||
}
|
||||
NSURL* myURL = [[NSBundle mainBundle] bundleURL];
|
||||
if (!myURL)
|
||||
{
|
||||
fprintf(stderr, "No bundle url found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
OSStatus status = LSSetDefaultHandlerForURLScheme(cfURL, (__bridge CFStringRef)myBundleId);
|
||||
if (status != noErr)
|
||||
{
|
||||
fprintf(stderr, "Error in LSSetDefaultHandlerForURLScheme: %d\n", (int)status);
|
||||
return;
|
||||
}
|
||||
OSStatus status = LSSetDefaultHandlerForURLScheme(cfURL, (__bridge CFStringRef)myBundleId);
|
||||
if (status != noErr)
|
||||
{
|
||||
fprintf(stderr, "Error in LSSetDefaultHandlerForURLScheme: %d\n", (int)status);
|
||||
return;
|
||||
}
|
||||
|
||||
status = LSRegisterURL((__bridge CFURLRef)myURL, true);
|
||||
if (status != noErr)
|
||||
{
|
||||
fprintf(stderr, "Error in LSRegisterURL: %d\n", (int)status);
|
||||
}
|
||||
status = LSRegisterURL((__bridge CFURLRef)myURL, true);
|
||||
if (status != noErr)
|
||||
fprintf(stderr, "Error in LSRegisterURL: %d\n", (int)status);
|
||||
}
|
||||
|
||||
void Discord_Register(const char* applicationId, const char* command)
|
||||
{
|
||||
if (command)
|
||||
RegisterCommand(applicationId, command);
|
||||
else
|
||||
{
|
||||
/* RAII Lite */
|
||||
@autoreleasepool {
|
||||
RegisterURL(applicationId);
|
||||
}
|
||||
}
|
||||
if (command)
|
||||
RegisterCommand(applicationId, command);
|
||||
else
|
||||
{
|
||||
/* RAII Lite */
|
||||
@autoreleasepool {
|
||||
RegisterURL(applicationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Discord_RegisterSteamGame(const char* applicationId, const char* steamId)
|
||||
{
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "steam://rungameid/%s", steamId);
|
||||
Discord_Register(applicationId, command);
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "steam://rungameid/%s", steamId);
|
||||
Discord_Register(applicationId, command);
|
||||
}
|
||||
|
150
deps/discord-rpc/src/discord_register_win.c
vendored
150
deps/discord-rpc/src/discord_register_win.c
vendored
@ -1,5 +1,4 @@
|
||||
#include "discord_rpc.h"
|
||||
#include "discord_register.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMCX
|
||||
@ -53,99 +52,99 @@ static LSTATUS regset(HKEY hkey,
|
||||
const void* data,
|
||||
DWORD len)
|
||||
{
|
||||
HKEY htkey = hkey, hsubkey = NULL;
|
||||
LSTATUS ret;
|
||||
if (subkey && subkey[0])
|
||||
{
|
||||
if ((ret = RegCreateKeyExW(hkey, subkey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hsubkey, 0)) !=
|
||||
LSTATUS ret;
|
||||
HKEY htkey = hkey, hsubkey = NULL;
|
||||
if (subkey && subkey[0])
|
||||
{
|
||||
if ((ret = RegCreateKeyExW(hkey, subkey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hsubkey, 0)) !=
|
||||
ERROR_SUCCESS)
|
||||
return ret;
|
||||
htkey = hsubkey;
|
||||
}
|
||||
ret = RegSetValueExW(htkey, name, 0, type, (const BYTE*)data, len);
|
||||
if (hsubkey && hsubkey != hkey)
|
||||
RegCloseKey(hsubkey);
|
||||
return ret;
|
||||
return ret;
|
||||
htkey = hsubkey;
|
||||
}
|
||||
ret = RegSetValueExW(htkey, name, 0, type, (const BYTE*)data, len);
|
||||
if (hsubkey && hsubkey != hkey)
|
||||
RegCloseKey(hsubkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void Discord_RegisterW(
|
||||
const wchar_t* applicationId, const wchar_t* command)
|
||||
{
|
||||
/* https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
|
||||
* we want to register games so we can run them as discord-<appid>://
|
||||
* Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions. */
|
||||
/* https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
|
||||
* we want to register games so we can run them as discord-<appid>://
|
||||
* Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions. */
|
||||
|
||||
DWORD len;
|
||||
LSTATUS result;
|
||||
wchar_t urlProtocol = 0;
|
||||
wchar_t keyName[256];
|
||||
wchar_t protocolName[64];
|
||||
wchar_t protocolDescription[128];
|
||||
wchar_t exeFilePath[MAX_PATH];
|
||||
DWORD exeLen = GetModuleFileNameW(NULL, exeFilePath, MAX_PATH);
|
||||
wchar_t openCommand[1024];
|
||||
DWORD len;
|
||||
LSTATUS result;
|
||||
wchar_t urlProtocol = 0;
|
||||
wchar_t keyName[256];
|
||||
wchar_t protocolName[64];
|
||||
wchar_t protocolDescription[128];
|
||||
wchar_t exeFilePath[MAX_PATH];
|
||||
DWORD exeLen = GetModuleFileNameW(NULL, exeFilePath, MAX_PATH);
|
||||
wchar_t openCommand[1024];
|
||||
|
||||
if (command && command[0])
|
||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%S", command);
|
||||
else
|
||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%S", exeFilePath);
|
||||
if (command && command[0])
|
||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%S", command);
|
||||
else
|
||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%S", exeFilePath);
|
||||
|
||||
StringCbPrintfW(protocolName, sizeof(protocolName),
|
||||
L"discord-%S", applicationId);
|
||||
StringCbPrintfW(
|
||||
protocolDescription, sizeof(protocolDescription),
|
||||
L"URL:Run game %S protocol", applicationId);
|
||||
StringCbPrintfW(keyName, sizeof(keyName), L"Software\\Classes\\%S", protocolName);
|
||||
HKEY key;
|
||||
LSTATUS status =
|
||||
StringCbPrintfW(protocolName, sizeof(protocolName),
|
||||
L"discord-%S", applicationId);
|
||||
StringCbPrintfW(
|
||||
protocolDescription, sizeof(protocolDescription),
|
||||
L"URL:Run game %S protocol", applicationId);
|
||||
StringCbPrintfW(keyName, sizeof(keyName), L"Software\\Classes\\%S", protocolName);
|
||||
HKEY key;
|
||||
LSTATUS status =
|
||||
RegCreateKeyExW(HKEY_CURRENT_USER, keyName, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "Error creating key\n");
|
||||
return;
|
||||
}
|
||||
len = (DWORD)lstrlenW(protocolDescription) + 1;
|
||||
result =
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "Error creating key\n");
|
||||
return;
|
||||
}
|
||||
len = (DWORD)lstrlenW(protocolDescription) + 1;
|
||||
result =
|
||||
RegSetKeyValueW(key, NULL, NULL, REG_SZ, protocolDescription, len * sizeof(wchar_t));
|
||||
if (FAILED(result)) {
|
||||
fprintf(stderr, "Error writing description\n");
|
||||
}
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing description\n");
|
||||
|
||||
len = (DWORD)lstrlenW(protocolDescription) + 1;
|
||||
result = RegSetKeyValueW(key, NULL, L"URL Protocol", REG_SZ, &urlProtocol, sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing description\n");
|
||||
len = (DWORD)lstrlenW(protocolDescription) + 1;
|
||||
result = RegSetKeyValueW(key, NULL, L"URL Protocol", REG_SZ, &urlProtocol, sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing description\n");
|
||||
|
||||
result = RegSetKeyValueW(
|
||||
key, L"DefaultIcon", NULL, REG_SZ, exeFilePath, (exeLen + 1) * sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing icon\n");
|
||||
result = RegSetKeyValueW(
|
||||
key, L"DefaultIcon", NULL, REG_SZ, exeFilePath, (exeLen + 1) * sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing icon\n");
|
||||
|
||||
len = (DWORD)lstrlenW(openCommand) + 1;
|
||||
result = RegSetKeyValueW(
|
||||
key, L"shell\\open\\command", NULL, REG_SZ, openCommand, len * sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing command\n");
|
||||
RegCloseKey(key);
|
||||
len = (DWORD)lstrlenW(openCommand) + 1;
|
||||
result = RegSetKeyValueW(
|
||||
key, L"shell\\open\\command", NULL, REG_SZ, openCommand, len * sizeof(wchar_t));
|
||||
if (FAILED(result))
|
||||
fprintf(stderr, "Error writing command\n");
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
void Discord_Register(const char* applicationId, const char* command)
|
||||
{
|
||||
wchar_t openCommand[1024];
|
||||
const wchar_t* wcommand = NULL;
|
||||
wchar_t appId[32];
|
||||
wchar_t appId[32];
|
||||
wchar_t openCommand[1024];
|
||||
const wchar_t* wcommand = NULL;
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||
if (command && command[0])
|
||||
{
|
||||
const int commandBufferLen =
|
||||
sizeof(openCommand) / sizeof(*openCommand);
|
||||
MultiByteToWideChar(CP_UTF8, 0, command, -1,
|
||||
openCommand, commandBufferLen);
|
||||
wcommand = openCommand;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||
|
||||
Discord_RegisterW(appId, wcommand);
|
||||
if (command && command[0])
|
||||
{
|
||||
const int commandBufferLen =
|
||||
sizeof(openCommand) / sizeof(*openCommand);
|
||||
MultiByteToWideChar(CP_UTF8, 0, command, -1,
|
||||
openCommand, commandBufferLen);
|
||||
wcommand = openCommand;
|
||||
}
|
||||
|
||||
Discord_RegisterW(appId, wcommand);
|
||||
}
|
||||
|
||||
void Discord_RegisterSteamGame(
|
||||
@ -172,7 +171,8 @@ void Discord_RegisterSteamGame(
|
||||
status = RegQueryValueExW(key,
|
||||
L"SteamExe", NULL, NULL, (BYTE*)steamPath, &pathBytes);
|
||||
RegCloseKey(key);
|
||||
if (status != ERROR_SUCCESS || pathBytes < 1) {
|
||||
if (status != ERROR_SUCCESS || pathBytes < 1)
|
||||
{
|
||||
fprintf(stderr, "Error reading SteamExe key\n");
|
||||
return;
|
||||
}
|
||||
|
13
deps/discord-rpc/src/discord_rpc.cpp
vendored
13
deps/discord-rpc/src/discord_rpc.cpp
vendored
@ -1,7 +1,6 @@
|
||||
#include "discord_rpc.h"
|
||||
|
||||
#include "backoff.h"
|
||||
#include "discord_register.h"
|
||||
#include "msg_queue.h"
|
||||
#include "rpc_connection.h"
|
||||
#include "serialization.h"
|
||||
@ -15,6 +14,18 @@
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
/* Forward declarations */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void Discord_Register(const char *a, const char *b);
|
||||
void Discord_RegisterSteamGame(const char *a, const char *b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
constexpr size_t MaxMessageSize{16 * 1024};
|
||||
constexpr size_t MessageQueueSize{8};
|
||||
constexpr size_t JoinQueueSize{8};
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <features/features_cpu.h>
|
||||
|
||||
#include "discord.h"
|
||||
#include "discord_register.h"
|
||||
|
||||
#include "../deps/discord-rpc/include/discord_rpc.h"
|
||||
|
||||
@ -90,6 +89,18 @@ static discord_state_t discord_st;
|
||||
|
||||
#define CDN_URL "https://cdn.discordapp.com/avatars"
|
||||
|
||||
/* Forward declarations */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void Discord_Register(const char *a, const char *b);
|
||||
void Discord_RegisterSteamGame(const char *a, const char *b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static discord_state_t *discord_get_ptr(void)
|
||||
{
|
||||
return &discord_st;
|
||||
|
Loading…
x
Reference in New Issue
Block a user