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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
|
# $Id: idnconf.tcl,v 1.1.1.1 2003/06/04 00:27:42 marka Exp $
#
# idnconf.tcl - configure idn wrapper
#
#############################################################################
# Copyright (c) 2000,2002 Japan Network Information Center.
# All rights reserved.
#
# By using this file, you agree to the terms and conditions set forth bellow.
#
# LICENSE TERMS AND CONDITIONS
#
# The following License Terms and Conditions apply, unless a different
# license is obtained from Japan Network Information Center ("JPNIC"),
# a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
# Chiyoda-ku, Tokyo 101-0047, Japan.
#
# 1. Use, Modification and Redistribution (including distribution of any
# modified or derived work) in source and/or binary forms is permitted
# under this License Terms and Conditions.
#
# 2. Redistribution of source code must retain the copyright notices as they
# appear in each source code file, this License Terms and Conditions.
#
# 3. Redistribution in binary form must reproduce the Copyright Notice,
# this License Terms and Conditions, in the documentation and/or other
# materials provided with the distribution. For the purposes of binary
# distribution the "Copyright Notice" refers to the following language:
# "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
#
# 4. The name of JPNIC may not be used to endorse or promote products
# derived from this Software without specific prior written approval of
# JPNIC.
#
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#############################################################################
global configFile configBack
global registryKey registryEnc registryDef
global filesCpy filesRen filesDel
# idnkit version
set version "1.0"
set configFile "idnconf.lst" ;# list of wrapped program
set configBack "idnconf.bak" ;# backup of previous data
set serverKey "HKEY_LOCAL_MACHINE\\Software\\JPNIC\\IDN"
set serverLogLevel LogLevel
set serverLogLevelDef -1
set serverLogLevelNone -1
set serverLogFile LogFile
set serverLogFileDef {C:\idn_wrapper.log}
set serverConfFile ConfFile
set perprogKey "HKEY_LOCAL_MACHINE\\Software\\JPNIC\\IDN\\PerProg\\"
set perprogEnc Encoding
set perprogDef Default
set logFileNameDef idn_wrapper.log
set confFileNameDef idn.conf
set filesCpy11 { "wsock32.dll" }
set filesCpy20 { "wsock32.dll" "ws2_32.dll" }
set filesDel11 { "wsock32.dll" }
set filesDel20 { "wsock32.dll" "ws2_32.dll" }
set local_dll 0
########################################################################
#
# OS version check
#
proc get_os_version {} {
global os_version tcl_platform
if {[llength [info globals os_version]] > 0} {
return $os_version
}
switch -- $tcl_platform(os) {
"Windows 95" {
switch -- $tcl_platform(osVersion) {
4.0 {
set os_version {Windows 95}
}
4.10 {
set os_version {Windows 98}
}
4.90 {
set os_version {Windows Me}
}
}
}
"Windows NT" {
switch -- $tcl_platform(osVersion) {
3.51 -
4.0 {
set os_version {Windows NT}
}
5.0 {
set os_version {Windows 2000}
}
default {
# XP or .NET
set os_version {Windows XP}
}
}
}
"Win32s" {
error "idn wrapper does not support Windows 3.1"
}
default {
set os_version "Unknown"
}
}
set os_version
}
proc support_dll_redirection {} {
global dll_redirection
if {[llength [info globals dll_redirection]] > 0} {
return $dll_redirection
}
switch -- [get_os_version] {
{Windows 95} -
{Windows NT} {
# cannot force local DLL reference by .local file.
set dll_redirection 0
}
default {
set dll_redirection 1
}
}
set dll_redirection
}
########################################################################
#
# handling pathname
#
proc getExeName { prg } {
set elem [file split $prg]
set leng [expr {[llength $elem] - 1}]
set name [lindex $elem $leng]
set exe [file rootname $name]
return $exe
}
proc getDirName { prg } {
file dirname $prg
}
proc getSystemDir {} {
global env
switch -- [get_os_version] {
"Windows 95" -
"Windows 98" -
"Windows Me" {
set sysDir $env(windir)/system
}
default {
set sysDir $env(SystemRoot)/system32
}
}
return $sysDir
}
########################################################################
#
# loadList / saveList
#
# loadList - load list of wrapped executables from $configFile
# saveList - save list of wrapped executables into $configFile
#
proc loadList {} {
global configFile configBack
if { [file exists $configFile] } {
file copy -force $configFile $configBack
}
set aList {}
set fd [open $configFile {CREAT RDONLY}]
while { ! [eof $fd]} {
set line [gets $fd]
if { [string length $line] > 0} {
lappend aList "$line"
}
}
close $fd
return $aList
}
proc saveList { aList } {
global configFile
file delete -force $configFile
set fd [open $configFile {CREAT WRONLY}]
foreach e $aList {
puts $fd $e
}
close $fd
}
########################################################################
#
# putList / getList - set/get list to/from listbox
#
proc putList { lb aList } {
foreach e $aList {
$lb insert end $e
}
}
proc getList { lb } {
$lb get 0 end
}
########################################################################
#
# checkList / appendList / deleteList - check / append / delete program from/to listbox
#
proc checkList { lb prg } {
set cnt 0
set lst [getList $lb]
foreach n $lst {
if { [string compare $prg $n] == 0 } {
incr cnt
}
}
return $cnt
}
proc appendList { lb prg } {
if { [checkList $lb $prg] == 0 } {
$lb insert end $prg
}
}
proc deleteList { lb prg } {
set cnt 0
set lst [getList $lb]
foreach n $lst {
if { [string compare $n $prg] == 0 } {
$lb delete $cnt
}
incr cnt
}
}
########################################################################
#
# registry operations
#
proc regGetEncode { prg } {
global perprogKey perprogEnc perprogDef
if { [string compare $prg "" ] == 0 } {
return $perprogDef
}
if {![isWindows]} {
return $perprogDef
}
package require registry 1.0
set name [getExeName $prg]
set key $perprogKey$name
if { [catch {set enc [registry get $key $perprogEnc]} err] } {
return $perprogDef
}
if { [string compare $enc ""] == 0 } {
return $perprogDef
}
return $enc
}
proc regSetEncode { prg enc } {
global perprogKey perprogEnc perprogDef
if {![isWindows]} {
return 1
}
package require registry 1.0
set name [getExeName $prg]
set key $perprogKey$name
if { [string compare $enc $perprogDef] == 0 } {
set enc ""
}
if { [catch {registry set $key $perprogEnc $enc sz} ] } {
return 2
}
return 0
}
proc regGetLogLevel {} {
global serverKey serverLogLevel serverLogLevelDef
regGetValue $serverKey $serverLogLevel $serverLogLevelDef
}
proc regSetLogLevel {level} {
global serverKey serverLogLevel
regSetValue $serverKey $serverLogLevel $level dword
}
proc regGetLogFile {} {
global serverKey serverLogFile serverLogFileDef
set file [regGetValue $serverKey $serverLogFile $serverLogFileDef]
if {[catch {file attributes $file -longname} lfile]} {
# Maybe $file doesn't exist (yet). Get the longname of
# directory portion.
set dir [file dirname $file]
if {[catch {file attributes $dir -longname} ldir]} {
set ldir $dir
}
set lfile [file join $ldir [file tail $file]]
}
file nativename $lfile
}
proc regSetLogFile {file} {
global serverKey serverLogFile
regSetValue $serverKey $serverLogFile [file nativename $file]
}
proc regGetConfFile {} {
global serverKey serverConfFile
set file [regGetValue $serverKey $serverConfFile {}]
if {[string compare $file {}] == 0} {
return {}
}
if {[catch {file attributes $file -longname} lfile]} {
# Maybe $file doesn't exist (yet). Get the longname of
# directory portion.
set dir [file dirname $file]
if {[catch {file attributes $dir -longname} ldir]} {
set ldir $dir
}
set lfile [file join $ldir [file tail $file]]
}
file nativename $lfile
}
proc regSetConfFile {file} {
global serverKey serverConfFile
regSetValue $serverKey $serverConfFile [file nativename $file]
}
proc regGetWhere {} {
global serverKey
regGetValue $serverKey Where 0
}
proc regSetWhere {where} {
global serverKey
regSetValue $serverKey Where $where dword
}
proc regGetValue {key name default} {
if {![isWindows]} {
puts "--regGetValue $key $name"
return $default
}
package require registry 1.0
if {[catch {registry get $key $name} value]} {
return $default
}
if {[string compare $value {}] == 0} {
return $default
}
return $value
}
proc regSetValue {key name value {type sz}} {
if {![isWindows]} {
puts "--regSetValue $key $name $value"
return 1
}
package require registry 1.0
if {[catch {registry set $key $name $value $type}]} {
return 2
}
return 0
}
########################################################################
#
# install / uninstall DLL s
#
proc fileInstall { prg } {
global env
global filesCpy11 filesCpy20
if {![isWindows]} {
return 1
}
switch -- [get_os_version] {
"Windows 95" -
"Windows 98" -
"Windows Me" {
set winDir $env(windir)
set sysDir $winDir/system
set filesCpy $filesCpy11
}
default {
set winDir $env(SystemRoot)
set sysDir $winDir/system32
set filesCpy $filesCpy20
}
}
set toDir [getDirName $prg ]
foreach n $filesCpy {
file copy -force $n $toDir
}
return 0
}
proc fileRemove { prg } {
global filesDel11 filesDel20
if {![isWindows]} {
return 1
}
switch -- [get_os_version] {
"Windows 95" {
set filesDel $filesDel11
}
"Windows 98" -
"Windows Me" {
set filesDel $filesDel20
}
default {
set filesDel $filesDel20
}
}
set fromDir [getDirName $prg ]
foreach n $filesDel {
file delete -force $fromDir/$n
}
return 0
}
########################################################################
#
# Wrap/Unwrap program
#
proc execWrap { pw lb dlg prg enc } {
set prgName [$prg get]
set encName [$enc get]
# Make sure the program name is not empty
if {[string compare $prgName {}] == 0} {
confErrorDialog $dlg "Program must be specified.\nClick \"Browse..\" button for browsing."
return
}
# It is dangerous to wrap programs in the system directory.
set prgdir [file nativename [getDirName $prgName]]
set sysdir [file nativename [getSystemDir]]
if {[string compare -nocase $prgdir $sysdir] == 0} {
tk_messageBox -icon error -type ok -title "Directory Error" \
-parent $dlg \
-message "Cannot wrap applications in the system directory.\nPlease copy the EXE file to elsewhere and wrap the copied one."
destroy $dlg
return 1
}
# Okay, copy the wrapper DLLs.
if { [fileInstall $prgName] } {
tk_messageBox -icon warning -type ok \
-title "Warning" \
-message "Cannot install DLLs" \
-parent $dlg
destroy $dlg
return 1
}
if { [regSetEncode $prgName $encName] } {
tk_messageBox -icon warning -type ok \
-title "Warning" \
-message "Cannot set encoding" \
-parent $dlg
fileRemove $prgName
destroy $dlg
return 2
}
# if local flag is on, create $prgName.local.
global local_dll
if {$local_dll} {
create_dot_local $prgName $dlg
} else {
remove_dot_local $prgName $dlg
}
if { [checkList $lb $prgName] == 0 } {
appendList $lb $prgName
}
saveList [getList $lb]
destroy $dlg
}
proc execUnwrap { pw lb dlg prg } {
set prgName [$prg get]
if {[support_dll_redirection] && [file exists $prgName.local]} {
set ans [tk_messageBox -icon question -type yesno \
-title "Confirmation" \
-message "Also remove $prgName.local file?" \
-parent $dlg]
if {[string compare $ans yes] == 0} {
remove_dot_local $prgName $dlg
}
}
if { [checkList $lb $prgName] == 1 } {
fileRemove $prgName
}
deleteList $lb $prgName
saveList [getList $lb]
destroy $dlg
}
proc create_dot_local {path {parent .}} {
set dotlocal $path.local
if {[file exists $dotlocal]} {
return 0
}
if {[catch {open $dotlocal w} fh]} {
tk_messageBox -icon warning -type ok -title "Warning" \
-message "Cannot create $dotlocal" -parent $parent
return -1
}
close $fh
return 0
}
proc remove_dot_local {path {parent .}} {
set dotlocal $path.local
if {[file exists $dotlocal] && [catch {file delete $dotlocal}]} {
tk_messageBox -icon warning -type ok -title "Warning" \
-message "Cannot remove $dotlocal" -parent $parent
return -1
}
return 0
}
########################################################################
#
# dialog for Wrap / Unwrap
#
proc syncEncode { v i op } {
global prgName encName
set enc [regGetEncode $prgName]
if { [string compare $encName $enc] != 0 } {
set encName $enc
}
}
proc confBrowse { p ePrg eEnc } {
set types {
{ "Executable" .exe }
}
set file [tk_getOpenFile -filetypes $types -parent $p ]
if { [string compare $file ""] == 0 } {
return
}
set enc [regGetEncode $file]
$ePrg delete 0 end
$ePrg insert 0 $file
}
proc confWrap { pw lb } {
global prgName encName local_dll
set idx [$lb curselection]
if { [llength $idx] == 1 } {
set prg [$lb get $idx]
set local_dll [file exists $prg.local]
} else {
set prg ""
}
set top .wrap
toplevel $top
grab $top
wm title $top "idn wrapper - Wrap Executable"
frame $top.f1 -bd 1 -relief raised
frame $top.f2 -bd 1 -relief raised
pack $top.f1 -side top -fill x -expand on
pack $top.f2 -side top -fill x -expand on
frame $top.f1.f
pack $top.f1.f -fill both -expand on -padx 4 -pady 4
set w $top.f1.f
label $w.prgtitle -text "Program:"
label $w.enctitle -text "Encoding:"
entry $w.prgname -relief sunken -width 56 -textvariable prgName
entry $w.encname -relief sunken -width 8 -textvariable encName
set w_prgname $w.prgname
set w_encname $w.encname
button $w.browse -text "Browse.." \
-command [list confBrowse $w $w_prgname $w_encname]
frame $w.rbf
radiobutton $w.rbf.encdef -text "Default" -variable encName \
-value "Default"
radiobutton $w.rbf.encutf -text "UTF-8" -variable encName \
-value "UTF-8"
pack $w.rbf.encdef $w.rbf.encutf -side left -padx 4
grid $w.prgtitle -row 0 -column 0 -sticky e
grid $w.enctitle -row 1 -column 0 -sticky e
grid $w.prgname -row 0 -column 1 -sticky we -pady 4 -padx 2 -columnspan 2
grid $w.browse -row 0 -column 3 -sticky w -pady 4 -padx 4
grid $w.encname -row 1 -column 1 -sticky we -pady 4 -padx 2
grid $w.rbf -row 1 -column 2 -sticky w -padx 2
if {[support_dll_redirection]} {
checkbutton $w.local -text "Force local DLL reference" \
-variable local_dll
grid $w.local -row 2 -column 1 -sticky w -padx 4 -pady 4
}
grid columnconfig $w 1 -weight 1 -minsize 20
grid columnconfig $w 2 -weight 2 -minsize 20
trace variable prgName w syncEncode
$w.prgname delete 0 end
$w.prgname insert 0 $prg
focus $w.prgname
set w $top.f2
button $w.wrap -text "Wrap" \
-command [list execWrap $pw $lb $top $w_prgname $w_encname]
button $w.cancel -text "Cancel" \
-command [list destroy $top]
pack $w.cancel -side right -fill y -padx 12 -pady 4
pack $w.wrap -side right -fill y -padx 12 -pady 4
tkwait window $top
}
proc confUnwrap { pw lb } {
set idx [$lb curselection]
if { [llength $idx] != 1 } {
tk_messageBox -icon warning -type ok \
-title "Warning" \
-message "first, select unwrapping executable" \
-parent $pw
return 0
}
set prg [$lb get $idx]
if { [string length $prg] == 0 } {
tk_messageBox -icon warning -type ok \
-title "Warning" \
-message "first, select unwrapping executable" \
-parent $pw
return 0
}
set top .unwrap
toplevel $top
grab $top
wm title $top "idn wrapper - Unwrap Executable"
frame $top.f1 -bd 1 -relief raised
frame $top.f2 -bd 1 -relief raised
pack $top.f2 -side bottom -fill x
pack $top.f1 -side bottom -fill x -expand on
frame $top.f1.f
pack $top.f1.f -padx 4 -pady 4 -fill both -expand on
set w $top.f1.f
label $w.prgtitle -text "Program:"
entry $w.prgname -relief sunken -width 56 -textvariable prgName
$w.prgname delete 0 end
$w.prgname insert 0 $prg
set w_prgname $w.prgname
grid $w.prgtitle -row 0 -column 0 -sticky w
grid $w.prgname -row 0 -column 1 -sticky we -pady 4
grid columnconfig $w 1 -weight 1 -minsize 20
set w $top.f2
button $w.wrap -text "Unwrap" \
-command [list execUnwrap $pw $lb $top $w_prgname]
button $w.cancel -text "Cancel" \
-command [list destroy $top]
pack $w.cancel -side right -padx 12 -pady 6
pack $w.wrap -side right -padx 12 -pady 6
focus $w.wrap
tkwait window $top
}
proc unwrapAll {pw lb} {
set ans [tk_messageBox -type yesno -default no -icon question \
-parent $pw -title {idn wrapper Configuration} \
-message {Really unwrap all programs?}]
if {[string compare $ans yes] != 0} {
return
}
foreach prog [$lb get 0 end] {
fileRemove $prog
}
if {[support_dll_redirection]} {
set delete_type yes
foreach prog [$lb get 0 end] {
if {![file exists $prog.local]} continue
switch -- $delete_type {
yes -
no {
set delete_type [dotLocalDialog $prog $delete_type]
}
}
switch -- $delete_type {
yes -
yesall {
remove_dot_local $prog $pw
}
}
}
}
$lb delete 0 end
saveList {}
}
proc rewrapAll {pw lb} {
set ans [tk_messageBox -type yesno -default yes -icon question \
-parent $pw -title {idn wrapper Configuration} \
-message {Really rewrap all programs?}]
if {[string compare $ans yes] != 0} {
return
}
foreach prog [$lb get 0 end] {
fileInstall $prog
}
}
proc confLog {pw} {
global _logLevel _logFile
set top .log
catch {destroy $top}
toplevel $top
wm title $top "idn wrapper - Log Configuration"
# wm transient $top $pw
set _logLevel [regGetLogLevel]
set _logFile [regGetLogFile]
frame $top.f1 -bd 1 -relief raised
frame $top.f2 -bd 1 -relief raised
pack $top.f2 -side bottom -fill x
pack $top.f1 -side top -fill both -expand on
set w $top.f1
label $w.lv_l -text "Log Level:"
frame $w.lv_v
global serverLogLevelNone
set i 0
foreach {lvl text} [list $serverLogLevelNone None \
0 Fatal 1 Error 2 Warning 3 Info 4 Trace] {
radiobutton $w.lv_v.btn$i -text $text -value $lvl -variable _logLevel
pack $w.lv_v.btn$i -side left -padx 3
incr i
}
label $w.ld_l -text "Log File:"
frame $w.ld_v
entry $w.ld_v.e -width 40 -textvariable _logFile
focus $w.ld_v.e
button $w.ld_v.b -text "Browse.." -command [list selectLog $top $w.ld_v.e]
pack $w.ld_v.b -side right -fill y -padx 6
pack $w.ld_v.e -side left -fill both -expand yes
#label $w.lo_l -text "Log Operation:"
frame $w.lo_v
button $w.lo_v.show -text "View" -command [list showLog $top]
button $w.lo_v.delete -text "Delete" -command [list deleteLog $top]
pack $w.lo_v.show $w.lo_v.delete -side left -padx 4
grid $w.lv_l -row 0 -column 0 -sticky e -padx 4
grid $w.ld_l -row 1 -column 0 -sticky e -padx 4
#grid $w.lo_l -row 2 -column 0 -sticky e -padx 4
grid $w.lv_v -row 0 -column 1 -sticky w -padx 4 -pady 4
grid $w.ld_v -row 1 -column 1 -sticky we -padx 4 -pady 4
grid $w.lo_v -row 2 -column 1 -sticky w -padx 4 -pady 4
set w $top.f2
button $w.ok -text "OK" -command [list configureLog $top]
button $w.cancel -text "Cancel" -command [list destroy $top]
pack $w.cancel -side right -padx 12 -pady 6
pack $w.ok -side right -padx 12 -pady 6
}
proc configureLog {top} {
global _logLevel _logFile
if {$_logLevel != [regGetLogLevel] ||
[string compare $_logFile [regGetLogFile]] != 0} {
set dir [file dirname $_logFile]
if {[string compare $dir {}]} {
if {![file exists $dir]} {
confErrorDialog $top "Directory $dir doesn't exist"
return
} elseif {![file isdirectory $dir]} {
confErrorDialog $top "$dir is not a directory"
return
}
}
regSetLogLevel $_logLevel
regSetLogFile $_logFile
tk_messageBox -type ok -default ok -icon info -parent $top \
-title "idn wrapper Configuration" \
-message "Changing log level or file does not affect already running processes."
}
destroy $top
}
proc selectLog {top e} {
global logFileNameDef
set file [tk_getSaveFile -title {idn wrapper Logfile Selection} \
-defaultextension .log \
-filetypes {{{Log Files} .log} {{All Files} *}} \
-initialfile $logFileNameDef \
-parent $top]
if {[string compare $file {}]} {
$e delete 0 end
$e insert insert $file
}
}
proc showLog {top} {
global _logFile
if {[catch {exec notepad.exe $_logFile &} r]} {
confErrorDialog $top "Cannot execute notepad"
}
}
proc deleteLog {top} {
global _logFile
set ans [tk_messageBox -type yesno -default no -icon question \
-parent $top -title "idn wrapper Configuration" \
-message "Really delete $_logFile?"]
if {[string compare $ans yes] == 0} {
file delete $_logFile
}
}
########################################################################
#
# dialog for .local deletion
#
proc dotLocalDialog {path {default yes}} {
set parent .
set dlg .dotlocaldlg
catch {destroy $dlg}
toplevel $dlg
wm iconname $dlg Dialog
wm title $dlg Confirmation
wm transient $dlg $parent
wm protocol $dlg WM_DELETE_WINDOW {}
frame $dlg.f1 -bd 1 -relief raised
frame $dlg.f2 -bd 1 -relief raised
pack $dlg.f1 -side top -fill x -expand on -ipadx 2m -ipady 4m
pack $dlg.f2 -side top -fill x -ipadx 2m
label $dlg.f1.bm -bitmap question -bd 0
label $dlg.f1.msg -text "Remove $path.local?" -wraplength 10c
pack $dlg.f1.bm -side left -padx 3m -pady 2m
pack $dlg.f1.msg -side left -padx 2m -pady 2m
global dotlocal_selection
foreach {btn lbl} {yes Yes no No yesall {Yes to All} noall {No to All}} {
set bw $dlg.f2.btn$btn
button $bw -text $lbl -default normal \
-command [list set dotlocal_selection $btn]
if {[string compare $default $btn] == 0} {
$bw configure -default active
focus $bw
}
bind $bw <Return> {%W flash; %W invoke}
pack $bw -side left -padx 3m -pady 2m
}
grab $dlg
::tk::PlaceWindow $dlg widget $parent
vwait dotlocal_selection
destroy $dlg
return $dotlocal_selection
}
########################################################################
#
# dialog for advanced configuration
#
proc advancedConf {pw} {
set top .adv
catch {destroy $top}
toplevel $top
wm title $top "idn wrapper - Advanced Configuration"
global _mdnOperation _confFile
set _mdnOperation [regGetWhere]
set _confFile [regGetConfFile]
foreach f {f1 f2 f3} {
frame $top.$f -bd 1 -relief raised
pack $top.$f -side top -fill x
}
set f $top.f1
label $f.lbl -text {IDN Wrapping Mode}
set w $f.f
frame $w
foreach {rb val txt} [list \
rb1 0 {Wrap both WINSOCK 1.1 and WINSOCK 2.0} \
rb2 2 {Wrap only WINSOCK 1.1} \
rb3 3 {Wrap only WINSOCK 2.0} \
rb4 1 "Wrap only WINSOCK2.0 if it exists.\nOtherwise wrap only WINSOCK1.1"] {
radiobutton $w.$rb -text $txt -variable _mdnOperation -value $val \
-anchor w -justify left
pack $w.$rb -side top -fill x -pady 1
}
pack $f.lbl -side top -fill x -pady 4
pack $w -side top -fill both -padx 20 -pady 10
set f $top.f2
label $f.lbl -text {IDN Configuration}
pack $f.lbl -side top -fill x -pady 6
set w $f.f
frame $w
pack $w -side top -fill both -padx 10 -pady 6
label $w.l1 -text {Config File:}
#label $w.l2 -text {Config Operation:}
entry $w.e -width 40 -textvariable _confFile
focus $w.e
button $w.br -text "Browse.." -command [list selectConf $top $w.e]
button $w.b -text Edit -command [list editConf $top]
grid $w.l1 -row 0 -column 0 -sticky e -padx 4
#grid $w.l2 -row 1 -column 0 -sticky e -padx 4
grid $w.e -row 0 -column 1 -sticky we -padx 4 -pady 4
grid $w.b -row 1 -column 1 -sticky w -padx 4 -pady 4
grid $w.br -row 0 -column 2 -sticky w -padx 4 -pady 4
set w $top.f3
button $w.ok -text "OK" -command [list advConf $top]
button $w.cancel -text "Cancel" -command [list destroy $top]
pack $w.cancel -side right -padx 12 -pady 8
pack $w.ok -side right -padx 12 -pady 8
}
proc editConf {top} {
global _confFile
if {[catch {exec notepad.exe $_confFile &} r]} {
confErrorDialog $top "Cannot execute notepad"
}
}
proc selectConf {top e} {
global confFileNameDef
set file [tk_getOpenFile -title {idn wrapper Config File Selection} \
-defaultextension .conf \
-filetypes {{{Config Files} .conf} {{All Files} *}} \
-initialfile $confFileNameDef \
-parent $top]
if {[string compare $file {}]} {
$e delete 0 end
$e insert insert $file
}
}
proc advConf {top} {
global _mdnOperation _confFile
regSetWhere $_mdnOperation
regSetConfFile $_confFile
destroy $top
}
########################################################################
#
# utility
#
proc confErrorDialog {top message} {
tk_messageBox -default ok -icon error -parent $top -type ok \
-title {idn wrapper Configuration Error} -message $message
}
proc isWindows {} {
global tcl_platform
expr {[string compare $tcl_platform(platform) "windows"] == 0}
}
########################################################################
#
# config program start here
#
wm title . "idn wrapper - Configuration"
wm iconname . "idn wrapper - Configuration"
label .title -bd 1 -relief raised -pady 5 \
-text "idn wrapper Configuration Program version $version"
frame .left -bd 1 -relief raised
frame .right -bd 1 -relief raised
frame .lst
label .lst.title -text "Wrapped Programs" -pady 3
listbox .lst.list -width 64 -height 16 -setgrid 1 \
-xscrollcommand ".lst.xscroll set" \
-yscrollcommand ".lst.yscroll set"
scrollbar .lst.yscroll -orient vertical -command ".lst.list yview"
scrollbar .lst.xscroll -orient horizontal -command ".lst.list xview"
grid .lst.title -row 0 -column 0 -columnspan 2 -sticky news
grid .lst.list -row 1 -column 0 -sticky news
grid .lst.xscroll -row 2 -column 0 -sticky news
grid .lst.yscroll -row 1 -column 1 -sticky news
grid rowconfig .lst 1 -weight 1
grid columnconfig .lst 0 -weight 1
frame .btn
button .btn.wrap -text "Wrap.." -command [list confWrap . .lst.list]
button .btn.unwrap -text "Unwrap.." -command [list confUnwrap . .lst.list]
button .btn.unwrapall -text "Unwrap All" -command [list unwrapAll . .lst.list]
button .btn.rewrapall -text "Rewrap All" -command [list rewrapAll . .lst.list]
frame .btn.spacing1 -width 1 -height 12 -bd 0
button .btn.log -text "Log.." -command [list confLog .]
frame .btn.spacing2 -width 1 -height 12 -bd 0
button .btn.adv -text "Advanced.." -command [list advancedConf .]
button .btn.exit -text Exit -command exit
pack .btn.wrap -side top -fill x -pady 4
pack .btn.unwrap -side top -fill x -pady 4
pack .btn.unwrapall -side top -fill x -pady 4
pack .btn.rewrapall -side top -fill x -pady 4
pack .btn.spacing1 -side top
pack .btn.log -side top -fill x -pady 4
pack .btn.spacing2 -side top
pack .btn.adv -side top -fill x -pady 4
pack .btn.exit -side bottom -fill x -pady 4
pack .lst -in .left -padx 4 -pady 4 -fill both -expand on
pack .btn -in .right -padx 6 -pady 4 -fill both -expand on
pack .title -side top -fill x
pack .right -side right -fill y
pack .left -side left -fill y -expand on
#
# then set current list into listbox
#
set theList [loadList]
#saveList $theList
putList .lst.list $theList
#
########################################################################
|