-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEDITPVT.CPP
440 lines (354 loc) · 12.3 KB
/
EDITPVT.CPP
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
/* ------------------------------------------------------------
* Filename ............... EditPvt.Cpp
*
* General Purpose ........ Edit private files settings
* ------------------------------------------------------------
* First date ............. 19 dec 1993
*
* First in version ....... 2.00
*
* Written by ............. Alain Schellinck
* ------------------------------------------------------------
* Revisions:
* ----------
*
* Date | By | Purpose |
* ---------+----+--------------------------------------------+
* | | |
* | | |
* | | |
*/
/*-------------------------------------------------------------------------*/
#include <io.h>
#include <stdlib.h>
#include <string.h>
#define Use_LinkedList
#include <TsWin.Hpp>
#define Uses_PbUsersIdx
#define Uses_PbUsersPb
#define Uses_PbUsersBbs
#include "ThProCfg.Hpp"
#include "Template.Hpp"
struct FileEntry
{
FileName fname;
LngT size;
Date date;
Time time;
};
LinkedList<_PrivateFile> far pvtfiles;
LinkedList<FileEntry> far filelist;
/*--] Code [-------------------------------------] sortedFileList [--------*/
/*
* Routine : compare()
* Purpose : compare two objects from the linked list
* ------------------------------------------------------------------------
* Parameters: pointer to 2 objects
* Return : return code from stricmp()
*
*/
int
CompareFileEntry(FileEntry& e1,FileEntry& e2)
{
return stricmp(e1.fname, e2.fname);
}
/*--] Code [-------------------------------------] File pick functions [---*/
/*
* Routine : listFile()
* Purpose : list the specified private file record
* ------------------------------------------------------------------------
* Parameters: record number, X and Y coordinates
* Return : None
*
*/
LCL void listFile(IntT recno, IntT x, IntT y)
{
ChrT c = '+';
char lp = '(';
char rp = ')';
FileName fn(pvtfiles[recno].fname);
if(strchr(fn,'\\'))
{
if(access(fn,0))
c = '-';
}
else
{
lp = rp = ' ';
if(access(FileName(cfg.pvtuploadpath, fn), 0))
c = '-';
}
fn.stripPath();
String keep_kill;
if(pvtfiles[recno].attr & PVTFILE_KEEP)
keep_kill = "KEEP";
else
keep_kill = "KILL";
tsw_maputs(x + 1, y, setFBColor(hYellow, nMagenta), form("[%c] %s %c%-12s%c - %-28.28s [%4s]",
c,
ChrP(pvtfiles[recno].date.format("DD MMM YY")),
lp,(char *)fn,rp,
pvtfiles[recno].to,
(char *)keep_kill
)
);
}
/*
* Routine : listFileEntry()
* Purpose : list the specified file from private files directory
* ------------------------------------------------------------------------
* Parameters: record number, X and Y coordinates
* Return : None
*
*/
LCL void listFileEntry(IntT recno, IntT x, IntT y)
{
FileEntry entry = filelist[recno];
tsw_maputs(x + 1, y, setFBColor(hYellow, nBlue), form("%-12.12s %s %s %6lu",
(char *)entry.fname,
(char *)entry.date.format("DD MMM CCYY"),
(char *)entry.time.format("HH:MM.SS"),
entry.size
)
);
}
/*
* Routine : editPvtFile()
* Purpose : edit private files
* ------------------------------------------------------------------------
* Parameters: None
* Return : None
*
*/
void editPvtFile()
{
KEY hotkeys[] =
{
KEY_INS,
KEY_DEL,
0
};
Field frm[]=
{
/* TYPE dataPtr choices hookFunc flags len width x y */
/* ------------------------------------------------------------------------------------------------------- */
{ FRM_STRING ,0 ,0 ,0 ,FRM_UPPER ,79 ,50 ,13 ,2 },
{ FRM_STRING ,0 ,0 ,0 ,0 ,35 ,36 ,13 ,4 },
{ FRM_STRING ,0 ,0 ,0 ,0 ,35 ,36 ,13 ,5 },
{ FRM_YESNO ,0 ,0 ,0 ,0 ,3 ,3 ,13 ,7 }
};
pvtfiles.kill();
File f;
if(f.open(FileName(syspath,"PVTFILES.PB")))
{
for(;;)
{
_PrivateFile tmp;
if(f.read(&tmp,sizeof(tmp)) != sizeof(tmp))
break;
if(tmp.fname[0])
pvtfiles.add(tmp);
}
f.close();
}
SelectWindow sw( pvtfiles.count(),
0x70,
listFile,
0,
NULL,
hotkeys );
sw.open( 3,
4,
77,
21,
0x5F,
SHADOW | BRACKETS,
CHISEL_BORDER,
0x5D,
NULL,
0x51 );
sw.title( "Personal Files", 0x5E );
for(;;)
{
tsw_showfooter( "\x1<Del>\x1 - Delete \x1<Ins>\x1 - Add \x1<Enter>\x1 - Edit", BAR_NORM, BAR_HIGH );
sw.redefine(pvtfiles.count());
ShrtT choice = sw.process();
if(choice == SL_ESC)
break;
if(choice == SL_HOTKEY)
{
switch(sw.hotkey)
{
case KEY_INS:
{
_PrivateFile tmp;
CLEAR_OBJECT(tmp);
choice = pvtfiles.count();
sw.current = choice;
tmp.date.today();
strcpy(tmp.from,cfg.sysopname);
pvtfiles.add(tmp);
}
break;
case KEY_DEL:
{
if(!pvtfiles.count())
{
tsw_beep();
continue;
}
FileName fn(cfg.pvtuploadpath,pvtfiles[sw.current].fname);
if(!access(fn,0))
if(askYesNo(form("Delete file %s ?",pvtfiles[sw.current].fname)) == TRUE)
unlink(fn);
pvtfiles.get(sw.current);
pvtfiles.remove();
continue;
}
}
}
ShrtT recno = choice;
KEY pickkeys[]=
{
KEY_ALTL , // list
NULL
};
FormWindow w( 7,
8,
74,
17,
0x3F,
SHADOW | BRACKETS,
CHISEL_BORDER,
0x3B,
NULL,
0x31 );
w.define( frm,
4,
0x31,
0x4E,
pickkeys,
NULL );
w.open();
w.title( "Edit Personal File", 0x3E );
w.attrib( 0x3F );
w << "\n FileName:\n"
"\n From user:"
"\n To user:\n"
"\n Delete?:";
bool kill_file = !(pvtfiles[recno].attr & PVTFILE_KEEP);
frm[0].value = pvtfiles[recno].fname;
frm[1].value = pvtfiles[recno].from;
frm[2].value = pvtfiles[recno].to;
frm[3].value = &kill_file;
for(;;)
{
tsw_showfooter("[\001ALT-L\001] Show file- or userlist", BAR_NORM, BAR_HIGH );
tsw_cursoron();
ShrtT choice = w.process();
if(choice == ED_ESC)
break;
if(choice == ED_HOT)
{
switch(w.scanHotKey)
{
case KEY_ALTL:
{
User user;
User::setDir(cfg.msgpath);
NumUsers = ShrtT(User::numUsers());
userFilter filter;
fillUserList(filter);
CLEAR_OBJECT(usrFind);
switch(w.getField())
{
case 0: // filename
{
FileName mask(cfg.pvtuploadpath);
mask.appendBS();
mask << "*.*";
filelist.kill();
{
DirScan find;
int status = find.first(mask);
while(status == TRUE)
{
FileEntry entry;
entry.fname = find.name();
entry.size = find.size();
entry.date = find.date();
entry.time = find.time();
filelist.add(entry);
status = find.next();
}
}
if(filelist.count() != 0)
{
filelist.sort(CompareFileEntry);
SelectWindow sw( filelist.count(),
0x70,
listFileEntry,
0,
NULL,
NULL );
sw.open( 13,
6,
67,
19,
0x17,
SHADOW | BRACKETS,
CHISEL_BORDER,
0x19,
NULL,
0x10 );
sw.title( ChrP( mask ), 0x1E );
tsw_cursoroff();
int fileno = sw.process();
if(fileno != SL_ESC)
{
strcpy(pvtfiles[recno].fname, filelist[fileno].fname);
}
}
continue;
}
case 1: // from user
{
ShrtT userno = pickUser(0);
if(userno != -1)
{
user.read(getDiskRecNo(userno));
strcpy(pvtfiles[recno].from, user.name);
}
continue;
}
case 2: // to user
{
ShrtT userno = pickUser(0);
if(userno != -1)
{
user.read(getDiskRecNo(userno));
strcpy(pvtfiles[recno].to, user.name);
}
continue;
}
}
}
}
}
}
pvtfiles[choice].attr = 0;
if(!kill_file)
pvtfiles[choice].attr |= PVTFILE_KEEP;
}
if(f.open(FileName(syspath,"PVTFILES.PB"),fmode_create))
{
for(pvtfiles.rewind(); !pvtfiles.eol();pvtfiles++)
{
if(f.write(&pvtfiles.get(),sizeof(_PrivateFile)) != sizeof(_PrivateFile))
break;
}
f.close();
}
tsw_cursoroff();
}
/*---------------------------] END OF THE CODE [---------------------------*/