Skip to content

Commit 3bff9fa

Browse files
committed
ファイル名の表示を隠せるように変更
1 parent 023e327 commit 3bff9fa

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

main.cpp

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//---------------------------------------------------------------------
22
// AviUtlでDiscord RPCを表示するプラグイン
33
//---------------------------------------------------------------------
4-
5-
// インクルード
64
#include <Windows.h>
75
#include <string>
86
#include <chrono>
@@ -20,15 +18,15 @@ static BOOL RPC_Enabled = TRUE;
2018
// ファイル名を表示するかどうか
2119
static BOOL RPC_Display_Filename = TRUE;
2220
// ステータス
23-
static int Status = NULL;
24-
// 現在編集中のファイル名
25-
static const char* FILTER_CURRENT_FILENAME = NULL;
21+
static int Status = RPC_STATUS_IDLING;
2622
// タイマーの識別子
2723
static UINT_PTR timer_identifer = NULL;
2824
// RPCが破棄されているかどうか
2925
static BOOL IS_Disposed = TRUE;
3026
// システム情報
3127
static LPSTR SYS_INFO_STR = NULL;
28+
// 開始時刻が一度でも設定されているか
29+
static BOOL RPC_Timestamp_Set = FALSE;
3230

3331
// Discord Core
3432
discord::Core* core{};
@@ -39,10 +37,11 @@ discord::Activity activity{};
3937
// フィルタ構造体定義
4038
//---------------------------------------------------------------------
4139
TCHAR FILTER_NAME[] = "AviUtl Discord RPC";
42-
#define CHECK_NUM 1
40+
#define CHECK_NUM 2
4341
TCHAR* CHECKBOX_NAMES[] = { "有効にする", "ファイル名を表示する"};
4442
int CHECKBOX_INITIAL_VAL[] = { 0 , 0 };
45-
TCHAR FILTER_INFO[] = "AviUtl Discord RPC version 0.99c by mtripg6666tdr";
43+
TCHAR FILTER_INFO[] = "AviUtl Discord RPC version 0.99d by mtripg6666tdr";
44+
TCHAR VERSION[] = "0.99d";
4645

