Skip to content

Commit

Permalink
Last small bug fixes and undo last commit as it doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
mellowagain committed Jul 8, 2018
1 parent 6b9aba6 commit 7e4d38e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
29 changes: 6 additions & 23 deletions src/common/rpc_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
#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 @@ -27,23 +21,12 @@ void rpc_wine::register_app(const char *app_id, const char *cmd) {
}

if (cmd == nullptr || !cmd[0]) {
#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
// FIXME: This will always point to Wine preloader instead of the actual game
char game_path[PATH_MAX];
if (readlink("/proc/self/exe", game_path, sizeof(game_path)) <= 0)
return;

cmd = game_path;
}

const char *desktop_file_format = "[Desktop Entry]\n"
Expand Down
2 changes: 1 addition & 1 deletion src/connections/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rpc_wine::base_connection *rpc_wine::base_connection::create() {

void rpc_wine::base_connection::destroy(rpc_wine::base_connection *&connection) {
connection->close_connection();
delete connection;
connection = nullptr;
}

bool rpc_wine::base_connection::open_connection() {
Expand Down
2 changes: 1 addition & 1 deletion src/connections/rpc_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rpc_wine::connection *rpc_wine::connection::create(const char *app_id) {
void rpc_wine::connection::destroy(rpc_wine::connection *&connection) {
connection->close_connection();
base_connection::destroy(connection->connection);
delete connection;
connection = nullptr;
}

void rpc_wine::connection::open_connection() {
Expand Down
8 changes: 7 additions & 1 deletion src/rpc_wine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void rpcw_initialize(const char *app_id, discord_event_handlers *handlers, int a
rpc_connection->on_connect = [](serialization::json_document &message) {
rpcw_update_handlers(&queued_handlers);

memset(&connected_user, 0, sizeof(discord_user));
memset(&connected_user, 0, sizeof(connected_user));

auto data = serialization::get_object_member(&message, "data");
auto user = serialization::get_object_member(data, "user");
Expand All @@ -103,6 +103,12 @@ void rpcw_initialize(const char *app_id, discord_event_handlers *handlers, int a
const char *username = serialization::get_string_member(user, "username");

if (user_id != nullptr && username != nullptr) {
// This is pretty ghetto
connected_user.user_id = (char*) malloc(64);
connected_user.username = (char*) malloc(32);
connected_user.discrim = (char*) malloc(8);
connected_user.avatar = (char*) malloc(256);

strcpy(connected_user.user_id, user_id);
strcpy(connected_user.username, username);

Expand Down
2 changes: 0 additions & 2 deletions src/serialization/allocators.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <cassert>

#include "allocators.hh"

rpc_wine::serialization::linear_allocator::linear_allocator(char *buffer, size_t size) {
Expand Down
2 changes: 1 addition & 1 deletion src/serialization/writers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void rpc_wine::serialization::write_optional_string(rpc_wine::serialization::jso
}

void rpc_wine::serialization::write_nonce(rpc_wine::serialization::json_writer &writer, int nonce) {
write_key(writer, "NONCE");
write_key(writer, "nonce");
writer.String(std::to_string(nonce).c_str());
}

Expand Down
2 changes: 1 addition & 1 deletion src/serialization/writers.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef RPC_WINE_WRITERS_HH
#define RPC_WINE_WRITERS_HH

#include "serialization.hh"
#include "../common/discord_defs.hh"
#include "serialization.hh"

namespace rpc_wine::serialization {

Expand Down

0 comments on commit 7e4d38e

Please sign in to comment.