-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathTool.c
363 lines (324 loc) · 8.32 KB
/
Tool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
* CLCL
*
* Tool.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include "General.h"
#include "Memory.h"
#include "String.h"
#include "Data.h"
#include "Ini.h"
#include "Message.h"
#include "Format.h"
#include "Tool.h"
/* Define */
/* Global Variables */
extern DATA_INFO history_data;
extern DATA_INFO regist_data;
// オプション
// option
extern OPTION_INFO option;
// 旧ツールのデータ情報
// Data information of old tool
typedef struct _CLIPINFO {
unsigned int Type;
TCHAR name[BUF_SIZE];
HANDLE Mem;
long Size;
long lParam;
int Flag;
} CLIPINFO;
/* Local Function Prototypes */
static void tool_data_reflect(const int call_type, TOOL_DATA_INFO *tdi);
static int tool_call_func_old(const HWND hWnd, const TOOL_INFO *ti, const int call_type, TOOL_DATA_INFO *tdi);
/*
* tool_title_to_index - タイトルからインデックスを取得
* Get index from title
*/
int tool_title_to_index(const TCHAR *title)
{
int i;
for (i = 0; i < option.tool_cnt; i++) {
if (!((option.tool_info + i)->call_type & CALLTYPE_MENU)) {
continue;
}
if (lstrcmp((option.tool_info + i)->title, title) == 0) {
return i;
}
}
return -1;
}
/*
* tool_initialize - ツール情報の初期化
* Initialize tool information
*/
BOOL tool_initialize(TCHAR *err_str)
{
HANDLE lib;
TCHAR buf[BUF_SIZE];
char cbuf[BUF_SIZE];
int i;
for (i = 0; i < option.tool_cnt; i++) {
if ((option.tool_info + i)->lib_file_path == NULL ||
*(option.tool_info + i)->lib_file_path == TEXT('\0')) {
continue;
}
// モジュールハンドル取得
// Get module handle
lib = (option.tool_info + i)->lib = LoadLibrary((option.tool_info + i)->lib_file_path);
if (lib == NULL) {
message_get_error(GetLastError(), buf);
wsprintf(err_str, TEXT("%s\r\n%s"), buf, (option.tool_info + i)->lib_file_path);
return FALSE;
}
// 形式毎の関数アドレス取得
// Get function address for each format
tchar_to_char((option.tool_info + i)->func_name, cbuf, BUF_SIZE - 1);
if ((option.tool_info + i)->old == 0 || (option.tool_info + i)->old == 2) {
(option.tool_info + i)->func = GetProcAddress(lib, cbuf);
} else {
(option.tool_info + i)->old_func = (OLD_TOOL_FUNC)GetProcAddress(lib, cbuf);
}
if ((option.tool_info + i)->func == NULL && (option.tool_info + i)->old_func == NULL) {
message_get_error(GetLastError(), buf);
wsprintf(err_str, TEXT("%s\r\n%s\r\n%s"), buf,
(option.tool_info + i)->lib_file_path, (option.tool_info + i)->func_name);
return FALSE;
}
}
return TRUE;
}
/*
* tool_data_copy - ツール用アイテムのコピーを作成
* Make a copy of the tool item
*/
TOOL_DATA_INFO *tool_data_copy(DATA_INFO *di, const BOOL next_copy)
{
TOOL_DATA_INFO *tdi;
if (di == NULL) {
return NULL;
}
if ((tdi = (TOOL_DATA_INFO *)mem_calloc(sizeof(TOOL_DATA_INFO))) == NULL) {
return NULL;
}
tdi->struct_size = sizeof(TOOL_DATA_INFO);
tdi->di = di;
if (di->child != NULL) {
tdi->child = tool_data_copy(di->child, TRUE);
}
if (next_copy == TRUE && di->next != NULL) {
tdi->next = tool_data_copy(di->next, TRUE);
}
return tdi;
}
/*
* tool_data_free - ツール用アイテムの解放
* Release tool items
*/
void tool_data_free(TOOL_DATA_INFO *tdi)
{
TOOL_DATA_INFO *wk_tdi;
while (tdi != NULL) {
wk_tdi = tdi->next;
if (tdi->child != NULL) {
tool_data_free(tdi->child);
}
mem_free(&tdi);
tdi = wk_tdi;
}
}
/*
* tool_data_reflect - ツール用アイテムを実体に反映
* Reflect tool items in the entity
*/
static void tool_data_reflect(const int call_type, TOOL_DATA_INFO *tdi)
{
DATA_INFO *di;
for (; tdi != NULL; tdi = tdi->next) {
di = tdi->di;
if (((call_type & CALLTYPE_MENU) || (call_type & CALLTYPE_VIEWER)) &&
(((call_type & CALLTYPE_HISTORY) && data_check(&history_data, di) == NULL) ||
((call_type & CALLTYPE_REGIST) && data_check(®ist_data, di) == NULL))) {
// リスト中にデータが見つからない
// No data found in the list
continue;
}
data_menu_free_item(di);
if (tdi->child != NULL) {
tool_data_reflect(call_type, tdi->child);
}
}
}
/*
* tool_call_func_old - 旧ツールの呼び出し
* Calling old tools
*/
static int tool_call_func_old(const HWND hWnd, const TOOL_INFO *ti, const int call_type, TOOL_DATA_INFO *tdi)
{
DATA_INFO *cdi;
TOOL_DATA_INFO *wk_tdi;
CLIPINFO ci;
int old_call_type;
int i;
int ret = TOOL_SUCCEED;
if (ti->old_func == NULL) {
return TOOL_ERROR;
}
if (call_type & CALLTYPE_MENU) {
if (tdi == NULL) {
return TOOL_SUCCEED;
}
old_call_type = OLD_CALLTYPE_MENU | OLD_CALLTYPE_ITEM_TO_CLIPBOARD;
} else if (call_type & CALLTYPE_VIEWER) {
if (tdi == NULL) {
return TOOL_SUCCEED;
}
old_call_type = OLD_CALLTYPE_VIEWER;
} else if (call_type & CALLTYPE_ADD_HISTORY) {
if (tdi == NULL) {
return TOOL_SUCCEED;
}
old_call_type = OLD_CALLTYPE_ADD_HISTORY;
} else if (call_type & CALLTYPE_ITEM_TO_CLIPBOARD) {
if (tdi == NULL) {
return TOOL_SUCCEED;
}
old_call_type = OLD_CALLTYPE_ITEM_TO_CLIPBOARD;
} else if (call_type & CALLTYPE_START) {
old_call_type = OLD_CALLTYPE_START | OLD_CALLTYPE_NOITEM;
} else if (call_type & CALLTYPE_END) {
old_call_type = OLD_CALLTYPE_END | OLD_CALLTYPE_NOITEM;
} else {
return TOOL_SUCCEED;
}
if (tdi == NULL) {
ti->func(hWnd, NULL, old_call_type, 0);
} else {
i = 0;
for (; tdi != NULL; tdi = tdi->next) {
if (tdi->di->type == TYPE_FOLDER || tdi->di->type == TYPE_ROOT) {
continue;
}
wk_tdi = tdi;
if (wk_tdi->di->type == TYPE_ITEM) {
cdi = format_get_priority_highest(wk_tdi->di);
for (wk_tdi = wk_tdi->child; wk_tdi != NULL && wk_tdi->di != cdi; wk_tdi = wk_tdi->next)
;
if (wk_tdi == NULL) {
continue;
}
}
ZeroMemory(&ci, sizeof(CLIPINFO));
ci.Type = wk_tdi->di->format;
lstrcpy(ci.name, wk_tdi->di->format_name);
ci.Mem = wk_tdi->di->data;
ci.Size = wk_tdi->di->size;
ci.Flag = wk_tdi->di->plugin_param;
if (ti->old_func(hWnd, (void *)&ci, old_call_type, i++) >= 0) {
wk_tdi->di->data = ci.Mem;
wk_tdi->di->size = ci.Size;
wk_tdi->di->plugin_param = ci.Flag;
ret |= TOOL_DATA_MODIFIED;
}
}
}
return ret;
}
/*
* tool_execute - ツールの呼び出し
* Calling a tool
*/
int tool_execute(const HWND hWnd, TOOL_INFO *ti, const int call_type, DATA_INFO *di, TOOL_DATA_INFO *tdi)
{
TOOL_DATA_INFO *wk_tdi = tdi;
TOOL_EXEC_INFO *tei;
int ctype = call_type;
int ret = TOOL_ERROR;
if (ti == NULL) {
return TOOL_ERROR;
}
// ツール用アイテムの設定
// Tool item settings
if (tdi == NULL) {
wk_tdi = tool_data_copy(di, FALSE);
}
// フラグの設定
// Flag setting
if (wk_tdi != NULL && ((ctype & CALLTYPE_MENU) || (ctype & CALLTYPE_VIEWER))) {
if (data_check(&history_data, wk_tdi->di) != NULL) {
ctype |= CALLTYPE_HISTORY;
} else if (data_check(®ist_data, wk_tdi->di) != NULL) {
ctype |= CALLTYPE_REGIST;
}
}
// 実行情報の設定
// Execution information setting
if ((tei = mem_calloc(sizeof(TOOL_EXEC_INFO))) == NULL) {
if (tdi == NULL) {
tool_data_free(wk_tdi);
}
return TOOL_ERROR;
}
tei->struct_size = sizeof(TOOL_EXEC_INFO);
tei->call_type = ctype;
if (ti->old == 2) {
tei->cmd_line = (TCHAR *)alloc_tchar_to_char(ti->cmd_line);
} else {
tei->cmd_line = alloc_copy(ti->cmd_line);
}
mem_free(&ti->cmd_line);
tei->lParam = ti->lParam;
if (ti->old == 0 || ti->old == 2) {
if (ti->func != NULL) {
// ツールの呼び出し
// Calling a tool
ret = ti->func(hWnd, tei, wk_tdi);
}
} else {
// 旧ツールの呼び出し
// Calling old tools
ret = tool_call_func_old(hWnd, ti, ctype, wk_tdi);
}
if (ti->old == 2) {
ti->cmd_line = alloc_char_to_tchar((char *)tei->cmd_line);
} else {
ti->cmd_line = alloc_copy(tei->cmd_line);
}
mem_free(&tei->cmd_line);
ti->lParam = tei->lParam;
mem_free(&tei);
if (ret & TOOL_DATA_MODIFIED) {
tool_data_reflect(ctype, wk_tdi);
}
if (tdi == NULL) {
tool_data_free(wk_tdi);
}
return ret;
}
/*
* tool_execute_all - 呼び出し方法にマッチするツールの実行
* Executing a tool that matches the calling method
*/
int tool_execute_all(const HWND hWnd, const int call_type, DATA_INFO *di)
{
int ret = TOOL_ERROR;
int i;
for (i = 0; i < option.tool_cnt; i++) {
if ((option.tool_info + i)->call_type & call_type) {
ret |= tool_execute(hWnd, option.tool_info + i, call_type, di, NULL);
if (ret & TOOL_CANCEL) {
return ret;
}
}
}
return ret;
}
/* End of source */