Skip to content

Commit

Permalink
Fixed bugs when closing AIMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Exle committed Apr 14, 2018
1 parent 1f38cca commit e3583a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
67 changes: 37 additions & 30 deletions AIMPRemote.cpp
@@ -1,11 +1,10 @@
#include <cmath>
#include "AIMPRemote.h"

AIMPRemote *AIMPRemote::PAIMPRemote;

AIMPRemote::AIMPRemote()
: FAIMPRemoteHandle(NULL),
MyWnd(NULL)
MyWnd(NULL)
{
PAIMPRemote = this;
ARTrackInfo = { 0 };
Expand All @@ -16,15 +15,15 @@ AIMPRemote::AIMPRemote()

AIMPRemote::~AIMPRemote()
{
AIMPSetRemoteHandle(NULL);
if (FAIMPRemoteHandle)
{
DestroyWindow(FAIMPRemoteHandle);
}

if (MyWnd != NULL)
if (MyWnd)
{
DestroyWindow(MyWnd);
}

delete FAIMPRemoteHandle;
delete MyWnd;
}

VOID AIMPRemote::AIMPExecuteCommand(INT ACommand)
Expand Down Expand Up @@ -60,14 +59,14 @@ VOID AIMPRemote::AIMPSetEvents(AIMPEvents *Events)
PAIMPRemote->AREvents = *Events;
}

BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND Value)
BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND *Value)
{
if (PAIMPRemote->FAIMPRemoteHandle == Value)
if (PAIMPRemote->FAIMPRemoteHandle == *Value)
{
return true;
}

if (PAIMPRemote->FAIMPRemoteHandle)
if (PAIMPRemote->FAIMPRemoteHandle && PAIMPRemote->MyWnd)
{
SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, AIMP_RA_CMD_UNREGISTER_NOTIFY, (LPARAM)PAIMPRemote->MyWnd);
}
Expand All @@ -90,7 +89,7 @@ BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND Value)
}
}

PAIMPRemote->FAIMPRemoteHandle = Value;
PAIMPRemote->FAIMPRemoteHandle = *Value;

PAIMPRemote->InfoUpdateVersionInfo();
PAIMPRemote->InfoUpdatePlayerState();
Expand All @@ -109,6 +108,11 @@ BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND Value)

BOOL AIMPRemote::InfoUpdateTrackInfo()
{
if (!AREvents.TrackInfo)
{
return true;
}

HANDLE hFile;
PAIMPRemoteFileInfo AIMPRemote_TrackInfo;
LPWSTR offset;
Expand Down Expand Up @@ -175,16 +179,18 @@ BOOL AIMPRemote::InfoUpdateTrackInfo()
UnmapViewOfFile(AIMPRemote_TrackInfo);
CloseHandle(hFile);

if (AREvents.TrackInfo != NULL)
{
AREvents.TrackInfo(&ARTrackInfo);
}
AREvents.TrackInfo(&ARTrackInfo);

return true;
}

BOOL AIMPRemote::InfoUpdatePlayerState()
{
if (!AREvents.State)
{
return true;
}

int AIMPRemote_State = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_STATE);
if (ARState == AIMPRemote_State)
{
Expand All @@ -193,48 +199,49 @@ BOOL AIMPRemote::InfoUpdatePlayerState()

ARState = AIMPRemote_State;

if (AREvents.State != NULL)
{
AREvents.State(ARState);
}
AREvents.State(ARState);

return true;
}

BOOL AIMPRemote::InfoUpdateTrackPositionInfo()
{
int AIMPRemote_PositionDur = (int)round(AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_DURATION) / 1000);
int AIMPRemote_PositionPos = (int)round(AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_POSITION) / 1000);
if (!AREvents.TrackPosition)
{
return true;
}

int AIMPRemote_PositionDur = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_DURATION) / 1000;
int AIMPRemote_PositionPos = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_POSITION) / 1000;

if (ARPosition.Duration == AIMPRemote_PositionDur
&& ARPosition.Position == AIMPRemote_PositionPos)
&& ARPosition.Position == AIMPRemote_PositionPos)
{
return false;
}

ARPosition.Duration = AIMPRemote_PositionDur;
ARPosition.Position = AIMPRemote_PositionPos;

if (AREvents.TrackPosition != NULL)
{
AREvents.TrackPosition(&ARPosition);
}
AREvents.TrackPosition(&ARPosition);

return true;
}

BOOL AIMPRemote::InfoUpdateVersionInfo()
{
if (!AREvents.Version)
{
return true;
}

int AIMPRemote_Version = AIMPGetPropertyValue(AIMP_RA_PROPERTY_VERSION);
if (AIMPRemote_Version != 0)
{
ARVersion.Version = static_cast<float>(HIWORD(AIMPRemote_Version)) / 100;
ARVersion.Build = LOWORD(AIMPRemote_Version);

if (AREvents.Version != NULL)
{
AREvents.Version(&ARVersion);
}
AREvents.Version(&ARVersion);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion AIMPRemote.h
Expand Up @@ -63,7 +63,7 @@ class AIMPRemote
static INT AIMPGetPropertyValue(INT APropertyID);
static BOOL AIMPSetPropertyValue(INT APropertyID, INT AValue);
static VOID AIMPSetEvents(AIMPEvents *Events);
static BOOL AIMPSetRemoteHandle(const HWND Value);
static BOOL AIMPSetRemoteHandle(const HWND *Value);
protected:
static LRESULT CALLBACK WMAIMPNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
Expand Down
1 change: 0 additions & 1 deletion DiscordRPC.cpp
Expand Up @@ -8,7 +8,6 @@ DiscordRPC::DiscordRPC()

DiscordRPC::~DiscordRPC()
{
ClearPresence();
Shutdown();
}

Expand Down
Binary file modified aimp_DiscordPresence.cpp
Binary file not shown.

0 comments on commit e3583a1

Please sign in to comment.