We were returning characters for various CTRL + Symbol keystrokes
[wine/multimedia.git] / tools / winelauncher.in
blob94ffba49aec4d2c53fdfbf74264af11f8b43ea31
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 if [ ! -x $WINEBIN/wine ] ; then
74 WINEBIN=`find $argv0_dir -maxdepth 1 -perm +0111 -type f -name 'wine' -printf "%h\n" | head -1`
77 if [ ! -x $WINEBIN/wine ] ; then
78 WINEBIN=`find $argv0_dir/../ -maxdepth 1 -perm +0111 -type f -name 'wine' -printf "%h\n" | head -1`
81 if [ ! -r $WINELIB/libwine.so ] ; then
82 WINELIB=`find $argv0_dir -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
85 if [ ! -r $WINELIB/libwine.so ] ; then
86 WINELIB=`find $argv0_dir/../ -maxdepth 2 -name 'libwine.so' -printf "%h\n" | head -1`
89 #------------------------------------------------------------------------------
90 # Hey, if we built Wine from source, let's add a little extra fun to
91 # mix it up a bit
92 #------------------------------------------------------------------------------
93 if [ -x $WINEBIN/server/wineserver ] ; then
94 WINESERVERBIN=$WINEBIN/server
97 if [ -r $WINELIB/dlls/libuser.so ] ; then
98 WINELIBDLLS=$WINELIB/dlls
102 #------------------------------------------------------------------------------
103 # Okay, set the paths and move on.
104 #------------------------------------------------------------------------------
105 export LD_LIBRARY_PATH=$WINELIB:$WINELIBDLLS:$LD_LIBRARY_PATH
106 export PATH=$WINEBIN:$WINESERVERBIN:$PATH
109 info_flag=~/.wine/.no_prelaunch_window_flag
110 debug_flag=~/.wine/.no_debug_window_flag
111 debug_options="-debugmsg warn+all"
113 if [ -f $info_flag ] ; then
114 use_info_message=0
115 else
116 use_info_message=1
119 if [ -f $debug_flag ] ; then
120 use_debug_message=0
121 else
122 use_debug_message=1
126 #------------------------------------------------------------------------------
127 # No arguments? Help 'em out
128 #------------------------------------------------------------------------------
129 always_see_output=0
130 no_args=0
131 if [ $# -eq 0 ] ; then
132 no_args=1
135 if [ $# -eq 1 -a foo$1 = foo ] ; then
136 no_args=1
139 if [ $no_args -eq 1 ] ; then
140 echo "Wine called with no arguments."
141 echo "Invoking $WINEBIN/wine $@ ..."
142 $XMESSAGE -buttons " Okay ":0," See the Wine Usage Statement ":1," Configure Wine ":2 \
143 -title "Welcome to Wine" \
146 You have started Wine without specifying any arguments.
148 Wine requires a least one argument - the name of the Windows
149 application you would like to run.
151 If you have launched this through the KDE menu system,
152 you can use the KDE file browser to select a Windows
153 exectuable and then click on it to launch Wine with
154 that application.
156 You can similarly use the GNOME file manager to
157 select a Windows executable and double click on it.
159 If you would like to see the command line arguments
160 for Wine, select the second option, below.
163 welcome_rc=$?
164 if [ $welcome_rc -eq 0 ] ; then
165 exit
168 if [ $welcome_rc -eq 2 ] ; then
169 which winesetup
170 if [ $? -eq 0 ] ; then
171 winesetup
172 else
173 if [ -x /opt/wine/bin/winesetup ] ; then
174 /opt/wine/bin/winesetup
175 else
176 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
179 exit
182 use_info_message=0
183 always_see_output=1
186 #------------------------------------------------------------------------------
187 # Optionally Warn the user we're going to be launching Wine...
188 #------------------------------------------------------------------------------
189 if [ $use_info_message -ne 0 ] ; then
190 echo "Invoking $WINEBIN/wine $@ ..."
191 $XMESSAGE -timeout 30 -buttons " Dismiss ":0," Never display this message again ":3 \
192 -title "Wine Launch Window" \
193 "Invoking $WINEBIN/wine $@ ...
195 This dialog box is a temporary status dialog to let you know
196 that Wine is attempting to launch your application.
198 Since Wine is still very much in a development stage, many
199 applications will fail silently. This dialog box is your indication
200 that we're *trying* to run your application.
202 This dialog box will automatically disappear after 30 seconds,
203 or after your application finishes.
205 You can permanently disable this dialog by selecting the option below.
207 info_message_pid=$!
210 #------------------------------------------------------------------------------
211 # Here's a little function to clean up after that dialog...
212 #------------------------------------------------------------------------------
213 function clean_up_info_message ()
215 if [ $use_info_message -ne 0 ] ; then
217 #------------------------------------------------------------------------------
218 # Okay, make sure that the notice window is dead (and kill it if it ain't)
219 #------------------------------------------------------------------------------
220 ps $info_message_pid >/dev/null 2>&1
221 if [ $? -ne 0 ] ; then
222 wait $info_message_pid
223 info_return=$?
224 else
225 info_return=0
226 kill $info_message_pid
229 #------------------------------------------------------------------------------
230 # If they didn't like the warning window, turn it off
231 #------------------------------------------------------------------------------
232 if [ $info_return -eq 3 ] ; then
233 $XMESSAGE -title "Wine Prelaunch Control" \
234 "Wine will now disable the prelaunch Window you just saw.
235 You will no longer be notified when Wine is attempting
236 to start a Windows application.
238 You can reenable this Window by removing the $info_flag file." -buttons " Okay ":0," Cancel ":1
239 if [ $? -eq 0 ] ; then
240 touch $info_flag
245 use_info_message=0
247 #------------------------------------------------------------------------------
248 # Generate a temporary log file name
249 #------------------------------------------------------------------------------
250 use_log_name=0
251 log_name=`mktemp /tmp/wine.log.XXXXXX`
252 if [ $? -eq 0 ] ; then
253 which tail >/dev/null 2>&1
254 if [ $? -eq 0 ]; then
255 use_log_name=1
259 #------------------------------------------------------------------------------
260 # Okay, really launch Wine...
261 #------------------------------------------------------------------------------
262 if [ $use_log_name -ne 0 ] ; then
263 #------------------------------------------------------------------------------
264 # Okay, we bend over backwards to run Wine, get that status,
265 # but still display its output to the screen.
266 # The obvious thing to do is to run wine and pipe output to tee,
267 # but then I can't find a way to get the return code of wine;
268 # I only get the return code of tee.
269 #------------------------------------------------------------------------------
270 $WINEBIN/wine "$@" >$log_name 2>&1 &
271 wine_pid=$!
273 tail -f $log_name &
274 tail_pid=$!
276 wait $wine_pid
277 wine_return=$?
279 kill $tail_pid
280 else
281 $WINEBIN/wine "$@"
282 wine_return=$?
285 #------------------------------------------------------------------------------
286 # Test the return code, and see if it fails
287 #------------------------------------------------------------------------------
288 if [ $always_see_output -eq 0 -a $wine_return -eq 0 ] ; then
289 echo "Wine exited with a successful status"
290 if [ $use_log_name -ne 0 ] ; then
291 rm -f $log_name
293 else
294 if [ $always_see_output -eq 0 ] ; then
295 echo "Wine failed with return code $wine_return"
298 #------------------------------------------------------------------------------
299 # Gracefully display a debug message if they like...
300 #------------------------------------------------------------------------------
301 while [ $use_debug_message -gt 0 ] ; do
303 #------------------------------------------------------------------------------
304 # Build up the menu of choices they can make...
305 #------------------------------------------------------------------------------
306 BUTTONS=' Okay :0'
307 if [ $use_log_name -ne 0 ] ; then
308 BUTTONS="$BUTTONS"', View Log :1'
311 BUTTONS="$BUTTONS"', Debug :2'
312 BUTTONS="$BUTTONS"', Configure :4'
313 BUTTONS="$BUTTONS"', Disable :3'
315 #------------------------------------------------------------------------------
316 # Build an error message
317 #------------------------------------------------------------------------------
318 MESSAGE="
319 Wine has exited with a failure status of $wine_return.
321 Wine is still development software, so there can be many
322 explanations for this problem.
324 You can choose to run Wine again with a higher level
325 of debug messages (the debug option, below).
327 You can attempt to reconfigure Wine to make it work better.
328 Note that one change you can make that will dramatically
329 effect Wine's behaviour is to change whether or not
330 Wine uses a true Windows partition, mounted under Linux,
331 or whether it uses an empty Windows directory.
332 The Wine Configuration program can assist you in making
333 those changes (select Configure, below, for more).
335 You can disable this message entirely by selecting the
336 Disable option below."
338 if [ $always_see_output -ne 0 -a $wine_return -eq 0 ] ; then
339 MESSAGE="
340 Wine has exited with a failure status of $wine_return.
342 You can disable this message entirely by selecting the
343 Disable option below."
347 if [ $use_log_name -ne 0 ] ; then
348 MESSAGE="$MESSAGE
350 Wine has captured a log of the Wine output in the file $log_name.
351 You may view this file by selecting View Log, below."
354 #------------------------------------------------------------------------------
355 # Display the message
356 #------------------------------------------------------------------------------
357 $XMESSAGE -title "Wine Finished With Error" -buttons "$BUTTONS" "$MESSAGE"
358 debug_return=$?
360 #------------------------------------------------------------------------------
361 # Dismiss the other window...
362 #------------------------------------------------------------------------------
363 clean_up_info_message
365 #------------------------------------------------------------------------------
366 # Process a configure instruction
367 #------------------------------------------------------------------------------
368 if [ $debug_return -eq 4 ] ; then
369 which winesetup
370 if [ $? -eq 0 ] ; then
371 winesetup
372 else
373 if [ -x /opt/wine/bin/winesetup ] ; then
374 /opt/wine/bin/winesetup
375 else
376 $XMESSAGE -title "Error" "Error: Unable to find winesetup in your PATH or in /opt/wine/bin"
379 continue;
382 #------------------------------------------------------------------------------
383 # Process a view instruction
384 #------------------------------------------------------------------------------
385 if [ $debug_return -eq 1 ] ; then
386 $XMESSAGE -title "View Wine Log" -file $log_name -buttons " Okay ":0,"Delete $log_name":1
387 if [ $? -eq 1 ] ; then
388 echo "Deleting $log_name"
389 rm -f $log_name
390 use_log_name=0
392 else
393 use_debug_message=0
396 #------------------------------------------------------------------------------
397 # If they didn't like the warning window, turn it off
398 #------------------------------------------------------------------------------
399 if [ $debug_return -eq 3 ] ; then
400 $XMESSAGE -title "Wine Debug Log Control" \
401 "Wine will now disable the Wine debug output control window you just saw.
402 You will no longer be notified when Wine fails to start a
403 Windows application.
405 You can reenable this Window by removing the $debug_flag file." -buttons " Okay ":0," Cancel ":1
407 if [ $? -eq 0 ] ; then
408 touch $debug_flag
413 #------------------------------------------------------------------------------
414 # If they want to retry with debug, let 'em.
415 #------------------------------------------------------------------------------
416 if [ $debug_return -eq 2 ] ; then
417 echo "Rerunning $0 $debug_options $@"
418 exec $0 $debug_options $@
420 done
424 clean_up_info_message