Subversion Repositories factorylink.flntsys

Rev

Rev 7 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1 mjordaan 1
// NTFlTask.cpp: implementation of the NTFlTask class.
2
//
3
//////////////////////////////////////////////////////////////////////
2 marcel 4
#pragma warning( disable : 4996 )
1 mjordaan 5
#include "stdafx.h"
6
#include "Registration.h"
7 mjordaan 7
#include "winbase.h"
1 mjordaan 8
 
9
#ifdef _DEBUG
10
#undef THIS_FILE
11
static char THIS_FILE[]=__FILE__;
12
#define new DEBUG_NEW
13
#endif
14
 
15
#define REGSTR_VALUE_USESCRPASSWORD _T("ScreenSaverIsSecure")
16
#define REGSTR_PATH_SCREENSAVE      _T("Control Panel\\Desktop")
17
#define REGSTR_VALUE_POLSYSTEM      _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")
18
#define REGSTR_VALUE_POLEXPLORER    _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer")
2 marcel 19
#define REGSTR_VALUE_TIMEZONE       _T("SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation")
7 mjordaan 20
#define REGSTR_VALUE_TIMEZONES      _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones")
1 mjordaan 21
 
7 mjordaan 22
using namespace System;
23
using namespace System::Globalization;
1 mjordaan 24
 
7 mjordaan 25
 
26
 
1 mjordaan 27
/////////////////////////////////////////////////////////////////////////////
28
// Description: Event function, only purpose is to let the system save the new
29
// tag value, on the tag object.
30
//
31
// Parameter: 
32
// 
33
// Returns: 
34
// 
35
// Comment: 
36
// 
37
/////////////////////////////////////////////////////////////////////////////
38
void SaveTagValueFL( FlTag *tag, void *data)
39
{
40
} //SaveTagValueFL
41
 
42
 
43
/////////////////////////////////////////////////////////////////////////////
44
// Description: Event function used for writing event message to the NT event
45
// viewer.
46
// 
47
// Parameter: 
48
// 
49
// Returns: 
50
// 
51
// Comment: 
52
// 
53
/////////////////////////////////////////////////////////////////////////////
54
void EventLogFL( FlTag *tag, void *data)
55
{
56
 
57
  C2EventLog *elog = (C2EventLog *)data;
58
 
59
  //digital trigger?
60
  if ((int)tag == 0) return;
61
 
62
  //log the message to the event viewer
63
  elog->theTask->Log2EventViewer( elog->GetEventType(), elog->GetLogText());
64
 
65
  //set the completion tag
66
  if (elog->flcompl.IsValid())
67
  {
68
 
69
    VAL val;
70
    val.dig = 1;
71
    elog->flcompl.Value( val);
72
    elog->flcompl.ForcedWrite();
73
  }
74
}
75
 
76
 
77
//////////////////////////////////////////////////////////////////////
78
// void ShutdownSystem( FlTag *tag, void *data)
79
// 
80
// 
81
//////////////////////////////////////////////////////////////////////
82
void ShutdownFL( FlTag *tag, void *data)
83
{
84
 
85
  CShutdown *shut = (CShutdown *)data;
86
  char lpDirectoryName[] = _T("A:\\");
87
  ULARGE_INTEGER FreeBytesAvailableToCaller;
88
  ULARGE_INTEGER TotalNumberOfBytes;
89
  ULARGE_INTEGER TotalNumberOfFreeBytes; 
90
  BOOL bRet = FALSE;
91
  int iRet = 0;
92
  int b = -1;
7 mjordaan 93
  long sectime = 0;
94
  int secyear  = 0;
95
  int secmonth = 0;
96
  int secday   = 0;
1 mjordaan 97
 
98
 
99
  //tag is digital, check for trigger
2 marcel 100
  if (tag->Type() == FL_DIGITAL)
101
  {
102
    if (!(int)(*tag)) return;
103
  }
1 mjordaan 104
 
105
  //action depends on flag info
106
  switch (shut->GetFlag())
107
  {
108
 
109
    case 1:
110
    case 2:
111
    case 3:
112
    case 4:
113
 
114
      //read parameter to determine if fl needs a shutdown
115
      if (shut->paratag.Type() != FL_UNDEFINED)
116
      {
117
        shut->paratag.Read();
118
        shut->para = shut->paratag;
119
        if (shut->para) shut->theTask->SetFlStop( true);
120
      }
121
 
122
      //first exit FactoryLink
123
      shut->theTask->SetShutdown( shut->GetFlag());
124
 
125
      //save our shutdown mode, we gon'a used it afterwards...
126
      break;
127
 
128
    case 5: //lock the workstation
129
      shut->theTask->LockSystem(); 
130
      break;   
131
 
132
    case 10: //set screen saver activation
133
      if (shut->paratag.Type() != FL_UNDEFINED)
134
      {
135
        shut->paratag.Read();
136
        shut->para = shut->paratag;
137
      }
138
 
139
      bRet = (shut->para != 0) ? 1: 0;
140
      b = SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, bRet, NULL, 0);
141
      if (!b)
142
        shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
143
      break;
144
 
145
    case 11: //get screen saver activation
146
 
147
      if (shut->paratag.Type() != FL_UNDEFINED)
148
      {
149
 
150
        b = SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0, &bRet, 0);
151
 
152
        //break if we failed
153
        if (!b)
154
        {
155
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
156
          break;
157
        }
158
 
159
        //check if a screen saver is defined
160
        if (bRet)
161
        {
162
 
163
          HKEY m_hkResult;
164
 
165
          if (RegOpenKeyEx( HKEY_CURRENT_USER, 
166
                            REGSTR_PATH_SCREENSAVE,
167
                            0,
168
                            KEY_ALL_ACCESS,
169
                            &m_hkResult) == ERROR_SUCCESS)
170
          {
171
 
172
            DWORD dwSize=0; 
173
 
174
            //get the current value
175
            bRet =!RegQueryValueEx( m_hkResult, _T("SCRNSAVE.EXE"), 
176
                                  NULL, NULL, NULL, &dwSize);
177
 
178
            RegCloseKey( m_hkResult);
179
          }
180
        }
181
 
182
        shut->paratag = (bRet == 0) ? 0: 1;
183
        shut->paratag.ForcedWrite();
184
      }
185
      break;
186
 
187
    case 12: //set screen saver timeout
188
 
189
      if (shut->paratag.Type() != FL_UNDEFINED)
190
      {
191
        shut->paratag.Read();
192
        shut->para = shut->paratag;
193
      }
194
 
195
      iRet = shut->para;
196
      b = SystemParametersInfo( SPI_SETSCREENSAVETIMEOUT, iRet, 0, 0);
197
      if (!b)
198
        shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
199
      break;
200
    case 13: //get screen saver timeout
201
 
202
      b = SystemParametersInfo( SPI_GETSCREENSAVETIMEOUT, 0, &iRet, 0);
203
 
204
      //break if we failed
205
      if (!b)
206
      {
207
        shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
208
        break;
209
      }
210
 
211
      if (shut->paratag.Type() != FL_UNDEFINED)
212
      {
213
        shut->paratag = iRet;
214
        shut->paratag.ForcedWrite();
215
      }
216
      break;
217
    case 14: //start screen saver
