-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitVDT.ps1
1640 lines (1528 loc) · 86.1 KB
/
SplitVDT.ps1
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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$ErrorActionPreference = 'Stop' # Abort, if something unexpectedly goes wrong.
$trace=$false
try {
Import-Module PsIni
} # Chargement du module PsIni (cf : https://github.com/lipkau/PsIni)
catch {
Install-Module -Scope CurrentUser PsIni
Import-Module PsIni # https://github.com/lipkau/PsIni
}
$SSHAvailable=$false
#if ($psversiontable.psversion.major -gt 5) {
<## WARN : Must be admin
# Install the OpenSSH Client and Server (https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse)
if ((Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.client*').state -eq "NotPresent") {
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
}
if ((Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.server*').state -eq "NotPresent") {
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
}
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
Install-Module Posh-SSH
get-command -module posh-ssh ==> Vide ou liste de commandes
# CD C:\_SUN\_HW_Installed
# msiexec.exe /package PowerShell-7.1.4-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=0 REGISTER_MANIFEST=1
#>
#(Get-Command New-PSSession).ParameterSets.Name # Must contain "SSHHOST" and "SSHHostHashParam"
#$session=New-SSHSession -ComputerName 192.168.168.40 -Credential (Get-Credential) -force
#(Invoke-SSHCommand -sshsession $session -command "ls").output
#write-host ("PowerShell V6 ou supérieur")
#} # Test et installation de SSH
#else {
if ($true) {
#https://github.com/darkoperator/Posh-SSH/tree/master/docs
if ((get-command -module posh-ssh).count -eq 0) {
$result=Get-PackageProvider|where "name" -eq "NuGet"
if ($result.count -gt 0) {
Write-Host("Installing prerequisite : NuGet provider")
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser
}
Write-Host("Installing module : Posh-SSH")
Install-Module -Scope CurrentUser Posh-SSH
}
if ((get-command -module posh-ssh).count -ne 0) {
$SSHavailable=$true
}
else {
write-host ("Module Posh-SSH not installed")
}
write-host ("PowerShell V5 ou inférieur")
}
#
# Concerne le fichier de configuration
#
$ConfigFile="config_SplitVDT.ini"
$ConfigSection="Default"
$ConfigFound=$false
$conf=[ordered]@{}
#
# Valeurs par défaut en dur au cas où le fichier de configuration ne contiendrait pas de section [Default]
#
$SkipComment=$false # Si $True => Insère une page d'info avant la page extraite
$EffacerFichiersAvant=$true # Si $True => Supprime tous les fichiers dans les répertoires destination avant de débuter l'extraction
$SourceDir=".\mta\teaser.tlt.vdt" # Source VDT sur la machine source (répertoire (avec wildcard possible) ou fichier)
$DestDir="TestMta" # Répertoire destination VDT sur la machine source [pages converties, pages commentaires]
$DestArboDir="TestMtaArbo" # Répertoire destination des noeuds arbos sur la machine source - ATTENTION, les points sont interdits
$SkipWarn127=$true # Saute les pages qui contiennent des char >127 (pages photo ?)
#
$CommentPageName="Cust_MPV.vdt" # Page VDT source commentaire sur la machine source
$CommentSourceDeLaPage="goto10.fr Amitel210b"
$CommentAuteurDeLaPage="LDFA"
$CommentText="Pages extraites de l'archive|'Amitel210b.lha' puis decoupees|automatiquement"
$CommentStartX=10 # Colonne de début des commentaires
$CommentTextStartX=2 # Colonne de début des commentaires (pour $CommentText seulement)
$CommentStartY=9 # Ligne de début des commentaires
$CommentAttribs="A"
#
$TargetGuideLink="" # Destiné au fichier Arbo
$PostFix=".vdt" # Post-fix des pages constituées (aussi destiné au fichier arbo)
$FieldList='[0,30,[],"Text01",2,"."]' # Position et attributs du champ de saisie
$TimerDelay=5
$DisplaySpeed=960 # en CPS
#
$TargetPageDir="/home/pi/python/PyMoIP/TestPages/Mta/"
$TargetArboDir="Mta" # Emplacement des fichiers arbo sur le serveur - ATTENTION, les points sont interdits
#
$RemoteHost="192.168.168.40"
$Service="arbo_teletel"
$ServerArboRoot="/home/pi/python/PyMoIP/Arbos"
#
$LineOffset=30
$LineHeigth=40
$PosButton=182
$LineWidth=@(550,400)
$ColPos=@(810,850)
$GUI_Groups=@(3,$ColPos[0],10,($LineWidth[0]+24),(3*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Répetroires locaux"),
@(3,$ColPos[0],170,($LineWidth[0]+24),(3*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Mode de conversion"),
@(8,$ColPos[0],320,($LineWidth[0]+24),(8*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Définition des pages d'infos/commentaires"),
@(2,($ColPos[1]+$LineWidth[0]),10 ,($LineWidth[1]+24),(2*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Répertoire effectif sur la machine serveur PyMoIP"),
@(5,($ColPos[1]+$LineWidth[0]),280,($LineWidth[1]+24),(5*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Constantes des noeuds d'arbo générés"),
@(1,($ColPos[1]+$LineWidth[0]),140,($LineWidth[1]+24),(2.5*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Chaines détectées pour la séparation des pages"),
@(1,10,10,($ColPos[0]-20),(1*$LineHeigth+$LineOffset-$LineHeigth/2+8),"Fichier de configuration"),
@(1,($ColPos[1]+$LineWidth[0]),520,($LineWidth[1]+24),(3*$LineHeigth+$LineOffset-$LineHeigth/2+5),"Hôte distant")
$Button_Click_Select_SourceDir = { Select_SourceDir }
$Button_Click_Select_DestDir = { Select_DestDir }
$Button_Click_Select_DestArboDir = { Select_DestArboDir }
$Button_Click_Select_CommentPageName = { Select_CommentPageName }
$Button_Click_Select_NewConf = { Select_NewConf }
$Button_Click_Select_DelConf = { Select_DelConf }
$Button_Click_Select_SaveConf = { Select_SaveConf }
$Event_TextChanged = {
#[System.Windows.Forms.MessageBox]::Show("Event_TextChanged" , "Will update GUI")
if ($trace -eq $true) { write-host("EventTextChanged()") }
$TextValue=GUI_GetTextValue
if ($trace -eq $true) { write-host("Test si valeur ComboBox GUI (`$Control.Text=" + $TextValue +") est different de la section en cours `$ConfigSection="+$ConfigSection) }
if ($TextValue -ne $ConfigSection) {
if ($trace -eq $true) { write-host("***********`r`n***********") }
if ($trace -eq $true) { write-host("Section changée") }
if ($trace -eq $true) { write-host("***********`r`n***********") }
SaveConfFromGUI
UpdateConfigSection $TextValue
#UpdateGUI_FromVars
UpdateVarsFromConf
UpdateGUI_NewSectionSelected
UpdateGUI_FromVars
if ($trace -eq $true) { write-host("***********`r`n") }
}
if ($trace -eq $true) { write-host("EventTextChanged() done") }
}
$GUI_Var=$data = @(
[pscustomobject]@{Grp=0;VarName='SourceDir'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[0]; SizY=18; Fileselect=$true; Callback = "Button_Click_Select_SourceDir"}
[pscustomobject]@{Grp=0;VarName='DestDir'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[0]; SizY=18; Fileselect=$true; Callback = "Button_Click_Select_DestDir"}
[pscustomobject]@{Grp=0;VarName='DestArboDir'; PosX=10; PosY=($LineHeigth * 2)+$LineOffset;SizX=$LineWidth[0]; SizY=18; Fileselect=$true; Callback = "Button_Click_Select_DestArboDir"}
[pscustomobject]@{Grp=1;VarName='SkipComment'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[0]; SizY=18; OnOffSelect=$true}
[pscustomobject]@{Grp=1;VarName='EffacerFichiersAvant'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[0]; SizY=18; OnOffSelect=$true}
[pscustomobject]@{Grp=1;VarName='SkipWarn127'; PosX=10; PosY=($LineHeigth * 2)+$LineOffset;SizX=$LineWidth[0]; SizY=18; OnOffSelect=$true}
[pscustomobject]@{Grp=2;VarName='CommentPageName'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[0]; SizY=18; Fileselect=$true; Callback = "Button_Click_Select_CommentPageName"}
[pscustomobject]@{Grp=2;VarName='CommentSourceDeLaPage'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=2;VarName='CommentAuteurDeLaPage'; PosX=10; PosY=($LineHeigth * 2)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=2;VarName='CommentText'; PosX=10; PosY=($LineHeigth * 3)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=2;VarName='CommentStartX'; PosX=10; PosY=($LineHeigth * 4)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true; IsInt=$true; MaxVal=39 ; MinVal=1}
[pscustomobject]@{Grp=2;VarName='CommentTextStartX'; PosX=10; PosY=($LineHeigth * 5)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true; IsInt=$true; MaxVal=39 ; MinVal=1}
[pscustomobject]@{Grp=2;VarName='CommentStartY'; PosX=10; PosY=($LineHeigth * 6)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true; IsInt=$true; MaxVal=24 ; MinVal=0}
[pscustomobject]@{Grp=2;VarName='CommentAttribs'; PosX=10; PosY=($LineHeigth * 7)+$LineOffset;SizX=$LineWidth[0]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=3;VarName='TargetPageDir'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=3;VarName='TargetArboDir'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=4;VarName='TargetGuideLink'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=4;VarName='PostFix'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=4;VarName='FieldList'; PosX=10; PosY=($LineHeigth * 2)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=4;VarName='TimerDelay'; PosX=10; PosY=($LineHeigth * 3)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true; IsFloat=$true; MaxVal=60 ; MinVal=0.01}
[pscustomobject]@{Grp=4;VarName='DisplaySpeed'; PosX=10; PosY=($LineHeigth * 4)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true; IsInt=$true; MaxVal=1920 ; MinVal=120}
[pscustomobject]@{Grp=5;VarName='SplitList'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[1]; SizY=(18*4); SplitSelect=$true}
[pscustomobject]@{Grp=6;VarName='ConfigSection'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=210; SizY=21; ConfSelect=$true ;
CallbackNew = "Button_Click_Select_NewConf";
CallbackDel = "Button_Click_Select_DelConf";
CallbackSave = "Button_Click_Select_SaveConf";
CallbackText = "Event_TextChanged"}
[pscustomobject]@{Grp=7;VarName='RemoteHost'; PosX=10; PosY=($LineHeigth * 0)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=7;VarName='Service'; PosX=10; PosY=($LineHeigth * 1)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
[pscustomobject]@{Grp=7;VarName='ServerArboRoot'; PosX=10; PosY=($LineHeigth * 2)+$LineOffset;SizX=$LineWidth[1]; SizY=18; TextSelect=$true}
)
$GUI_Desc=@( "Source VDT sur la machine source (répertoire (avec wildcard possible) ou fichier)",
"Destination VDT sur la machine source [pages converties et pages commentaires]",
"Destination des noeuds arbos sur la machine source - ATTENTION, les points sont interdits",
"Si True => N'insère pas de page d'info/commentaires avant la page extraite",
"Si True => Supprime tous les fichiers dans les répertoires destination avant de débuter l'extraction",
"Si True => Saute les pages qui contiennent des char >127 (pages photo ?)",
"Page VDT source 'infos/commentaire' sur la machine source",
"Origine de la (série de) page(s) <40 caractères",
"Auteur de l'origine <40 caractères",
"Commentaire libre (x lignes <40 caractères) séparées de '|'",
"Colonne de début (1 à 39)",
"Colonne de début pour le commentaire libre (1 à 39)",
"Ligne de début (0 à 24)",
"Attributs @=Noir, A=Rouge, B=Vert, C=Jaune, D=Bleu, E=Magenta, F=Cyan, G=Blanc ...",
"Pages VDT - ATTENTION, '\' => '/' sous Linux !",
"Noeuds arbo - ATTENTION, '\' => '.' pour module python !",
"Noeud d'arbo pour la touche [GUIDE] (ou '' ou vide)",
"PostFix des pages VDT (.vdt)",
"Définition du champ de saisie (ou [] si vide)",
"Temps de pause nominal (>0 !)",
"Vitesse de transmission théorique en CPS pour correction tempo (120 ou 960)",
"[1 chaine par ligne - valeurs séparées par des ','] (ex 12 ou x1F,x40,x41 )",
"Choix de la section",
"Hôte distant",
"Service",
"Racine des arbos de PyMoIP-Server"
)
#
function UpdateVarsFromConf () {
if ($trace -eq $true) { write-host("UpdateVarsFromConf() - Mise à jour des variables globales depuis `$conf[$ConfigSection]") }
#if ($conf[$ConfigSection]["SkipComment"]) { $SkipComment=[bool] (($conf[$ConfigSection]["SkipComment"]).toupper() -eq $true) }
if ($conf[$ConfigSection]["SkipComment"]) { set-variable -name "SkipComment" -scope script -value ([bool] (($conf[$ConfigSection]["SkipComment"]).toupper() -eq $true)) }
if ($conf[$ConfigSection]["EffacerFichiersAvant"]) { set-variable -name "EffacerFichiersAvant" -scope script -value ([bool] (($conf[$ConfigSection]["EffacerFichiersAvant"]).toupper() -eq $true)) }
if ($conf[$ConfigSection]["SourceDir"]) { set-variable -name "SourceDir" -scope script -value ([string]$conf[$ConfigSection]["SourceDir"]) }
if ($conf[$ConfigSection]["DestDir"]) { set-variable -name "DestDir" -scope script -value ([string]$conf[$ConfigSection]["DestDir"]) }
if ($conf[$ConfigSection]["DestArboDir"]) { set-variable -name "DestArboDir" -scope script -value ([string]$conf[$ConfigSection]["DestArboDir"]) }
if ($conf[$ConfigSection]["SkipWarn127"]) { set-variable -name "SkipWarn127" -scope script -value ([bool] (($conf[$ConfigSection]["SkipWarn127"]).toupper() -eq $true)) }
#
if ($conf[$ConfigSection]["CommentPageName"]) { set-variable -name "CommentPageName" -scope script -value ([string]$conf[$ConfigSection]["CommentPageName"]) }
if ($conf[$ConfigSection]["CommentSourceDeLaPage"]) { set-variable -name "CommentSourceDeLaPage" -scope script -value ([string]$conf[$ConfigSection]["CommentSourceDeLaPage"]) }
if ($conf[$ConfigSection]["CommentAuteurDeLaPage"]) { set-variable -name "CommentAuteurDeLaPage" -scope script -value ([string]$conf[$ConfigSection]["CommentAuteurDeLaPage"]) }
if ($conf[$ConfigSection]["CommentText"]) { set-variable -name "CommentText" -scope script -value ([string]$conf[$ConfigSection]["CommentText"]) }
if ($conf[$ConfigSection]["CommentStartX"]) { set-variable -name "CommentStartX" -scope script -value ([int]$conf[$ConfigSection]["CommentStartX"]) }
if ($conf[$ConfigSection]["CommentTextStartX"]) { set-variable -name "CommentTextStartX" -scope script -value ([int]$conf[$ConfigSection]["CommentTextStartX"]) }
if ($conf[$ConfigSection]["CommentStartY"]) { set-variable -name "CommentStartY" -scope script -value ([int]$conf[$ConfigSection]["CommentStartY"]) }
if ($conf[$ConfigSection]["CommentAttribs"]) { set-variable -name "CommentAttribs" -scope script -value ([string]$conf[$ConfigSection]["CommentAttribs"]) }
#
if ($conf[$ConfigSection]["TargetGuideLink"]) { set-variable -name "TargetGuideLink" -scope script -value ([string]$conf[$ConfigSection]["TargetGuideLink"]) }
if ($conf[$ConfigSection]["PostFix"]) { set-variable -name "PostFix" -scope script -value ([string]$conf[$ConfigSection]["PostFix"]) }
if ($conf[$ConfigSection]["FieldList"]) { set-variable -name "FieldList" -scope script -value ([string]$conf[$ConfigSection]["FieldList"]) }
if ($conf[$ConfigSection]["TimerDelay"]) { set-variable -name "TimerDelay" -scope script -value ([float]$conf[$ConfigSection]["TimerDelay"]) }
if ($conf[$ConfigSection]["DisplaySpeed"]) { set-variable -name "DisplaySpeed" -scope script -value ([int]$conf[$ConfigSection]["DisplaySpeed"]) }
#
if ($conf[$ConfigSection]["SplitList"]) { $SplitList=[string]$conf[$ConfigSection]["SplitList"]
if ($trace -eq $true) { $SplitList }
$SplitTabList=@()
$SplitList=$SplitList.Split("[")
foreach ($z in $SplitList) {
if ($z.Length) {
$SplitTabList+=($z.split("]"))[0]
}
else {
if ($trace -eq $true) { write-host("Empty line found in `$SplitList (skipped)") }
}
}
set-variable -name "SplitTabList" -scope script -value ($SplitTabList)
$SplitTab=[byte[]]@() # Création (effacement) du tableau binaire correspondant
ConvertSplitTabList ([ref]$SplitTab) # Remplissage du tableau binaire à partir du tableau de chaines
set-variable -name "SplitTab" -scope script -value ($SplitTab) # Création (effacement) du tableau binaire correspondant
for (($i = 0),($IndexSplitTab=[int[]]@()); $i -lt $SplitTab.count; $i++) { $IndexSplitTab+=0} # Création (effacement) du tableau d'index correspondant
set-variable -name "IndexSplitTab" -scope script -value ($IndexSplitTab) # Création (effacement) du tableau binaire correspondant
} # Maj de $SplitTab et $IndexSplitTab à partir de $SplitList
#
if ($conf[$ConfigSection]["TargetPageDir"]) { set-variable -name "TargetPageDir" -scope script -value ([string]$conf[$ConfigSection]["TargetPageDir"]) }
if ($conf[$ConfigSection]["TargetArboDir"]) { set-variable -name "TargetArboDir" -scope script -value ([string]$conf[$ConfigSection]["TargetArboDir"]) }
if ($conf[$ConfigSection]["RemoteHost"]) { set-variable -name "RemoteHost" -scope script -value ([string]$conf[$ConfigSection]["RemoteHost"]) }
if ($conf[$ConfigSection]["Service"]) { set-variable -name "Service" -scope script -value ([string]$conf[$ConfigSection]["Service"]) }
if ($conf[$ConfigSection]["ServerArboRoot"]) { set-variable -name "ServerArboRoot" -scope script -value ([string]$conf[$ConfigSection]["ServerArboRoot"]) }
if ($trace -eq $true) { write-host("UpdateVarsFromConf() done") }
} # Mise à jour des variables globales depuis $conf[$ConfigSection]
function ConvertSplitTabList ([ref]$SplitTab) {
if ($SplitTab.value.count -gt 0) { write-host("[ref]SplitTab should have been cleared before ConvertSplitTabList call !")}
foreach ($elem in $SplitTabList) {
#write-host ("ConvertSplitTabList "+$elem)
$ToBytes=@()
foreach ($byte in ($elem.split(","))) {
#$byte
$byte=$byte.trim()
if (($byte.split('x').length) -gt 1) {
$byte=$byte.split('x')[$byte.split('x').length - 1]
} else {
$byte=[Convert]::ToString($byte, 16)
}
$ToBytes+=[system.convert]::ToByte($byte,16)
}
$splittab.value+=""
$SplitTab.value[($SplitTab.value.count)-1]=$ToBytes
}
if ($trace -eq $true) { write-host("ConvertSplitTabList() Converted "+$splitTab.value.count+" elements from SplitTabList") }
#$SplitTab
}
#
# Construction de la liste de split [$SplitTab] par défaut
#
$SplitTabList=@() # Création d'un tableau de chaines
#$SplitTabList+="12" # Ajout d'une chaine par défaut (x12 = Effacement d'écran) pour séparation des pages
$SplitTabList+="xff,x00,x12" # Ajout d'une chaine par défaut (x12 = Effacement d'écran) pour séparation des pages
$SplitTabList+="1,2,3" # Ajout d'une chaine par défaut (x12 = Effacement d'écran) pour séparation des pages
$SplitTab=[byte[]]@() # Création (effacement) du tableau binaire correspondant
ConvertSplitTabList ([ref]$SplitTab) # Remplissage du tableau binaire à partir du tableau de chaines
for (($i = 0),($IndexSplitTab=[int[]]@()); $i -lt $SplitTab.count; $i++) { $IndexSplitTab+=0} # Création (effacement) du tableau d'index correspondant
if (Test-Path -Path $ConfigFile -PathType Leaf) {
$conf = Get-IniContent $ConfigFile
if ($trace -eq $true) { Write-Host "$ConfigFile loaded" }
foreach ($key in $conf.keys) {
if ($Key -match $ConfigSection) {
$ConfigFound=$true
if ($trace -eq $true) { write-host ("`$ConfigSection '"+ $key+"' found in "+$ConfigFile) }
#if ($trace -eq $true) { $conf[$ConfigSection] }
#
UpdateVarsFromConf
}
}
} # Charger la configuration dans $conf[] depuis le fichier $ConfigFile - Si $ConfigSection trouvée, MAJ des variables à partir de $conf[]
else {
if ($trace -eq $true) { Write-Host "$ConfigFile not found - Left empty !" }
}
if ($ConfigFound -ne $true) {
$ConfigFound=$true
if ($trace -eq $true) { Write-Host ("Section ["+ $ConfigSection + "] not found - defaults used !") }
$conf+=[ordered] @{$ConfigSection={}}
#$conf[$ConfigSection]+=@{"Bla"="Blu"}
$conf[$ConfigSection]=@{}
#$conf[$ConfigSection]+=@{"zaz"="hjgfjhfjg"}
$conf[$ConfigSection]+=@{"SkipComment"= $SkipComment }
$conf[$ConfigSection]+=@{"EffacerFichiersAvant"= $EffacerFichiersAvant }
$conf[$ConfigSection]+=@{"SourceDir"= $SourceDir }
$conf[$ConfigSection]+=@{"DestDir"= $DestDir }
$conf[$ConfigSection]+=@{"DestArboDir"= $DestArboDir }
$conf[$ConfigSection]+=@{"SkipWarn127"= $SkipWarn127 }
#
$conf[$ConfigSection]+=@{"CommentPageName"= $CommentPageName }
$conf[$ConfigSection]+=@{"CommentSourceDeLaPage"= $CommentSourceDeLaPage }
$conf[$ConfigSection]+=@{"CommentAuteurDeLaPage"= $CommentAuteurDeLaPage }
$conf[$ConfigSection]+=@{"CommentText"= $CommentText }
$conf[$ConfigSection]+=@{"CommentStartX"= $CommentStartX }
$conf[$ConfigSection]+=@{"CommentTextStartX"= $CommentTextStartX }
$conf[$ConfigSection]+=@{"CommentStartY"= $CommentStartY }
$conf[$ConfigSection]+=@{"CommentAttribs"= $CommentAttrib }
#
$conf[$ConfigSection]+=@{"TargetGuideLink"= $TargetGuideLink }
$conf[$ConfigSection]+=@{"PostFix"= $PostFix }
$conf[$ConfigSection]+=@{"FieldList"= $FieldList }
$conf[$ConfigSection]+=@{"TimerDelay"= $TimerDelay }
$conf[$ConfigSection]+=@{"DisplaySpeed"= $DisplaySpeed }
#
$SplittedList=""
$NbElem=0
foreach ($elem in $SplitTab) {
$NbByte=0
$ResultElem="["
foreach ($byte in $elem) {
$ResultElem+=$byte
$NbByte+=1
if ($NbByte -ne $elem.length) {
$ResultElem+=","
}
}
$ResultElem+="]"
$NbElem+=1
if ($NbElem -ne $SplitTab.Count) {
$ResultElem+=","
}
$SplittedList+=$ResultElem
}
$conf[$ConfigSection]+=@{"SplitList"= $SplittedList }
#
$conf[$ConfigSection]+=@{"TargetPageDir"= $TargetPageDir }
$conf[$ConfigSection]+=@{"TargetArboDir"= $TargetArboDir }
$conf[$ConfigSection]+=@{"RemoteHost"= $RemoteHost }
$conf[$ConfigSection]+=@{"Service"= $Service }
$conf[$ConfigSection]+=@{"ServerArboRoot"= $ServerArboRoot }
} # Si $ConfigSection n'a pas été trouvée, l'ajouter à $conf[] à partir des variables définies par défaut
function AddSearchValue {
param ( $ValueToAdd )
$z=$IndexSplitTab.length
$IndexSplitTab+=0
$SplitTab+=""
#$SplitTab[1]=[byte]255
$SplitTab[$z]=$ValueToAdd
return $SplitTab, $IndexSplitTab
}
function PositionTextAttribs {
Param
( $PosX, $PosY, $Text, $Attribs
)
$enc = [system.Text.Encoding]::UTF8
$data1 = ""
foreach ($Attrib in $Attribs.ToCharArray()) {
if ($data1 -eq "") {
$data1= $enc.GetBytes([char]27)
} else {
$data1= $data1 + $enc.GetBytes([char]27)
}
$data1=$data1 + $enc.GetBytes($Attrib)
}
$data1=$data1 + $enc.GetBytes($Text)
return [byte]31,[byte]($PosY+64),[byte]($PosX+64), $data1
}
function UpdateArboFileLink { param ($ArboFileName, $ArboLink, $ArboLinkValue)
write-host("UpdateArboFileKink() : ArboFileName="+$ArboFileName+" ArboLink="+ $ArboLink + " ArboLinkValue=" + $ArboLinkValue)
$temp=get-content -Path ($ArboFileName+".py") -Encoding UTF8 # Lire le noeud arbo correspondant pour mettre à jour son lien
$temp.Split("`r")
$newtemp=""
foreach ($templine in $temp) {
if ($templine.split("=")[0] -eq $ArboLink) {
$newtemp=$newtemp+ $ArboLink + "="+'"'+$TargetArboDir+"."+$ArboLinkValue+'"'+"`r"
}
else {
$newtemp=$newtemp+$templine+"`r"
}
}
$newtemp|Set-Content -Path ($ArboFileName+".py") -Encoding UTF8
}
function ReturnJustFile { param ($ArboName)
$JustFile=$ArboName.Split("\")
$JustFile=$JustFile[$JustFile.length-1]
return $JustFile
}
function ReturnTargetArboDir { param ($TargetArboDir)
#if ($TargetArboDir.length -gt 0) {
# $TargetArboDir=$TargetArboDir+"."
#}
return $TargetArboDir
}
function NewPage {
Param ( $CountPage, # Numéro de la page courante
$PrevIndex, # Début de la page courante
$CountByte, # Fin de la page courante
$PageComment, # Contenu initial VDT de la page commantaire
$PageBase, # Répertoire destination des pages VDT sur cette machine
$ArboBase # Répertoire destination des noeuds arbo sur cette machine
)
[hashtable]$return = @{}
$CountPage=$CountPage+1
#
# Get page contents
#
$Size=$CountByte - $PrevIndex
$PageContent = new-object byte[] $Size
$index=0
$warned127=$false
foreach ($byte in $PageContent) {
$PageContent[$index]=$MyContent[$index+$Previndex]
#write-host ($PageContent[$index])
if (($PageContent[$index] -gt 127) -and ($warned127 -eq $false)) {
$outputBox.lines += ("WARN : Byte>127 at index "+$index)
$warned127=$true
}
$index+=1
}
#
# Construction de la page commentaires
#
# Nom du fichier source
$MyFile=$SourceFile.name
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+0) ($MyFile) $CommentAttribs
# Date de la dernière modif du fichier source
$LastWrite=$FileDesc.LastWriteTime.ToShortDateString()
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+1) $LastWrite $CommentAttribs
# Numéro de page dans le fichier source
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+2) ([string]$Countpage) $CommentAttribs
# Début de la page dans le fichier source
$StartOffset=[System.Convert]::ToString($PrevIndex,16)
while ($StartOffset.length -lt 4) {
$StartOffset = "0"+$StartOffset
}
$StartOffset = "0x"+$StartOffset
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+3) $StartOffset $CommentAttribs
# Fin de la page dans le fichier source
$EndOffset=[System.Convert]::ToString($CountByte,16)
while ($EndOffset.length -lt 4) {
$EndOffset = "0"+$EndOffset
}
$EndOffset = "0x"+$EndOffset
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+4) $EndOffset $CommentAttribs
# Source de la page
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+5) $CommentSourceDeLaPage $CommentAttribs
# Auteur de la page
$PageComment+= PositionTextAttribs $CommentStartX ($CommentStartY+6) $CommentAuteurDeLaPage $CommentAttribs
# Commentaires dans les commentaires
$CountLine=0
foreach ($CommentLine in $CommentText.Split("|")) {
$PageComment+= PositionTextAttribs $CommentTextStartX ($CommentStartY+8+$CountLine) $CommentLine $CommentAttribs
$CountLine=$CountLine+1
}
$ArboName=$ArboBase+"-"+[string]$CountPage # ATTENTION le .py ne doit pas figurer dans le lien
if ($UpdatePrevNode -eq "") {
$ArboFirst=$ArboName
}
if ((($warned127 -eq $false) -or ($SkipWarn127 -eq $false)) -and ($Size -gt 0)){
#
# Ecriture des fichiers [noeud précédent, noeud actuel, page commentaire, page VDT]
#
if ($UpdatePrevNode -ne "") { # Si une précédente page a été générée
UpdateArboFileLink $UpdatePrevNode "TimerLink" (ReturnJustFile $ArboName)
}
#
# Sauvegarde du noeud arbo
#
#$JustFile=$PageBase.Split("\")
#$JustFile=$JustFile[$JustFile.length-1]
$NodeContent="# "+$ArboName+".py`r"
$NodeContent=$NodeContent+"# Autogenere le "+ (get-date) +"`r"
$NodeContent=$NodeContent+"# `r"
$NodeContent=$NodeContent+"PageDir="+'"'+$TargetPageDir+'"'+"`r"
$NodeContent=$NodeContent+"FirstFile=1`r"
if ($SkipComment) {
$NodeContent=$NodeContent+"LastFile=1`r"
} else
{ $NodeContent=$NodeContent+"LastFile=2`r"
}
#$NodeContent=$NodeContent+"PrefixFile="+'"'+($JustFile+"-"+[string]$CountPage+"-")+'"'+"`r"
$NodeContent=$NodeContent+"PrefixFile="+'"'+((ReturnJustFile $PageBase)+"-"+[string]$CountPage+"-")+'"'+"`r"
$NodeContent=$NodeContent+"PostfixFile="+'"'+$PostFix+'"'+"`r"
$NodeContent=$NodeContent+"GuideLink="+'"'+$TargetGuideLink+'"'+"`r"
$NodeContent=$NodeContent+"TimeoutLink="+'""'+"`r"
$NodeContent=$NodeContent+"TimerLink="+'""'+"`r"
# $JustFile=$UpdatePrevNode.Split("\")
#$NodeContent=$NodeContent+"RetourLink="+'"'+$JustFile[$JustFile.length-1]+'"'+"`r" # Ici, le chemin sera à vérifier
$NodeContent=$NodeContent+ "RetourLink="+'"'+ (ReturnTargetArboDir $TargetArboDir) + "."+ (ReturnJustFile $UpdatePrevNode) +'"'+"`r" # Ici, le chemin sera à vérifier
$NodeContent=$NodeContent+"ConstList=[]`r"
$NodeContent=$NodeContent+"VarList=[]`r"
$NodeContent=$NodeContent+"FieldList=["+$FieldList+"]`r"
$NodeContent=$NodeContent+"TimeoutLimit=240`r"
$temp=[Math]::Round([Math]::Ceiling($Size/$DisplaySpeed * 100) / 100, 2)+$TimerDelay
$temp=ReplaceChar ([string]$temp) "," "."
$NodeContent=$NodeContent+"TimerDelay="+$temp+"`r"
$NodeContent=$NodeContent+"Module="+'"module_menu"'+"`r"
$NodeContent|Set-Content -Path ($ArboName+".py") -Encoding UTF8
$UpdatePrevNode=$ArboName
#
# Sauvegarde de la page commentaire
#
if (!$SkipComment) {
$PageName=$PageBase+"-"+[string]$CountPage+"-1"+$PostFix
$PageComment | Set-Content -Path $PageName -Encoding byte
#Write-Host("Page:"+[string]$CountPage+" Size:"+[string]$Size+" Offset="+[System.Convert]::ToString($CountByte,16)+" "+$PageName)
}
#
# Sauvegarde de la page
#
if ($SkipComment) {
$PageName=$PageBase+"-"+[string]$CountPage+"-1"+$PostFix
}
else
{ $PageName=$PageBase+"-"+[string]$CountPage+"-2"+$PostFix
}
$PageContent | Set-Content -Path $PageName -Encoding byte
$outputBox.lines += ("File:"+[string]$CountFiles+" Page:"+[string]$CountPage+" Size:"+[string]$Size+" Offset="+[System.Convert]::ToString($CountByte,16)+" "+$PageName)
#
#
}
else
{ if ($size -gt 0) {
$outputBox.lines += ("WARN127 : Skipped page "+[string]$Countpage+" starting at offset "+$StartOffset)
}
$CountPage=$CountPage-1
}
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
$PrevIndex=$CountByte
$return.PrevNode = $UpdatePrevNode
$return.ArboFirst = $ArboFirst
$return.CountPage = $CountPage
$return.PrevIndex = $PrevIndex
$return.skipped = [bool]($warned127 -and $SkipWarn127)
return $return
}
function ClearAllSplit {
$Tab=0
#$IndexSplit=0
#Set-Variable -scope 1 -Name "IndexSplit" -Value (0)
while ($tab -lt $IndexSplitTab.Count) {
#Set-Variable -scope 1 -Name "IndexSplitTab[$Tab]" -Value (0)
$IndexSplitTab[$Tab]=0
$tab=$Tab+1
}
}
function TestInSplitTab {
param ( $byte )
[hashtable]$return = @{}
$Tab=0
$RetVal=$false
while (($tab -lt $IndexSplitTab.Count) -and ($RetVal -eq $false)){
#$RetVal=$byte -eq $SplitChar[$IndexSplit]
#$RetVal=$byte -eq $SplitTab[0][$IndexSplit]
#foreach ($t in $SplitTab) {Write-Host $t}
#foreach ($t in $indexSplitTab) {Write-Host $t}
#write-host $SplitTab[$Tab]
#write-host $SplitTab[$Tab][$IndexSplitTab[$Tab]]
#write-host $IndexSplitTab[$Tab]
$RetVal=$byte -eq $SplitTab[$Tab][$IndexSplitTab[$Tab]]
if ($RetVal) {
#$IndexSplit+=1
#Set-Variable -scope 1 -Name "IndexSplit" -Value ($IndexSplit + 1)
$z=$IndexSplitTab[$Tab]+1
#Set-Variable -scope 1 -Name "IndexSplitTab[$Tab]" -Value ($IndexSplitTab[$tab] + 1)
$IndexSplitTab[$Tab]=$IndexSplitTab[$Tab]+1
#write-host $IndexSplitTab[$Tab]
}
else
{
#$IndexSplit=0
#Set-Variable -scope 1 -Name "IndexSplitTab[$tab]" -Value (0)
$IndexSplitTab[$Tab]=0
}
$tab=$Tab+1
}
$return.Found = [bool]($RetVal)
#$return.SearchIndex = $IndexSplit
$return.SearchIndex = $IndexSplitTab[($Tab-1)]
#$return.SearchLen = $SplitChar.length
#$return.SearchLen = $SplitTab[0].length
$return.SearchLen = $SplitTab[($Tab-1)].length
return $return
}
function ReplaceChar {
param ($ArboBase, $Search, $Replace)
$temp=($arbobase.Split($Search))
$ArboBase=[system.String]::Join($Replace, $temp)
return $arbobase
}
function CreateDestDir { param ( $DestDir )
if (Test-Path -Path $DestDir -PathType Container) {
$outputBox.lines +="Le dossier '$DestDir' existe."
return $true
} else {
if (Test-Path -Path $DestDir) {
$outputBox.lines += "'$DestDir' est un fichier !"
return $false
} else {
if (New-Item -ItemType "directory" -Path $DestDir) {
$outputBox += "Le dossier '$DestDir' a été créé"
return $true
} else {
return $false
}
}
}
}
function CheckDestDir { param ()
$Result=$false
if (CreateDestDir($DestDir)) {
if (CreateDestDir($DestArboDir)) {
$Result=$true
}
}
return $Result
}
function SplitVDT { param ($outputBox)
# Init - Charger page commentaire (sans commentaires !)
if (!$SkipComment) {
if (Test-Path -Path $CommentPageName -PathType leaf) {
$MyCommentContent=get-content ($CommentPageName) -Encoding Byte -Raw
}
else {
$MyCommentContent=[byte]""
$outputBox.lines += "Problème avec '$CommentPageName' : n'est pas un fichier !"
}
}
# Tester / Créer DestDir + DestArboDir
if ((CheckDestDir) -eq $false) {
$outputBox.lines += "Problème avec '$DestDir' ou '$DestArboDir' !"
}
else {
# Effacer DestDir + DestArboDir
if ($EffacerFichiersAvant) {
Get-ChildItem $DestDir | Remove-Item
Get-ChildItem $DestArboDir | Remove-Item
$outputBox.lines += "'$DestDir' et '$DestArboDir' on été vidés"
}
# Balayer le dossier '$Sourcedir'
$outputBox.lines += ("Traitement de '$SourceDir' ...")
$SourceFiles=Get-ChildItem $SourceDir
$CountFiles=0
$TotalCountPages=0
$TotalCountSkipped=0
$UpdatePrevNode=""
foreach ($SourceFile in $SourceFiles) {
if ($sourcefile.PSIsContainer -eq $false) { #Test-Path -Path $ConfigFile -PathType Leaf) {
$CountFiles=$CountFiles+1
$PageBase=$DestDir+"\"+$SourceFile.Name
$ArboBase=$DestArboDir+"\"+$SourceFile.Name
$ArboBase=ReplaceChar $ArboBase "." "_"
$outputBox.lines += ("Découpage de la page '"+$SourceFile+"'")
$MyContent=get-content ($SourceFile) -Encoding Byte -Raw
$FileDesc=Get-Childitem ($SourceFile)
[int]$CountByte=0
[int]$CountPage=0
[int]$PrevIndex=0
[int]$CountSkipped=0
ClearAllSplit
foreach ($byte in $MyContent) {
#if ($byte -eq $SplitChar) {
$return=TestInSplitTab($byte)
if ($return.found) {
if ($return.SearchIndex -eq $return.SearchLen) {
$return =NewPage $CountPage $PrevIndex ($CountByte-$return.SearchLen+1) $MyCommentContent $PageBase $ArboBase
$UpdatePrevNode = $return.PrevNode
$ArboFirst=$return.ArboFirst
$CountPage = $return.CountPage
$PrevIndex = $return.PrevIndex
if ($return.skipped) {
$CountSkipped=$CountSkipped+1
}
}
}
$CountByte=$CountByte+1
}
if ($CountByte -ne $PrevIndex){
$return =NewPage $CountPage $PrevIndex $CountByte $MyCommentContent $PageBase $ArboBase
$UpdatePrevNode = $return.PrevNode
$ArboFirst=$return.ArboFirst
$CountPage = $return.CountPage
$PrevIndex = $return.PrevIndex
if ($return.skipped) {
$CountSkipped=$CountSkipped+1
}
}
$outputBoxlines += ( "Fichier '"+$SourceFile+"' découpé en "+[string]$CountPage+" pages (et "+$CountSkipped+" pages sautées).")
$TotalCountPages=$TotalCountPages+$CountPage
$TotalCountSkipped=$TotalCountSkipped+$CountSkipped
}
}
if ($ArboFirst -ne $UpdatePrevNode) {
write-host("ArboPrev="+$UpdatePrevNode)
write-host("ArboFirst="+$ArboFirst)
UpdateArboFileLink $ArboFirst "RetourLink" (ReturnJustFile $UpdatePrevNode)
UpdateArboFileLink $UpdatePrevNode "TimerLink" (ReturnJustFile $ArboFirst)
}
}
$outputBox.lines += ""
$outputBox.lines += ([string]$CountFiles+" fichiers traité(s) dans '"+$SourceDir+"'")
$outputBox.lines += ("... produisant "+[string]$TotalCountpages+" page(s) (et "+$TotalCountSkipped+" pages sautées).")
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
}
############################################## Start GUI functions
function StartButton {
if ($trace -eq $true) { write-host "StartButton()" }
if ($outputBox.lines.Count -gt 1) {
$outputBox.lines += ""
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
}
$Button.Text = "Traitement en cours"
$Button.Refresh()
SaveConfFromGUI
UpdateVarsFromConf
SplitVDT ($outputBox)
$Button.Text = "Démarrer"
if ($trace -eq $true) { write-host "StartButton() done" }
} #end pingInfo
function StartButton2 {
if ($trace -eq $true) { write-host "StartButton2()" }
SaveConfFromGUI
UpdateVarsFromConf
$ok=$false
if ($creds.GetType().name -eq "PSCredential") {
if ($creds.UserName -ne "") {
if ($trace -eq $true) { write-host("Déjà identifié") }
$ok=$true
}
}
if ($ok -eq $false) {
try {
$creds=Get-Credential
Set-Variable -scope script -Name "creds" -Value $creds
$ok=$true
}
catch {
$ok=$false
}
}
#write-host ("Openning session to RemoteHost ("+$RemoteHost+")")
#$SSHsession=New-SSHSession -ComputerName $RemoteHost -Credential ($creds) -force
#if ($SSHsession) {
if ($ok -eq $true) {
#$SSHsession=New-SSHSession -ComputerName $RemoteHost -Credential ($creds) -force
#
# Envoyer une commande à un Linux (et traiter le retour)
#
#$MyCommand="ls -1 -d "+$ServerArboRoot+"/"+$Service+"/"+$TargetArboDir+"/* -p|grep -v /$"
#"ls "+$ServerArboRoot+"/"+$Service+"/"+$TargetArboDir
#write-host("MyCommand ='"+$MyCommand+"'")
#$result=Invoke-SSHCommand -sshsession $SSHsession -command $MyCommand
#if ($result.ExitStatus -eq 0) {
# write-host("[Status OK for command ['"+ $MyCommand +"']")
#}
#else {
# write-host("[Status "+[string]$result.ExitStatus+" for command ['"+ $MyCommand +"']")
#}
#foreach ($file in $result.Output) {
# write-host($file)
#}
$Button2.Text = "Transfert en cours"
$Button2.Refresh()
#write-host($DestDir)
$outputBox.lines += ("User:"+([string]$creds.UserName))
$count=0
$counta=0
foreach ($file in Get-ChildItem $DestDir) {
if ($File.PSIsContainer -eq $false) {
#write-host ("Src:"+([string]$file.fullname))
#write-host ("Dst:"+$TargetPageDir+$file.name)
$outputBox.lines += ("Src:"+([string]$file.fullname))
$outputBox.lines += ("Dst:"+$TargetPageDir+$file.name)
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
$count=$count+1
try {
set-SCPItem -ComputerName $RemoteHost -Credential $creds -path ([string]$file.fullname) -destination ($TargetPageDir) #-newname ($file.name)
}
catch {
$outputBox.lines += ("Erreur ... mauvais user/password ?")
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
break
}
}
}
$outputBox.lines += ("")
# write-host($DestArboDir)
$temp=$ServerArboRoot + "/" + $Service+ "/"
if ($TargetArboDir.length -gt 0) {
$temp = $temp + (ReplaceChar $TargetArboDir "." "/")+"/"
}
foreach ($file in Get-ChildItem $DestArboDir) {
if ($File.PSIsContainer -eq $false) {
#write-host ("Src:"+([string]$file.fullname))
#write-host ("Dst:"+$temp + $file.name)
$outputBox.lines += ("Src:"+([string]$file.fullname))
$outputBox.lines += ("Dst:"+$temp + $file.name)
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
$counta=$counta+1
try {
set-SCPItem -ComputerName $RemoteHost -Credential $creds -path ($file.fullname) -destination ($temp) # -newname ($file.name)
}
catch {
$outputBox.lines += ("Erreur ... mauvais user/password ?")
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
break
}
}
}
$outputBox.lines += ("")
$outputBox.lines += ("Transféré "+[string]$count+" pages et "+[string]$counta+" noeuds arbo." )
$outputBox.lines += ("")
$outputBox.SelectionStart = $outputBox.Text.Length;
$outputBox.ScrollToCaret()
$outputBox.Refresh()
#
# Copier un fichier vers Linux
#
#set-SCPItem -ComputerName 192.168.168.40 -Credential $creds -path ".\config_SplitVDT.ini" -destination "/home/pi/python/mod_test" -NewName "testbla1.txt"
$Button2.Text = "Transférer"
#Remove-SSHSession $SSHsession
}
if ($trace -eq $true) { write-host "StartButton2() done" }
}
function StartButton3 {
try {
$creds=Get-Credential
Set-Variable -scope script -Name "creds" -Value $creds
}
catch {
write-host("Cancelled")
}
}
function GUI_getValues($formTitle, $textTitle){
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Script:userInput=""
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $formTitle
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$Script:userInput=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$Script:userInput=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CANCELButton = New-Object System.Windows.Forms.Button
$CANCELButton.Location = New-Object System.Drawing.Size(150,120)
$CANCELButton.Size = New-Object System.Drawing.Size(75,23)
$CANCELButton.Text = "CANCEL"
$CANCELButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CANCELButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,30)
$objLabel.Text = $textTitle
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,50)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
return $userInput
}
function GUI_popUp($text,$title) {
$a = new-object -comobject wscript.shell
$b = $a.popup($text,0,$title,0)
}
function Select_SourceDir {
if ($trace -eq $true) { write-host "Select_SourceDir"}
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ InitialDirectory = $SourceDir}#[Environment]::GetFolderPath('Desktop') }
$fileBrowser.Title = "Select_SourceDir"
$result = $FileBrowser.ShowDialog()
if ($result -eq [Windows.Forms.DialogResult]::OK){
#write-host("File="+$FileBrowser.FileName)
set-variable -name "SourceDir" -value ($FileBrowser.FileName) -scope script
UpdateGUI_FromVars
}
if ($trace -eq $true) { write-host "Select_SourceDir done"}
}
function Select_DestDir {
if ($trace -eq $true) { write-host "Select_DestDir" }
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.selectedpath = "."
$FolderBrowser.Description = "Select_DestDir"
$result = $FolderBrowser.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }))
if ($result -eq [Windows.Forms.DialogResult]::OK){
#write-host("Folder="+$FolderBrowser.SelectedPath)