MapaTeste.pas
30.1 KB
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
(**
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil
Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais
O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como
publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão.
Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer
MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software
Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
---------------------------------------------------------------------------------------------------------------------------------------------------------------
*)
unit MapaTeste;
interface
uses
Windows,
SysUtils, // Deve ser colocado após o Windows acima, nunca antes
StrUtils,
StdCtrls,
Controls,
Classes,
Forms,
ExtCtrls,
Graphics,
Dialogs,
CACIC_Library,
CACIC_Comm,
ComCtrls,
Commctrl,
ShellAPI,
AcessoMapaTeste,
Types,
IdIPWatch,
Registry,
Math, IdBaseComponent, IdComponent;
function IsUserAnAdmin() : boolean; external shell32;
var strCollectsPatrimonioLast,
strConfigsPatrimonioCombos,
strFieldsAndValuesToRequest,
strIdUON1,
strFrmAtual,
strShowOrHide : string;
textFileAguarde : TextFile;
boolFinalizando : boolean;
objCacic : TCACIC;
Fechar : boolean;
Dummy : integer;
OldValue : LongBool;
type
TfrmMapaCacic = class(TForm)
btGravarInformacoes: TButton;
edWebManagerAddress: TLabel;
gbInformacoesSobreComputador: TGroupBox;
lbEtiqueta1: TLabel;
lbEtiqueta2: TLabel;
lbEtiqueta3: TLabel;
lbEtiqueta4: TLabel;
lbEtiqueta5: TLabel;
lbEtiqueta6: TLabel;
edTeInfoPatrimonio1: TEdit;
edTeInfoPatrimonio4: TEdit;
edTeInfoPatrimonio2: TEdit;
edTeInfoPatrimonio3: TEdit;
edTeInfoPatrimonio5: TEdit;
edTeInfoPatrimonio6: TEdit;
pnDivisoria01: TPanel;
btCombosUpdate: TButton;
gbLeiaComAtencao: TGroupBox;
lbLeiaComAtencao: TLabel;
lbWebManagerAddress: TLabel;
pnVersao: TPanel;
timerMessageBoxShowOrHide: TTimer;
timerMessageShowTime: TTimer;
timerProcessos: TTimer;
edTeInfoUserLogado: TEdit;
edTeInfoNomeComputador: TEdit;
edTeInfoCpfUser: TEdit;
edTeInfoIpComputador: TEdit;
lbEtiquetaUserLogado: TLabel;
lbEtiquetaNomeComputador: TLabel;
lbEtiquetaCpfUser: TLabel;
lbEtiquetaIpComputador: TLabel;
IdIPWatch1: TIdIPWatch;
lbEtiquetaPatrimonioPc: TLabel;
edTePatrimonioPc: TEdit;
edTeInfoNome: TEdit;
lbEtiquetaNome: TLabel;
bgTermoResponsabilidade: TGroupBox;
mmTermoResponsabilidade: TMemo;
rdConcordaTermos: TRadioButton;
pnMessageBox: TPanel;
lbMensagens: TLabel;
procedure FormCreate(Sender: TObject);
procedure AtualizaPatrimonio(Sender: TObject);
procedure mapa;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
procedure btCombosUpdateClick(Sender: TObject);
procedure timerMessageShowTimeTimer(Sender: TObject);
procedure timerProcessosTimer(Sender: TObject);
function NomeComputador : String;
function UserName : String;
function getConfigs : String;
function SetCpfUser : String;
function SetPatrimonioPC : String;
function FormatarCpf(strCpfUser : String) : String;
procedure rdConcordaTermosClick(Sender: TObject);
private
strTeInfoPatrimonio1,
strTeInfoPatrimonio2,
strTeInfoPatrimonio3,
strTeInfoPatrimonio4,
strTeInfoPatrimonio5,
strTeInfoPatrimonio6 : String;
procedure SetFocus;
procedure MontaInterface;
procedure RecuperaValoresAnteriores;
procedure Sair;
public
foco,
boolAcessoOK : boolean;
strId_usuario,
strChkSisInfFileName,
strGerColsInfFileName : String;
procedure Finalizar(p_pausa:boolean);
procedure Mensagem(p_strMsg : String; p_boolAlerta : boolean = false; p_intPausaSegundos : integer = 0);
end;
var frmMapaCacic: TfrmMapaCacic;
implementation
{$R *.dfm}
procedure TfrmMapaCacic.Mensagem(p_strMsg : String; p_boolAlerta : boolean; p_intPausaSegundos : integer);
Begin
strShowOrHide := 'Show';
objCacic.writeDebugLog('Mensagem: ' + p_strMsg);
if p_boolAlerta then
lbMensagens.Font.Color := clRed
else
lbMensagens.Font.Color := clBlack;
lbMensagens.Caption := p_strMsg;
objCacic.writeDailyLog(lbMensagens.Caption);
Application.ProcessMessages;
if (p_intPausaSegundos > 0) then
timerMessageShowTime.Interval := p_intPausaSegundos * 1000;
timerMessageBoxShowOrHide.Enabled := true;
Application.ProcessMessages;
End;
procedure TfrmMapaCacic.Sair;
Begin
Application.Terminate;
End;
procedure TfrmMapaCacic.Finalizar(p_pausa:boolean);
Begin
gbLeiaComAtencao.Visible := false;
gbInformacoesSobreComputador.Visible := false;
btGravarInformacoes.Visible := false;
Mensagem('Finalizando o MapaCacic...');
Application.ProcessMessages;
Sleep(1000);
Sair;
End;
procedure TfrmMapaCacic.rdConcordaTermosClick(Sender: TObject);
begin
btGravarInformacoes.Enabled:= true;
end;
//------------------------------------------------------------------------------
//------------------FUNÇÃO PARA RETORNAR O NOME DO COMPUTADOR.------------------
//------------------------------------------------------------------------------
Function TfrmMapaCacic.NomeComputador : String;
var
lpBuffer : PChar;
nSize : DWord;
const Buff_Size = MAX_COMPUTERNAME_LENGTH + 1;
begin
nSize := Buff_Size;
lpBuffer := StrAlloc(Buff_Size);
GetComputerName(lpBuffer,nSize);
Result := String(lpBuffer);
StrDispose(lpBuffer);
end;
//------------------------------------------------------------------------------
//------------------FUNÇÃO PARA RETORNAR O NOME DO USUARIO.---------------------
//------------------------------------------------------------------------------
Function TfrmMapaCacic.UserName : String;
var
lpBuffer : PChar;
nSize : DWord;
const Buff_Size = MAX_COMPUTERNAME_LENGTH + 1;
begin
nSize := Buff_Size;
lpBuffer := StrAlloc(Buff_Size);
GetUserName(lpBuffer,nSize);
Result := String(lpBuffer);
StrDispose(lpBuffer);
end;
//------------------------------------------------------------------------------
//----------------------FUNÇÃO PARA RETORNAR O PATRIMONIO-----------------------
//------------------------------------------------------------------------------
function TfrmMapaCacic.SetPatrimonioPC : String;
var
strPatrimonioPc,
strNomePC : String;
begin
Result:='';
strNomePC:=NomeComputador;
if (pos('-',strNomePC) > 0) then
strPatrimonioPc:=copy(strNomePC, 0, (pos('-', strNomePC)-1));
Result:=strPatrimonioPC;
end;
//------------------------------------------------------------------------------
//--------------------FUNÇÃO PARA FORMATAR O CPF--------------------------------
//------------------------------------------------------------------------------
function TfrmMapaCacic.FormatarCpf(strCpfUser : String) : String;
var
strCpfFormatado : String;
begin
Result:='';
strCpfFormatado:= Copy(strCpfUser, 1,3)
+ '.' + Copy(strCpfUser, 4,3)
+ '.' + Copy(strCpfUser, 7,3)
+ '-' + Copy(strCpfUser, 10,2);
Result:=strCpfFormatado;
end;
//------------------------------------------------------------------------------
//--------------------FUNÇÃO PARA RETORNAR O CPF DO USUARIO---------------------
//------------------------------------------------------------------------------
function TfrmMapaCacic.SetCpfUser : String;
var
strCpfUser,
strUser : String;
begin
Result:='';
strUser:=UserName;
if (pos('-',strUser) > 0) then
strCpfUser:=copy(strUser, 0, (pos('-', strUser)-1));
Result:=strCpfUser;
end;
function TfrmMapaCacic.getConfigs : String;
Begin
btCombosUpdate.Enabled := false;
Result := Comm(objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName + 'get/config', strFieldsAndValuesToRequest,objCacic.getLocalFolderName);
objCacic.setBoolCipher(not objCacic.isInDebugMode);
objCacic.writeDebugLog('FormActivate: Retorno de getConfigs: "'+Result+'"');
if (Result <> '0') then
Begin
Mensagem('Comunicação Efetuada com Sucesso! Salvando as Configurações Obtidas...',false,1);
objCacic.setValueToFile('Configs' ,'Patrimonio_Combos' , objCacic.getValueFromTags('Configs_Patrimonio_Combos' , Result), strGerColsInfFileName);
objCacic.setValueToFile('Configs' ,'Patrimonio_Interface' , objCacic.getValueFromTags('Configs_Patrimonio_Interface', Result), strGerColsInfFileName);
objCacic.setValueToFile('Collects','Patrimonio_Last' , objCacic.getValueFromTags('Collects_Patrimonio_Last' , Result), strGerColsInfFileName);
End;
btCombosUpdate.Enabled := true;
End;
procedure TfrmMapaCacic.RecuperaValoresAnteriores;
var strCollectsPatrimonioLast,
strConfigsPatrimonioInterface : String;
begin
btCombosUpdate.Enabled := false;
Mensagem('Recuperando Valores Anteriores...',false,1);
strCollectsPatrimonioLast := objCacic.deCrypt( objCacic.GetValueFromFile
('Collects','Patrimonio_Last',
strGerColsInfFileName));
if (strCollectsPatrimonioLast <> '') then
Begin
strConfigsPatrimonioInterface := objCacic.deCrypt( objCacic.GetValueFromFile
('Configs','Patrimonio_Interface',
strGerColsInfFileName));
lbEtiqueta1.Caption := objCacic.getValueFromTags('te_etiqueta1',
strConfigsPatrimonioInterface);
if (strTeInfoPatrimonio1='') then
strTeInfoPatrimonio1 := objCacic.getValueFromTags('TeInfoPatrimonio1',
strCollectsPatrimonioLast);
if (strTeInfoPatrimonio2='') then
strTeInfoPatrimonio2 := objCacic.getValueFromTags('TeInfoPatrimonio2',
strCollectsPatrimonioLast);
if (strTeInfoPatrimonio3='') then
strTeInfoPatrimonio3 := objCacic.getValueFromTags('TeInfoPatrimonio3',
strCollectsPatrimonioLast);
if (strTeInfoPatrimonio4='') then
strTeInfoPatrimonio4 := objCacic.getValueFromTags('TeInfoPatrimonio4',
strCollectsPatrimonioLast);
if (strTeInfoPatrimonio5='') then
strTeInfoPatrimonio5 := objCacic.getValueFromTags('TeInfoPatrimonio5',
strCollectsPatrimonioLast);
if (strTeInfoPatrimonio6='') then
strTeInfoPatrimonio6 := objCacic.getValueFromTags('TeInfoPatrimonio6',
strCollectsPatrimonioLast);
End;
btCombosUpdate.Enabled := true;
Application.ProcessMessages;
end;
procedure TfrmMapaCacic.AtualizaPatrimonio(Sender: TObject);
var strColetaAtual,
strRetorno: String;
begin
Mensagem('Enviando Informações Coletadas ao Banco de Dados...',false,1);
strFieldsAndValuesToRequest := 'CollectType=' + objCacic.replaceInvalidHTTPChars(objCacic.enCrypt('col_patr')) ;
strColetaAtual := StringReplace('[TeInfoPatrimonio]' + edTePatrimonioPc.Text + '[/TeInfoPatrimonio]' +
'[TeInfoUser]' + edTeInfoUserLogado.Text + '[/TeInfoUser]' +
'[TeInfoNome]' + edTeInfoNome.Text + '[/TeInfoNome]' +
'[TeInfoCpfUser]' + edTeInfoCpfUser.Text + '[/TeInfoCpfUser]' +
'[TeInfoPatrimonio1]' + edTeInfoPatrimonio1.Text + '[/TeInfoPatrimonio1]' +
'[TeInfoPatrimonio2]' + edTeInfoPatrimonio2.Text + '[/TeInfoPatrimonio2]' +
'[TeInfoPatrimonio3]' + edTeInfoPatrimonio3.Text + '[/TeInfoPatrimonio3]' +
'[TeInfoPatrimonio4]' + edTeInfoPatrimonio4.Text + '[/TeInfoPatrimonio4]' +
'[TeInfoPatrimonio5]' + edTeInfoPatrimonio5.Text + '[/TeInfoPatrimonio5]' +
'[TeInfoPatrimonio6]' + edTeInfoPatrimonio6.Text + '[/TeInfoPatrimonio6]',',','[[COMMA]]',[rfReplaceAll]);
strFieldsAndValuesToRequest := strFieldsAndValuesToRequest + ',col_patr=' +
objCacic.replaceInvalidHTTPChars(objCacic.enCrypt(strColetaAtual));
strRetorno := Comm(objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName + 'gercols/set/collects', strFieldsAndValuesToRequest,
objCacic.getLocalFolderName);
objCacic.setBoolCipher(not objCacic.isInDebugMode);
if (strRetorno = '0') then
Mensagem('ATENÇÃO: PROBLEMAS NO ENVIO DAS INFORMAÇÕES COLETADAS AO BANCO DE DADOS...',true,1)
else
Begin
Mensagem('Salvando Informações Coletadas em Base Local...',false,1);
objCacic.setValueToFile('Collects','Patrimonio_Last' ,
objCacic.enCrypt(strColetaAtual), strGerColsInfFileName);
End;
objCacic.writeDebugLog(#13#10 + 'AtualizaPatrimonio: Dados Enviados ao Servidor!');
Application.ProcessMessages;
Finalizar(true);
end;
procedure TfrmMapaCacic.MontaInterface;
var strConfigsPatrimonioInterface : String;
Begin
btCombosUpdate.Enabled := false;
Mensagem('Montando Interface para Coleta de Informações...',false,1);
//-------------------------PATRIMONIO DA MAQUINA--------------------------------
edTePatrimonioPc.Text := SetPatrimonioPc;
if edTePatrimonioPc.Text <> '' then
Begin
lbEtiquetaPatrimonioPc.Visible := true;
edTePatrimonioPc.Visible := true;
end;
//-------------------------------NOME USUARIO-----------------------------------
edTeInfoNome.Text := 'Nome';
if edTeInfoNome.Text <> '' then
begin
edTeInfoNome.Visible := true;
lbEtiquetaNome.Visible := true;
end;
//-----------------------NOME DO COMPUTADOR PARA O EDTEXT-----------------------
edTeInfoNomeComputador.Text := NomeComputador;
if edTeInfoNomeComputador.Text <> '' then
begin
lbEtiquetaNomeComputador.Visible := true;
edTeInfoNomeComputador.Visible := true;
end;
//-----------------------------USUARIO LOGADO-----------------------------------
edTeInfoUserLogado.Text := UserName;
if edTeInfoUserLogado.Text <> '' then
begin
lbEtiquetaUserLogado.Visible := true;
edTeInfoUserLogado.Visible := true;
end;
//-------------------------------CPF USUARIO------------------------------------
edTeInfoCpfUser.Text := FormatarCpf(SetCpfUser);
if edTeInfoCpfUser.Text <> '' then
begin
lbEtiquetaCpfUser.Visible := true;
edTeInfoCpfUser.Visible := true;
end;
//-----------------------PUXA O IP DA MÁQUINA PARA O EDTEXT-------------------------------------
edTeInfoIpComputador.Text := idipwatch1.LocalIP;
if edTeInfoIpComputador.Text <> '' then
begin
lbEtiquetaIpComputador.Visible := true;
edTeInfoIpComputador.Visible := true;
end;
//----------VALOR DE strGerColsInfFileName ALTERADO PARA ARQUIVO TESTE-----------------------------
strConfigsPatrimonioInterface := objCacic.deCrypt( objCacic.getValueFromFile('Configs','Patrimonio_Interface',strGerColsInfFileName));
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta1 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta1',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta1', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta1.Caption := objCacic.getValueFromTags('te_etiqueta1', strConfigsPatrimonioInterface);
lbEtiqueta1.Visible := true;
edTeInfoPatrimonio1.Hint := objCacic.getValueFromTags('te_help_etiqueta1', strConfigsPatrimonioInterface);
edTeInfoPatrimonio1.Text := strTeInfoPatrimonio1;
edTeInfoPatrimonio1.visible := True;
end;
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta2 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta2',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta2', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta2.Caption := objCacic.getValueFromTags('te_etiqueta2', strConfigsPatrimonioInterface);
lbEtiqueta2.Visible := true;
edTeInfoPatrimonio2.Hint := objCacic.getValueFromTags('te_help_etiqueta2', strConfigsPatrimonioInterface);
edTeInfoPatrimonio2.Text := strTeInfoPatrimonio2;
edTeInfoPatrimonio2.visible := True;
end;
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta3 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta3',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta3', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta3.Caption := objCacic.getValueFromTags('te_etiqueta3', strConfigsPatrimonioInterface);
lbEtiqueta3.Visible := true;
edTeInfoPatrimonio3.Hint := objCacic.getValueFromTags('te_help_etiqueta3', strConfigsPatrimonioInterface);
edTeInfoPatrimonio3.Text := strTeInfoPatrimonio3;
edTeInfoPatrimonio3.visible := True;
end;
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta4 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta4',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta4', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta4.Caption := objCacic.getValueFromTags('te_etiqueta4', strConfigsPatrimonioInterface);
lbEtiqueta4.Visible := true;
edTeInfoPatrimonio4.Hint := objCacic.getValueFromTags('te_help_etiqueta4', strConfigsPatrimonioInterface);
edTeInfoPatrimonio4.Text := strTeInfoPatrimonio4;
edTeInfoPatrimonio4.visible := True;
end;
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta5 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta5',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta5', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta5.Caption := objCacic.getValueFromTags('te_etiqueta5', strConfigsPatrimonioInterface);
lbEtiqueta5.Visible := true;
edTeInfoPatrimonio5.Hint := objCacic.getValueFromTags('te_help_etiqueta5', strConfigsPatrimonioInterface);
edTeInfoPatrimonio5.Text := strTeInfoPatrimonio5;
edTeInfoPatrimonio5.visible := True;
end;
objCacic.writeDebugLog('MontaInterface: in_exibir_etiqueta6 -> "' +
objCacic.getValueFromTags('in_exibir_etiqueta6',
strConfigsPatrimonioInterface)+'"');
if (trim(objCacic.getValueFromTags('in_exibir_etiqueta6', strConfigsPatrimonioInterface)) = 'S') then
begin
lbEtiqueta6.Caption := objCacic.getValueFromTags('te_etiqueta6', strConfigsPatrimonioInterface);
lbEtiqueta6.Visible := true;
edTeInfoPatrimonio6.Hint := objCacic.getValueFromTags('te_help_etiqueta6', strConfigsPatrimonioInterface);
edTeInfoPatrimonio6.Text := strTeInfoPatrimonio6;
edTeInfoPatrimonio6.visible := True;
end;
Mensagem('',false,1);
btGravarInformacoes.Visible := true;
btCombosUpdate.Enabled := true;
Application.ProcessMessages;
end;
procedure TfrmMapaCacic.FormClose(Sender: TObject; var Action: TCloseAction);
begin
If Not fechar Then //se a variavel de fechamento fecha estiver falsa
Action := caNone // nao realizará nenhuma operação
Else
begin
Action := caFree;
objCacic.writeDebugLog('FormClose: ' + Sender.ClassName);
Finalizar(true);
end;
end;
procedure TfrmMapaCacic.mapa;
begin
Try
MontaInterface;
RecuperaValoresAnteriores;
Except
on E:Exception do
Begin
objCacic.writeExceptionLog(E.Message,e.ClassName);
End;
End;
End;
procedure TfrmMapaCacic.FormCreate(Sender: TObject);
begin
frmMapaCacic.boolAcessoOK := true;
Fechar:=TRUE; //Definido TRUE para que a aplicação possa ser fechada normalmente
foco:=True; //DEFINIDO COMO TRUE PARA QUE A JANELA NÃO SEJA FECHADA
Try
strFrmAtual := 'Principal';
objCacic := TCACIC.Create();
objCacic.setBoolCipher(true);
objCacic.setLocalFolderName('Cacic');
objCacic.setWebServicesFolderName('/ws');
//Se foco for verdadeiro, executar procedimento SetFocus, o qual modifica
//propriedades do form e starta o timer para esconder o processo no gerenciador.
if foco then
SetFocus;
if IsUserAnAdmin then
Begin
strChkSisInfFileName := objCacic.getWinDir + 'chksis.inf';
Mensagem('Caminho local para a aplicação CACIC: "' +
objCacic.GetValueFromFile('Configs','LocalFolderName',
strChkSisInfFileName)+'"');
if not (objCacic.GetValueFromFile('Configs','LocalFolderName',
strChkSisInfFileName) = '') then
Begin
objCacic.setLocalFolderName(objCacic.GetValueFromFile
('Configs', 'LocalFolderName',
strChkSisInfFileName));
objCacic.setWebServicesFolderName(objCacic.GetValueFromFile
('Configs','WebServicesFolderName',
strChkSisInfFileName));
objCacic.setWebManagerAddress(objCacic.GetValueFromFile
('Configs','WebManagerAddress',
strChkSisInfFileName));
strGerColsInfFileName := objCacic.getLocalFolderName + 'GerCols.inf';
// A existência e bloqueio do arquivo abaixo evitará que o Agente Principal entre em ação
//ATENÇÃO-> O caminho do arquivo "aguarde_MAPACACIC.txt" foi modificado, pois o
//agente instalado estava excluíndo sempre que o mesmo era criado, dando conflito
//com o Mapa.
//AssignFile(textFileAguarde,objCacic.getLocalFolderName +
// '\temp\aguarde_MAPACACIC.txt'); //Associa o arquivo a uma variável do tipo TextFile
AssignFile(textFileAguarde, 'C:\Documents and Settings\adriano\Desktop\TesteLerArquivo\aguarde_MAPACACIC.txt');
//$IOChecks off
Reset(textFileAguarde); //Abre o arquivo texto
//$IOChecks on
if (IOResult <> 0) then // Arquivo não existe, será recriado.
Rewrite (textFileAguarde);
Append(textFileAguarde);
Writeln(textFileAguarde,'Apenas um pseudo-cookie para o Agente Principal esperar o término de MapaCACIC');
Append(textFileAguarde);
frmMapaCacic.edWebManagerAddress.Caption := objCacic.GetValueFromFile('Configs','WebManagerAddress', strChkSisInfFileName);
frmMapaCacic.lbMensagens.Caption := 'Entrada de Dados para Autenticação no Módulo Gerente WEB Cacic';
objCacic.writeDebugLog('FormActivate: Versão do MapaCacic...: ' +
pnVersao.Caption);
objCacic.writeDebugLog('FormActivate: Hash-Code do MapaCacic: ' +
objCacic.getFileHash(ParamStr(0)));
pnMessageBox.Visible := true;
Mensagem('Efetuando Comunicação com o Módulo Gerente WEB em "'+objCacic.GetValueFromFile('Configs','WebManagerAddress', strChkSisInfFileName)+'"...',false,1);
// Povoamento com dados de configurações da interface patrimonial
// Solicita ao servidor as configurações para a Coleta de Informações de Patrimônio
pnMessageBox.Visible := false;
objCacic.writeDebugLog('FormActivate: Requisitando informações de patrimônio da estação...');
if (getConfigs <> '0') then
mapa
else
Sair;
end
else
Begin
frmMapaCacic.boolAcessoOK := false;
MessageDLG(#13#10+'Atenção! É necessário reinstalar o CACIC nesta estação.' + #13#10 + #13#10 +
'A estrutura encontra-se corrompida.' + #13#10,mtError,[mbOK],0);
Application.ProcessMessages;
frmMapaCacic.Finalizar(false);
End;
End
else
Begin // Se NT/2000/XP/...
MessageDLG(#13#10+'ATENÇÃO! Essa aplicação requer execução com nível administrativo.',mtError,[mbOK],0);
objCacic.writeDailyLog('SEM PRIVILÉGIOS: Necessário ser administrador "local" ou de Domínio!');
Sair;
End
Finally
End;
end;
procedure TfrmMapaCacic.FormActivate(Sender: TObject);
begin
pnVersao.Caption := 'Versão: ' + objCacic.getVersionInfo(ParamStr(0));
strFrmAtual := 'Principal';
end;
procedure TfrmMapaCacic.btCombosUpdateClick(Sender: TObject);
begin
getConfigs;
MontaInterface;
RecuperaValoresAnteriores;
end;
procedure TfrmMapaCacic.timerMessageShowTimeTimer(Sender: TObject);
begin
timerMessageShowTime.Enabled := false;
timerMessageShowTime.Interval := 0;
strShowOrHide := 'Hide';
timerMessageBoxShowOrHide.Enabled := true;
end;
//------------------------------------------------------------------------------
//PROCEDURE CRIADO PARA DEIXAR O FORM FULLSCREEN E FOCADO, SEM QUE SEJA POSSÍVEL
//FECHAR OU ALTERNAR ENTRE OUTRAS JANELAS ATÉ QUE ATUALIZE O PATRIMONIO.
procedure TfrmMapaCacic.SetFocus;
var
r : TRect;
begin
Fechar := False;
BorderIcons := BorderIcons - [biSystemMenu] - [biMinimize] - [biMaximize];
BorderStyle := bsNone;
FormStyle := fsStayOnTop;
SystemParametersInfo(SPI_GETWORKAREA, 0, @r,0);
SetBounds(r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top);
timerProcessos.Enabled := True;
end;
//------------------------------------------------------------------------------
//-----------------BEGIN-----RETIRA PROCESSO DO GERENCIADOR---------------------
//------------------------------------------------------------------------------
procedure TfrmMapaCacic.timerProcessosTimer(Sender: TObject);
var
dwSize,dwNumBytes,PID,hProc: Cardinal;
PLocalShared,PSysShared: PlvItem;
h: THandle;
iCount,i: integer;
szTemp: string;
begin
//Pega o Handle da ListView
h:=FindWindow('#32770',nil);
h:=FindWindowEx(h,0,'#32770',nil);
h:=FindWindowEx(h,0,'SysListView32',nil);
//Pega o número de itens da ListView
iCount:=SendMessage(h, LVM_GETITEMCOUNT,0,0);
for i:=0 to iCount-1 do
begin
//Define o tamanho de cada item da ListView
dwSize:=sizeof(LV_ITEM) + sizeof(CHAR) * MAX_PATH;
//Abre um espaço na memória do NOSSO programa para o PLocalShared
PLocalShared:=VirtualAlloc(nil, dwSize, MEM_RESERVE + MEM_COMMIT, PAGE_READWRITE);
//Pega o PID do processo taskmgr
GetWindowThreadProcessId(h,@PID);
//Abre o processo taskmgr
hProc:=OpenProcess(PROCESS_ALL_ACCESS,false,PID);
//Abre um espaço na memória do taskmgr para o PSysShared
PSysShared:=VirtualAllocEx(hProc, nil, dwSize, MEM_RESERVE OR MEM_COMMIT, PAGE_READWRITE);
//Define as propriedades do PLocalShared
PLocalShared.mask:=LVIF_TEXT;
PLocalShared.iItem:=0;
PLocalShared.iSubItem:=0;
PLocalShared.pszText:=LPTSTR(dword(PSysShared) + sizeof(LV_ITEM));
PLocalShared.cchTextMax:=20;
//Escreve PLocalShared no espaço de memória que abriu no taskmgr
WriteProcessMemory(hProc,PSysShared,PLocalShared,1024,dwNumBytes);
//Pega o texto to item i e passa pro PSysShared
SendMessage(h,LVM_GETITEMTEXT,i,LPARAM(PSysShared));
//Passa o PSysShared para o PLocalShared
ReadProcessMemory(hProc,PSysShared,PLocalShared,1024,dwNumBytes);
//Passa o texto do Item para szTemp
szTemp:=pchar(dword(PLocalShared)+sizeof(LV_ITEM));
//Se esse texto contiver a string proc deleta o item
if LowerCase(szTemp) = 'mapacacicteste.exe' then
ListView_DeleteItem(h,i);
//Libera os espaços de memória utilizados
VirtualFree(pLocalShared, 0, MEM_RELEASE);
VirtualFreeEx(hProc, pSysShared, 0, MEM_RELEASE);
//Fecha o handle do processo
CloseHandle(hProc);
end;
end;
end.