From 84c39ea299e57bafb3b867cabbff23807c493154 Mon Sep 17 00:00:00 2001 From: routersys Date: Wed, 9 Sep 2026 14:03:48 +0900 Subject: [PATCH] =?UTF-8?q?=E6=B1=8E=E7=94=A8=E3=83=97=E3=83=A9=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=AE=E9=9B=9B=E5=BD=A2=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyEdit.vcxproj | 5 +++ ProxyEdit.vcxproj.filters | 51 ++++++++++++++++++++++++++-- src/HostContext.cpp | 70 +++++++++++++++++++++++++++++++++++++++ src/HostContext.h | 36 ++++++++++++++++++++ src/Log.cpp | 65 ++++++++++++++++++++++++++++++++++++ src/Log.h | 13 ++++++++ src/Plugin.cpp | 36 ++++++++++++++++++++ 7 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 src/HostContext.cpp create mode 100644 src/HostContext.h create mode 100644 src/Log.cpp create mode 100644 src/Log.h create mode 100644 src/Plugin.cpp diff --git a/ProxyEdit.vcxproj b/ProxyEdit.vcxproj index 2d1b767..f70d8c1 100644 --- a/ProxyEdit.vcxproj +++ b/ProxyEdit.vcxproj @@ -92,9 +92,14 @@ + + + + + diff --git a/ProxyEdit.vcxproj.filters b/ProxyEdit.vcxproj.filters index 27ca470..b9ebbf9 100644 --- a/ProxyEdit.vcxproj.filters +++ b/ProxyEdit.vcxproj.filters @@ -6,12 +6,59 @@ cpp;c;cc;cxx - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx + {93995380-89BD-4B04-88EB-625FBE52EBFC} + h;hpp;hxx + + + {93995380-89BD-4B04-88EB-625FBE52EBFB} + h;hpp + + + {67DA6AB6-F800-4C08-8B7A-83BB121AAD01} + txt;ini;md + + ソース ファイル + + + ソース ファイル + + + ソース ファイル + + + ヘッダー ファイル + + + ヘッダー ファイル + + + SDK + + + SDK + + + SDK + + + SDK + + + SDK + + + SDK + + + SDK + + + SDK + diff --git a/src/HostContext.cpp b/src/HostContext.cpp new file mode 100644 index 0000000..68663bc --- /dev/null +++ b/src/HostContext.cpp @@ -0,0 +1,70 @@ +#include "HostContext.h" + +namespace pe { + +namespace { + +EDIT_HANDLE* g_edit = nullptr; +CONFIG_HANDLE* g_config = nullptr; +CACHE_HANDLE* g_cache = nullptr; +HWND g_host = nullptr; +HINSTANCE g_instance = nullptr; + +} + +void SetEditHandle(EDIT_HANDLE* handle) { g_edit = handle; } +void SetConfigHandle(CONFIG_HANDLE* handle) { g_config = handle; } +void SetCacheHandle(CACHE_HANDLE* handle) { g_cache = handle; } +void SetHostWindow(HWND window) { g_host = window; } +void SetModuleInstance(HINSTANCE instance) { g_instance = instance; } + +EDIT_HANDLE* Edit() { return g_edit; } +CONFIG_HANDLE* Config() { return g_config; } +CACHE_HANDLE* Cache() { return g_cache; } +HWND HostWindow() { return g_host; } +HINSTANCE ModuleInstance() { return g_instance; } + +EDIT_INFO EditInfo() { + EDIT_INFO info{}; + if (g_edit) g_edit->get_edit_info(&info, sizeof(info)); + return info; +} + +int EditState() { + if (!g_edit) return EDIT_HANDLE::EDIT_STATE_EDIT; + return g_edit->get_edit_state(); +} + +bool Exporting() { + return EditState() == EDIT_HANDLE::EDIT_STATE_SAVE; +} + +int LayoutSize(const char* key) { + if (!g_config) return 0; + return g_config->get_layout_size(g_config, key); +} + +COLORREF ThemeColor(const char* key, COLORREF fallback) { + if (!g_config) return fallback; + int code = g_config->get_color_code(g_config, key); + if (code < 0) return fallback; + return RGB((code >> 16) & 0xFF, (code >> 8) & 0xFF, code & 0xFF); +} + +const wchar_t* Translate(const wchar_t* text) { + if (!g_config) return text; + const wchar_t* translated = g_config->translate(g_config, text); + return translated ? translated : text; +} + +bool CallEditSection(void* param, void (*proc)(void* param, EDIT_SECTION* edit)) { + if (!g_edit) return false; + return g_edit->call_edit_section_param(param, proc); +} + +bool CallReadSection(void* param, void (*proc)(void* param, EDIT_SECTION* edit)) { + if (!g_edit) return false; + return g_edit->call_read_section_param(param, proc); +} + +} diff --git a/src/HostContext.h b/src/HostContext.h new file mode 100644 index 0000000..6caa4d5 --- /dev/null +++ b/src/HostContext.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include + +#include "plugin2.h" +#include "config2.h" +#include "cache2.h" + +namespace pe { + +void SetEditHandle(EDIT_HANDLE* handle); +void SetConfigHandle(CONFIG_HANDLE* handle); +void SetCacheHandle(CACHE_HANDLE* handle); +void SetHostWindow(HWND window); +void SetModuleInstance(HINSTANCE instance); + +EDIT_HANDLE* Edit(); +CONFIG_HANDLE* Config(); +CACHE_HANDLE* Cache(); +HWND HostWindow(); +HINSTANCE ModuleInstance(); + +EDIT_INFO EditInfo(); +int EditState(); +bool Exporting(); + +int LayoutSize(const char* key); +COLORREF ThemeColor(const char* key, COLORREF fallback); +const wchar_t* Translate(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/Log.cpp b/src/Log.cpp new file mode 100644 index 0000000..9b81891 --- /dev/null +++ b/src/Log.cpp @@ -0,0 +1,65 @@ +#include "Log.h" + +#include +#include + +namespace pe { + +namespace { + +LOG_HANDLE* g_log = nullptr; + +#ifdef PE_DEBUG_LOG +void WriteFileLog(const wchar_t* text) { + wchar_t path[MAX_PATH]; + if (GetTempPathW(MAX_PATH, path) == 0) return; + wcsncat_s(path, L"ProxyEdit.log", _TRUNCATE); + FILE* file = nullptr; + if (_wfopen_s(&file, path, L"a+, ccs=UTF-8") != 0 || !file) return; + SYSTEMTIME now; + GetLocalTime(&now); + fwprintf(file, L"%02d:%02d:%02d.%03d [%lu] %s\n", now.wHour, now.wMinute, now.wSecond, + now.wMilliseconds, GetCurrentThreadId(), text); + fclose(file); +} +#endif + +void Emit(const wchar_t* text, bool warning) { + if (g_log) { + if (warning) g_log->warn(g_log, text); + else g_log->log(g_log, text); + } +#ifdef PE_DEBUG_LOG + WriteFileLog(text); +#else + (void)text; +#endif +} + +void Format(const wchar_t* format, va_list args, bool warning) { + wchar_t buffer[1024]; + _vsnwprintf_s(buffer, _TRUNCATE, format, args); + Emit(buffer, warning); +} + +} + +void SetLogHandle(LOG_HANDLE* handle) { + g_log = handle; +} + +void Say(const wchar_t* format, ...) { + va_list args; + va_start(args, format); + Format(format, args, false); + va_end(args); +} + +void Warn(const wchar_t* format, ...) { + va_list args; + va_start(args, format); + Format(format, args, true); + va_end(args); +} + +} diff --git a/src/Log.h b/src/Log.h new file mode 100644 index 0000000..54fcf7f --- /dev/null +++ b/src/Log.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include "logger2.h" + +namespace pe { + +void SetLogHandle(LOG_HANDLE* handle); +void Say(const wchar_t* format, ...); +void Warn(const wchar_t* format, ...); + +} diff --git a/src/Plugin.cpp b/src/Plugin.cpp new file mode 100644 index 0000000..8caa9d3 --- /dev/null +++ b/src/Plugin.cpp @@ -0,0 +1,36 @@ +#include + +#include "HostContext.h" +#include "Log.h" + +using namespace pe; + +COMMON_PLUGIN_TABLE common_plugin_table = { + L"プロキシ編集", + L"プロキシ編集 version 1.0.0", +}; + +EXTERN_C __declspec(dllexport) COMMON_PLUGIN_TABLE* GetCommonPluginTable(void) { + return &common_plugin_table; +} +EXTERN_C __declspec(dllexport) DWORD RequiredVersion() { return 2010000; } +EXTERN_C __declspec(dllexport) void InitializeLogger(LOG_HANDLE* handle) { SetLogHandle(handle); } +EXTERN_C __declspec(dllexport) void InitializeConfig(CONFIG_HANDLE* handle) { SetConfigHandle(handle); } +EXTERN_C __declspec(dllexport) void InitializeCache(CACHE_HANDLE* handle) { SetCacheHandle(handle); } +EXTERN_C __declspec(dllexport) bool InitializePlugin(DWORD) { return true; } + +EXTERN_C __declspec(dllexport) void RegisterPlugin(HOST_APP_TABLE* host) { + SetEditHandle(host->create_edit_handle()); + SetHostWindow(Edit()->get_host_app_window()); +} + +EXTERN_C __declspec(dllexport) void UninitializePlugin() { +} + +BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID) { + if (reason == DLL_PROCESS_ATTACH) { + DisableThreadLibraryCalls(module); + SetModuleInstance((HINSTANCE)module); + } + return TRUE; +}