From 6b553ac03370aaa16d1b85c5f9f5c7b61b684ffb Mon Sep 17 00:00:00 2001 From: routersys Date: Wed, 9 Sep 2026 17:50:24 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=8A=9B=E3=81=AE=E5=89=8D=E3=81=AB?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=A9=E3=82=A4=E3=83=B3=E3=82=92?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=9D=90=E3=81=B8=E6=88=BB=E3=81=99=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyEdit.vcxproj | 4 +- ProxyEdit.vcxproj.filters | 6 ++ src/ExportGuard.cpp | 117 ++++++++++++++++++++++++++++++++++++++ src/ExportGuard.h | 12 ++++ src/HostContext.cpp | 6 ++ src/HostContext.h | 1 + src/Plugin.cpp | 3 + src/ScanController.cpp | 27 ++++++++- src/ScanController.h | 5 ++ 9 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 src/ExportGuard.cpp create mode 100644 src/ExportGuard.h diff --git a/ProxyEdit.vcxproj b/ProxyEdit.vcxproj index 0e751bb..1e5a7bc 100644 --- a/ProxyEdit.vcxproj +++ b/ProxyEdit.vcxproj @@ -67,7 +67,7 @@ Windows - user32.lib;gdi32.lib;ole32.lib;shell32.lib;shlwapi.lib;windowscodecs.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies) + user32.lib;comctl32.lib;gdi32.lib;ole32.lib;shell32.lib;shlwapi.lib;windowscodecs.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies) true @@ -94,6 +94,7 @@ + @@ -114,6 +115,7 @@ + diff --git a/ProxyEdit.vcxproj.filters b/ProxyEdit.vcxproj.filters index caea12b..a5862c8 100644 --- a/ProxyEdit.vcxproj.filters +++ b/ProxyEdit.vcxproj.filters @@ -25,6 +25,9 @@ ソース ファイル + + ソース ファイル + ソース ファイル @@ -78,6 +81,9 @@ ヘッダー ファイル + + ヘッダー ファイル + ヘッダー ファイル diff --git a/src/ExportGuard.cpp b/src/ExportGuard.cpp new file mode 100644 index 0000000..bf73842 --- /dev/null +++ b/src/ExportGuard.cpp @@ -0,0 +1,117 @@ +#include "ExportGuard.h" + +#include + +#include +#include + +#include "HostContext.h" +#include "Log.h" +#include "ScanController.h" + +namespace pe { + +namespace { + +const UINT_PTR kSubclassId = 0x50450003; + +HWND g_host = nullptr; +bool g_hooked = false; +std::set g_output_commands; +bool g_collected = false; +bool g_restored = false; +bool g_in_command = false; + +std::wstring WithoutMarker(const wchar_t* text) { + std::wstring result; + for (const wchar_t* cursor = text; cursor && *cursor; cursor++) { + if (*cursor != L'&') result.push_back(*cursor); + } + return result; +} + +void CollectLeaves(HMENU menu, std::set& into) { + const int count = GetMenuItemCount(menu); + for (int index = 0; index < count; index++) { + HMENU sub = GetSubMenu(menu, index); + if (sub) { + CollectLeaves(sub, into); + continue; + } + const int id = GetMenuItemID(menu, index); + if (id > 0) into.insert(id); + } +} + +bool FindOutputMenu(HMENU menu, const std::wstring& wanted, std::set& into) { + const int count = GetMenuItemCount(menu); + for (int index = 0; index < count; index++) { + HMENU sub = GetSubMenu(menu, index); + if (!sub) continue; + wchar_t label[256]{}; + GetMenuStringW(menu, index, label, 256, MF_BYPOSITION); + if (WithoutMarker(label) == wanted) { + CollectLeaves(sub, into); + return true; + } + if (FindOutputMenu(sub, wanted, into)) return true; + } + return false; +} + +void CollectOutputCommands() { + if (g_collected) return; + HMENU menu = GetMenu(g_host); + if (!menu) return; + g_collected = true; + const std::wstring wanted = WithoutMarker(LanguageText(L"Menu", L"ファイル出力(&U)")); + if (!FindOutputMenu(menu, wanted, g_output_commands)) { + FindOutputMenu(menu, WithoutMarker(L"ファイル出力(&U)"), g_output_commands); + } +} + +LRESULT CALLBACK GuardProc(HWND window, UINT message, WPARAM first, LPARAM second, UINT_PTR, + DWORD_PTR) { + if (message == WM_COMMAND && second == 0 && HIWORD(first) <= 1) { + CollectOutputCommands(); + if (g_output_commands.count((int)LOWORD(first)) > 0 && !g_in_command) { + g_in_command = true; + SuspendAutomaticScan(true); + g_restored = RestoreForExport() > 0; + LRESULT result = DefSubclassProc(window, message, first, second); + g_in_command = false; + NoticeEditActivity(); + return result; + } + } + return DefSubclassProc(window, message, first, second); +} + +} + +void StartExportGuard() { + if (g_hooked) return; + g_host = HostWindow(); + if (!g_host) return; + g_hooked = SetWindowSubclass(g_host, GuardProc, kSubclassId, 0) != FALSE; +} + +void StopExportGuard() { + if (!g_hooked) return; + RemoveWindowSubclass(g_host, GuardProc, kSubclassId); + g_hooked = false; + g_host = nullptr; +} + +void NoticeEditActivity() { + if (g_in_command) return; + if (!AutomaticScanSuspended()) return; + if (EditState() != EDIT_HANDLE::EDIT_STATE_EDIT) return; + SuspendAutomaticScan(false); + if (g_restored) { + g_restored = false; + ApplyAfterExport(); + } +} + +} diff --git a/src/ExportGuard.h b/src/ExportGuard.h new file mode 100644 index 0000000..0ba830c --- /dev/null +++ b/src/ExportGuard.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace pe { + +void StartExportGuard(); +void StopExportGuard(); + +void NoticeEditActivity(); + +} diff --git a/src/HostContext.cpp b/src/HostContext.cpp index 7c11a92..0acca33 100644 --- a/src/HostContext.cpp +++ b/src/HostContext.cpp @@ -56,6 +56,12 @@ FONT_INFO* HostFont(const char* key) { return g_config->get_font_info(g_config, key); } +const wchar_t* LanguageText(const wchar_t* section, const wchar_t* text) { + if (!g_config || !g_config->get_language_text) return text; + const wchar_t* found = g_config->get_language_text(g_config, section, text); + return found ? found : text; +} + const wchar_t* Translate(const wchar_t* text) { if (!g_config) return text; const wchar_t* translated = g_config->translate(g_config, text); diff --git a/src/HostContext.h b/src/HostContext.h index de799fc..57f065a 100644 --- a/src/HostContext.h +++ b/src/HostContext.h @@ -30,6 +30,7 @@ int LayoutSize(const char* key); COLORREF ThemeColor(const char* key, COLORREF fallback); FONT_INFO* HostFont(const char* key); const wchar_t* Translate(const wchar_t* text); +const wchar_t* LanguageText(const wchar_t* section, const wchar_t* text); bool CallEditSection(void* param, void (*proc)(void* param, EDIT_SECTION* edit)); bool CallReadSection(void* param, void (*proc)(void* param, EDIT_SECTION* edit)); diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f5c3d9f..fc539dc 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -3,6 +3,7 @@ #include "HostContext.h" #include "Log.h" #include "MediaDecoder.h" +#include "ExportGuard.h" #include "Notifier.h" #include "ProxyBuilder.h" #include "ProxyInput.h" @@ -39,9 +40,11 @@ EXTERN_C __declspec(dllexport) void RegisterPlugin(HOST_APP_TABLE* host) { StartScanController(); StartBuilder(); StartNotifier(); + StartExportGuard(); } EXTERN_C __declspec(dllexport) void UninitializePlugin() { + StopExportGuard(); StopNotifier(); DestroyStatusPanel(); StopScanController(); diff --git a/src/ScanController.cpp b/src/ScanController.cpp index abd294b..580814e 100644 --- a/src/ScanController.cpp +++ b/src/ScanController.cpp @@ -11,6 +11,7 @@ #include "HostContext.h" #include "Log.h" +#include "ExportGuard.h" #include "Notify.h" #include "ProxyBuilder.h" #include "ProxyFormat.h" @@ -27,6 +28,7 @@ namespace { const wchar_t* kEffect = L"動画ファイル"; const wchar_t* kItem = L"ファイル"; std::atomic g_scanning{false}; +std::atomic g_suspended{false}; std::atomic g_pending{0}; std::atomic g_stop{false}; std::thread g_worker; @@ -161,7 +163,8 @@ void ScanWorker() { ScanResult result = ApplyProxies(); Say(L"プロキシへ差し替えました: 対象 %d 件、差し替え %d 件", result.eligible, result.swapped); PublishStateChange(); - } else if ((taken & kRequestAutomatic) && CurrentSettings().enabled) { + } else if ((taken & kRequestAutomatic) && CurrentSettings().enabled && + !g_suspended.load()) { ScanResult result = ApplyProxies(); if (result.swapped > 0) { Say(L"自動でプロキシへ差し替えました: %d 件", result.swapped); @@ -172,6 +175,7 @@ void ScanWorker() { } void OnHostEvent(void*) { + NoticeEditActivity(); Post(kRequestAutomatic); } @@ -297,6 +301,27 @@ void RequestApply() { Post(kRequestApply); } +int RestoreForExport() { + ScanResult result = RestoreOriginals(); + if (result.restored > 0) Say(L"出力のため元素材へ戻しました: %d 件", result.restored); + PublishStateChange(); + return result.restored; +} + +void ApplyAfterExport() { + ScanResult result = ApplyProxies(); + if (result.swapped > 0) Say(L"出力が終わったのでプロキシへ戻しました: %d 件", result.swapped); + PublishStateChange(); +} + +void SuspendAutomaticScan(bool suspend) { + g_suspended.store(suspend); +} + +bool AutomaticScanSuspended() { + return g_suspended.load(); +} + void RequestRestore() { Post(kRequestRestore); } diff --git a/src/ScanController.h b/src/ScanController.h index bae4119..ba44310 100644 --- a/src/ScanController.h +++ b/src/ScanController.h @@ -20,6 +20,11 @@ struct ScanResult { void RegisterScanMenus(HOST_APP_TABLE* host); void RequestApply(); void RequestRestore(); + +int RestoreForExport(); +void ApplyAfterExport(); +void SuspendAutomaticScan(bool suspend); +bool AutomaticScanSuspended(); bool IsProxyPath(const std::wstring& path); std::wstring SourceOfProxy(const std::wstring& path); void StartScanController();