218
 
219
      //digital tag as trigger
220
      if (shut->fltag.Type() == FL_DIGITAL)
221
      {
222
 
223
        if (shut->fltag.Read()) break;
224
        if ((int)shut->fltag != (int)1) break;
225
      }
226
 
227
      //screensaver can only start if screensaver is allowed
228
      //bRet = TRUE;
229
      //SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0, &bRet, 0);
230
      //if (!bRet) break;
231
      {
232
      SendMessage( GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE,0);
233
      }
234
/*
235
      if (SystemParametersInfo( SPI_GETSCREENSAVETIMEOUT, 0, &iRet, 0))
236
      {
237
 
238
        SystemParametersInfo( SPI_SETSCREENSAVETIMEOUT, 1, 0, 0);
239
 
240
        for (int i = 0; i < 200; i++)
241
          shut->theTask->FlSleep( 10);
242
 
243
        SystemParametersInfo( SPI_SETSCREENSAVETIMEOUT, iRet, 0, 0);
244
      }*/
245
      break;
246
 
247
    case 20: //is screen saver secure
248
 
249
      if (shut->paratag.Type() != FL_UNDEFINED)
250
      {
251
 
252
        HKEY m_hkResult;
253
 
254
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
255
                          REGSTR_PATH_SCREENSAVE,
256
                          0,
257
                          KEY_ALL_ACCESS,
258
                          &m_hkResult) == ERROR_SUCCESS)
259
        {
260
 
261
          unsigned char val[ 40] = _T("0");
262
          DWORD dwSize=40; 
263
 
264
          //get the current value
265
          if (RegQueryValueEx( m_hkResult, REGSTR_VALUE_USESCRPASSWORD, 
266
                               NULL, NULL, val, &dwSize))
267
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
268
 
269
          shut->paratag = (*val == '0') ? 0: 1;
270
          shut->paratag.ForcedWrite();
271
 
272
          RegCloseKey( m_hkResult);
273
        }
274
        else
275
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
276
      }
277
      break;   
278
 
279
    case 21: //set screen saver secure
280
 
281
      {
282
 
283
        HKEY m_hkResult;
284
 
285
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
286
                          REGSTR_PATH_SCREENSAVE,
287
                          0,
288
                          KEY_ALL_ACCESS,
289
                          &m_hkResult) == ERROR_SUCCESS)
290
        {
291
 
292
          if (shut->paratag.Type() != FL_UNDEFINED)
293
            shut->paratag.Read();
294
 
295
          int TagVal = shut->paratag;
296
          CString pw = TagVal ? _T("1"): _T("0");
297
 
298
          if (RegSetValueEx( m_hkResult, REGSTR_VALUE_USESCRPASSWORD,
299
                             0, REG_SZ, (unsigned char *)((LPCTSTR)pw), 2))
300
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
301
 
302
          RegCloseKey( m_hkResult);
303
        }
304
        else
305
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
306
      }
307
      break;   
308
 
309
    case 30: //get button state lock system
310
 
311
      if (shut->paratag.Type() != FL_UNDEFINED)
312
      {
313
 
314
        HKEY m_hkResult;
315
        unsigned char val[ 40] = _T("0");
316
 
317
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
318
                          REGSTR_VALUE_POLSYSTEM,
319
                          0,
320
                          KEY_ALL_ACCESS,
321
                          &m_hkResult) == ERROR_SUCCESS)
322
        {
323
 
324
          DWORD dwSize=40; 
325
 
326
          //get the current value
327
          if (RegQueryValueEx( m_hkResult, _T("DisableLockWorkstation"), 
328
                               NULL, NULL, val, &dwSize))
329
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
330
 
331
          RegCloseKey( m_hkResult);
332
        }
333
        else
334
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
335
 
336
        shut->paratag = (*val == '0') ? 0: 1;
337
        shut->paratag.ForcedWrite();
338
      }
339
      break;   
340
 
341
    case 31: //set button state lock system
342
 
343
      {
344
 
345
        HKEY m_hkResult;
346
 
347
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
348
                          REGSTR_VALUE_POLSYSTEM,
349
                          0,
350
                          KEY_ALL_ACCESS,
351
                          &m_hkResult) == ERROR_SUCCESS)
352
        {
353
 
354
          if (shut->paratag.Type() != FL_UNDEFINED)
355
            shut->paratag.Read();
356
 
357
          int TagVal = shut->paratag;
358
          DWORD dWord = TagVal ? 1: 0;
359
 
360
          if (RegSetValueEx( m_hkResult, _T("DisableLockWorkstation"),
2 marcel 361
                             0, REG_DWORD, (unsigned char *)(&dWord), sizeof(DWORD)))
1 mjordaan 362
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
363
 
364
          RegCloseKey( m_hkResult);
365
        }
366
        else
367
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
368
      }
369
      break;   
370
 
371
    case 32: //get button state taskmanager
372
 
373
      if (shut->paratag.Type() != FL_UNDEFINED)
374
      {
375
 
376
        HKEY m_hkResult;
377
        unsigned char val[ 40] = _T("0");
378
 
379
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
380
                          REGSTR_VALUE_POLSYSTEM,
381
                          0,
382
                          KEY_ALL_ACCESS,
383
                          &m_hkResult) == ERROR_SUCCESS)
384
        {
385
 
386
          DWORD dwSize=40; 
387
 
388
          //get the current value
389
          if (RegQueryValueEx( m_hkResult, _T("DisableTaskMgr"), 
390
                               NULL, NULL, val, &dwSize))
391
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
392
 
393
          RegCloseKey( m_hkResult);
394
        }
395
        else
396
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
397
 
398
        shut->paratag = (*val == '0') ? 0: 1;
399
        shut->paratag.ForcedWrite();
400
      }
401
      break;   
402
 
403
    case 33: //set button state taskmanager
404
 
405
      {
406
 
407
        HKEY m_hkResult;
408
 
409
        if (RegOpenKeyEx( HKEY_CURRENT_USER, 
410
                          REGSTR_VALUE_POLSYSTEM,
411
                          0,
412
                          KEY_ALL_ACCESS,
413
                          &m_hkResult) == ERROR_SUCCESS)
414
        {
415
 
416
          if (shut->paratag.Type() != FL_UNDEFINED)
417
            shut->paratag.Read();
418
 
419
          int TagVal = shut->paratag;
420
          DWORD dWord = TagVal ? 1: 0;
421
 
422
          if (RegSetValueEx( m_hkResult, _T("DisableTaskMgr"),
423
                             0, REG_DWORD, (unsigned char *)(&dWord), sizeof(DWORD)))
424
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
425
 
426
          RegCloseKey( m_hkResult);
427
        }
428
        else
429
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFWRITE");
430
      }
431
      break;   
432
 
2 marcel 433
    case 40: //get activetimebias
434
 
435
      if (shut->paratag.Type() != FL_UNDEFINED)
436
      {
437
 
438
        HKEY m_hkResult;
439
        unsigned char val[ 40] = _T("0");
440
 
441
        if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
442
                          REGSTR_VALUE_TIMEZONE,
443
                          0,
444
                          KEY_ALL_ACCESS,
445
                          &m_hkResult) == ERROR_SUCCESS)
