Make sure that MSG_PeekMessage uses an internal variable to avoid
[wine/hacks.git] / tools / winelauncher.in
blobe1dcb6957a20c3738acd7d66e64b698269bb2d49
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.
7 #
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 #------------------------------------------------------------------------------
20 #------------------------------------------------------------------------------
21 # Primary configuration area - change this if you installed Wine to
22 # a location other than @prefix@
23 #------------------------------------------------------------------------------
24 prefix=@prefix@
26 #------------------------------------------------------------------------------
27 # Secondary configuration area; change these at your own risk.
28 #------------------------------------------------------------------------------
29 exec_prefix=@exec_prefix@
30 WINEBIN=@bindir@
31 WINELIB=@libdir@
32 WINESERVERBIN=
33 WINELIBDLLS=
35 #------------------------------------------------------------------------------
36 # Establish Color Scheme
37 #------------------------------------------------------------------------------
38 COLOR=' -xrm *.Command.background:darkgrey
39 -xrm *.Command.foreground:black
40 -xrm *.Text.background:black
41 -xrm *.Text.foreground:green
42 -xrm *.Form.background:grey
43 -xrm *.Form.foreground:green
44 -xrm *.foreground:green
45 -xrm *.background:black'
48 #------------------------------------------------------------------------------
49 # Locate either xmessage or gmessage, if we can.
50 #------------------------------------------------------------------------------
51 type xmessage >/dev/null 2>/dev/null
52 if [ $? -ne 0 ] ; then
53 echo "
54 Warning:
55 The Wine launcher is unable to find xmessage.
57 This launcher script relies heavily on finding this tool,
58 and without it, it will behave poorly.
60 Most Linux distributions have one or the other of these
61 tools.
63 We strongly recommend that you use your distributions
64 software methods to locate xmessage."
66 else
67 XMESSAGE="xmessage $COLOR"
71 #------------------------------------------------------------------------------
72 # We're going to do a lot of fancy footwork below.
73 # Before we get started, it would be nice to know the argv0,
74 # of the actual script we're running (and lets remove at least
75 # one level of symlinking).
76 #------------------------------------------------------------------------------
77 real_name=`find $0 -type l -printf "%l\n"`
78 if [ ! $real_name ]; then
79 real_name=$0;
81 argv0_dir=`find $real_name -printf "%h\n"`
83 if [ -z $argv0_dir ] ; then
84 argv0_dir=.
87 #------------------------------------------------------------------------------
88 # Okay, now all that junk above was established at configure time.
89 # However, if this is an RPM install, they may have chosen
90 # to relocate this installation. If so, that stuff above
91 # is all broken and we should rejigger it.
92 #------------------------------------------------------------------------------
93 WINE_BIN_NAME=wine.bin
94 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
95 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
98 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
99 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
102 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
103 WINE_BIN_NAME=wine
104 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
105 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
108 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
109 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
113 if [ ! -r $WINELIB/libwine.so ] ; then
114 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
117 if [ ! -r $WINELIB/libwine.so ] ; then
118 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
121 if [ -x $WINEBIN/wineserver ] ; then
122 WINESERVER=$WINEBIN/wineserver
125 #------------------------------------------------------------------------------
126 # Hey, if we built Wine from source, let's add a little extra fun to
127 # mix it up a bit
128 #------------------------------------------------------------------------------
129 if [ -x $WINEBIN/server/wineserver ] ; then
130 WINESERVER=$WINEBIN/server/wineserver
133 if [ -r $WINELIB/dlls/libuser.so ] ; then
134 WINELIBDLLS=$WINELIB/dlls
138 #------------------------------------------------------------------------------
139 # Okay, set the paths and move on.
140 #------------------------------------------------------------------------------
141 export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
142 export PATH=$WINEBIN:$PATH
143 export WINEDLLPATH=$WINELIBDLLS
144 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
146 info_flag=~/.wine/.no_prelaunch_window_flag
147 debug_flag=~/.wine/.no_debug_window_flag
148 debug_options="-debugmsg warn+all"
150 if [ -f $info_flag ] ; then
151 use_info_message=0
152 else
153 use_info_message=1
156 if [ -f $debug_flag ] ; then
157 use_debug_message=0
158 else
159 use_debug_message=1
163 #------------------------------------------------------------------------------
164 # No arguments? Help 'em out
165 #------------------------------------------------------------------------------
166 always_see_output=0
167 no_args=0
168 if [ $# -eq 0 ] ; then
169 no_args=1
172 if [ $# -eq 1 -a foo$1 = foo ] ; then
173 no_args=1
176 if [ $no_args -eq 1 ] ; then
177 echo "Wine called with no arguments."
178 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
179 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
180 -title "Welcome to Wine" \
183 You have started Wine without specifying any arguments.
185 Wine requires a least one argument - the name of the Windows
186 application you would like to run.
188 If you have launched this through the KDE menu system,
189 you can use the KDE file browser to select a Windows
190 exectuable and then click on it to launch Wine with
191 that application.
193 You can similarly use the GNOME file manager to
194 select a Windows executable and double click on it.
196 If you would like to see the command line arguments
197 for Wine, select the second option, below.
200 welcome_rc=$?
201 if [ $welcome_rc -eq 0 ] ; then
202 exit
205 if [ $welcome_rc -eq 2 ] ; then
206 which winesetup
207 if [ $? -eq 0 ] ; then
208 winesetup
209 else
210 if [ -x /opt/wine/bin/winesetup ] ; then
211 /opt/wine/bin/winesetup
212 else
213 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
216 exit
219 use_info_message=0
220 always_see_output=1
223 #------------------------------------------------------------------------------
224 # No config file? Offer to help 'em out...
225 #------------------------------------------------------------------------------
226 conf=0
228 while [ $conf -eq 0 ] ; do
230 if [ -f ~/.winerc ] ; then
231 conf=1
233 if [ -f ~/.wine/config ] ; then
234 conf=2
236 if [ -f /etc/wine.conf ] ; then
237 conf=3
240 if [ $conf -ne 0 ] ; then
241 break;
244 echo "No configuration file detected."
245 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
246 -title "Welcome to Wine" \
249 You have started Wine but we cannot find a Wine
250 configuration file.
252 This is normal if you have never run Wine before.
253 If this is the case, select the 'Configure Wine'
254 option, below, to create a configuration file.
257 init_rc=$?
258 if [ $init_rc -eq 0 ] ; then
259 exit
262 if [ $init_rc -eq 1 ] ; then
263 break
266 if [ $init_rc -eq 2 ] ; then
267 which winesetup
268 if [ $? -eq 0 ] ; then
269 winesetup
270 else
271 if [ -x /opt/wine/bin/winesetup ] ; then
272 /opt/wine/bin/winesetup
273 else
274 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
279 done
281 #------------------------------------------------------------------------------
282 # Optionally Warn the user we're going to be launching Wine...
283 #------------------------------------------------------------------------------
284 if [ $use_info_message -ne 0 ] ; then
285 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
286 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
287 -title "Wine Launch Window" \
288 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
290 This dialog box is a temporary status dialog to let you know
291 that Wine is attempting to launch your application.
293 Since Wine is still very much in a development stage, many
294 applications will fail silently. This dialog box is your indication
295 that we're *trying* to run your application.
297 This dialog box will automatically disappear after 30 seconds,
298 or after your application finishes.
300 You can permanently disable this dialog by selecting the option below.
302 info_message_pid=$!
305 #------------------------------------------------------------------------------
306 # Here's a little function to clean up after that dialog...
307 #------------------------------------------------------------------------------
308 clean_up_info_message ()
310 if [ $use_info_message -ne 0 ] ; then
312 #------------------------------------------------------------------------------
313 # Okay, make sure that the notice window is dead (and kill it if it ain't)
314 #------------------------------------------------------------------------------
315 ps $info_message_pid >/dev/null 2>&1
316 if [ $? -ne 0 ] ; then
317 wait $info_message_pid
318 info_return=$?
319 else
320 info_return=0
321 kill $info_message_pid
324 #------------------------------------------------------------------------------
325 # If they didn't like the warning window, turn it off
326 #------------------------------------------------------------------------------
327 if [ $info_return -eq 3 ] ; then
328 $XMESSAGE -title "Wine Prelaunch Control" \
329 "Wine will now disable the prelaunch Window you just saw.
330 You will no longer be notified when Wine is attempting
331 to start a Windows application.
333 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
334 if [ $? -eq 0 ] ; then
335 touch $info_flag
340 use_info_message=0
342 #------------------------------------------------------------------------------
343 # Generate a temporary log file name
344 #------------------------------------------------------------------------------
345 use_log_name=0
346 log_name=`mktemp /tmp/wine.log.XXXXXX`
347 if [ $? -eq 0 ] ; then
348 which tail >/dev/null 2>&1
349 if [ $? -eq 0 ]; then
350 use_log_name=1
354 #------------------------------------------------------------------------------
355 # Okay, really launch Wine...
356 #------------------------------------------------------------------------------
357 if [ $use_log_name -ne 0 ] ; then
358 #------------------------------------------------------------------------------
359 # Okay, we bend over backwards to run Wine, get that status,
360 # but still display its output to the screen.
361 # The obvious thing to do is to run wine and pipe output to tee,
362 # but then I can't find a way to get the return code of wine;
363 # I only get the return code of tee.
364 #------------------------------------------------------------------------------
365 $WINEBIN/$WINE_BIN_NAME "$@" >$log_name 2>&1 &
366 wine_pid=$!
368 tail -f $log_name &
369 tail_pid=$!
371 wait $wine_pid
372 wine_return=$?
374 kill $tail_pid
375 else
376 $WINEBIN/$WINE_BIN_NAME "$@"
377 wine_return=$?
380 #------------------------------------------------------------------------------
381 # Test the return code, and see if it fails
382 #------------------------------------------------------------------------------
383 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
384 echo "Wine exited with a successful status"
385 if [ $use_log_name -ne 0 ] ; then
386 rm -f $log_name
388 else
389 if [ $always_see_output -eq 0 ] ; then
390 echo "Wine failed with return code $wine_return"
393 #------------------------------------------------------------------------------
394 # Gracefully display a debug message if they like...
395 #------------------------------------------------------------------------------
396 while [ $use_debug_message -gt 0 ] ; do
398 #------------------------------------------------------------------------------
399 # Build up the menu of choices they can make...
400 #------------------------------------------------------------------------------
401 BUTTONS=' Okay :0'
402 if [ $use_log_name -ne 0 ] ; then
403 BUTTONS="$BUTTONS"', View Log :1'
406 BUTTONS="$BUTTONS"', Debug :2'
407 BUTTONS="$BUTTONS"', Configure :4'
408 BUTTONS="$BUTTONS"', Disable :3'
410 #------------------------------------------------------------------------------
411 # Build an error message
412 #------------------------------------------------------------------------------
413 MESSAGE="
414 Wine has exited with a failure status of $wine_return.
416 Wine is still development software, so there can be many
417 explanations for this problem.
419 You can choose to run Wine again with a higher level
420 of debug messages (the debug option, below).
422 You can attempt to reconfigure Wine to make it work better.
423 Note that one change you can make that will dramatically
424 effect Wine's behaviour is to change whether or not
425 Wine uses a true Windows partition, mounted under Linux,
426 or whether it uses an empty Windows directory.
427 The Wine Configuration program can assist you in making
428 those changes (select Configure, below, for more).
430 You can disable this message entirely by selecting the
431 Disable option below."
433 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
434 MESSAGE="
435 Wine has exited with a failure status of $wine_return.
437 You can disable this message entirely by selecting the
438 Disable option below."
442 if [ $use_log_name -ne 0 ] ; then
443 MESSAGE="$MESSAGE
445 Wine has captured a log of the Wine output in the file $log_name.
446 You may view this file by selecting View Log, below."
449 #------------------------------------------------------------------------------
450 # Display the message
451 #------------------------------------------------------------------------------
452 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
453 debug_return=$?
455 #------------------------------------------------------------------------------
456 # Dismiss the other window...
457 #------------------------------------------------------------------------------
458 clean_up_info_message
460 #------------------------------------------------------------------------------
461 # Process a configure instruction
462 #------------------------------------------------------------------------------
463 if [ $debug_return -eq 4 ] ; then
464 which winesetup
465 if [ $? -eq 0 ] ; then
466 winesetup
467 else
468 if [ -x /opt/wine/bin/winesetup ] ; then
469 /opt/wine/bin/winesetup
470 else
471 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
474 continue;
477 #------------------------------------------------------------------------------
478 # Process a view instruction
479 #------------------------------------------------------------------------------
480 if [ $debug_return -eq 1 ] ; then
481 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
482 if [ $? -eq 1 ] ; then
483 echo "Deleting $log_name"
484 rm -f $log_name
485 use_log_name=0
487 else
488 use_debug_message=0
491 #------------------------------------------------------------------------------
492 # If they didn't like the warning window, turn it off
493 #------------------------------------------------------------------------------
494 if [ $debug_return -eq 3 ] ; then
495 $XMESSAGE -title "Wine Debug Log Control" \
496 "Wine will now disable the Wine debug output control window you just saw.
497 You will no longer be notified when Wine fails to start a
498 Windows application.
500 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
502 if [ $? -eq 0 ] ; then
503 touch $debug_flag
508 #------------------------------------------------------------------------------
509 # If they want to retry with debug, let 'em.
510 #------------------------------------------------------------------------------
511 if [ $debug_return -eq 2 ] ; then
512 echo "Rerunning $0 $debug_options $@"
513 exec $0 $debug_options $@
515 done
519 clean_up_info_message