Convert most of the file APIs to Unicode.
[wine/wine-kai.git] / tools / winecheck
blob22afaed314758cb606fa6490c53b3851f0d680e4
1 #!/usr/bin/perl -w
3 # This program checks the whole Wine environment configuration.
4 # (or that's at least what it's supposed to do once it's finished)
5 # Copyright (C) 2001 Andreas Mohr
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # FIXME:
22 # - implement cmdline arguments e.g. for confirmation keypress
23 # in case of a problem
25 # TODO:
26 # - implement it in a much more systematic way. This is a quick hack for now
27 # (like every Perl program ;-)
28 # And much more so since I'm NOT a Perl hacker
29 # - test/tweak on non-Linux systems
32 use Getopt::Long;
33 use strict;
35 my $hold = 0;
37 my $count_tests = 0;
38 my $count_ok = 0;
39 my $count_notice = 0;
40 my $count_suspect = 0;
41 my $count_bad = 0;
42 my $count_critical = 0;
43 my $count_failed = 0;
45 my $is_notchecked = 0;
46 my $is_ok = 1;
47 my $is_notice = 2;
48 my $is_suspect = 3;
49 my $is_bad = 4;
50 my $is_critical = 5;
51 my $is_failed = 6;
53 my $factor_suspect = 0.995;
54 my $factor_bad = 0.95;
55 my $factor_critical = 0.85;
56 my $factor_failed = 0.15;
58 my $correctness = 100.0;
60 my $indent = 0;
62 my ($level, $reason, $advice);
64 my $advice_chmod = "If your user account is supposed to be able to access
65 it properly, use chmod as root to fix it (\"man chmod\")";
66 my $advice_fs = "The Filesystem option indicates the filesystem behaviour Wine is supposed to *emulate*, not the filesystem which is there";
68 my $dev_read = 1;
69 my $dev_write = 2;
70 my $dev_open = 4;
72 select(STDERR); $| = 1; # make unbuffered
73 select(STDOUT); $| = 1; # make unbuffered
75 #--------------------------------- main program --------------------------------
76 &Introduction();
77 &Check_BaseFiles();
78 &Check_ConfigFile();
79 &Check_Devices();
80 &Check_Registry();
81 &Check_WindowsFiles();
82 &Print_Score();
84 #------------------------------- support functions -----------------------------
85 sub Do_PrintHeader {
86 my ($str) = @_;
87 my $len = length($str);
88 my $num = int((80 - $len - 2)/2);
89 my $i;
91 print "\n";
92 for ($i = 0; $i < $num; $i++) {
93 print "-";
95 print " ".$str." ";
96 for ($i = 0; $i < $num; $i++) {
97 print "-";
99 if ($len % 2)
101 print "-";
103 print "\n";
106 sub Do_Check {
107 my ($text) = @_;
108 my $test_no;
109 my $indent_str = "";
111 $count_tests++;
112 $test_no = sprintf("%03d", $count_tests);
113 for (my $i = 0; $i < $indent; $i++)
115 $indent_str = $indent_str." ";
117 print sprintf("%.60s", $test_no.".".$indent_str." Checking ".$text."... ");
120 sub Do_PrintResult {
121 my($level, $str, $advice, $skip_score) = @_;
122 my $err;
123 my $key;
125 if ($level == $is_notchecked)
127 $err = "NOT CHECKED";
128 $str = "";
129 $advice = "";
131 elsif ($level == $is_ok)
133 $err = "OK";
134 $str = "";
135 $advice = "";
136 $count_ok++;
138 elsif ($level == $is_notice)
140 $err = "NOTICE";
141 $count_notice++;
143 elsif ($level == $is_suspect)
145 $err = "SUSPICIOUS";
146 $count_suspect++;
147 if (! $skip_score)
149 $correctness *= $factor_suspect;
152 elsif ($level == $is_bad)
154 $err = "BAD";
155 $count_bad++;
156 if (! $skip_score)
158 $correctness *= $factor_bad;
161 elsif ($level == $is_critical)
163 $err = "CRITICAL";
164 $count_critical++;
165 if (! $skip_score)
167 $correctness *= $factor_critical;
170 elsif ($level == $is_failed)
172 $err = "FAILED";
173 $count_failed++;
174 if (! $skip_score)
176 $correctness *= $factor_failed;
179 print $err;
180 if ($str)
182 print " (".$str.")";
184 print ".";
185 if ($hold)
187 print " Press Enter.";
188 $key = getc(STDIN);
190 else
192 print "\n";
194 if ($advice)
196 print "- ADVICE: ".$advice.".\n";
200 #-------------------------------- main functions ------------------------------
201 sub Introduction {
202 print "This script verifies the configuration of the whole Wine environment.\n";
203 print "Note that this is an ALPHA version, and thus it doesn't catch all problems !\n";
204 print "The results of the checks are printed on the right side:\n";
205 print "OK - test passed without problems.\n";
206 print "NOTICE - Not a problem but something for the user to be aware of.\n";
207 print "SUSPICIOUS - potentially problematic. You might want to look into that.\n";
208 print "BAD - This is a problem, and it leads to configuration score penalty.\n";
209 print "CRITICAL - A critical problem which can easily lead to malfunction.\n";
210 print "FAILED - This problem leads to Wine failure almost certainly.\n";
211 print "\nThe result will be printed as a percentage score indicating config completeness.\n";
212 print "\n";
213 if ($hold)
215 my $key;
216 print "Press Enter to continue or Ctrl-C to exit.";
217 $key = getc(STDIN);
221 sub Check_BaseFiles {
222 my $line;
224 Do_PrintHeader("checking Wine base files");
226 $level = $is_ok;
227 Do_Check("for file \"wine\"");
228 $line = `which wine`;
229 if (!$line)
231 $level = $is_failed;
232 $reason = "file not found";
233 $advice = "Make sure the \"wine\" command is in your PATH (echo \$PATH; export PATH=xxx)";
235 Do_PrintResult($level, $reason, $advice);
237 # check for config mess
238 $level = $is_ok;
239 my @output = ();
240 Do_Check("for correct .so lib config (please wait)");
242 # Build list of library directories.
243 # First parse ld.so.conf to find system-wide lib directories.
244 my @dirlist = ();
245 open (LDCONF, "</etc/ld.so.conf");
246 while (<LDCONF>) {
247 s/\#.*//; # eliminate comments
248 chomp;
249 if (-d $_) { push @dirlist, $_; }
251 close (LDCONF);
252 # Next parse LD_LIBRARY_PATH to find user-specific lib dirs.
253 my ($dir);
254 if ($ENV{'LD_LIBRARY_PATH'}) {
255 my (@ld_dirs) = split (/:/, $ENV{'LD_LIBRARY_PATH'});
256 foreach $dir (@ld_dirs) {
257 if (-d $dir) { push @dirlist, $dir; }
261 # Now check for a libwine.so in each directory
262 foreach $dir (@dirlist) {
263 my ($target) = $dir . "/libwine.so";
264 if (-f $target) { push @output, $target; }
266 #print "DEBUG: found libwine: @output\n";
268 if (@output > 1)
270 $level = $is_suspect;
271 my $dirs = "";
272 foreach $line (@output) {
273 chomp $line;
274 $dirs = $dirs." ".$line;
276 $reason = "libwine.so found ".@output." times:".$dirs;
277 $advice = "check whether this is really ok";
279 Do_PrintResult($level, $reason, $advice);
282 sub Do_Config_Drive {
283 my ($drive, $entries, $values) = @_;
284 my $index = 0;
285 my $arg;
286 my $path = "";
287 my $type = "";
288 my $label = "";
289 my $serial = "";
290 my $device = "";
291 my $fs = "";
292 my $unknown = "";
293 my $level;
294 my $my_advice_fat = "If that doesn't help, change mount options in case of VFAT (\"umask\" option)";
296 print "\n>>> Checking drive ".$drive." settings:\n";
297 $reason = "";
298 while (@$entries[$index])
300 $arg = @$values[$index];
301 SWITCH: for (@$entries[$index]) {
302 /^path$/i && do { $path = $arg; last; };
303 /^type$/i && do { $type = $arg; last; };
304 /^label$/i && do { $label = $arg; last; };
305 /^serial$/i && do { $serial = $arg; last; };
306 /^device$/i && do { $device = $arg; last; };
307 /^filesystem$/i && do { $fs = $arg; last; };
308 $unknown = @$entries[$index];
310 $index++;
313 $indent++;
315 my $serious = ($drive =~ /^C$/i) || ($type =~ /^cdrom$/i);
317 ##### check Path #####
318 Do_Check("Path option");
319 $level = $is_ok;
320 $advice = "The syntax of the Path option has to be something like /my/mount/point";
321 if (! $path)
323 $level = $serious ? $is_failed : $is_bad;
324 $reason = "no Path option given in config file";
326 elsif ($path =~ /\\/)
328 $level = $serious ? $is_failed : $is_bad;
329 $reason = "wrong Path format ".$path;
331 elsif ($path =~ /\$\{(.*)\}$/)
333 # get path assigned to environment variable
334 my $envpath = $ENV{$1};
335 if (! $envpath)
337 $level = $serious ? $is_failed : $is_critical;
338 $reason = "Path \"".$path."\" references environment variable \"".$1."\" which is undefined";
339 $advice = "set environment variable before starting Wine or give a \"real\" directory instead";
341 else
343 $path = $envpath;
344 goto PERMCHECK; # hmpf
347 else
349 PERMCHECK:
350 if (!-e $path)
352 $level = $serious ? $is_failed : $is_suspect;
353 $reason = $path." does not exist !";
354 $advice = "create this directory or point Path to a real directory";
356 elsif (!-r $path)
358 $level = $serious ? $is_failed : $is_bad;
359 $reason = $path." is not readable for you";
360 $advice = $advice_chmod.". ".$my_advice_fat;
362 elsif ((! ($type =~ /^cdrom$/i)) && (!-w $path))
364 $level = ($drive =~ /^C$/i) ? $is_failed : $is_suspect;
365 $reason = $path." is not writable for you";
366 $advice = $advice_chmod.". ".$my_advice_fat;
368 else # check permissions of the drive's directories
370 my(@output) = ();
371 push (@output, `find $path 2>&1 1>/dev/null`);
372 foreach my $line (@output) {
373 if ($line =~ /find:\ (.*):\ Permission denied$/)
375 $level = ($drive =~ /^C$/i) ? $is_critical : $is_suspect;
376 $reason = "directory $1 is not accessible for you";
377 $advice = $advice_chmod.". ".$my_advice_fat;
378 last;
383 Do_PrintResult($level, $reason, $advice);
385 ##### check Type #####
386 if ($type)
388 Do_Check("Type option");
389 $level = $is_ok;
390 SWITCH: for ($type) {
391 /^floppy$/i && do { last; };
392 /^hd$/i && do { last; };
393 /^network$/i && do { last; };
394 /^cdrom$/i && do {
395 if (! $device)
397 $level = $is_critical;
398 $reason = "no Device option found -> CD-ROM labels can''t be read";
399 $advice = "add Device option and make sure the device given is accessible by you";
401 last;
403 /^ramdisk$/i && do { last; };
404 if ($type)
406 $level = $is_bad;
407 $reason = "invalid Type setting ".$type;
408 $advice = "use one of \"floppy\", \"hd\", \"network\" or \"cdrom\"";
411 Do_PrintResult($level, $reason, $advice);
414 ##### FIXME: check Label and Serial here #####
416 ##### check Device #####
417 if ($device)
419 my $mode = ($type =~ /^cdrom$/i) ? $dev_read : $dev_read|$dev_write;
420 &Do_CheckDevice("device", $device, 1, $mode);
423 ##### check Filesystem #####
424 if ($fs)
426 Do_Check("Filesystem option");
427 $level = $is_ok;
428 SWITCH: for ($fs) {
429 /^(dos|fat|msdos|unix)$/i && do {
430 $level = $is_bad;
431 $reason = "You probably don't want to use \"".$fs."\". ".$advice_fs;
432 if ($fs =~ /^unix$/i)
434 $advice = "This should almost never be used";
436 else
438 $advice = "only use ".$fs." if you only have a crappy 8.3 filename (i.e.: non-LFN) DOS FAT kernel filesystem driver";
440 last;
442 /^vfat$/i && do { last; };
443 /^win95$/i && do { last; };
444 if ($fs)
446 $level = $is_bad;
447 $reason = "invalid Filesystem setting ".$type;
448 $advice = "use one of \"win95\", \"msdos\" or \"unix\"";
451 Do_PrintResult($level, $reason, $advice);
453 $indent--;
454 if ($reason) {
455 print "--> PROBLEM.\n";
457 else
459 print "--> OK.\n";
463 sub Do_Config_Main {
464 my ($file) = shift;
465 my ($config, $line);
466 my $section = "";
467 my (@entries, @values);
468 LINE: while (<$file>)
470 $line = $_;
471 next LINE if ($line =~ /[\ ]*[;#]/); # skip comments
472 chomp $line;
473 #print "line: ".$line."\n";
474 if ($line =~ /\[(.*)\]/) # end of section/next section ?
476 my $nextsection = $1;
477 my $found = 1;
478 SWITCH: for ($section) {
479 /Drive\ (.)/i && do { &Do_Config_Drive($1, \@entries, \@values); last; };
480 if ($section)
482 $found = 0;
485 $section = $found ? $nextsection : "";
486 @entries = (); @values = ();
487 next LINE;
489 if ($line =~ /^[\ \t]*\"(.*)\"[\ \t]*\=[\ \t]*\"(.*)\"/)
491 push(@entries, $1);
492 push(@values, $2);
497 sub Check_ConfigFile {
498 my $config = "$ENV{'HOME'}/.wine/config";
499 my $indrive = 0;
501 Do_PrintHeader("checking config file");
503 Do_Check("config file access");
504 open(CFGFILE, $config);
505 if (! <CFGFILE>)
507 if (!-e $config) {
508 $reason = $config." does not exist";
509 $advice = "it is ok in case you have ~/.winerc. If you don''t, then you''re in trouble !";
511 elsif (!-r $config) {
512 $reason = $config." not readable";
513 $advice = $advice_chmod;
515 Do_PrintResult($is_failed, $reason, $advice);
516 return;
518 if (!-w $config)
520 Do_PrintResult($is_failed, $config." not writable", "wineserver needs to be able to write to config file. ".$advice_chmod);
522 else
524 Do_PrintResult($is_ok);
526 Do_Config_Main(\*CFGFILE);
527 close(CFGFILE);
530 sub Do_CheckDevice {
531 my($descr, $dev, $output, $mode) = @_;
532 my $level = $is_ok;
533 my $errstr = "";
535 if (! $mode)
537 $mode = $dev_read|$dev_write|$dev_open;
539 ($output != -1) && Do_Check($descr." ".$dev);
541 my $err_level = ($output == 1) ? $is_critical : $is_bad;
543 if (!-e $dev)
545 $level = $err_level;
546 $reason = $dev." does not exist";
547 $advice = "use MAKEDEV script to create it";
548 goto FAILED;
550 if (($mode & $dev_read) && (!-r $dev))
552 $level = $err_level;
553 $reason = $dev." is not readable for you";
554 $advice = $advice_chmod;
555 goto FAILED;
557 if (($mode & $dev_write) && (!-w $dev))
559 $level = $err_level;
560 $reason = $dev." is not writable for you";
561 $advice = $advice_chmod;
562 goto FAILED;
564 if (($mode & $dev_open) && (!open(DEVICE, ">$dev")))
566 $level = $err_level;
567 $reason = "no kernel driver for ".$dev."?";
568 $advice = "module loading problems ? Read /usr/src/linux/Documentation/modules.txt";
569 goto FAILED;
572 FAILED:
573 close(DEVICE);
574 ($output != -1) && Do_PrintResult($level, $reason, $advice);
577 sub Check_Devices {
578 # FIXME: check joystick and scsi devices !
579 my $dev_sound = "/dev/dsp";
580 my $dev_mixer = "/dev/mixer";
581 my $dev_sequencer = "/dev/sequencer";
582 my $dev_mem = "/dev/mem";
584 Do_PrintHeader("checking system devices used by Wine");
585 &Do_CheckDevice("sound device", $dev_sound, 1);
586 &Do_CheckDevice("audio mixer device", $dev_mixer, 1);
587 &Do_CheckDevice("MIDI sequencer device", $dev_sequencer, 0);
590 sub Check_Registry {
591 my(@entries) = ();
592 my $regfile = $ENV{'HOME'}."/.wine/system.reg";
594 Do_PrintHeader("checking registry configuration");
596 Do_Check("availability of winedefault.reg entries");
597 push (@entries, `grep "SHAREDMEMLOCATION" $regfile`);
598 if (@entries)
600 Do_PrintResult($is_ok);
602 else
604 Do_PrintResult($is_critical, "entry \"SHAREDMEMLOCATION\" not found in system.reg registry file", "file winedefault.reg doesn't seem to have been applied using regapi");
606 @entries = ();
608 Do_Check("availability of windows registry entries");
609 # FIXME: use a different key for check if Wine adds this one to its
610 # default registry.
611 push (@entries, `grep "Default Taskbar" $regfile`);
612 if (@entries)
614 Do_PrintResult($is_ok);
616 else
618 Do_PrintResult($is_notice, "entry \"Default Taskbar\" not found", "A Windows registry does not seem to have been added to Wine as this typical Windows registry entry does not exist in Wine's registry. A complete original Windows registry entry set will *not* be available with a no-windows install. Usually this will present no problem in running applications although this can affect newer programs");
620 @entries = ();
623 sub Check_WindowsFiles {
626 sub Print_Score {
627 # my ($score_total, $score_reached, $score_percent);
629 # $score_total = $count_tests * 20;
630 # $score_reached = $count_ok * 20 +
631 # $count_bad * 15 +
632 # $count_critical * 5 +
633 # $count_failed * 0;
634 # $score_percent = $score_reached * 100 / $score_total;
636 print "\n";
637 print $count_tests." tests. ".$count_suspect." suspicious, ".$count_bad." bad, ".$count_critical." critical, ".$count_failed." failed.\n";
638 print sprintf "Wine configuration correctness score: %2.2f%%\n", $correctness;