4746
FILTER_DLL filter = {
4847
// flag
@@ -136,13 +135,16 @@ BOOL func_init(FILTER* fp) {
136135
SYS_INFO info;
137136
if (fp->exfunc->get_sys_info(NULL, &info)) {
138137
LPSTR ver = info.info;
139-
LPSTR app_name = "AviUtl ";
140-
//LPSTR plugin_str = " (RPC powered by AviUtl RPC Plugin by mtripg6666tdr)";
141-
int num = strlen(ver) + strlen(app_name) + /*strlen(plugin_str) +*/ 1;
138+
LPSTR app_name = "AviUtl" " ";
139+
LPSTR rpc_ver = " (RPC v";
140+
LPSTR rpc_ver_end = ")";
141+
int num = strlen(ver) + strlen(app_name) + strlen(rpc_ver) + strlen(VERSION) + strlen(rpc_ver_end) + 1;
142142
SYS_INFO_STR = new char[num];
143143
strcpy_s(SYS_INFO_STR, num, app_name);
144144
strcat_s(SYS_INFO_STR, num, ver);
145-
//strcat_s(SYS_INFO_STR, num, plugin_str);
145+
strcat_s(SYS_INFO_STR, num, rpc_ver);
146+
strcat_s(SYS_INFO_STR, num, VERSION);
147+
strcat_s(SYS_INFO_STR, num, rpc_ver_end);
146148
}
147149
return TRUE;
148150
}
@@ -163,17 +165,27 @@ BOOL func_exit(FILTER* fp) {
163165
// 設定変更
164166
//---------------------------------------------------------------------
165167
BOOL func_update(FILTER* fp, int status) {
168+
BOOL initialized = FALSE;
166169
switch (fp->check[0]) {
167170
case FILTER_CHECKBOX_STATUS_ON:
168-
RPC_Enabled = TRUE;
169-
Initialize_RPC();
170-
Update_RPC(fp, NULL, Status, TRUE);
171+
if (!RPC_Enabled) {
172+
initialized = RPC_Enabled = TRUE;
173+
Initialize_RPC();
174+
Update_RPC(fp, NULL, Status, TRUE);
175+
}
171176
break;
172177
case FILTER_CHECKBOX_STATUS_OFF:
173-
RPC_Enabled = FALSE;
174-
Dispose_RPC();
178+
if (RPC_Enabled) {
179+
RPC_Enabled = FALSE;
180+
Dispose_RPC();
181+
}
175182
break;
176183
}
184+
BOOL fn_now = fp->check[1] == FILTER_CHECKBOX_STATUS_ON;
185+
if (fn_now != RPC_Display_Filename || initialized) {
186+
RPC_Display_Filename = fn_now;
187+
PostMessage(fp->hwnd, WM_FILTER_CHANGE_PARAM_POST_EVENT, NULL, NULL);
188+
}
177189
return TRUE;
178190
}
179191

@@ -230,6 +242,9 @@ BOOL func_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void* e
230242
case WM_FILTER_SAVE_START:
231243
Update_RPC(filterPtr, editPtr, RPC_STATUS_SAVING, TRUE);
232244
break;
245+
case WM_FILTER_CHANGE_PARAM_POST_EVENT:
246+
Update_RPC(filterPtr, editPtr, Status, FALSE);
247+
break;
233248
}
234249
return FALSE;
235250
}
@@ -246,6 +261,7 @@ BOOL Initialize_RPC() {
246261
}
247262
if (IS_Disposed) {
248263
discord::Core::Create(FILTER_RPC_CLIENT_ID, DiscordCreateFlags_NoRequireDiscord, &core);
264+
RPC_Timestamp_Set = FALSE;
249265
IS_Disposed = FALSE;
250266
}
251267
return TRUE;
@@ -260,7 +276,7 @@ BOOL Update_RPC(FILTER* filterPtr, void* editPtr, int status, bool isStart) {
260276
}
261277
if (!IS_Disposed) {
262278
std::string detail = "";
263-
if (editPtr != NULL && filterPtr != NULL) {
279+
if (RPC_Display_Filename && editPtr != NULL && filterPtr != NULL) {
264280
FILE_INFO fi;
265281
SYS_INFO si;
266282
if (filterPtr->exfunc->get_sys_info(editPtr, &si) &&
@@ -307,13 +323,12 @@ BOOL Update_RPC(FILTER* filterPtr, void* editPtr, int status, bool isStart) {
307323
activity.SetState(StateStr.c_str());
308324
activity.GetAssets().SetLargeImage("aviutl_icon_large");
309325
activity.GetAssets().SetLargeText(SYS_INFO_STR == NULL ? "AviUtl" : SYS_INFO_STR);
310-
if (isStart) {
326+
if (isStart || !RPC_Timestamp_Set) {
311327
activity.GetTimestamps().SetStart(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count());
328+
RPC_Timestamp_Set = TRUE;
312329
}
313-
if (detail != "") {
314-
activity.SetDetails(detail.c_str());
315-
}
316-
330+
331+
activity.SetDetails(detail.c_str());
317332
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {
318333

319334
});
@@ -328,6 +343,8 @@ BOOL Dispose_RPC() {
328343
if (core != NULL) {
329344
core->ActivityManager().ClearActivity([](discord::Result result) {
330345
});
346+
core->~Core();
347+
core = NULL;
331348
}
332349
return TRUE;
333350
}

main.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ void mem_free(void);
88
BOOL func_init(FILTER*);
99
BOOL func_exit(FILTER*);
1010
BOOL func_update(FILTER*);
11-
BOOL func_project_save(void* fp, void* editp, void* data, int* size);
1211
BOOL func_modify_title(FILTER*);
1312
BOOL func_WndProc(HWND, UINT, WPARAM, LPARAM, void*, FILTER*);
1413
BOOL Initialize_RPC();
@@ -22,10 +21,16 @@ void __stdcall func_timer_tick(HWND, UINT, UINT_PTR, DWORD);
2221
#define FILTER_CHECKBOX_STATUS_ON 1
2322

2423
// ステータスを表すフラグ
24+
25+
// ステータスが「編集中」
2526
#define RPC_STATUS_EDITING 1
27+
// ステータスが「アイドル中」
2628
#define RPC_STATUS_IDLING 2
29+
// ステータスが「エンコード中」
2730
#define RPC_STATUS_SAVING 3
2831

2932
// タイマー間隔
3033
#define RPC_UPDATE_TICK 1000
34+
35+
#define WM_FILTER_CHANGE_PARAM_POST_EVENT (WM_USER+10011)
3136
#endif // !AVIUTL_DISCORD_RPC_MAIN

0 commit comments

Comments
 (0)