-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.c
466 lines (344 loc) · 12.8 KB
/
file.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/**************************************************************************
WWWC (wwwc.dll)
file.c
Copyright (C) 1996-2003 by Nakashima Tomoaki. All rights reserved.
http://www.nakka.com/
nakka@nakka.com
**************************************************************************/
/**************************************************************************
Include Files
**************************************************************************/
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include "String.h"
#include "http.h"
#include "StrTbl.h"
#include "wwwcdll.h"
#include "resource.h"
/**************************************************************************
Define
**************************************************************************/
#define BUFSIZE 256
// #define BUFSIZE 2048
#define NOCMP_SIZE 1
#define NOCMP_DATE 2
/**************************************************************************
Global Variables
**************************************************************************/
extern HINSTANCE ghinst;
extern char DateFormat[];
extern char TimeFormat[];
int LresultCmp(char *Oldbuf, char *Newbuf);
int ExecItem(HWND hWnd, char *buf, char *cmdline);
/******************************************************************************
FILE_InitItem
アイテムの初期化
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_InitItem(HWND hWnd, struct TPITEM *tpItemInfo)
{
/* 更新マーク(*)を除去する */
if(tpItemInfo->Size != NULL && tpItemInfo->Size[0] != '\0' && tpItemInfo->Size[lstrlen(tpItemInfo->Size) - 1] == '*'){
tpItemInfo->Size[lstrlen(tpItemInfo->Size) - 1] = '\0';
}
if(tpItemInfo->Date != NULL && tpItemInfo->Date[0] != '\0' && tpItemInfo->Date[lstrlen(tpItemInfo->Date) - 1] == '*'){
tpItemInfo->Date[lstrlen(tpItemInfo->Date) - 1] = '\0';
}
return 0;
}
/******************************************************************************
FILE_Initialize
チェック開始の初期化
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_Initialize(HWND hWnd, struct TPITEM *tpItemInfo)
{
return 0;
}
/******************************************************************************
FILE_Cancel
チェックのキャンセル
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_Cancel(HWND hWnd, struct TPITEM *tpItemInfo)
{
return 0;
}
/******************************************************************************
FILE_Timer
タイマー (1秒間隔)
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_Timer(HWND hWnd, struct TPITEM *tpItemInfo)
{
return CHECK_SUCCEED;
}
/******************************************************************************
FILE_Start
チェックの開始
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_Start(HWND hWnd, struct TPITEM *tpItemInfo)
{
WIN32_FIND_DATA FindData;
HANDLE hFindFile;
int CmpMsg = ST_DEFAULT;
char buf[BUFSIZE];
char *FileName;
FILETIME lFileTime;
SYSTEMTIME fSysTime;
char *p;
char fDay[BUFSIZE];
char fTime[BUFSIZE];
for(FileName = tpItemInfo->CheckURL + lstrlen("file:"); *FileName == '/' && *FileName != '\0'; FileName++);
if((hFindFile = FindFirstFile(FileName, &FindData)) != INVALID_HANDLE_VALUE){
FindClose(hFindFile);
//サイズの比較
wsprintf(buf, "%ld", (long)FindData.nFileSizeLow);
/* 前回チェック時のものと比較する */
if(GetOptionInt(tpItemInfo->Option1, 1) == 0 && LresultCmp(tpItemInfo->Size, buf) != 0){
CmpMsg = ST_UP;
}
/* アイテムに今回のチェック内容をセットする */
if(tpItemInfo->Size != NULL){
GlobalFree(tpItemInfo->Size);
}
tpItemInfo->Size = (char *)GlobalAlloc(GPTR, sizeof(char) * lstrlen(buf) + 1);
lstrcpy(tpItemInfo->Size, buf);
//更新日の比較
FileTimeToLocalFileTime(&(FindData.ftLastWriteTime), &lFileTime);
FileTimeToSystemTime(&lFileTime, &fSysTime);
if(*DateFormat == '\0'){
p = NULL;
}else{
p = DateFormat;
}
if(GetDateFormat(0, 0, &fSysTime, p, fDay, BUFSIZE - 1) == 0){
SendMessage(hWnd, WM_CHECKEND, ST_ERROR, (LPARAM)tpItemInfo);
return CHECK_END;
}
if(*TimeFormat == '\0'){
p = NULL;
}else{
p = TimeFormat;
}
if(GetTimeFormat(0, 0, &fSysTime, p, fTime, BUFSIZE - 1) == 0){
SendMessage(hWnd, WM_CHECKEND, ST_ERROR, (LPARAM)tpItemInfo);
return CHECK_END;
}
wsprintf(buf, "%s %s", fDay, fTime);
/* 前回チェック時のものと比較する */
if(GetOptionInt(tpItemInfo->Option1, 0) == 0 && LresultCmp(tpItemInfo->Date, buf) != 0){
CmpMsg = ST_UP;
}
/* アイテムに今回のチェック内容をセットする */
if(tpItemInfo->Date != NULL){
GlobalFree(tpItemInfo->Date);
}
tpItemInfo->Date = (char *)GlobalAlloc(GPTR, sizeof(char) * lstrlen(buf) + 1);
lstrcpy(tpItemInfo->Date,buf);
}else{
CmpMsg = ST_ERROR;
}
SendMessage(hWnd, WM_CHECKEND, CmpMsg, (LPARAM)tpItemInfo);
return CHECK_END;
}
/******************************************************************************
FILE_GetItemText
クリップボード用アイテムのテキストの設定
******************************************************************************/
__declspec(dllexport) HANDLE CALLBACK FILE_GetItemText(struct TPITEM *tpItemInfo)
{
HANDLE hMemText;
char *buf;
char *p;
for(buf = tpItemInfo->CheckURL + lstrlen("file:"); *buf == '/' && *buf != '\0'; buf++);
if((hMemText = GlobalAlloc(GHND, lstrlen(buf) + 1)) == NULL){
return NULL;
}
if((p = GlobalLock(hMemText)) == NULL){
GlobalFree(hMemText);
return NULL;
}
lstrcpy(p,buf);
GlobalUnlock(hMemText);
return hMemText;
}
/******************************************************************************
FILE_CreateDropItem
アイテムのドロップファイルの設定
******************************************************************************/
__declspec(dllexport) BOOL CALLBACK FILE_CreateDropItem(struct TPITEM *tpItemInfo, char *fPath, char *iPath, char *ret)
{
char *buf;
for(buf = tpItemInfo->CheckURL + lstrlen("file:"); *buf == '/' && *buf != '\0'; buf++);
lstrcpy(ret, buf);
return TRUE;
}
/******************************************************************************
FILE_ExecItem
アイテムの実行
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_ExecItem(HWND hWnd, char *Action, struct TPITEM *tpItemInfo)
{
char *buf = NULL;
int rc = -1;
if(lstrcmp(Action,"open") == 0){
if(tpItemInfo->CheckURL != NULL){
for(buf = tpItemInfo->CheckURL + lstrlen("file:"); *buf == '/' && *buf != '\0'; buf++);
}
if(buf != NULL && *buf != '\0'){
rc = ExecItem(hWnd, buf, NULL);
}else{
MessageBox(hWnd, STR_ERR_MSG_FILEOPEN, STR_ERR_TITLE_FILEOPEN, MB_ICONEXCLAMATION);
return -1;
}
}
// 1 を返すとアイコンを初期化する。
return rc;
}
/******************************************************************************
FilePropertyProc
アイテムのプロパティ設定ダイアログ
******************************************************************************/
static BOOL CALLBACK FilePropertyProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
struct TPITEM *tpItemInfo;
char buf[BUFSIZE];
char tmp[BUFSIZE + 10];
char *p, *r;
switch (uMsg)
{
case WM_INITDIALOG:
/* ウィンドウにアイテム情報を待避する */
SetWindowLong(hDlg,DWL_USER,(long)lParam);
tpItemInfo = (struct TPITEM *)lParam;
/* アイテムの情報が空でない場合はアイテムの内容を表示する */
if(tpItemInfo->Title != NULL){
SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_SETTEXT, 0, (LPARAM)tpItemInfo->Title);
}else{
SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_SETTEXT, 0, (LPARAM)STR_NEWITEMNAME);
}
if(tpItemInfo->CheckURL != NULL){
SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_SETTEXT, 0, (LPARAM)tpItemInfo->CheckURL);
}else{
SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_SETTEXT, 0, (LPARAM)"file:///");
}
if(tpItemInfo->Comment != NULL){
SendMessage(GetDlgItem(hDlg, IDC_EDIT_COMMENT), WM_SETTEXT, 0, (LPARAM)tpItemInfo->Comment);
}else{
SendMessage(GetDlgItem(hDlg, IDC_EDIT_COMMENT), WM_SETTEXT, 0, (LPARAM)"");
}
CheckDlgButton(hDlg, IDC_CHECK_DATE, !GetOptionInt(tpItemInfo->Option1, 0));
CheckDlgButton(hDlg, IDC_CHECK_SIZE, !GetOptionInt(tpItemInfo->Option1, 1));
break;
case WM_CLOSE:
EndDialog(hDlg, FALSE);
break;
case WM_COMMAND:
switch(wParam)
{
case IDC_BUTTON_BROWS:
if(FileSelect(hDlg, "*.*", STR_FILTER_FILESELECT, STR_TITLE_FILESELECT, buf, NULL, 1) == -1){
break;
}
wsprintf(tmp, "file:///%s", buf);
SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_SETTEXT, 0, (LPARAM)tmp);
for(r = p = buf; *p != '\0'; p++){
if(IsDBCSLeadByte((BYTE)*p) == TRUE){
p++;
}else if(*p == '\\' || *p == '/'){
r = p;
}
}
SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_SETTEXT, 0, (LPARAM)(r + 1));
break;
case IDOK:
/* ウィンドウからアイテムの情報を取得する */
tpItemInfo = (struct TPITEM *)GetWindowLong(hDlg, DWL_USER);
/* タイトル */
if(tpItemInfo->Title != NULL){
GlobalFree(tpItemInfo->Title);
}
tpItemInfo->Title = GlobalAlloc(GPTR, SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_GETTEXTLENGTH, 0, 0) + 1);
SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_GETTEXT,
SendMessage(GetDlgItem(hDlg, IDC_EDIT_TITLE), WM_GETTEXTLENGTH, 0, 0) + 1, (LPARAM)tpItemInfo->Title);
/* URL */
if(tpItemInfo->CheckURL != NULL){
GlobalFree(tpItemInfo->CheckURL);
}
tpItemInfo->CheckURL = GlobalAlloc(GPTR, SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_GETTEXTLENGTH, 0, 0) + 1);
SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_GETTEXT,
SendMessage(GetDlgItem(hDlg, IDC_EDIT_URL), WM_GETTEXTLENGTH, 0, 0) + 1, (LPARAM)tpItemInfo->CheckURL);
/* コメント */
if(tpItemInfo->Comment != NULL){
GlobalFree(tpItemInfo->Comment);
}
tpItemInfo->Comment = GlobalAlloc(GPTR, SendMessage(GetDlgItem(hDlg, IDC_EDIT_COMMENT), WM_GETTEXTLENGTH, 0, 0) + 1);
SendMessage(GetDlgItem(hDlg, IDC_EDIT_COMMENT), WM_GETTEXT,
SendMessage(GetDlgItem(hDlg, IDC_EDIT_COMMENT), WM_GETTEXTLENGTH, 0, 0) + 1, (LPARAM)tpItemInfo->Comment);
/* チェックオプション */
if(tpItemInfo->Option1 != NULL){
GlobalFree(tpItemInfo->Option1);
}
tpItemInfo->Option1 = (char *)GlobalAlloc(GPTR, 5);
if(tpItemInfo->Option1 != NULL){
wsprintf(tpItemInfo->Option1, "%d;;%d",
!IsDlgButtonChecked(hDlg, IDC_CHECK_DATE),
!IsDlgButtonChecked(hDlg, IDC_CHECK_SIZE));
}
EndDialog(hDlg, TRUE);
break;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
/******************************************************************************
FILE_Property
アイテムのプロパティ
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_Property(HWND hWnd, struct TPITEM *tpItemInfo)
{
/* プロパティのダイアログを表示する */
if(DialogBoxParam(ghinst, MAKEINTRESOURCE(IDD_DIALOG_FILEPROP), hWnd, FilePropertyProc, (long)tpItemInfo) == FALSE){
return -1;
}
return 0;
}
/******************************************************************************
FILE_ProtocolProperty
プロトコルのプロパティ
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_ProtocolProperty(HWND hWnd)
{
return 0;
}
/******************************************************************************
FILE_GetInfo
プロトコル情報
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_GetInfo(struct TPPROTOCOLINFO *tpInfo)
{
int i = 0;
lstrcpy(tpInfo->Scheme, "file:");
lstrcpy(tpInfo->NewMenu, STR_GETINFO_FILE_NEWMENU);
lstrcpy(tpInfo->FileType, "");
tpInfo->tpMenu = (struct TPPROTOCOLMENU *)GlobalAlloc(GPTR, sizeof(struct TPPROTOCOLMENU));
tpInfo->tpMenuCnt = 1;
lstrcpy(tpInfo->tpMenu[i].Name, STR_GETINFO_FILE_OPEN);
lstrcpy(tpInfo->tpMenu[i].Action, "open");
tpInfo->tpMenu[i].Default = TRUE;
tpInfo->tpMenu[i].Flag = 0;
return 0;
}
/******************************************************************************
FILE_EndNotify
WWWCの終了の通知
******************************************************************************/
__declspec(dllexport) int CALLBACK FILE_EndNotify(void)
{
return 0;
}
/* End of source */