Added sample config file in the new format.
[wine/multimedia.git] / tools / winelauncher.in
blobc73e0d2637bf9093a9fc6fa3dbd3a190f4877b39
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 XMESSAGE="xmessage $COLOR"
51 #------------------------------------------------------------------------------
52 # We're going to do a lot of fancy footwork below.
53 # Before we get started, it would be nice to know the argv0,
54 # of the actual script we're running (and lets remove at least
55 # one level of symlinking).
56 #------------------------------------------------------------------------------
57 real_name=`find $0 -type l -printf "%l\n"`
58 if [ ! $real_name ]; then
59 real_name=$0;
61 argv0_dir=`find $real_name -printf "%h\n"`
63 if [ -z $argv0_dir ] ; then
64 argv0_dir=.
67 #------------------------------------------------------------------------------
68 # Okay, now all that junk above was established at configure time.
69 # However, if this is an RPM install, they may have chosen
70 # to relocate this installation. If so, that stuff above
71 # is all broken and we should rejigger it.
72 #------------------------------------------------------------------------------
73 WINE_BIN_NAME=wine.bin
74 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
75 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
78 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
79 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
82 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
83 WINE_BIN_NAME=wine
84 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
85 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
88 if [ ! -x $WINEBIN/$WINE_BIN_NAME ] ; then
89 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name "$WINE_BIN_NAME" -printf "%h\n" | head -1`
93 if [ ! -r $WINELIB/libwine.so ] ; then
94 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
97 if [ ! -r $WINELIB/libwine.so ] ; then
98 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
101 if [ -x $WINEBIN/wineserver ] ; then
102 WINESERVER=$WINEBIN/wineserver
105 #------------------------------------------------------------------------------
106 # Hey, if we built Wine from source, let's add a little extra fun to
107 # mix it up a bit
108 #------------------------------------------------------------------------------
109 if [ -x $WINEBIN/server/wineserver ] ; then
110 WINESERVER=$WINEBIN/server/wineserver
113 if [ -r $WINELIB/dlls/libuser.so ] ; then
114 WINELIBDLLS=$WINELIB/dlls
118 #------------------------------------------------------------------------------
119 # Okay, set the paths and move on.
120 #------------------------------------------------------------------------------
121 export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
122 export PATH=$WINEBIN:$PATH
123 export WINEDLLPATH=$WINELIBDLLS
124 export WINELOADER=$WINEBIN/$WINE_BIN_NAME
126 info_flag=~/.wine/.no_prelaunch_window_flag
127 debug_flag=~/.wine/.no_debug_window_flag
128 debug_options="-debugmsg warn+all"
130 if [ -f $info_flag ] ; then
131 use_info_message=0
132 else
133 use_info_message=1
136 if [ -f $debug_flag ] ; then
137 use_debug_message=0
138 else
139 use_debug_message=1
143 #------------------------------------------------------------------------------
144 # No arguments? Help 'em out
145 #------------------------------------------------------------------------------
146 always_see_output=0
147 no_args=0
148 if [ $# -eq 0 ] ; then
149 no_args=1
152 if [ $# -eq 1 -a foo$1 = foo ] ; then
153 no_args=1
156 if [ $no_args -eq 1 ] ; then
157 echo "Wine called with no arguments."
158 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
159 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
160 -title "Welcome to Wine" \
163 You have started Wine without specifying any arguments.
165 Wine requires a least one argument - the name of the Windows
166 application you would like to run.
168 If you have launched this through the KDE menu system,
169 you can use the KDE file browser to select a Windows
170 exectuable and then click on it to launch Wine with
171 that application.
173 You can similarly use the GNOME file manager to
174 select a Windows executable and double click on it.
176 If you would like to see the command line arguments
177 for Wine, select the second option, below.
180 welcome_rc=$?
181 if [ $welcome_rc -eq 0 ] ; then
182 exit
185 if [ $welcome_rc -eq 2 ] ; then
186 which winesetup
187 if [ $? -eq 0 ] ; then
188 winesetup
189 else
190 if [ -x /opt/wine/bin/winesetup ] ; then
191 /opt/wine/bin/winesetup
192 else
193 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
196 exit
199 use_info_message=0
200 always_see_output=1
203 #------------------------------------------------------------------------------
204 # No config file? Offer to help 'em out...
205 #------------------------------------------------------------------------------
206 conf=0
208 while [ $conf -eq 0 ] ; do
210 if [ -f ~/.winerc ] ; then
211 conf=1
213 if [ -f ~/.wine/config ] ; then
214 conf=2
216 if [ -f /etc/wine.conf ] ; then
217 conf=3
220 if [ $conf -ne 0 ] ; then
221 break;
224 echo "No configuration file detected."
225 $XMESSAGE -buttons " Cancel ":0," Proceed ":1," Configure Wine ":2 \
226 -title "Welcome to Wine" \
229 You have started Wine but we cannot find a Wine
230 configuration file.
232 This is normal if you have never run Wine before.
233 If this is the case, select the 'Configure Wine'
234 option, below, to create a configuration file.
237 init_rc=$?
238 if [ $init_rc -eq 0 ] ; then
239 exit
242 if [ $init_rc -eq 1 ] ; then
243 break
246 if [ $init_rc -eq 2 ] ; then
247 which winesetup
248 if [ $? -eq 0 ] ; then
249 winesetup
250 else
251 if [ -x /opt/wine/bin/winesetup ] ; then
252 /opt/wine/bin/winesetup
253 else
254 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
259 done
261 #------------------------------------------------------------------------------
262 # Optionally Warn the user we're going to be launching Wine...
263 #------------------------------------------------------------------------------
264 if [ $use_info_message -ne 0 ] ; then
265 echo "Invoking $WINEBIN/$WINE_BIN_NAME $@ ..."
266 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
267 -title "Wine Launch Window" \
268 "Invoking $WINEBIN/$WINE_BIN_NAME $@ ...
270 This dialog box is a temporary status dialog to let you know
271 that Wine is attempting to launch your application.
273 Since Wine is still very much in a development stage, many
274 applications will fail silently. This dialog box is your indication
275 that we're *trying* to run your application.
277 This dialog box will automatically disappear after 30 seconds,
278 or after your application finishes.
280 You can permanently disable this dialog by selecting the option below.
282 info_message_pid=$!
285 #------------------------------------------------------------------------------
286 # Here's a little function to clean up after that dialog...
287 #------------------------------------------------------------------------------
288 function clean_up_info_message ()
290 if [ $use_info_message -ne 0 ] ; then
292 #------------------------------------------------------------------------------
293 # Okay, make sure that the notice window is dead (and kill it if it ain't)
294 #------------------------------------------------------------------------------
295 ps $info_message_pid >/dev/null 2>&1
296 if [ $? -ne 0 ] ; then
297 wait $info_message_pid
298 info_return=$?
299 else
300 info_return=0
301 kill $info_message_pid
304 #------------------------------------------------------------------------------
305 # If they didn't like the warning window, turn it off
306 #------------------------------------------------------------------------------
307 if [ $info_return -eq 3 ] ; then
308 $XMESSAGE -title "Wine Prelaunch Control" \
309 "Wine will now disable the prelaunch Window you just saw.
310 You will no longer be notified when Wine is attempting
311 to start a Windows application.
313 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
314 if [ $? -eq 0 ] ; then
315 touch $info_flag
320 use_info_message=0
322 #------------------------------------------------------------------------------
323 # Generate a temporary log file name
324 #------------------------------------------------------------------------------
325 use_log_name=0
326 log_name=`mktemp /tmp/wine.log.XXXXXX`
327 if [ $? -eq 0 ] ; then
328 which tail >/dev/null 2>&1
329 if [ $? -eq 0 ]; then
330 use_log_name=1
334 #------------------------------------------------------------------------------
335 # Okay, really launch Wine...
336 #------------------------------------------------------------------------------
337 if [ $use_log_name -ne 0 ] ; then
338 #------------------------------------------------------------------------------
339 # Okay, we bend over backwards to run Wine, get that status,
340 # but still display its output to the screen.
341 # The obvious thing to do is to run wine and pipe output to tee,
342 # but then I can't find a way to get the return code of wine;
343 # I only get the return code of tee.
344 #------------------------------------------------------------------------------
345 $WINEBIN/$WINE_BIN_NAME "$@" >$log_name 2>&1 &
346 wine_pid=$!
348 tail -f $log_name &
349 tail_pid=$!
351 wait $wine_pid
352 wine_return=$?
354 kill $tail_pid
355 else
356 $WINEBIN/$WINE_BIN_NAME "$@"
357 wine_return=$?
360 #------------------------------------------------------------------------------
361 # Test the return code, and see if it fails
362 #------------------------------------------------------------------------------
363 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
364 echo "Wine exited with a successful status"
365 if [ $use_log_name -ne 0 ] ; then
366 rm -f $log_name
368 else
369 if [ $always_see_output -eq 0 ] ; then
370 echo "Wine failed with return code $wine_return"
373 #------------------------------------------------------------------------------
374 # Gracefully display a debug message if they like...
375 #------------------------------------------------------------------------------
376 while [ $use_debug_message -gt 0 ] ; do
378 #------------------------------------------------------------------------------
379 # Build up the menu of choices they can make...
380 #------------------------------------------------------------------------------
381 BUTTONS=' Okay :0'
382 if [ $use_log_name -ne 0 ] ; then
383 BUTTONS="$BUTTONS"', View Log :1'
386 BUTTONS="$BUTTONS"', Debug :2'
387 BUTTONS="$BUTTONS"', Configure :4'
388 BUTTONS="$BUTTONS"', Disable :3'
390 #------------------------------------------------------------------------------
391 # Build an error message
392 #------------------------------------------------------------------------------
393 MESSAGE="
394 Wine has exited with a failure status of $wine_return.
396 Wine is still development software, so there can be many
397 explanations for this problem.
399 You can choose to run Wine again with a higher level
400 of debug messages (the debug option, below).
402 You can attempt to reconfigure Wine to make it work better.
403 Note that one change you can make that will dramatically
404 effect Wine's behaviour is to change whether or not
405 Wine uses a true Windows partition, mounted under Linux,
406 or whether it uses an empty Windows directory.
407 The Wine Configuration program can assist you in making
408 those changes (select Configure, below, for more).
410 You can disable this message entirely by selecting the
411 Disable option below."
413 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
414 MESSAGE="
415 Wine has exited with a failure status of $wine_return.
417 You can disable this message entirely by selecting the
418 Disable option below."
422 if [ $use_log_name -ne 0 ] ; then
423 MESSAGE="$MESSAGE
425 Wine has captured a log of the Wine output in the file $log_name.
426 You may view this file by selecting View Log, below."
429 #------------------------------------------------------------------------------
430 # Display the message
431 #------------------------------------------------------------------------------
432 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
433 debug_return=$?
435 #------------------------------------------------------------------------------
436 # Dismiss the other window...
437 #------------------------------------------------------------------------------
438 clean_up_info_message
440 #------------------------------------------------------------------------------
441 # Process a configure instruction
442 #------------------------------------------------------------------------------
443 if [ $debug_return -eq 4 ] ; then
444 which winesetup
445 if [ $? -eq 0 ] ; then
446 winesetup
447 else
448 if [ -x /opt/wine/bin/winesetup ] ; then
449 /opt/wine/bin/winesetup
450 else
451 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
454 continue;
457 #------------------------------------------------------------------------------
458 # Process a view instruction
459 #------------------------------------------------------------------------------
460 if [ $debug_return -eq 1 ] ; then
461 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
462 if [ $? -eq 1 ] ; then
463 echo "Deleting $log_name"
464 rm -f $log_name
465 use_log_name=0
467 else
468 use_debug_message=0
471 #------------------------------------------------------------------------------
472 # If they didn't like the warning window, turn it off
473 #------------------------------------------------------------------------------
474 if [ $debug_return -eq 3 ] ; then
475 $XMESSAGE -title "Wine Debug Log Control" \
476 "Wine will now disable the Wine debug output control window you just saw.
477 You will no longer be notified when Wine fails to start a
478 Windows application.
480 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
482 if [ $? -eq 0 ] ; then
483 touch $debug_flag
488 #------------------------------------------------------------------------------
489 # If they want to retry with debug, let 'em.
490 #------------------------------------------------------------------------------
491 if [ $debug_return -eq 2 ] ; then
492 echo "Rerunning $0 $debug_options $@"
493 exec $0 $debug_options $@
495 done
499 clean_up_info_message