-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathData.c
373 lines (337 loc) · 8.2 KB
/
Data.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
364
365
366
367
368
369
370
371
372
373
/*
* CLCL
*
* Data.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 "ClipBoard.h"
#include "Format.h"
/* Define */
/* Global Variables */
// オプション
extern OPTION_INFO option;
/* Local Function Prototypes */
/*
* data_create_data - データの作成
*/
DATA_INFO *data_create_data(const UINT format, TCHAR *format_name, const HANDLE data, const DWORD size, const BOOL init, TCHAR *err_str)
{
DATA_INFO *new_item;
// アイテムの確保
if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
message_get_error(GetLastError(), err_str);
return NULL;
}
new_item->struct_size = sizeof(DATA_INFO);
new_item->type = TYPE_DATA;
new_item->format = (format != 0) ? format : clipboard_get_format(0, format_name);
new_item->format_name = alloc_copy(format_name);
new_item->format_name_hash = str2hash(new_item->format_name);
new_item->data = data;
new_item->size = size;
format_initialize_item(new_item, (data == NULL) ? init : FALSE);
return new_item;
}
/*
* data_create_item - アイテムの作成
*/
DATA_INFO *data_create_item(const TCHAR *title, const BOOL set_date, TCHAR *err_str)
{
DATA_INFO *new_item;
// アイテムの確保
if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
message_get_error(GetLastError(), err_str);
return NULL;
}
new_item->struct_size = sizeof(DATA_INFO);
new_item->type = TYPE_ITEM;
new_item->title = alloc_copy(title);
if (set_date == TRUE) {
data_set_modified(new_item);
}
return new_item;
}
/*
* data_create_folder - フォルダの作成
*/
DATA_INFO *data_create_folder(const TCHAR *title, TCHAR *err_str)
{
DATA_INFO *new_item;
// アイテムの確保
if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
message_get_error(GetLastError(), err_str);
return NULL;
}
new_item->struct_size = sizeof(DATA_INFO);
new_item->title = alloc_copy(title);
new_item->type = TYPE_FOLDER;
return new_item;
}
/*
* data_item_copy - アイテムのコピーを作成
*/
DATA_INFO *data_item_copy(const DATA_INFO *di, const BOOL next_copy, const BOOL move_flag, TCHAR *err_str)
{
DATA_INFO *new_di;
if (di == NULL) {
return NULL;
}
if ((new_di = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
message_get_error(GetLastError(), err_str);
return NULL;
}
new_di->struct_size = sizeof(DATA_INFO);
new_di->type = di->type;
new_di->title = alloc_copy(di->title);
new_di->format_name = alloc_copy(di->format_name);
new_di->format_name_hash = di->format_name_hash;
new_di->format = di->format;
new_di->modified.dwLowDateTime = di->modified.dwLowDateTime;
new_di->modified.dwHighDateTime = di->modified.dwHighDateTime;
new_di->window_name = alloc_copy(di->window_name);
new_di->plugin_string = alloc_copy(di->plugin_string);
new_di->plugin_param = di->plugin_param;
if (move_flag == TRUE) {
new_di->hkey_id = di->hkey_id;
new_di->op_modifiers = di->op_modifiers;
new_di->op_virtkey = di->op_virtkey;
new_di->op_paste = di->op_paste;
}
// データのコピー
if (di->data != NULL && (new_di->data = format_copy_data(di->format_name, di->data, &new_di->size)) == NULL) {
new_di->data = clipboard_copy_data(di->format, di->data, &new_di->size);
}
// 子アイテムのコピー
if (di->child != NULL && (new_di->child = data_item_copy(di->child, TRUE, move_flag, err_str)) == NULL) {
data_free(new_di);
return NULL;
}
// 次アイテムのコピー
if (next_copy == TRUE && di->next != NULL &&
(new_di->next = data_item_copy(di->next, TRUE, move_flag, err_str)) == NULL) {
data_free(new_di);
return NULL;
}
return new_di;
}
/*
* data_delete - アイテムの削除
*/
BOOL data_delete(DATA_INFO **root, DATA_INFO *del_di, const BOOL free_item)
{
DATA_INFO *di;
if (root == NULL || *root == NULL || del_di == NULL) {
return FALSE;
}
if (*root == del_di) {
*root = del_di->next;
del_di->next = NULL;
if (free_item == TRUE) {
data_free(del_di);
}
return TRUE;
}
for (di = *root; di != NULL; di = di->next) {
if (di->next == del_di) {
// 削除
di->next = del_di->next;
del_di->next = NULL;
if (free_item == TRUE) {
data_free(del_di);
}
return TRUE;
}
if (di->child != NULL && data_delete(&di->child, del_di, free_item) == TRUE) {
return TRUE;
}
}
return FALSE;
}
/*
* data_adjust - アイテムの整理
*/
void data_adjust(DATA_INFO **root)
{
DATA_INFO *di = *root;
DATA_INFO *wk_di;
while (di != NULL) {
if (di->type == TYPE_ITEM && di->child == NULL) {
wk_di = di->next;
// 削除
data_delete(root, di, TRUE);
di = wk_di;
} else {
if (di->type == TYPE_FOLDER) {
data_adjust(&di->child);
}
di = di->next;
}
}
}
/*
* data_menu_free - アイテムに関連付けられたメニュー情報を解放
*/
void data_menu_free_item(DATA_INFO *di)
{
// テキストの解放
if (di->free_title == TRUE) {
mem_free(&di->menu_title);
}
di->menu_title = NULL;
di->free_title = FALSE;
// アイコンの解放
if (di->free_icon == TRUE && di->menu_icon != NULL) {
DestroyIcon(di->menu_icon);
}
di->menu_icon = NULL;
di->free_icon = FALSE;
// ビットマップの解放
if (di->free_bitmap == TRUE && di->menu_bitmap != NULL) {
DeleteObject((HGDIOBJ)di->menu_bitmap);
}
di->menu_bitmap = NULL;
di->free_bitmap = FALSE;
di->menu_bmp_width = 0;
di->menu_bmp_height = 0;
}
void data_menu_free(DATA_INFO *di)
{
for (; di != NULL; di = di->next) {
data_menu_free_item(di);
if (di->child != NULL) {
data_menu_free(di->child);
}
}
}
/*
* data_free - アイテムの解放
*/
void data_free(DATA_INFO *di)
{
DATA_INFO *wk_di;
while (di != NULL) {
wk_di = di->next;
if (di->child != NULL) {
data_free(di->child);
}
format_free_item(di);
if (di->data != NULL && format_free_data(di->format_name, di->data) == FALSE) {
clipboard_free_data(di->format_name, di->data);
}
data_menu_free_item(di);
mem_free(&di->title);
mem_free(&di->format_name);
mem_free(&di->window_name);
mem_free(&di->plugin_string);
mem_free(&di);
di = wk_di;
}
}
/*
* data_check - アイテムの存在チェック
*/
DATA_INFO *data_check(DATA_INFO *di, const DATA_INFO *check_di)
{
DATA_INFO *cdi;
DATA_INFO *ret_di;
if (di == NULL || di->child == NULL) {
return NULL;
}
for (cdi = di->child; cdi != NULL; cdi = cdi->next) {
if (cdi == check_di) {
return di;
}
if ((ret_di = data_check(cdi, check_di)) != NULL) {
return ret_di;
}
}
return NULL;
}
/*
* data_set_modified - 更新日時を設定
*/
void data_set_modified(DATA_INFO *di)
{
SYSTEMTIME sys_time;
if (di->type != TYPE_ITEM) {
ZeroMemory(&di->modified, sizeof(FILETIME));
return;
}
GetLocalTime(&sys_time);
SystemTimeToFileTime(&sys_time, &di->modified);
}
/*
* data_get_modified_string - 更新日時文字列を取得
*/
BOOL data_get_modified_string(const DATA_INFO *di, TCHAR *ret)
{
SYSTEMTIME sys_time;
TCHAR str_day[BUF_SIZE], str_time[BUF_SIZE];
TCHAR *p;
if (di->type != TYPE_ITEM ||
(di->modified.dwLowDateTime == 0 && di->modified.dwHighDateTime == 0)) {
*ret = TEXT('\0');
return FALSE;
}
// ファイルタイムをシステムタイムに変換
if (FileTimeToSystemTime(&di->modified, &sys_time) == FALSE) {
*ret = TEXT('\0');
return FALSE;
}
// 日付文字列の取得
p = option.data_date_format;
if (p == NULL || *p == TEXT('\0')) {
p = NULL;
}
GetDateFormat(0, 0, &sys_time, p, str_day, BUF_SIZE - 1);
// 時間文字列の取得
p = option.data_time_format;
if (p == NULL || *p == TEXT('\0')) {
p = NULL;
}
GetTimeFormat(0, 0, &sys_time, p, str_time, BUF_SIZE - 1);
wsprintf(ret, TEXT("%s %s"), str_day, str_time);
return TRUE;
}
/*
* data_get_title - アイテムのタイトルを取得
*/
TCHAR *data_get_title(DATA_INFO *di)
{
DATA_INFO *wk_di;
static TCHAR buf[BUF_SIZE];
TCHAR *p;
TCHAR *ret;
wk_di = format_get_priority_highest(di);
format_get_menu_title(wk_di);
if (di->title != NULL) {
ret = di->title;
} else if (wk_di->menu_title != NULL) {
ret = wk_di->menu_title;
} else if (wk_di->format_name != NULL) {
p = buf;
*(p++) = TEXT('(');
lstrcpyn(p, wk_di->format_name, BUF_SIZE - 3);
p += lstrlen(p);
*(p++) = TEXT(')');
*(p++) = TEXT('\0');
ret = buf;
} else {
ret = TEXT("");
}
return ret;
}
/* End of source */