3 # Create menu/desktop entries for an application
4 # This is used by the IShellLink interface
6 # Copyright 2000 Alexandre Julliard
7 # Copyright 2006 Vitaliy Margolen
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 # Note that the link is a relative unix-style path name. Since the / character
25 # is not valid in Windows filenames it is an adequate separator to show the
40 usage: wineshelllink options
43 --desktop create a desktop link
44 --menu create a menu entry
45 --path xx path to the application
46 --link xx name of link to create, including path
47 --args xx command-line arguments for the application
48 --icon xx icon to display
49 --workdir xx working directory for the application
50 --descr xx application description
56 if [ $# -eq 0 ] ; then
63 --desktop) mode
="desktop"; shift 1 ;;
64 --menu) mode
="menu"; shift 1 ;;
65 --path) path
="$2"; shift 2 ;;
66 --link) link
="$2"; shift 2 ;;
67 --args) args
="$2"; shift 2 ;;
68 --icon) icon
="$2"; shift 2 ;;
69 --descr) descr
="$2"; shift 2 ;;
70 --workdir) workdir
="$2"; shift 2 ;;
75 if [ -z "$mode" ] ; then
76 echo "Either --desktop or --menu required"
80 if [ -z "$link" ] ; then
81 echo "You must specify a link name with --link"
90 Exec=env WINEPREFIX="${WINEPREFIX:-$HOME/.wine}" wine "$path" $args
94 [ -z "$descr" ] ||
echo "Comment=$descr"
95 [ -z "$workdir" ] ||
echo "Path=$workdir"
96 [ -z "$xpmicon" ] ||
echo "Icon=$xpmicon"
105 if [ "$1" = "wine" ] ; then
114 # copy the icon file to a specified dir and set xpmicon to the resulting path
119 xpmicon
=`basename "$icon"`
120 xpmicon
=${xpmicon%.*}
131 xdg_config_dir
="${XDG_CONFIG_HOME:-$HOME/.config}/menus/applications-merged"
132 xdg_data_dir
="${XDG_DATA_HOME:-$HOME/.local/share}"
134 # Create common directories
135 mkdir
-p "$xdg_config_dir"
136 mkdir
-p "$xdg_data_dir/desktop-directories"
140 tmp
="$xdg_config_dir/$1.menu"
142 if [ -r "$tmp" ] ; then
148 print substr($0,RSTART+1)
159 menu
=`echo "$1" | sed 's!/!-!g'`
160 filename
=`echo "$2" | sed 's!/!-!g'`
162 tmpfile
=`mktemp /tmp/wine.XXXXXX`
164 echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"'
165 echo '"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">'
167 echo ' <Name>Applications</Name>'
174 echo " <Name>$fullname-$i</Name>"
175 echo " <Directory>$fullname-$i.directory</Directory>"
177 dir_file_name
="$xdg_data_dir/desktop-directories/$fullname-$i.directory"
178 if [ ! -f "$dir_file_name" ] ; then
179 directory_entry
"$i" > "$dir_file_name"
181 test "$i" = "wine" || fullname
="$fullname-$i"
188 for i
in `get_menu_entries "$menu"`
190 test "$i" = "$filename" && continue
191 echo " <Filename>$i</Filename>"
195 echo " <Filename>$filename</Filename>"
206 mv -f $tmpfile "$xdg_config_dir/$menu.menu"
210 copy_icon
"$xdg_data_dir/icons"
212 linkname
=`basename "$link"`
214 if [ $mode = "menu" ] ; then
215 mkdir
-p "$xdg_data_dir/applications/wine/`dirname "$link"`"
217 linkpath
=`dirname "$link"`
218 if [ "$linkpath" = "." ] ; then
221 linkpath
="/$linkpath"
224 desktop_entry
> "$xdg_data_dir/applications/wine/$link.desktop"
225 write_menu_file
"wine$linkpath" "wine$linkpath/$linkname.desktop"
227 if [ -d "$HOME/Desktop" ]
229 desktop_target
="$HOME/Desktop/$linkname.desktop"
231 desktop_target
="$HOME/$linkname.desktop"
233 desktop_entry
> "$desktop_target"