446
        {
447
 
448
          DWORD dwSize=40; 
449
 
450
          //get the current value
451
          if (RegQueryValueEx( m_hkResult, _T("ActiveTimeBias"), 
452
                               NULL, NULL, val, &dwSize))
453
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
454
 
455
          RegCloseKey( m_hkResult);
456
        }
457
        else
458
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
459
 
7 mjordaan 460
        shut->paratag = (*((int *)val)) * 60;
2 marcel 461
        shut->paratag.ForcedWrite();
462
      }
463
      break;   
464
 
465
    case 41: //get active timebias for daylight saving time
466
    case 42: //set UTC time, corrected with daylight saving time
7 mjordaan 467
    case 43: //remove daylight saving time offset
468
    case 44: //find if given time is within daylight saving
2 marcel 469
 
470
      if (shut->paratag.Type() != FL_UNDEFINED)
471
      {
472
 
473
        HKEY m_hkResult;
474
        unsigned char actbias[ 40] = _T("0");
7 mjordaan 475
        unsigned char zbias[ 40] = _T("0");
2 marcel 476
		    int actualbias = 0;
7 mjordaan 477
        int zonebias = 0;
2 marcel 478
        unsigned char dlbias[ 40] = _T("0");
479
		    int daylight = 0;
480
 
481
        if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
482
                          REGSTR_VALUE_TIMEZONE,
483
                          0,
484
                          KEY_ALL_ACCESS,
485
                          &m_hkResult) == ERROR_SUCCESS)
486
        {
487
 
488
          DWORD dwSize=40; 
489
 
490
          //get the current value
491
          if (RegQueryValueEx( m_hkResult, _T("ActiveTimeBias"), NULL, NULL, actbias, &dwSize))
492
            shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
493
		      else
494
          {
495
            if (RegQueryValueEx( m_hkResult, _T("DaylightBias"), NULL, NULL, dlbias, &dwSize))
496
              shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
497
			      else
7 mjordaan 498
            {
499
              if (RegQueryValueEx( m_hkResult, _T("Bias"), NULL, NULL, zbias, &dwSize))
500
                shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
501
              else
502
			        {
503
                zonebias = *((int *)zbias);
504
                actualbias = *((int *)actbias);
505
                if (zonebias == actualbias)
506
                  daylight = (int)0;
507
                else
508
                  daylight = *((int *)dlbias);
509
			        }
510
            }
2 marcel 511
		      }    
512
          RegCloseKey( m_hkResult);
513
        }
514
        else
515
          shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
516
 
517
        if (shut->GetFlag() == 41)
518
        {
7 mjordaan 519
          shut->paratag = (int)(daylight) * 60;
2 marcel 520
          shut->paratag.ForcedWrite();
521
        }
7 mjordaan 522
 
523
        if (shut->GetFlag() == 42)
2 marcel 524
        {
525
          LANA utc = tag->Value().lana;
7 mjordaan 526
          //daylight = (int)(actualbias - daylight) * 60;
527
          utc = utc + ((LANA)actualbias * 60);
2 marcel 528
          shut->paratag = utc;
529
          shut->paratag.ForcedWrite();
530
        }
7 mjordaan 531
 
532
        if (shut->GetFlag() == 43)
533
        {
534
          LANA utc = tag->Value().lana;
535
          utc = utc + ((LANA)(daylight) * 60);
536
          shut->paratag = utc;
537
          shut->paratag.ForcedWrite();
538
        }
539
 
540
        if (shut->GetFlag() == 44)
541
        {
542
          //TIME_ZONE_INFORMATION dtz;
543
          //GetTimeZoneInformation( &dtz);
544
          HKEY m_hkTzone;
545
          unsigned char tzInfo[ 500] = _T("0");
546
          DWORD tzSize = 500;
547
 
548
          DateTime nowDT = DateTime::Now;
549
          sectime = (long)tag->Value().lana;
550
          secyear  = (sectime > 86400) ? 1980 : nowDT.Year;
551
          secmonth = (sectime > 86400) ? 1    : nowDT.Month;
552
          secday   = (sectime > 86400) ? 1    : nowDT.Day;
553
 
554
          DateTime myDT = DateTime(secyear, secmonth, secday).AddSeconds( (double)((long)tag->Value().lana));
555
          char regkey[250];
556
          //char zname[250];
557
 
558
          //int i = 0;
559
 
560
          //while(myTZ->CurrentTimeZone->StandardName[i] != '\0')
561
          //{
562
          //  zname[i] = (CHAR)myTZ->CurrentTimeZone->StandardName[i];
563
          //  ++i;
564
          //}
565
 
566
          sprintf( regkey, "%s\\%s", REGSTR_VALUE_TIMEZONES, shut->theTask->GetTimeZone());
567
 
568
          if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
569
                            (LPCSTR)regkey,
570
                            0,
571
                            KEY_QUERY_VALUE,
572
                            &m_hkTzone) == ERROR_SUCCESS)
573
          {
574
 
575
            if (RegQueryValueEx( m_hkTzone, _T("TZI"), NULL, NULL, tzInfo, &tzSize))
576
              shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
577
            else
578
            {
579
 
580
              //TIME_ZONE_INFORMATION *tz = ((TIME_ZONE_INFORMATION *)tzInfo);
581
              SYSTEMTIME *dayTm = ((SYSTEMTIME *)(&tzInfo[28]));
582
              SYSTEMTIME *stnTm = ((SYSTEMTIME *)(&tzInfo[12]));
583
 
584
              /*typedef struct _SYSTEMTIME {
585
                WORD wYear;
586
                WORD wMonth;
587
                WORD wDayOfWeek;
588
                WORD wDay;
589
                WORD wHour;
590
                WORD wMinute;
591
                WORD wSecond;
592
                WORD wMilliseconds;
593
              } SYSTEMTIME, *PSYSTEMTIME;*/
594
 
595
              DateTime myDayLight = DateTime( myDT.Year, dayTm->wMonth + 1, 1, dayTm->wHour, 0, 0); 
596
              myDayLight = myDayLight.AddSeconds( (double)((long)myDayLight.DayOfWeek * -86400L));
597
              DateTime myStnLight = DateTime( myDT.Year, stnTm->wMonth + 1, 1, stnTm->wHour, 0, 0); 
598
              myStnLight = myStnLight.AddSeconds( (double)((long)myStnLight.DayOfWeek * -86400L));
599
 
600
              int zomertijd = ((myDT <= myStnLight) && (myDT >= myDayLight));
601
              int offset = 0;
602
              if (zomertijd && (daylight == 0)) offset = 3600;
603
              shut->paratag = tag->Value().lana + offset;
604
              shut->paratag.ForcedWrite();
605
            }
606
 
607
            RegCloseKey( m_hkTzone);
608
          }
609
          else shut->theTask->RunTimeManager( FLS_ERROR, "SYSINFOREAD");
610
        }
2 marcel 611
      }
612
      break;   
7 mjordaan 613
    case 45: //convert sectime to ISO8601	year-mo-dyThr:mi:sc.mse
2 marcel 614
 
7 mjordaan 615
      if (shut->paratag.Type() != FL_UNDEFINED)
