- support DirectInput 8 interfaces.
[wine/multimedia.git] / tools / winelauncher.in
bloba4ce82d54d51650350e26736097c0fcb209e8f51
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # Winelauncher
4 # This shell script attempts to intelligently manage the process
5 # of launching a program with Wine. It adds some level of
6 # visual feedback to an end user.
8 # Usage:
9 # winelauncher [options] "<windows program> [program arguments]"
11 # This script is meant to be installed to /usr/bin/wine, and
12 # to be used to invoke a Windows executable.
13 # The options are passed through directly to Wine, and are
14 # documented in the Wine man page.
16 # Copyright (c) 2000 by Jeremy White for CodeWeavers
18 # This library is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU Lesser General Public
20 # License as published by the Free Software Foundation; either
21 # version 2.1 of the License, or (at your option) any later version.
23 # This library is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 # Lesser General Public License for more details.
28 # You should have received a copy of the GNU Lesser General Public
29 # License along with this library; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Primary configuration area - change this if you installed Wine to
35 # a different location
36 #------------------------------------------------------------------------------
37 WINEBIN=@bindir@
38 WINELIB=@libdir@
39 WINESERVER=
40 WINEDLLPATH=@dlldir@
42 #------------------------------------------------------------------------------
43 # Establish Color Scheme
44 #------------------------------------------------------------------------------
45 COLOR=' -xrm *.Command.background:darkgrey
46 -xrm *.Command.foreground:black
47 -xrm *.Text.background:black
48 -xrm *.Text.foreground:green
49 -xrm *.Form.background:grey
50 -xrm *.Form.foreground:green
51 -xrm *.foreground:green
52 -xrm *.background:black'
55 #------------------------------------------------------------------------------
56 # Locate either xmessage or gmessage, if we can.
57 #------------------------------------------------------------------------------
58 type xmessage >/dev/null 2>/dev/null
59 if [ $? -ne 0 ] ; then
60 echo "
61 Warning:
62 The Wine launcher is unable to find xmessage.
64 This launcher script relies heavily on finding this tool,
65 and without it, it will behave poorly.
67 Most Linux distributions have one or the other of these
68 tools.
70 We strongly recommend that you use your distribution's
71 software methods to locate xmessage."
73 else
74 XMESSAGE="xmessage $COLOR"
78 #------------------------------------------------------------------------------
79 # We're going to do a lot of fancy footwork below.
80 # Before we get started, it would be nice to know the argv0
81 # of the actual script we're running (and lets remove at least
82 # one level of symlinking).
83 #------------------------------------------------------------------------------
84 argv0_path=`which $0`
85 if [ -z $argv0_path ] ; then
86 argv0_path=$0
89 real_name=`find $argv0_path -type l -printf "%l\n"`
90 if [ ! $real_name ]; then
91 real_name=$argv0_path
92 elif [ ! -x $real_name ]; then
93 real_name=`find $argv0_path -printf "%h\n"`/$real_name
96 argv0_dir=`find $real_name -printf "%h\n"`
98 if [ -z $argv0_dir ] ; then
99 argv0_dir=.
102 #------------------------------------------------------------------------------
103 # Okay, now all that junk above was established at configure time.
104 # However, if this is an RPM install, they may have chosen
105 # to relocate this installation. If so, that stuff above
106 # is all broken and we should rejigger it.
107 #------------------------------------------------------------------------------
108 WINE_BIN_NAME=wine.bin
109 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
110 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
113 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
114 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
117 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
118 WINE_BIN_NAME=wine
119 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
120 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
123 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
124 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
128 if [ ! -r $WINELIB/libwine.so ] ; then
129 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
132 if [ ! -r $WINELIB/libwine.so ] ; then
133 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
136 if [ -x $WINEBIN/wineserver ] ; then
137 WINESERVER=$WINEBIN/wineserver
140 #------------------------------------------------------------------------------
141 # Hey, if we built Wine from source, let's add a little extra fun to
142 # mix it up a bit
143 #------------------------------------------------------------------------------
144 if [ -x $WINEBIN/server/wineserver ] ; then
145 WINESERVER=$WINEBIN/server/wineserver
148 if [ -r $WINELIB/dlls/ntdll.dll.so ] ; then
149 WINEDLLPATH=$WINELIB/dlls
153 #------------------------------------------------------------------------------
154 # Okay, set the paths and move on.
155 #------------------------------------------------------------------------------
156 export LD_LIBRARY_PATH=$WINELIB:$LD_LIBRARY_PATH
157 export PATH=$WINEBIN:$PATH
158 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
159 export WINEDLLPATH
160 export WINESERVER
162 info_flag=~/.wine/.no_prelaunch_window_flag
163 debug_flag=~/.wine/.no_debug_window_flag
164 debug_options="-debugmsg warn+all"
166 if [ -f $info_flag ] ; then
167 use_info_message=0
168 else
169 use_info_message=1
172 if [ -f $debug_flag ] ; then
173 use_debug_message=0
174 else
175 use_debug_message=1
179 #------------------------------------------------------------------------------
180 # Handle winelib apps going through here
181 #------------------------------------------------------------------------------
182 winelib=0
183 if [ -f $argv0_path.so ] ; then
184 winelib=1
185 export WINEPRELOAD=$argv0_path.so
189 #------------------------------------------------------------------------------
190 # No arguments? Help 'em out
191 #------------------------------------------------------------------------------
192 always_see_output=0
193 no_args=0
194 if [ $# -eq 0 ] ; then
195 no_args=1
198 if [ $# -eq 1 -a "$1" = "" ] ; then
199 no_args=1
202 if [ $winelib -eq 1 ] ; then
203 no_args=0
206 if [ $no_args -eq 1 ] ; then
207 echo "Wine called with no arguments."
208 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
209 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
210 -title "Welcome to Wine" \
213 You have started Wine without specifying any arguments.
215 Wine requires a least one argument - the name of the Windows
216 application you would like to run.
218 If you have launched this through the KDE menu system,
219 you can use the KDE file browser to select a Windows
220 exectuable and then click on it to launch Wine with
221 that application.
223 You can similarly use the GNOME file manager to
224 select a Windows executable and double click on it.
226 If you would like to see the command line arguments
227 for Wine, select the second option, below.
230 welcome_rc=$?
231 if [ $welcome_rc -eq 0 ] ; then
232 exit
235 if [ $welcome_rc -eq 2 ] ; then
236 which winesetup
237 if [ $? -eq 0 ] ; then
238 winesetup
239 else
240 if [ -x /opt/wine/bin/winesetup ] ; then
241 /opt/wine/bin/winesetup
242 else
243 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
246 exit
249 use_info_message=0
250 always_see_output=1
253 #------------------------------------------------------------------------------
254 # No config file? Offer to help 'em out...
255 #------------------------------------------------------------------------------
256 conf=0
258 while [ $conf -eq 0 ] ; do
260 if [ -f ~/.winerc ] ; then
261 conf=1
263 if [ -f ~/.wine/config ] ; then
264 conf=2
266 if [ -f /etc/wine.conf ] ; then
267 conf=3
270 if [ $conf -ne 0 ] ; then
271 break;
274 echo "No configuration file detected."
275 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
276 -title "Welcome to Wine" \
279 You have started Wine but we cannot find a Wine
280 configuration file.
282 This is normal if you have never run Wine before.
283 If this is the case, select the 'Configure Wine'
284 option, below, to create a configuration file.
287 init_rc=$?
288 if [ $init_rc -eq 0 ] ; then
289 exit
292 if [ $init_rc -eq 1 ] ; then
293 break
296 if [ $init_rc -eq 2 ] ; then
297 which winesetup
298 if [ $? -eq 0 ] ; then
299 winesetup
300 else
301 if [ -x /opt/wine/bin/winesetup ] ; then
302 /opt/wine/bin/winesetup
303 else
304 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
309 done
311 #------------------------------------------------------------------------------
312 # Optionally Warn the user we're going to be launching Wine...
313 #------------------------------------------------------------------------------
314 if [ $use_info_message -ne 0 ] ; then
315 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
316 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
317 -title "Wine Launch Window" \
318 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
320 This dialog box is a temporary status dialog to let you know
321 that Wine is attempting to launch your application.
323 Since Wine is still very much in a development stage, many
324 applications will fail silently. This dialog box is your indication
325 that we're *trying* to run your application.
327 This dialog box will automatically disappear after 30 seconds,
328 or after your application finishes.
330 You can permanently disable this dialog by selecting the option below.
332 info_message_pid=$!
335 #------------------------------------------------------------------------------
336 # Here's a little function to clean up after that dialog...
337 #------------------------------------------------------------------------------
338 clean_up_info_message ()
340 if [ $use_info_message -ne 0 ] ; then
342 #------------------------------------------------------------------------------
343 # Okay, make sure that the notice window is dead (and kill it if it ain't)
344 #------------------------------------------------------------------------------
345 ps $info_message_pid >/dev/null 2>&1
346 if [ $? -ne 0 ] ; then
347 wait $info_message_pid
348 info_return=$?
349 else
350 info_return=0
351 kill $info_message_pid
354 #------------------------------------------------------------------------------
355 # If they didn't like the warning window, turn it off
356 #------------------------------------------------------------------------------
357 if [ $info_return -eq 3 ] ; then
358 $XMESSAGE -title "Wine Prelaunch Control" \
359 "Wine will now disable the prelaunch Window you just saw.
360 You will no longer be notified when Wine is attempting
361 to start a Windows application.
363 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
364 if [ $? -eq 0 ] ; then
365 touch $info_flag
370 use_info_message=0
372 #------------------------------------------------------------------------------
373 # Generate a temporary log file name
374 #------------------------------------------------------------------------------
375 if [ -n "$TMP" ] ; then
376 log_dir="$TMP"
377 else
378 log_dir="/tmp"
380 use_log_name=0
381 log_name=`mktemp "$log_dir/wine.log.XXXXXX"`
382 if [ $? -eq 0 ] ; then
383 use_log_name=1
385 use_status_name=0
386 status_name=`mktemp "$log_dir/wine.status.XXXXXX"`
387 if [ $? -eq 0 ] ; then
388 use_status_name=1
391 #------------------------------------------------------------------------------
392 # Okay, really launch Wine...
393 #------------------------------------------------------------------------------
394 if [ $use_log_name -ne 0 -a $use_status_name -ne 0 ] ; then
395 ( $WINEBIN/$WINE_BIN_NAME "$@"; echo $? >$status_name ) 2>&1 | tee "$log_name"
396 wine_return=`cat $status_name`
397 else
398 $WINEBIN/$WINE_BIN_NAME "$@"
399 wine_return=$?
401 if [ $use_status_name -ne 0 ] ; then
402 rm -f $status_name
405 #------------------------------------------------------------------------------
406 # Test the return code, and see if it fails
407 #------------------------------------------------------------------------------
408 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
409 echo "Wine exited with a successful status"
410 if [ $use_log_name -ne 0 ] ; then
411 rm -f "$log_name"
413 else
414 if [ $always_see_output -eq 0 ] ; then
415 echo "Wine failed with return code $wine_return"
418 #------------------------------------------------------------------------------
419 # Gracefully display a debug message if they like...
420 #------------------------------------------------------------------------------
421 while [ $use_debug_message -gt 0 ] ; do
423 #------------------------------------------------------------------------------
424 # Build up the menu of choices they can make...
425 #------------------------------------------------------------------------------
426 BUTTONS=' Okay :0'
427 if [ $use_log_name -ne 0 ] ; then
428 BUTTONS="$BUTTONS"', View Log :1'
431 BUTTONS="$BUTTONS"', Debug :2'
432 BUTTONS="$BUTTONS"', Configure :4'
433 BUTTONS="$BUTTONS"', Disable :3'
435 #------------------------------------------------------------------------------
436 # Build an error message
437 #------------------------------------------------------------------------------
438 MESSAGE="
439 Wine has exited with a failure status of $wine_return.
441 Wine is still development software, so there can be many
442 explanations for this problem.
444 You can choose to run Wine again with a higher level
445 of debug messages (the debug option, below).
447 You can attempt to reconfigure Wine to make it work better.
448 Note that one change you can make that will dramatically
449 effect Wine's behaviour is to change whether or not
450 Wine uses a true Windows partition, mounted under Linux,
451 or whether it uses an empty Windows directory.
452 The Wine Configuration program can assist you in making
453 those changes (select Configure, below, for more).
455 You can disable this message entirely by selecting the
456 Disable option below."
458 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
459 MESSAGE="
460 Wine has exited with a failure status of $wine_return.
462 You can disable this message entirely by selecting the
463 Disable option below."
467 if [ $use_log_name -ne 0 ] ; then
468 MESSAGE="$MESSAGE
470 Wine has captured a log of the Wine output in the file $log_name.
471 You may view this file by selecting View Log, below."
474 #------------------------------------------------------------------------------
475 # Display the message
476 #------------------------------------------------------------------------------
477 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
478 debug_return=$?
480 #------------------------------------------------------------------------------
481 # Dismiss the other window...
482 #------------------------------------------------------------------------------
483 clean_up_info_message
485 #------------------------------------------------------------------------------
486 # Process a configure instruction
487 #------------------------------------------------------------------------------
488 if [ $debug_return -eq 4 ] ; then
489 which winesetup
490 if [ $? -eq 0 ] ; then
491 winesetup
492 else
493 if [ -x /opt/wine/bin/winesetup ] ; then
494 /opt/wine/bin/winesetup
495 else
496 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
499 continue;
502 #------------------------------------------------------------------------------
503 # Process a view instruction
504 #------------------------------------------------------------------------------
505 if [ $debug_return -eq 1 ] ; then
506 $XMESSAGE -title "View Wine Log" -file "$log_name" -buttons " Okay ":0,"Delete $log_name":1
507 if [ $? -eq 1 ] ; then
508 echo "Deleting $log_name"
509 rm -f "$log_name"
510 use_log_name=0
512 else
513 use_debug_message=0
516 #------------------------------------------------------------------------------
517 # If they didn't like the warning window, turn it off
518 #------------------------------------------------------------------------------
519 if [ $debug_return -eq 3 ] ; then
520 $XMESSAGE -title "Wine Debug Log Control" \
521 "Wine will now disable the Wine debug output control window you just saw.
522 You will no longer be notified when Wine fails to start a
523 Windows application.
525 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
527 if [ $? -eq 0 ] ; then
528 touch $debug_flag
533 #------------------------------------------------------------------------------
534 # If they want to retry with debug, let 'em.
535 #------------------------------------------------------------------------------
536 if [ $debug_return -eq 2 ] ; then
537 echo "Rerunning $0 $debug_options $@"
538 exec $0 $debug_options "$@"
540 done
544 clean_up_info_message
546 # killed by signal?
547 if [ $wine_return -ge 128 ]; then
548 # try to kill myself with the same signal
549 kill -$[wine_return - 128] $$
550 # if we get here the kill didn't work
551 exit 1