Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 1959a1c

Browse files
committed
ストリームからチャンネル名を取得するように設定から変更できるように。
1 parent 8da87a6 commit 1959a1c

File tree

1 file changed

+102
-19
lines changed

1 file changed

+102
-19
lines changed

TvTestRPC/TvTestRPC.cpp

Lines changed: 102 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,44 @@
33

44
#include "stdafx.h"
55
#include <time.h>
6+
#include <shlwapi.h>
7+
#include "resource.h"
8+
#pragma comment(lib,"shlwapi.lib")
9+
610
class CMyPlugin : public TVTest::CTVTestPlugin
711
{
812
DiscordEventHandlers handlers;
9-
static LRESULT CALLBACK EventCallback(UINT Event, LPARAM lParam1, LPARAM lParam2, void *pClientData);
13+
static LRESULT CALLBACK EventCallback(UINT Event, LPARAM lParam1, LPARAM lParam2, void* pClientData);
14+
static INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, void* pClientData);
15+
bool ShowDialog(HWND hwndOwner);
16+
POINT m_SettingsDialogPos;
17+
TCHAR m_szIniFileName[MAX_PATH];
18+
bool conf_mode = false;
19+
bool conf_isFinalized = false;
20+
bool InitSettings();
21+
bool pluginState = false;
22+
void InitDiscord();
23+
void UpdateState();
24+
static const int DEFAULT_POS = INT_MIN;
1025

1126
public:
12-
bool pluginState;
13-
void discordInit();
14-
void UpdateState();
1527
time_t SystemTime2Timet(const SYSTEMTIME&);
1628

17-
bool GetPluginInfo(TVTest::PluginInfo *pInfo) override
29+
bool GetPluginInfo(TVTest::PluginInfo* pInfo) override
1830
{
1931
pInfo->Type = TVTest::PLUGIN_TYPE_NORMAL;
20-
pInfo->Flags = 0;
32+
pInfo->Flags = TVTest::PLUGIN_FLAG_HASSETTINGS;
2133
pInfo->pszPluginName = L"TvTest RPC";
2234
pInfo->pszCopyright = L"(c) 2019-2020 noriokun4649";
2335
pInfo->pszDescription = L"DiscordRPCをTvTestで実現します。Discordで視聴中のチャンネルなどの情報が通知されます。";
24-
return true;
36+
return true;
2537
}
2638

2739
bool Initialize() override
2840
{
29-
discordInit();
41+
InitDiscord();
3042
m_pApp->SetEventCallback(EventCallback, this);
31-
return true;
43+
return true;
3244
}
3345
bool Finalize() override
3446
{
@@ -37,16 +49,24 @@ class CMyPlugin : public TVTest::CTVTestPlugin
3749
}
3850
};
3951

40-
void CMyPlugin::discordInit()
52+
53+
bool CMyPlugin::InitSettings() {
54+
::GetModuleFileName(g_hinstDLL, m_szIniFileName, MAX_PATH);
55+
::PathRenameExtension(m_szIniFileName, TEXT(".ini"));
56+
conf_mode = ::GetPrivateProfileInt(TEXT("Settings"), TEXT("Mode"), conf_mode, m_szIniFileName) != 0;
57+
m_pApp->AddLog(m_szIniFileName);
58+
conf_isFinalized = true;
59+
return true;
60+
}
61+
62+
void CMyPlugin::InitDiscord()
4163
{
4264
Discord_Initialize("577065126084214816", &handlers, 1, NULL);
4365
}
4466

