-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathRegist.c
263 lines (234 loc) · 4.73 KB
/
Regist.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
/*
* CLCL
*
* Regist.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 "File.h"
#include "Regist.h"
#include "ClipBoard.h"
#include "Format.h"
/* Define */
/* Global Variables */
// オプション
extern OPTION_INFO option;
/* Local Function Prototypes */
/*
* regist_path_to_item - パスから登録アイテムを取得
*/
DATA_INFO *regist_path_to_item(DATA_INFO *di, TCHAR *path)
{
TCHAR buf[BUF_SIZE];
TCHAR *p, *r;
if (path == NULL || path == TEXT('\0')) {
return di;
}
if (di == NULL) {
return NULL;
}
p = path;
if (*p == TEXT('\\') || *p == TEXT('/')) {
p++;
}
if (*p == TEXT('\0')) {
return di;
}
// パスを展開
for (r = buf; *p != TEXT('\0'); p++, r++) {
#ifndef UNICODE
if (IsDBCSLeadByte((BYTE)*p) == TRUE) {
*(r++) = *(p++);
*r = *p;
continue;
}
#endif
if (*p == TEXT('\\') || *p == TEXT('/')) {
break;
}
*r = *p;
}
*r = TEXT('\0');
// 名前からアイテムを取得
for (; di != NULL; di = di->next) {
if (di->type == TYPE_FOLDER && di->title != NULL &&
lstrcmpi(di->title, buf) == 0) {
break;
}
}
if (di == NULL) {
return NULL;
}
if (*p != TEXT('\0')) {
// 再帰
return regist_path_to_item(di->child, p);
}
return di->child;
}
/*
* regist_create_folder - 登録アイテムにフォルダを追加
*/
DATA_INFO *regist_create_folder(DATA_INFO **root, const TCHAR *title, TCHAR *err_str)
{
DATA_INFO *new_item;
DATA_INFO *di;
// 同名のフォルダはエラーとする
for (di = *root; di != NULL; di = di->next) {
if (di->type == TYPE_FOLDER && lstrcmpi(di->title, title) == 0) {
return NULL;
}
}
// フォルダの作成
if ((new_item = data_create_folder(title, err_str)) == NULL) {
return NULL;
}
// フォルダの追加
if (*root == NULL) {
new_item->next = *root;
*root = new_item;
} else {
for (di = *root; di->next != NULL; di = di->next)
;
di->next = new_item;
}
return new_item;
}
/*
* regist_merge_item - 登録アイテムのマージ
*/
DATA_INFO *regist_merge_item(DATA_INFO **root, const DATA_INFO *from_di, const BOOL move_flag, TCHAR *err_str)
{
DATA_INFO *di, *wk_di;
switch (from_di->type) {
case TYPE_DATA:
case TYPE_ITEM:
if ((wk_di = data_item_copy(from_di, FALSE, move_flag, err_str)) == NULL) {
return NULL;
}
// ウィンドウ名の除去
mem_free(&wk_di->window_name);
if (*root == NULL) {
*root = wk_di;
di = *root;
} else {
for (di = *root; di->next != NULL; di = di->next)
;
di->next = wk_di;
di = di->next;
}
break;
case TYPE_FOLDER:
// フォルダの検索
for (wk_di = *root; wk_di != NULL; wk_di = wk_di->next) {
if (wk_di->type == TYPE_FOLDER && lstrcmpi(wk_di->title, from_di->title) == 0) {
break;
}
}
if (wk_di == NULL) {
// フォルダの追加
if ((wk_di = regist_create_folder(root, from_di->title, err_str)) == NULL) {
return NULL;
}
}
// アイテムをコピー
for (di = from_di->child; di != NULL; di = di->next) {
if (regist_merge_item(&wk_di->child, di, move_flag, err_str) == NULL) {
break;
}
}
di = wk_di;
break;
}
return di;
}
/*
* regist_regist_hotkey - ホットキーの登録
*/
BOOL regist_regist_hotkey(const HWND hWnd, DATA_INFO *di, int *id)
{
DATA_INFO *cdi = di;
BOOL ret = TRUE;
for (; cdi != NULL; cdi = cdi->next) {
switch (cdi->type) {
case TYPE_FOLDER:
if (regist_regist_hotkey(hWnd, cdi->child, id) == FALSE) {
ret = FALSE;
}
break;
case TYPE_ITEM:
if (cdi->op_virtkey != 0) {
if (RegisterHotKey(hWnd, *id,
cdi->op_modifiers, cdi->op_virtkey) == FALSE) {
ret = FALSE;
} else {
cdi->hkey_id = *id;
(*id)++;
}
}
break;
case TYPE_DATA:
break;
}
}
return ret;
}
/*
* regist_unregist_hotkey - ホットキーの解除
*/
void regist_unregist_hotkey(const HWND hWnd, DATA_INFO *di)
{
DATA_INFO *cdi = di;
for (; cdi != NULL; cdi = cdi->next) {
switch (cdi->type) {
case TYPE_FOLDER:
regist_unregist_hotkey(hWnd, cdi->child);
break;
case TYPE_ITEM:
if (cdi->hkey_id != 0) {
UnregisterHotKey(hWnd, cdi->hkey_id);
cdi->hkey_id = 0;
}
break;
case TYPE_DATA:
break;
}
}
}
/*
* regist_hotkey_to_item - ホットキーIDからアイテムを検索
*/
DATA_INFO *regist_hotkey_to_item(DATA_INFO *di, const int id)
{
DATA_INFO *cdi = di;
DATA_INFO *ret;
for (; cdi != NULL; cdi = cdi->next) {
switch (cdi->type) {
case TYPE_FOLDER:
if ((ret = regist_hotkey_to_item(cdi->child, id)) != NULL) {
return ret;
}
break;
case TYPE_ITEM:
if (cdi->hkey_id == id) {
return cdi;
}
break;
case TYPE_DATA:
break;
}
}
return NULL;
}
/* End of source */