616
      {
4 marcel 617
 
7 mjordaan 618
        DateTime nowDT = DateTime::Now;
619
        sectime = (long)tag->Value().lana;
620
        secyear  = (sectime > 864000) ? 1980 : nowDT.Year;
621
        secmonth = (sectime > 864000) ? 1    : nowDT.Month;
622
        secday   = (sectime > 864000) ? 1    : nowDT.Day;
623
 
624
        DateTime myDT = DateTime(secyear, secmonth, secday);
625
        myDT = myDT.AddSeconds( (double)sectime);
626
        char msgDT[100];
627
        int iyear = myDT.Year;
628
        int imonth = myDT.Month;
629
        int iday = myDT.Day;
630
        int ihour = myDT.Hour;
631
        int imin = myDT.Minute;
632
        int isec = myDT.Second;
633
        if (secyear == 1980)
634
          sprintf( msgDT, "%4d-%02d-%02d %02d:%02d:%02d", iyear, imonth, iday, ihour, imin, isec);
635
        else
636
          sprintf( msgDT, "%02d:%02d:%02d", ihour, imin, isec);
637
 
638
        shut->paratag = msgDT;
639
        shut->paratag.ForcedWrite();
640
      }
641
      break;
642
 
1 mjordaan 643
    case 100: //get free disk space
644
    case 101:
645
    case 102:
646
    case 103:
647
    case 104:
648
    case 105:
649
    case 106:
650
    case 107:
651
    case 108:
652
    case 109:
653
    case 110:
654
    case 111:
655
    case 112:
656
    case 113:
657
    case 114:
658
    case 115:
659
    case 116:
660
    case 117:
661
    case 118:
662
    case 119:
663
    case 120:
664
    case 121:
665
    case 122:
666
    case 123:
667
    case 124:
668
    case 125:
669
      //get free diskspace
670
      lpDirectoryName[0] += (shut->GetFlag() % 100);
671
      b = GetDiskFreeSpaceEx( lpDirectoryName, &FreeBytesAvailableToCaller,
672
                              &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
673
      //FreeBytesAvailableToCaller.LowPart = (FreeBytesAvailableToCaller.LowPart >> 10) & 0x003fffff;
674
      //FreeBytesAvailableToCaller.HighPart = (FreeBytesAvailableToCaller.HighPart << 32) & 0xfffffC00;
675
      //FreeBytesAvailableToCaller.LowPart |= FreeBytesAvailableToCaller.HighPart;
676
      FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 10);
9 mjordaan 677
 
7 mjordaan 678
      if (shut->theTask->GetUseGB())
679
        FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 20);
680
      else
681
      {
682
        if (shut->theTask->GetUseMB())
683
          FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 10);
684
      }
1 mjordaan 685
      if (!b)
686
        shut->theTask->RunTimeManager( FLS_ERROR, "DISKACCESS", lpDirectoryName);
687
      else
688
      {
689
 
690
        //write the output tag
691
        if (shut->paratag.Type() != FL_UNDEFINED)
692
        {
693
          shut->paratag = FreeBytesAvailableToCaller.LowPart;
694
          shut->paratag.ForcedWrite();
695
        }
696
      }
697
      break;
698
 
699
    case 200: //get used disk space
700
    case 201:
701
    case 202:
702
    case 203:
703
    case 204:
704
    case 205:
705
    case 206:
706
    case 207:
707
    case 208:
708
    case 209:
709
    case 210:
710
    case 211:
711
    case 212:
712
    case 213:
713
    case 214:
714
    case 215:
715
    case 216:
716
    case 217:
717
    case 218:
718
    case 219:
719
    case 220:
720
    case 221:
721
    case 222:
722
    case 223:
723
    case 224:
724
    case 225:
725
      //get used disk space
726
      lpDirectoryName[0] += (shut->GetFlag() % 200);
727
      GetDiskFreeSpaceEx( lpDirectoryName, &FreeBytesAvailableToCaller,
728
                          &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
729
      //TotalNumberOfBytes.LowPart = (TotalNumberOfBytes.LowPart >> 10) & 0x003fffff;
730
      //TotalNumberOfBytes.HighPart = (TotalNumberOfBytes.HighPart << 32) & 0xfffffC00;
731
      //TotalNumberOfBytes.LowPart |= TotalNumberOfBytes.HighPart;
9 mjordaan 732
 
733
      FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 10);
1 mjordaan 734
      TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 10);
735
 
7 mjordaan 736
      if (shut->theTask->GetUseGB())
9 mjordaan 737
      {
7 mjordaan 738
        TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 20);
9 mjordaan 739
        FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 20);
740
      }
7 mjordaan 741
      else
742
      {
743
        if (shut->theTask->GetUseMB())
9 mjordaan 744
        {
7 mjordaan 745
          TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 10);
9 mjordaan 746
          FreeBytesAvailableToCaller.QuadPart = (FreeBytesAvailableToCaller.QuadPart >> 10);
747
        }
7 mjordaan 748
      }
1 mjordaan 749
 
750
      if (!b)
751
        shut->theTask->RunTimeManager( FLS_ERROR, "DISKACCESS", lpDirectoryName);
752
      else
753
      {
754
 
755
        //write the output tag
756
        if (shut->paratag.Type() != FL_UNDEFINED)
757
        {
9 mjordaan 758
          //number of used bytes: total size - used size
759
          shut->paratag = TotalNumberOfBytes.LowPart - FreeBytesAvailableToCaller.LowPart;
760
          shut->paratag.ForcedWrite();
761
        }
762
      }
763
      break;
764
 
765
    case 300: //get total disk space
766
    case 301:
767
    case 302:
768
    case 303:
769
    case 304:
770
    case 305:
771
    case 306:
772
    case 307:
773
    case 308:
774
    case 309:
775
    case 310:
776
    case 311:
777
    case 312:
778
    case 313:
779
    case 314:
780
    case 315:
781
    case 316:
782
    case 317:
783
    case 318:
784
    case 319:
785
    case 320:
786
    case 321:
787
    case 322:
788
    case 323:
789
    case 324:
790
    case 325:
791
      //get total disk space
792
      lpDirectoryName[0] += (shut->GetFlag() % 300);
793
      GetDiskFreeSpaceEx( lpDirectoryName, &FreeBytesAvailableToCaller,
794
                          &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
795
      //TotalNumberOfBytes.LowPart = (TotalNumberOfBytes.LowPart >> 10) & 0x003fffff;
796
      //TotalNumberOfBytes.HighPart = (TotalNumberOfBytes.HighPart << 32) & 0xfffffC00;
797
      //TotalNumberOfBytes.LowPart |= TotalNumberOfBytes.HighPart;
798
      TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 10);
799
 
800
      if (shut->theTask->GetUseGB())
801
        TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 20);
802
      else
803
      {
804
        if (shut->theTask->GetUseMB())
805
          TotalNumberOfBytes.QuadPart = (TotalNumberOfBytes.QuadPart >> 10);
806
      }
807
 
808
      if (!b)
809
        shut->theTask->RunTimeManager( FLS_ERROR, "DISKACCESS", lpDirectoryName);
810
      else
811
      {
812
 
813
        //write the output tag
814
        if (shut->paratag.Type() != FL_UNDEFINED)
815
        {
1 mjordaan 816
          shut->paratag = TotalNumberOfBytes.LowPart;
817
          shut->paratag.ForcedWrite();
818
        }
819
      }
