From 6b9aba634a3be96c81a626d0d65fe6feb9a0c0b6 Mon Sep 17 00:00:00 2001 From: Marc3842h Date: Sat, 7 Jul 2018 22:56:10 +0200 Subject: [PATCH] Fix for game path always pointing to wineserver --- src/common/rpc_register.cc | 29 ++++++++++++++++++++++++----- src/rpc_wine.cc | 15 +++++++++++---- src/rpc_wine.hh | 6 ++++-- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/common/rpc_register.cc b/src/common/rpc_register.cc index 190e09b..d42c998 100644 --- a/src/common/rpc_register.cc +++ b/src/common/rpc_register.cc @@ -1,13 +1,20 @@ #include +#include #include #include #include +#include #include #include #include "../utils/utils.hh" #include "rpc_register.hh" +#if defined(__WINE__) + #define WIN32_LEAN_AND_MEAN + #include +#endif + // Add a desktop file and update some mime handlers so that xdg-open does the right thing. void rpc_wine::register_app(const char *app_id, const char *cmd) { const char *home_dir = getenv("HOME"); @@ -20,11 +27,23 @@ void rpc_wine::register_app(const char *app_id, const char *cmd) { } if (cmd == nullptr || !cmd[0]) { - char game_path[PATH_MAX]; - if (readlink("/proc/self/exe", game_path, sizeof(game_path)) <= 0) - return; - - cmd = game_path; + #if defined(__WINE__) + wchar_t game_path[PATH_MAX]; + + unsigned int length = GetModuleFileNameW(nullptr, game_path, sizeof(game_path)); + if (length == 0) + return; + + char *buffer; + wcstombs(buffer, game_path, wcslen(game_path)); + cmd = buffer; + #else + char game_path[PATH_MAX]; + if (readlink("/proc/self/exe", game_path, sizeof(game_path)) <= 0) + return; + + cmd = game_path; + #endif } const char *desktop_file_format = "[Desktop Entry]\n" diff --git a/src/rpc_wine.cc b/src/rpc_wine.cc index 68b84d1..c56d6d5 100644 --- a/src/rpc_wine.cc +++ b/src/rpc_wine.cc @@ -10,6 +10,9 @@ #include "serialization/writers.hh" #include "utils/backoff.hh" +// Put rpc_wine into the global namespace for convenience +using namespace rpc_wine; + static connection *rpc_connection = nullptr; static discord_event_handlers queued_handlers {}; @@ -46,7 +49,9 @@ static std::mutex handler_mutex; static discord_user connected_user; +#if defined(__cplusplus) extern "C" { // Prevent mangle of function names (Wine can't find them if mangled by C++ compiler) +#endif // Discord Rich Presence API - discord_rpc.h @@ -61,9 +66,9 @@ void rpcw_initialize(const char *app_id, discord_event_handlers *handlers, int a if (auto_register) { if (steam_id != nullptr && steam_id[0]) { - rpc_wine::register_steam_game(app_id, steam_id); + register_steam_game(app_id, steam_id); } else { - rpc_wine::register_app(app_id, nullptr); + register_app(app_id, nullptr); } } @@ -414,11 +419,13 @@ void rpcw_update_presence(const discord_rich_presence *presence) { // Discord Register API - discord_register.h void rpcw_register(const char *app_id, const char *cmd) { - rpc_wine::register_app(app_id, cmd); + register_app(app_id, cmd); } void rpcw_register_steam_game(const char *app_id, const char *steam_id) { - rpc_wine::register_steam_game(app_id, steam_id); + register_steam_game(app_id, steam_id); } +#if defined(__cplusplus) }; +#endif diff --git a/src/rpc_wine.hh b/src/rpc_wine.hh index 892e79d..93d8231 100644 --- a/src/rpc_wine.hh +++ b/src/rpc_wine.hh @@ -3,9 +3,9 @@ #include "common/discord_defs.hh" -using namespace rpc_wine; - +#if defined(__cplusplus) extern "C" { // Prevent mangle of function names (Wine can't find them if mangled by C++ compiler) +#endif // Discord Rich Presence API - discord_rpc.h @@ -31,6 +31,8 @@ void rpcw_register(const char *app_id, const char *cmd); void rpcw_register_steam_game(const char *app_id, const char *steam_id); +#if defined(__cplusplus) }; +#endif #endif //RPC_WINE_RPC_WINE_HH