crypt32: Separate checking the tag of encoded bits from decoding the bits.
[wine/multimedia.git] / tools / wineshelllink
blob297c38efec26d73689eac01a8351695829bd5009
1 #!/bin/sh
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
26 # menu structure.
28 mode=""
29 args=""
30 menu=""
31 icon=""
32 descr=""
33 link=""
34 path=""
35 workdir=""
37 usage()
39 cat <<EOF
40 usage: wineshelllink options
42 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
52 EOF
53 exit 2
56 if [ $# -eq 0 ] ; then
57 usage
60 while [ $# -gt 0 ]
62 case "$1" in
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 ;;
71 *) usage ;;
72 esac
73 done
75 if [ -z "$mode" ] ; then
76 echo "Either --desktop or --menu required"
77 usage
80 if [ -z "$link" ] ; then
81 echo "You must specify a link name with --link"
82 usage
85 desktop_entry()
87 cat <<EOF
88 [Desktop Entry]
89 Name=$linkname
90 Exec=env WINEPREFIX="${WINEPREFIX:-$HOME/.wine}" wine "$path" $args
91 Type=Application
92 StartupWMClass=Wine
93 EOF
94 [ -z "$descr" ] || echo "Comment=$descr"
95 [ -z "$workdir" ] || echo "Path=$workdir"
96 [ -z "$icon" ] || echo "Icon=$icon"
99 directory_entry()
101 cat <<EOF
102 [Desktop Entry]
103 Type=Directory
105 if [ "$1" = "wine" ] ; then
106 echo "Name=Wine"
107 echo "Icon=wine"
108 else
109 echo "Name=$1"
110 echo "Icon=folder"
114 # XDG
116 xdg_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/menus/applications-merged"
117 xdg_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
119 # Create common directories
120 mkdir -p "$xdg_config_dir"
121 mkdir -p "$xdg_data_dir/desktop-directories"
123 get_menu_entries()
125 tmp="$xdg_config_dir/$1.menu"
127 if [ -r "$tmp" ] ; then
128 awk '
129 BEGIN { RS="<" }
130 /^Filename/ {
131 RSTART=index($0,">")
132 if (RSTART>0) {
133 print substr($0,RSTART+1)
135 }' $tmp
139 # Input
140 # menu file name
141 # new item
142 write_menu_file()
144 menu=`echo "$1" | sed 's!/!-!g'`
145 filename=`echo "$2" | sed 's!/!-!g'`
147 tmpfile=`mktemp /tmp/wine.XXXXXX`
149 echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"'
150 echo '"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">'
151 echo '<Menu>'
152 echo ' <Name>Applications</Name>'
154 IFS="/"
156 fullname='wine'
157 for i in $1; do
158 echo " <Menu>"
159 echo " <Name>$fullname-$i</Name>"
160 echo " <Directory>$fullname-$i.directory</Directory>"
162 dir_file_name="$xdg_data_dir/desktop-directories/$fullname-$i.directory"
163 if [ ! -f "$dir_file_name" ] ; then
164 directory_entry "$i" > "$dir_file_name"
166 test "$i" = "wine" || fullname="$fullname-$i"
167 done
169 echo " <Include>"
171 IFS="
173 for i in `get_menu_entries "$menu"`
175 test "$i" = "$filename" && continue
176 echo " <Filename>$i</Filename>"
177 done
179 # New record
180 echo " <Filename>$filename</Filename>"
181 echo " </Include>"
183 IFS='/'
184 for i in $1; do
185 echo " </Menu>"
186 done
187 echo '</Menu>'
188 ) > $tmpfile
189 chmod 0600 $tmpfile
191 mv -f $tmpfile "$xdg_config_dir/$menu.menu"
195 linkname=`basename "$link"`
197 if [ $mode = "menu" ] ; then
198 mkdir -p "$xdg_data_dir/applications/wine/`dirname "$link"`"
200 linkpath=`dirname "$link"`
201 if [ "$linkpath" = "." ] ; then
202 linkpath=""
203 else
204 linkpath="/$linkpath"
207 desktop_entry > "$xdg_data_dir/applications/wine/$link.desktop"
208 write_menu_file "wine$linkpath" "wine$linkpath/$linkname.desktop"
209 else
210 if [ -d "$HOME/Desktop" ]
211 then
212 desktop_target="$HOME/Desktop/$linkname.desktop"
213 else
214 desktop_target="$HOME/$linkname.desktop"
216 desktop_entry > "$desktop_target"
219 exit 0