820
      break;
9 mjordaan 821
 
1 mjordaan 822
    default:
823
      break;
824
  }
825
 
826
  //set the completion tag
827
  if (shut->flcompl.IsValid())
828
  {
829
 
830
    VAL val;
831
    val.dig = 1;
832
    shut->flcompl.Value( val);
833
    shut->flcompl.ForcedWrite();
834
  }
835
}
836
 
837
 
838
//////////////////////////////////////////////////////////////////////
839
// void KeyQuery( FlTag *tag, void *data)
840
// 
841
// 
842
//////////////////////////////////////////////////////////////////////
843
void KeyQuery( FlTag *tag, void *data)
844
{
845
 
846
  CKeyStroke *key = (CKeyStroke *)data;
847
  VAL val;
848
 
849
 
850
  //digital trigger?
851
  if ((int)tag == 0) return;
852
 
853
  val.dig =0; //default is locking off
854
 
855
  //check if keyboard dirver is present, up and running
856
  if (!key->theTask->m_oKeyFilter.IsAttached())
857
    key->theTask->RunTimeManager( FLS_ERROR, "NOKEYBOARD");
858
  else 
859
  {
860
    int mykey;
861
 
862
    //get actual key state
863
    key->theTask->m_oKeyFilter.IsKeyDisabled( &mykey,
864
                                              key->GetKey(),
865
                                              key->GetShift(),
866
                                              key->GetAlt(),
867
                                              key->GetControl());
868
 
869
    if (mykey) val.dig = 1; //defined value!!!
870
  }
871
 
872
  //set the (actual) key-state tag
873
  if (key->flstate.IsValid())
874
  {
875
 
876
    key->flstate.Value( val);
877
    key->flstate.Write();
878
  }
879
 
880
  //set completion tag
881
  if (key->flcompl.IsValid())
882
  {
883
 
884
    val.dig = 1;
885
    key->flcompl.Value( val);
886
    key->flcompl.ForcedWrite();
887
  }
888
}
889
 
890
 
891
//////////////////////////////////////////////////////////////////////
892
// void KeyFiltering( FlTag *tag, void *data)
893
// 
894
// 
895
//////////////////////////////////////////////////////////////////////
896
void KeyFiltering( FlTag *tag, void *data)
897
{
898
 
899
  CKeyStroke *key = (CKeyStroke *)data;
900
  VAL val;
901
 
902
 
903
  val.dig = 0;
904
 
905
  //check if keyboard dirver is present, up and running
906
  if (!key->theTask->m_oKeyFilter.IsAttached())
907
    key->theTask->RunTimeManager( FLS_ERROR, "NOKEYBOARD");
908
  else
909
  {
910
 
911
    if ((int)(*tag)) 
912
    {
913
 
914
      key->theTask->m_oKeyFilter.ReplaceKey( key->GetKey(),
915
                                             key->GetShift(),
916
                                             key->GetAlt(),
917
                                             key->GetControl(), 
918
                                             key->GetReplaceKey());
919
      val.dig = 1;
920
    }
921
    else
922
      key->theTask->m_oKeyFilter.EnableKey( key->GetKey(), 
923
                                            key->GetShift(), 
924
                                            key->GetAlt(), 
925
                                            key->GetControl()); 
926
  }
927
 
928
  //set the (actual) key-state tag
929
  if (key->flstate.IsValid())
930
  {
931
 
932
    key->flstate.Value( val);
933
    key->flstate.Write();
934
  }
935
 
936
  //set completion tag
937
  if (key->flcompl.IsValid())
938
  {
939
 
940
    val.dig = 1;
941
    key->flcompl.Value( val);
942
    key->flcompl.ForcedWrite();
943
  }
944
}
945
 
946
 
947
//////////////////////////////////////////////////////////////////////
948
// UINT MyControllingFunction( LPVOID pParam)
949
// 
950
// 
951
//////////////////////////////////////////////////////////////////////
952
UINT MyControllingFunction( LPVOID pParam)
953
{
954
 
955
  CMbox *mbox = (CMbox *)pParam;
956
 
957
 
958
  //clear the time out counter
959
  mbox->ResetCounter();
960
 
961
  //display the message box
962
  int ret = MessageBox( GetDesktopWindow(), mbox->dialog_text, mbox->dialog_title, mbox->m_iT);
963
 
964
  //generate the desired return coe for the thread
965
  int type = mbox->m_iT & (MB_ABORTRETRYIGNORE|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL);
966
  switch (type)
967
  {
968
 
969
    case MB_ABORTRETRYIGNORE:
970
      if (ret == IDABORT) ret = 0;
971
      if (ret == IDRETRY) ret = 1;
972
      if (ret == IDIGNORE) ret = 2;
973
      break;
974
 
975
    case MB_OKCANCEL:
976
      if (ret == IDOK) ret = 1;
977
      else ret = 0;
978
      break;
979
 
980
    case MB_RETRYCANCEL:
981
      if (ret == IDRETRY) ret = 1;
982
      else ret = 0;
983
      break;
984
 
985
    case MB_YESNO:
986
      if (ret == IDYES) ret = 1;
987
      else ret = 0;
988
      break;
989
 
990
    case MB_YESNOCANCEL:
991
      if (ret == IDYES) ret = 1;
992
      if (ret == IDNO) ret = 0;
993
      if (ret == IDCANCEL) ret = 2;
994
      break;
995
 
996
    default: break;
997
  }
998
  return ret;
999
}
1000
 
1001
 
