Skip to content

Commit

Permalink
Fix for game path always pointing to wineserver
Browse files Browse the repository at this point in the history
  • Loading branch information
mellowagain committed Jul 7, 2018
1 parent a9a55eb commit 6b9aba6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
29 changes: 24 additions & 5 deletions src/common/rpc_register.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cwchar>
#include <pwd.h>
#include <unistd.h>

#include "../utils/utils.hh"
#include "rpc_register.hh"

#if defined(__WINE__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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");
Expand All @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions src/rpc_wine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down Expand Up @@ -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

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions src/rpc_wine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 6b9aba6

Please sign in to comment.