4567
void CMyPlugin::UpdateState()
4668
{
47-
TVTest::ChannelInfo ChannelInfo;
4869
TVTest::ProgramInfo Info;
49-
ChannelInfo.Size = sizeof(ChannelInfo);
5070
Info.Size = sizeof(Info);
5171
wchar_t eventName[128];
5272
wchar_t eventText[128];
@@ -61,15 +81,25 @@ void CMyPlugin::UpdateState()
6181
std::string eventNamed;
6282
time_t start;
6383
time_t end;
64-
84+
6585
if (m_pApp->GetCurrentProgramInfo(&Info)) {
6686
eventNamed = wide_to_utf8(Info.pszEventName);
6787
end = SystemTime2Timet(Info.StartTime) + Info.Duration;
6888
start = SystemTime2Timet(Info.StartTime);
6989
}
70-
if (m_pApp->GetCurrentChannelInfo(&ChannelInfo) ) {
71-
m_pApp->AddLog(ChannelInfo.szChannelName);
72-
channelName = wide_to_utf8(ChannelInfo.szChannelName);
90+
if (!conf_mode) {
91+
TVTest::ServiceInfo Service;
92+
Service.Size = sizeof(Service);
93+
if (m_pApp->GetServiceInfo(0, &Service)) {
94+
channelName = wide_to_utf8(Service.szServiceName);
95+
}
96+
}
97+
else {
98+
TVTest::ChannelInfo ChannelInfo;
99+
ChannelInfo.Size = sizeof(ChannelInfo);
100+
if (m_pApp->GetCurrentChannelInfo(&ChannelInfo)) {
101+
channelName = wide_to_utf8(ChannelInfo.szChannelName);
102+
}
73103
}
74104
DiscordRichPresence discordPresence;
75105
memset(&discordPresence, 0, sizeof(discordPresence));
@@ -95,19 +125,70 @@ time_t CMyPlugin::SystemTime2Timet(const SYSTEMTIME& st)
95125
return mktime(&gm);
96126
}
97127

98-
TVTest::CTVTestPlugin *CreatePluginClass()
128+
TVTest::CTVTestPlugin* CreatePluginClass()
99129
{
100130
return new CMyPlugin;
101131
}
102-
LRESULT CALLBACK CMyPlugin::EventCallback(UINT Event, LPARAM lParam1, LPARAM lParam2, void *pClientData)
132+
133+
bool CMyPlugin::ShowDialog(HWND hwndOwner) {
134+
135+
TVTest::ShowDialogInfo Info;
136+
Info.Flags = 0;
137+
Info.hinst = g_hinstDLL;
138+
Info.pszTemplate = MAKEINTRESOURCE(IDD_DIALOG1);
139+
Info.pMessageFunc = SettingsDlgProc;
140+
Info.pClientData = this;
141+
Info.hwndOwner = hwndOwner;
142+
if (m_SettingsDialogPos.x != DEFAULT_POS && m_SettingsDialogPos.y != DEFAULT_POS) {
143+
Info.Flags |= TVTest::SHOW_DIALOG_FLAG_POSITION;
144+
Info.Position = m_SettingsDialogPos;
145+
}
146+
147+
return m_pApp->ShowDialog(&Info) == IDOK;
148+
}
149+
150+
INT_PTR CALLBACK CMyPlugin::SettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, void* pClientData) {
151+
CMyPlugin* pThis = static_cast<CMyPlugin*>(pClientData);
152+
switch (uMsg)
153+
{
154+
case WM_INITDIALOG:
155+
::CheckDlgButton(hDlg, IDC_CHECK1, pThis->conf_mode ? BST_CHECKED : BST_UNCHECKED);
156+
return TRUE;
157+
case WM_COMMAND:
158+
switch (LOWORD(wParam)) {
159+
case IDOK:
160+
pThis->conf_mode = ::IsDlgButtonChecked(hDlg, IDC_CHECK1) == BST_CHECKED;
161+
if (pThis->conf_isFinalized) {
162+
struct IntString {
163+
IntString(int Value) { ::wsprintf(m_szBuffer, TEXT("%d"), Value); }
164+
operator LPCTSTR() const { return m_szBuffer; }
165+
TCHAR m_szBuffer[16];
166+
};
167+
168+
::WritePrivateProfileString(TEXT("Settings"), TEXT("Mode"), IntString(pThis->conf_mode), pThis->m_szIniFileName);
169+
}
170+
pThis->UpdateState();
171+
case IDCANCEL:
172+
::EndDialog(hDlg, LOWORD(wParam));
173+
return TRUE;
174+
}
175+
default:
176+
break;
177+
return FALSE;
178+
}
179+
return FALSE;
180+
}
181+
182+
LRESULT CALLBACK CMyPlugin::EventCallback(UINT Event, LPARAM lParam1, LPARAM lParam2, void* pClientData)
103183
{
104-
CMyPlugin *pThis = static_cast<CMyPlugin *>(pClientData);
184+
CMyPlugin* pThis = static_cast<CMyPlugin*>(pClientData);
105185
bool fEnable = lParam1 != 0;
106186
switch (Event)
107187
{
108188
case TVTest::EVENT_PLUGINENABLE:
109189
if (fEnable) {
110190
pThis->UpdateState();
191+
pThis->InitSettings();
111192
}
112193
else
113194
{
@@ -121,6 +202,8 @@ LRESULT CALLBACK CMyPlugin::EventCallback(UINT Event, LPARAM lParam1, LPARAM lPa
121202
case TVTest::EVENT_SERVICEUPDATE:
122203
pThis->UpdateState();
123204
return TRUE;
205+
case TVTest::EVENT_PLUGINSETTINGS:
206+
return pThis->ShowDialog(reinterpret_cast<HWND>(lParam1));
124207
}
125208
return 0;
126209
}

0 commit comments

Comments
 (0)