1002
//////////////////////////////////////////////////////////////////////
1003
// void FlNTMessagebox( FlTag *tag, void *data)
1004
// 
1005
// 
1006
//////////////////////////////////////////////////////////////////////
1007
void FlNTMessagebox( FlTag *tag, void *data)
1008
{
1009
 
1010
  CMbox *mbox = (CMbox *)data;
1011
 
1012
  //trigger to show the message box, otherwise keep quiet
1013
  if ((int)(*tag)) 
1014
  {
1015
 
1016
    //UINT t = (mbox->dialog_topmost) ? MB_TOPMOST|MB_SETFOREGROUND: MB_SETFOREGROUND;
1017
    UINT t = (mbox->dialog_topmost) ? MB_TOPMOST: 0;
1018
 
1019
    //type of message box
1020
    switch (mbox->dialog_type)
1021
    {
1022
 
1023
      case 1: t |= MB_ABORTRETRYIGNORE; break;
1024
      case 3: t |= MB_OKCANCEL; break;
1025
      case 4: t |= MB_RETRYCANCEL; break;
1026
      case 5: t |= MB_YESNO; break;
1027
      case 6: t |= MB_YESNOCANCEL; break;
1028
      default: t |= MB_OK; break;
1029
    }
1030
 
1031
    //icon for message box
1032
    switch (mbox->dialog_icon)
1033
    {
1034
 
1035
      case 1: t |= MB_ICONEXCLAMATION; break;
1036
      case 2: t |= MB_ICONWARNING; break;
1037
      case 3: t |= MB_ICONINFORMATION; break;
1038
      case 4: t |= MB_ICONASTERISK; break;
1039
      case 5: t |= MB_ICONQUESTION; break;
1040
      case 6: t |= MB_ICONSTOP; break;
1041
      case 7: t |= MB_ICONERROR; break;
1042
      case 8: t |= MB_ICONHAND; break;
1043
      default: break;
1044
    }
1045
 
1046
    //load the text
1047
    int x = mbox->fltext.Type();
1048
    if (x != FL_UNDEFINED)
1049
    {
1050
      if (!mbox->fltext.Read())
1051
        strcpy( mbox->dialog_text, (char *)(mbox->fltext));
1052
    }
1053
 
1054
    //load the title
1055
    if (mbox->fltitle.Type() != FL_UNDEFINED)
1056
    {
1057
      if (!mbox->fltitle.Read())
1058
      strcpy( mbox->dialog_title, (char *)(mbox->fltitle));
1059
    }
1060
 
1061
    //show the message box
1062
    (mbox->theTask)->SetRunMode( 0);
1063
    mbox->m_iT = t;
1064
 
1065
    //start a thread, on completion we have the value to return to FL
1066
    //AfxBeginThread( MyControllingFunction, (void *)mbox);
1067
    if (mbox->m_Thread == NULL)
1068
    {
1069
 
1070
      mbox->m_Thread = new CWinThread( MyControllingFunction, (void *)mbox);
1071
      mbox->m_Thread->m_bAutoDelete = FALSE;
1072
      mbox->m_Thread->CreateThread();
1073
 
1074
      mbox->theTask->FlSleep( 100);
1075
 
1076
      for( int i =0; i < 40; i++)
1077
      {
1078
 
1079
        HWND hWnd = FindWindow( NULL, mbox->dialog_title);
1080
 
1081
        if (hWnd)
1082
        {
1083
          if (GetForegroundWindow() == hWnd)
1084
          {
1085
 
1086
            mbox->theTask->FlSleep( 50);
1087
            Beep( 200, 10);
1088
            Beep( 500, 20);
1089
            break;
1090
          }
1091
          else
1092
          {
1093
            //BringWindowToTop( hWnd);
1094
            //SetWindowPos( hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SW_RESTORE);
1095
            //SetWindowPos( hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
1096
            SetForegroundWindow( hWnd);
1097
 
1098
            //SetWindowPos( hWnd, HWND_TOP, 500, 500, 0, 0,SWP_NOSIZE); 
1099
 
1100
            //SetActiveWindow( hWnd)
1101
          }
1102
        }
1103
 
1104
        mbox->theTask->FlSleep( 5);
1105
      }
1106
    }
1107
  }
1108
}
1109
 
1110
 
1111
//////////////////////////////////////////////////////////////////////
1112
// Construction/Destruction
1113
//////////////////////////////////////////////////////////////////////
1114
 
1115
//////////////////////////////////////////////////////////////////////
1116
// NTFlTask::NTFlTask( char *Name, char *Desc)
1117
// 
1118
// 
1119
//////////////////////////////////////////////////////////////////////
1120
NTFlTask::NTFlTask( char *Name, char *Desc)
1121
  : FlTask( Name, Desc)
1122
{
1123
 
1124
  m_iShutdown = 0;
1125
  FlShutdown = NULL;
1126
  DlgRegistration = NULL;
1127
  m_bFlStop = false;
1128
}
1129
 
1130
//////////////////////////////////////////////////////////////////////
1131
// NTFlTask::~NTFlTask()
1132
// 
1133
// 
1134
//////////////////////////////////////////////////////////////////////
1135
NTFlTask::~NTFlTask()
1136
{
1137
 
1138
 
1139
  //task must be running, according to FactoryLink
1140
  if (GetId() >= 0)
1141
    Stopping();
1142
}
1143
 
1144
//////////////////////////////////////////////////////////////////////
1145
// Overloaded functions
1146
//////////////////////////////////////////////////////////////////////
1147
 
1148
//////////////////////////////////////////////////////////////////////
1149
// void NTFlTask::CTload()
1150
// 
1151
// 
1152
//////////////////////////////////////////////////////////////////////
1153
void NTFlTask::CTload()
1154
{
1155
 
1156
  FlCTfile      CTfile;
1157
  int           i, ct;
1158
  CT_KEYSTROKE  *key_info;
1159
  CT_SHUTDOWN   *shut_info;
1160
  #ifdef INCLUDE_MSGBOX
1161
  CT_MESSAGEBOX *mess_box;
1162
  #endif
1163
  CT_EVENTLOG   *elog_info;
1164
  CKeyStroke    *keystroke;
1165
  CShutdown     *shutdown;
1166
  #ifdef INCLUDE_MSGBOX
1167
  CMbox         *mbox;
1168
  #endif
1169
  C2EventLog    *elog;
1170
 
1171
 
1172
  //check for opened CT archive file
1173
  if (!CTfile.IsOpen() ||!CTfile.NoTables())
1174
  {
1175
 
1176
    //adjust message according to situation 
1177
    if (!CTfile.NoTables())
1178
      RunTimeManager( FLS_ERROR, "NOTRIGGERS");
1179
    else
1180
      RunTimeManager( FLS_ERROR, "NOCT");
1181
 
1182
    return;
1183
  }
1184
 
1185
  //loop through the tables, processing each in turn
1186
  for (ct = 0; ct < CTfile.NoTables(); ct++)
1187
  {
1188
 
1189
    //read the index for this table
1190
    if (CTfile.ReadIndex( ct) != GOOD)
1191
      continue;
1192
 
1193
    //continue if there are no records
1194
    if (!CTfile.NoRecords())
1195
      continue;
1196
 
1197
    switch (CTfile.Type())
1198
    {
1199
 
1200
      //parameter AD conversion
1201
      case CTID_KEYSTROKES:
1202
 
1203
        //read all the records of the CT
1204
        for (i = 0; i < CTfile.NoRecords(); i++)
1205
        {
1206
 
1207
          //read the main record
1208
          key_info = (CT_KEYSTROKE *)CTfile.ReadRecord( i);
1209
 
1210
          //allocate memory for the new object
1211
          if (!(keystroke = new CKeyStroke( key_info, this))) //&theFlTask)))
1212
            return;
1213
 
1214
          //add element to list
1215
          m_aKey.Add( keystroke);
1216
 
1217
          //add trigger: input tag
1218
          SetEvent( keystroke->theTag, KeyFiltering, keystroke);
1219
        }
1220
        break;
1221
 
1222
      case CTID_SHUTDOWNS:
1223
 
1224
        //read all the records of the CT
1225
        for (i = 0; i < CTfile.NoRecords(); i++)
1226
        {
1227
 
1228
          //read the main record
1229
          shut_info = (CT_SHUTDOWN *)CTfile.ReadRecord( i);
1230
 
1231
          //allocate memory for the new object
1232
          if (!(shutdown = new CShutdown( shut_info, this)))//&theFlTask)))
1233
            return;
1234
 
1235
          //add element to list
1236
          m_aShutdown.Add( shutdown);
1237
 
1238
          //add trigger: input tag
1239
          SetEvent( shutdown->fltag, ShutdownFL, shutdown);
1240
        }
1241
        break;
1242
 
1243
      case CTID_MESSAGEBOX:
1244
 
1245
        #ifdef INCLUDE_MSGBOX
1246
        //read all the records of the CT
1247
        for (i = 0; i < CTfile.NoRecords(); i++)
1248
        {
1249
 
1250
          //read the main record
1251
          mess_box = (CT_MESSAGEBOX *)CTfile.ReadRecord( i);
1252
 
1253
          //allocate memory for the new object
1254
          if (!(mbox = new CMbox( mess_box, this)))//&theFlTask)))
1255
            return;
1256
 
1257
          //add element to list
1258
          m_aMessageBox.Add( mbox);
1259
 
1260
          //add trigger: input tag
1261
          SetEvent( mbox->fltag, FlNTMessagebox, mbox);
1262
        }
1263
        #endif
1264
        break;
1265
 
1266
      case CTID_EVENTLOG:
1267
 
1268
        //read all the records of the CT
1269
        for (i = 0; i < CTfile.NoRecords(); i++)
1270
        {
1271
 
1272
          //read the main record
1273
          elog_info = (CT_EVENTLOG *)CTfile.ReadRecord( i);
1274
 
1275
          //allocate memory for the new object
1276
          if (!(elog = new C2EventLog( elog_info, this)))//&theFlTask)))
1277
            return;
1278
 
1279
          //add element to list
1280
          m_aEventLog.Add( elog);
1281
 
1282
          //add trigger: event type
1283
          if (elog->flevent.IsValid()) SetEvent( elog->flevent, SaveTagValueFL, elog);
1284
 
1285
          //add trigger: message
1286
          if (elog->fltext.IsValid()) SetEvent( elog->fltext, SaveTagValueFL, elog);
1287
 
1288
          //add trigger: log action
1289
          if (elog->fltag.IsValid()) SetEvent( elog->fltag, EventLogFL, elog);
1290
        }
1291
        break;
1292
    }
1293
  }
1294
}
1295
 
