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
|
#!/usr/bin/env perl
# For testing, edit $ro_dir and $luaprog as needed;
# $ro_dir should be a read-only directory and
# $luaprog should be a working lua executable but not texlua.
# Under Unix/Linux, just test whether loading of win32 modules is skipped.
use strict;
BEGIN {
$^W = 1;
my $me=$0;
$me=~s!\\!/!g if $^O=~/^MSWin(32|64)$/i;
if ($me=~m!/!) {
# wingoo-demo now in a subsubdirectory:
($::installerdir=$me)=~s!(.*)/[^/]+/[^/]+/[^/]*$!$1!;
} else {
# This shouldn't occur if called from batchfile
$::installerdir='./../..';
}
@INC = ("$::installerdir/tlpkg/installer/perllib") if ($^O=~/^MSWin(32|64)$/i);
unshift (@INC, "$::installerdir/tlpkg");
}
use TeXLive::TLUtils qw( get_system_tmpdir );
use TeXLive::TLWinGoo qw(
win_version
is_vista
admin
non_admin
admin_again
dir_writable
reg_country
get_system_path
get_user_path
get_system_env
get_user_env
expand_string
win_which_dir
global_tmpdir
add_texbindir_to_path
remove_texbindirs_from_path
setenv_reg
unsetenv_reg
register_script_type
unregister_script_type
broadcast_env
update_assocs
wg_error
); # safe under Unix/Linux!
my $ro_dir = "z:/aps";
my $luadir = "x:/utils0";
my $luaprog;
my $pathsave = $ENV{'PATH'};
my $pathextsave = $ENV{'PATHEXT'};
$::LOGLEVELTERMINAL=$::LOG_DDDEBUG;
$::LOGLEVELFILE=$::LOG_ZERO;
#sub pathnew {
# my $p = expand_string(get_system_path()).';'.
# expand_string(get_user_path());
# $p =~ s!/!\\!g;
# return $p;
#}
#sub getenvnew {
# # only use this for REG_SZ values!
# my $env_var = shift;
# return TeXLive::TLWinGoo::get_user_env()->{$env_var} or
# TeXLive::TLWinGoo::get_system_env()->{$env_var} or "";
# #my $env_data = TeXLive::TLWinGoo::get_user_env()->{$env_var};
# #if (not $env_data) {
# # $env_data = TeXLive::TLWinGoo::get_system_env()->{$env_var};
# #}
# #if (not $env_data) { $env_data = ""; }
# #return $env_data;
#}
sub pause {
my $mess = shift;
print( $mess."\nType any key..." );
read STDIN,my $dummy, 1;
}
sub run_and_pause {
my $command = shift;
#my $setenv = "set PATH=".pathnew().
# " & set TEXBINDIR=".getenvnew('TEXBINDIR').
# " & set PATHEXT=".getenvnew('PATHEXT');
#my $cmd_prompt = expand_string ($ENV{'COMSPEC'});
#system ($cmd_prompt . ' /C "'.$setenv.' & '.$command.' & pause"');
print "Type $command in a new command prompt\n";
read STDIN,my $dummy, 1;
}
sub maybenot {
my $bool = shift;
return $bool ? " is " : " is not ";
}
# two uses:
# - is the parent directory writable?
# - is the script interpreted by lua or by texlua?
sub create_file {
my $name = shift;
return 1 if -e $name;
return 0 unless open DUMMY, ">".$name;
print DUMMY 's = tostring(0.0000001)'."\n"; # lua: 1e-7; texlua: 0
print DUMMY 'print("0.0000001 becomes " .. s)'."\n";
close DUMMY;
return 1;
}
sub print_search_paths {
print "System path: ".get_system_path()."\n";
print "User path: ".get_user_path()."\n";
}
sub print_lua_out {
my $luatest = expand_string( $ENV{'TEMP'} ) . "/testlua";
my $luatestlua = $luatest . ".texlua";
unlink $luatestlua if -e $luatestlua;
create_file( $luatestlua );
#$ENV{'PATH'} = expand_string($pathsave) . ";" . $ENV{'TEMP'};
#my $usersave = get_user_path();
#$userpath = ($usersave ? "$usersave;" .
#run_and_pause ('testlua');
$luatest =~ s!/!\\!g;
#run_and_pause ("set PATHEXT=%PATHEXT%;.TEXLUA & set TEXBINDIR=".$luatest);
run_and_pause ($luatest);
#print "Lua[tex] result: ".`testlua`."\n";
#$ENV{'PATH'} = $pathsave;
unlink $luatestlua;
}
sub print_assoc_cmd {
my $ext = shift;
my $cmdout = `assoc $ext`;
chomp $cmdout if $cmdout;
if (!$cmdout) { print "Extension unknown says assoc\n"; return; }
my $ftype = $cmdout;
$ftype =~ s/.*=//;
if (!$ftype) { print "Extension unknown says assoc\n"; return; }
$cmdout = `ftype $ftype`;
if (!$cmdout) { print "Filetype unknown says ftype\n"; return; }
$cmdout =~ s/.*=//;
print( $ext.' command is: '.$cmdout." says ftype\n" );
}
### end of subs ###
my $real_admin = admin();
print( "\nGENERAL; ALSO UNIX\n" );
print ( "\nINC\n" . (join "\n", @INC) . "\n\n");
# admin
if (admin()) {
print "Admin or not_on_Windows\n";
} else {
print "Not admin\n";
}
# global_tmpdir
print "\nGlobal tempdir: " . global_tmpdir()."\n";
# Windows version
print "Windows version: ".win_version()."\n";
print maybenot(is_vista()). " Vista\n";
if ($^O !~ /^MSWin(32|64)$/i) {
print "Not Windows; bailing out...\n";
exit;
}
### end of non-windows
#my @winversion = Win32::GetOSVersion();
#print "Windows version: " . $winversion[1] . "\n";
# country
print "\n***\nCountry: " . reg_country() . "\n";
# dir_writable
my $wr_dir = $ENV{'USERPROFILE'};
$wr_dir =~ s/\\/\//g;
mkdir $wr_dir unless -e $wr_dir;
print "\n***\nTesting for writability\n";
print $wr_dir . maybenot(dir_writable($wr_dir)) . "writable\n";
print $ro_dir . maybenot(dir_writable($ro_dir)) . "writable\n";
# expand_string
print( "\n***\nExpansion\n" );
print expand_string("pre\\%systemROOT%\\post")."\n";
# win_which_dir
print( "\n***\nFinding an executable\n" );
print "cmd.exe found in " . win_which_dir("cmd.exe") . "\n";
my $system_tmpdir=get_system_tmpdir();
print( "\n***\nPath; admin and user\n\n" );
my ($wr_dir1, $wr_dir2);
foreach ("admin", "user") {
if ($_ eq "admin") {
next unless $real_admin;
admin_again();
} else {
non_admin();
}
print "\n***\n" . ((admin() ? "Is" : "Not") . " an admin\n");
# adding and removing texbindir
print( "\ntexbindir on searchpath:\n" );
$wr_dir1 = $wr_dir . "/tex1";
mkdir $wr_dir1 unless -e $wr_dir1;
create_file( $wr_dir1."/tex.exe" );
add_texbindir_to_path($wr_dir1);
print( "Take 1\n" );
print_search_paths();
print "tex.exe found in " . win_which_dir("tex.exe") . "\n";
$wr_dir2 = $wr_dir . "/tex2";
mkdir $wr_dir2 unless -e $wr_dir2;
create_file( $wr_dir2."/tex.exe" );
add_texbindir_to_path($wr_dir2);
print( "Take 2\n" );
print_search_paths();
print "tex.exe found in " . win_which_dir("tex.exe") . "\n";
print( "Mopping up...\n" );
remove_texbindirs_from_path();
print_search_paths();
# broadcast environment changes
broadcast_env();
pause( maybenot(admin())." admin; check environment in new dosbox\n\n" );
}
remove_texbindirs_from_path();
rmdir $wr_dir1 if unlink $wr_dir1.'/tex.exe';
rmdir $wr_dir2 if unlink $wr_dir2.'/tex.exe';
print( "Dummy texs removed from path\n");
# the problem case: no admin, but TeX on system path
print( "\nNon-admin path problem\n" );
my $fn = expand_string("%windir%")."/TEX.EXE";
$fn =~ s/\\/\//g;
non_admin();
if (create_file($fn)) { # a tex.exe on the system path!
add_texbindir_to_path(expand_string($wr_dir2));
my @wge = wg_error();
if (@wge) {
print $wge[1]."\n";
}
print( "Cannot remove tex from system searchpath\n" );
print_search_paths();
print "Wrong tex.exe found in " . win_which_dir("tex.exe") . "\n";
unlink $fn;
remove_texbindirs_from_path();
broadcast_env();
pause( "Non-admin: check environment in new dosbox" );
} else {
print "Cannot test; cannot create $fn\n";
}
# texlua filetype: plain lua for user, texlua for admin.
# differentiation: texlua rounds .0000001 to 0, lua doesn't
# The texlua command is REG_EXPAND_SZ, parameterized with %TEXBINDIR%.
print( "\n***\nRegistering and unregistering filetypes\n\n" );
unregister_script_type(".texlua");
unsetenv_reg('TEXBINDIR');
update_assocs();
broadcast_env();
print_assoc_cmd( '.texlua' );
foreach ("admin", "user") {
if ($_ eq "admin") {
next unless $real_admin;
admin_again();
} else {
non_admin();
}
print "\n***\n" . ((admin() ? "Is" : "Not") . " an admin\n");
# adding a filetype
my $luaprog = admin() ? "texlua.exe" : "lua.exe";
my $texbindir = admin() ? $::installerdir."/bin/win32" : $luadir;
$texbindir =~ s!/!\\!g;
setenv_reg("TEXBINDIR", $texbindir);
register_script_type(".texlua", "%TEXBINDIR%\\".$luaprog );
broadcast_env();
update_assocs();
print "\n***\nAfter registering script type\n";
print_assoc_cmd( '.texlua' );
print_lua_out();
print( "\***\nNow unregister\n" );
unregister_script_type(".texlua");
update_assocs();
print_assoc_cmd( '.texlua' );
print_lua_out();
print( "Now re-register (not shown)\n" );
register_script_type(".texlua", "%TEXBINDIR%\\".$luaprog );
update_assocs();
# broadcast environment changes
broadcast_env();
}
unregister_script_type(".texlua");
unsetenv_reg('TEXBINDIR');
update_assocs();
broadcast_env();
print_assoc_cmd( '.texlua' );
|