1296
 
1297
//////////////////////////////////////////////////////////////////////
1298
// void NTFlTask::Starting()
1299
// 
1300
// 
1301
//////////////////////////////////////////////////////////////////////
1302
void NTFlTask::Starting()
1303
{
1304
 
1305
  int i;
1306
 
1307
 
1308
  //initialise shutdown tag
1309
  FlShutdown = new FlTag( GT_SHUTDOWN);
1310
  FlShutdown->Read();
1311
  TAG  t = {3, 34};
1312
  FlTag          RTMmsg( t); 
1313
  RTMmsg.Read();
1314
 
1315
  //check registration
1316
  //Registration();
1317
 
1318
  //load additional ini settings
1319
  m_iUseMB = GetPrivateProfileInteger( _T("DiskSpace"), _T("UseMB"), 0);
7 mjordaan 1320
  m_iUseGB = GetPrivateProfileInteger( _T("DiskSpace"), _T("UseGB"), 0);
1 mjordaan 1321
 
7 mjordaan 1322
  m_sTimeZoneName = GetPrivateProfileString( _T("TimeZone"), _T("TimeZoneName"), _T("W. Europe Standard Time"));
1323
 
1 mjordaan 1324
  //walk through the key list and do all the enabling/disabling
1325
  for (i = 0; i < m_aKey.GetSize(); i++)
1326
  {
1327
 
1328
    //first read the tag
1329
    m_aKey.GetAt( i)->theTag.Read();
1330
    KeyFiltering( &m_aKey.GetAt( i)->theTag, m_aKey.GetAt( i));
1331
  }
1332
 
1333
  //walk through the shutdown list
1334
//  for (i = 0; i < m_aShutdown.GetSize(); i++)
1335
//  {
1336
 
1337
    //first read the tag
1338
//    m_aShutdown.GetAt( i)->fltag.Read();
1339
//    ShutdownFL( &m_aShutdown.GetAt( i)->fltag, m_aShutdown.GetAt( i));
1340
//  }
1341
 
1342
  //walk through the msgbox list
1343
//  for (i = 0; i < m_aMessageBox.GetSize(); i++)
1344
//  {
1345
 
1346
    //first read the tag
1347
//    m_aMessageBox.GetAt( i)->fltag.Read();
1348
//    FlNTMessagebox( &m_aMessageBox.GetAt( i)->fltag, m_aMessageBox.GetAt( i));
1349
//  }
1350
}
1351
 
1352
//////////////////////////////////////////////////////////////////////
1353
// void NTFlTask::ShutdownSystem()
1354
// 
1355
// Shutdown the system, thsi is done after we told the FL runtime ma-
1356
// nager we are closed, so don't use any call were we need our (inva-
1357
// lid) FL-id
1358
//////////////////////////////////////////////////////////////////////
1359
void NTFlTask::ShutdownSystem()
1360
{
1361
 
1362
  //do a shutdown if needed
1363
  if (m_iShutdown)
1364
  {
1365
 
1366
    //wait until FL is gone, the are no more users
1367
    if (m_bFlStop)
1368
    {
1369
 
1370
      while (fl_get_nkusrs() != -1)
1371
        Sleep( 10);
1372
    }
1373
 
1374
    //now we can shutdown our system, first get the rights needed
1375
    //only user limitations can now block us
1376
    HANDLE token = NULL;
1377
 
1378
    if (OpenProcessToken( GetCurrentProcess(), 
1379
                          TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
1380
                          &token))
1381
    {
1382
 
1383
      //get the LUID for SE_SHUTDOWN_NAME, on our own system
1384
      LUID Luid;
1385
      LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &Luid);
1386
 
1387
      //get the privileges
1388
      char privileges[ 1024];
1389
      DWORD ret = 0;
1390
      if (GetTokenInformation( token, TokenPrivileges, (void *)privileges, 
1391
                               sizeof( privileges), &ret))
1392
      {
1393
 
1394
        TOKEN_PRIVILEGES *viewp = (TOKEN_PRIVILEGES *)privileges;
1395
        int i;
1396
 
1397
        //find the one we need and enable
2 marcel 1398
        for (i = 0; i < (int)viewp->PrivilegeCount; i++)
1 mjordaan 1399
        {
1400
 
1401
          if ((viewp->Privileges[ i].Luid.LowPart == Luid.LowPart) &&
1402
              (viewp->Privileges[ i].Luid.HighPart == Luid.HighPart))
1403
          {
1404
 
1405
            viewp->Privileges[ i].Attributes = SE_PRIVILEGE_ENABLED;
1406
 
1407
            AdjustTokenPrivileges( token, FALSE, viewp, 0, NULL, NULL);
1408
            break;
1409
          }
1410
        }
1411
      }
1412
 
1413
      //do a shutdown, force applications to close
1414
      ExitWindowsEx( m_lShutdownFlag, EWX_FORCE);
1415
    }
1416
  }
1417
}
1418
 
1419
//////////////////////////////////////////////////////////////////////
1420
// void NTFlTask::SetShutdown(long Flag)
1421
// 
1422
// 
1423
//////////////////////////////////////////////////////////////////////
1424
void NTFlTask::SetShutdown(long Flag)
1425
{
1426
 
1427
  m_iShutdown = 1;
1428
 
1429
 
1430
  //convert flag for shutdown
1431
  switch (Flag)
1432
  {
1433
 
1434
    case 1: m_lShutdownFlag = EWX_LOGOFF; break;
1435
    case 2: m_lShutdownFlag = EWX_POWEROFF; break;
1436
    case 3: m_lShutdownFlag = EWX_REBOOT; break;
1437
    case 4: m_lShutdownFlag = EWX_SHUTDOWN; break;
1438
    default: m_iShutdown = 0; break;
1439
  }
1440
 
1441
  if (m_bFlStop)
1442
  {
1443
 
1444
    if (FlShutdown)
1445
    {
1446
 
1447
      *FlShutdown = m_iShutdown;
1448
      if (m_iShutdown) FlShutdown->ForcedWrite(); //STOP FactoryLink
1449
    }
1450
    else
1451
      RunTimeManager( FLS_ERROR, "NOSTOPTAG");
1452
  }
1453
  else
1454
  {
1455
 
1456
    //factorylink is not stopping, just exit windows....
1457
    ShutdownSystem();
1458
  }
1459
}
1460
 
1461
//////////////////////////////////////////////////////////////////////
1462
// void NTFlTask::LockSystem()
1463
// 
1464
// Lock the workstation
1465
//////////////////////////////////////////////////////////////////////
1466
void NTFlTask::LockSystem()
1467
{
1468
 
1469
  LockWorkStation(); //not supported
1470
}
1471
 
1472
//////////////////////////////////////////////////////////////////////
1473
// void NTFlTask::Polling()
1474
// 
1475
// This is for us, we are processing a messagebox, just wait until it
1476
// is closed, then we can write the return value.
1477
//////////////////////////////////////////////////////////////////////
1478
void NTFlTask::Polling()
1479
{
1480
 
1481
  int i;
1482
  int s = m_aMessageBox.GetSize();
1483
  CMbox *mbox;
1484
  DWORD exitcode;
1485
 
1486
 
1487
  //check all posible message box threads
1488
  for (i = 0; i < s; i++)
1489
  {
1490
 
1491
    mbox = m_aMessageBox.ElementAt(i);
1492
 
1493
    //if we have a handle, get the return value, if already present
1494
    if (mbox->m_Thread != NULL)
1495
    {
1496
 
1497
      mbox->TimeOut();
1498
 
1499
      if (!GetExitCodeThread(  mbox->m_Thread->m_hThread, &exitcode))
1500
        exitcode = 0; //error assume no exit code
1501
 
1502
      if (exitcode == STILL_ACTIVE)
1503
        continue;  //go to next thread
1504
      else
1505
      {
1506
 
1507
        //we have a return code, just write it
1508
        mbox->flresult = (int)exitcode;
1509
        mbox->flresult.ForcedWrite();
1510
        mbox->m_Thread->Delete(); //destroy the thread
1511
        delete mbox->m_Thread;
1512
        mbox->m_Thread = NULL;
1513
        SetRunMode();
1514
      }
1515
    }
1516
  }
1517
 
1518
  //call the original one, it does some sleeping...
1519
  FlTask::Polling();
1520
}
1521
 
1522
//////////////////////////////////////////////////////////////////////
1523
// void NTFlTask::Registration()
1524
// 
1525
// Registraiton window if task is not registered
1526
//////////////////////////////////////////////////////////////////////
1527
void NTFlTask::Registration()
1528
{
1529
 
1530
  if (DlgRegistration == NULL)
1531
    DlgRegistration = new CRegistration;
1532
 
1533
  //check if applicaiton is registrated
1534
  if (!DlgRegistration->IsRegistered()) 
1535
    DlgRegistration->DoModal();
1536
}
1537
 
1538
 
1539
//////////////////////////////////////////////////////////////////////
1540
// void NTFlTask::Stopping()
1541
// 
1542
// 
1543
//////////////////////////////////////////////////////////////////////
1544
void NTFlTask::Stopping()
1545
{
1546
 
1547
  int i;
1548
 
1549
 
1550
  //clean all keystroke objects
1551
  for (i = 0; i < m_aKey.GetSize(); i++)
1552
    delete m_aKey.GetAt( i);
1553
 
1554
  //clean all keystroke objects
1555
  for (i = 0; i < m_aMessageBox.GetSize(); i++)
1556
    delete m_aMessageBox.GetAt( i);
1557
 
1558
  //clean all shutdown objects
1559
  for (i = 0; i < m_aShutdown.GetSize(); i++)
1560
    delete m_aShutdown.GetAt( i);
1561
 
1562
  //delete the object arrays
1563
  m_aKey.RemoveAll();
1564
  m_aMessageBox.RemoveAll();
1565
  m_aShutdown.RemoveAll();
1566
 
1567
  if (DlgRegistration != NULL)
1568
    delete DlgRegistration;
1569
 
1570
  //delete the shutdown tag
1571
  if (FlShutdown)
1572
    delete FlShutdown;
1573
}
1574
 
1575
 
1576
//////////////////////////////////////////////////////////////////////
1577
// void NTFlTask::SetFlStop(BOOL flag)
1578
// 
1579
// 
1580
//////////////////////////////////////////////////////////////////////
1581
void NTFlTask::SetFlStop(BOOL flag)
1582
{
1583
 
1584
 
1585
  m_bFlStop = flag;
1586
}
1587
 
1588
 
1589
//////////////////////////////////////////////////////////////////////
1590
// void CMbox::ResetCounter()
1591
// 
1592
// 
1593
//////////////////////////////////////////////////////////////////////
1594
void CMbox::ResetCounter()
1595
{
1596
 
1597
  m_iCounter50 = 0;
1598
}
1599
 
1600
//////////////////////////////////////////////////////////////////////
1601
// BOOL CMbox::TimeOut(BOOL update)
1602
// 
1603
// 
1604
//////////////////////////////////////////////////////////////////////
1605
BOOL CMbox::TimeOut(BOOL update)
1606
{
1607
 
1608
  //return false if there is no timeout
1609
  if (!dialog_time) return FALSE;
1610
 
1611
  if (m_iCounter50 > (dialog_time * 20))
1612
    return Kill();
1613
  else
1614
    m_iCounter50++;
1615
 
1616
  return FALSE;
1617
}
1618
 
1619
 
1620
//////////////////////////////////////////////////////////////////////
1621
// BOOL CMbox::Kill()
1622
// 
1623
// Destroy the messagbox displayed.
1624
//////////////////////////////////////////////////////////////////////
1625
BOOL CMbox::Kill()
1626
{
1627
 
1628
 
1629
  if ((m_hMbox = FindWindow( NULL, dialog_title)) == NULL) 
1630
    return FALSE;
1631
 
1632
  SendMessage( m_hMbox, WM_SYSCOMMAND, SC_CLOSE,0);
1633
  return TRUE;
1634
}
1635
 
1636
void CMbox::ToFront()
1637
{
1638
 
1639
//  if ((m_hMbox = FindWindow( NULL, dialog_title)) == NULL) 
1640
//    return;
1641
 
1642
  SendMessage( GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE,0);
1643
}
1644
 
1645
int NTFlTask::GetUseMB()
1646
{
1647
 
1648
  return m_iUseMB;
1649
}
7 mjordaan 1650
 
1651
int NTFlTask::GetUseGB()
1652
{
1653
 
1654
  return m_iUseGB;
1655
}
1656
 
1657
 
1658
char *NTFlTask::GetTimeZone()
1659
{
1660
 
1661
  return m_sTimeZoneName.GetBuffer();
1662
}