1 | #!/usr/bin/env bash
|
---|
2 |
|
---|
3 | # default directories
|
---|
4 | dxvk_lib32=${dxvk_lib32:-"x32"}
|
---|
5 | dxvk_lib64=${dxvk_lib64:-"x64"}
|
---|
6 |
|
---|
7 | # figure out where we are
|
---|
8 | basedir=$(dirname "$(readlink -f $0)")
|
---|
9 |
|
---|
10 | # figure out which action to perform
|
---|
11 | action="$1"
|
---|
12 |
|
---|
13 | case "$action" in
|
---|
14 | install)
|
---|
15 | ;;
|
---|
16 | uninstall)
|
---|
17 | ;;
|
---|
18 | *)
|
---|
19 | echo "Unrecognized action: $action"
|
---|
20 | echo "Usage: $0 [install|uninstall] [--without-dxgi] [--with-d3d10] [--symlink]"
|
---|
21 | exit 1
|
---|
22 | esac
|
---|
23 |
|
---|
24 | # process arguments
|
---|
25 | shift
|
---|
26 |
|
---|
27 | with_dxgi=true
|
---|
28 | with_d3d10=false
|
---|
29 | file_cmd="cp -v"
|
---|
30 |
|
---|
31 | while (($# > 0)); do
|
---|
32 | case "$1" in
|
---|
33 | "--without-dxgi")
|
---|
34 | with_dxgi=false
|
---|
35 | ;;
|
---|
36 | "--with-d3d10")
|
---|
37 | with_d3d10=true
|
---|
38 | ;;
|
---|
39 | "--symlink")
|
---|
40 | file_cmd="ln -s -v"
|
---|
41 | ;;
|
---|
42 | esac
|
---|
43 | shift
|
---|
44 | done
|
---|
45 |
|
---|
46 | # check wine prefix before invoking wine, so that we
|
---|
47 | # don't accidentally create one if the user screws up
|
---|
48 | if [ -n "$WINEPREFIX" ] && ! [ -f "$WINEPREFIX/system.reg" ]; then
|
---|
49 | echo "$WINEPREFIX:"' Not a valid wine prefix.' >&2
|
---|
50 | exit 1
|
---|
51 | fi
|
---|
52 |
|
---|
53 | # find wine executable
|
---|
54 | export WINEDEBUG=-all
|
---|
55 | # disable mscoree and mshtml to avoid downloading
|
---|
56 | # wine gecko and mono
|
---|
57 | export WINEDLLOVERRIDES="mscoree,mshtml="
|
---|
58 |
|
---|
59 | wine="wine"
|
---|
60 | wine64="wine64"
|
---|
61 | wineboot="wineboot"
|
---|
62 |
|
---|
63 | # $PATH is the way for user to control where wine is located (including custom Wine versions).
|
---|
64 | # Pure 64-bit Wine (non Wow64) requries skipping 32-bit steps.
|
---|
65 | # In such case, wine64 and winebooot will be present, but wine binary will be missing,
|
---|
66 | # however it can be present in other PATHs, so it shouldn't be used, to avoid versions mixing.
|
---|
67 | wine_path=$(dirname "$(which $wineboot)")
|
---|
68 | wow64=true
|
---|
69 | if ! [ -f "$wine_path/$wine" ]; then
|
---|
70 | wine=$wine64
|
---|
71 | wow64=false
|
---|
72 | fi
|
---|
73 |
|
---|
74 | # resolve 32-bit and 64-bit system32 path
|
---|
75 | winever=$($wine --version | grep wine)
|
---|
76 | if [ -z "$winever" ]; then
|
---|
77 | echo "$wine:"' Not a wine executable. Check your $wine.' >&2
|
---|
78 | exit 1
|
---|
79 | fi
|
---|
80 |
|
---|
81 | # ensure wine placeholder dlls are recreated
|
---|
82 | # if they are missing
|
---|
83 | $wineboot -u
|
---|
84 |
|
---|
85 | win64_sys_path=$($wine64 winepath -u 'C:\windows\system32' 2> /dev/null)
|
---|
86 | win64_sys_path="${win64_sys_path/$'\r'/}"
|
---|
87 | if $wow64; then
|
---|
88 | win32_sys_path=$($wine winepath -u 'C:\windows\system32' 2> /dev/null)
|
---|
89 | win32_sys_path="${win32_sys_path/$'\r'/}"
|
---|
90 | fi
|
---|
91 |
|
---|
92 | if [ -z "$win32_sys_path" ] && [ -z "$win64_sys_path" ]; then
|
---|
93 | echo 'Failed to resolve C:\windows\system32.' >&2
|
---|
94 | exit 1
|
---|
95 | fi
|
---|
96 |
|
---|
97 | # create native dll override
|
---|
98 | overrideDll() {
|
---|
99 | $wine reg add 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v $1 /d native /f >/dev/null 2>&1
|
---|
100 | if [ $? -ne 0 ]; then
|
---|
101 | echo -e "Failed to add override for $1"
|
---|
102 | exit 1
|
---|
103 | fi
|
---|
104 | }
|
---|
105 |
|
---|
106 | # remove dll override
|
---|
107 | restoreDll() {
|
---|
108 | $wine reg delete 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v $1 /f > /dev/null 2>&1
|
---|
109 | if [ $? -ne 0 ]; then
|
---|
110 | echo "Failed to remove override for $1"
|
---|
111 | fi
|
---|
112 | }
|
---|
113 |
|
---|
114 | # copy or link dxvk dll, back up original file
|
---|
115 | installFile() {
|
---|
116 | dstfile="${1}/${3}.dll"
|
---|
117 | srcfile="${basedir}/${2}/${3}.dll"
|
---|
118 |
|
---|
119 | if [ -f "${srcfile}.so" ]; then
|
---|
120 | srcfile="${srcfile}.so"
|
---|
121 | fi
|
---|
122 |
|
---|
123 | if ! [ -f "${srcfile}" ]; then
|
---|
124 | echo "${srcfile}: File not found. Skipping." >&2
|
---|
125 | return 1
|
---|
126 | fi
|
---|
127 |
|
---|
128 | if [ -n "$1" ]; then
|
---|
129 | if [ -f "${dstfile}" ] || [ -h "${dstfile}" ]; then
|
---|
130 | if ! [ -f "${dstfile}.old" ]; then
|
---|
131 | mv -v "${dstfile}" "${dstfile}.old"
|
---|
132 | else
|
---|
133 | rm -v "${dstfile}"
|
---|
134 | fi
|
---|
135 | $file_cmd "${srcfile}" "${dstfile}"
|
---|
136 | else
|
---|
137 | echo "${dstfile}: File not found in wine prefix" >&2
|
---|
138 | return 1
|
---|
139 | fi
|
---|
140 | fi
|
---|
141 | return 0
|
---|
142 | }
|
---|
143 |
|
---|
144 | # remove dxvk dll, restore original file
|
---|
145 | uninstallFile() {
|
---|
146 | dstfile="${1}/${3}.dll"
|
---|
147 | srcfile="${basedir}/${2}/${3}.dll"
|
---|
148 |
|
---|
149 | if [ -f "${srcfile}.so" ]; then
|
---|
150 | srcfile="${srcfile}.so"
|
---|
151 | fi
|
---|
152 |
|
---|
153 | if ! [ -f "${srcfile}" ]; then
|
---|
154 | echo "${srcfile}: File not found. Skipping." >&2
|
---|
155 | return 1
|
---|
156 | fi
|
---|
157 |
|
---|
158 | if ! [ -f "${dstfile}" ] && ! [ -h "${dstfile}" ]; then
|
---|
159 | echo "${dstfile}: File not found. Skipping." >&2
|
---|
160 | return 1
|
---|
161 | fi
|
---|
162 |
|
---|
163 | if [ -f "${dstfile}.old" ]; then
|
---|
164 | rm -v "${dstfile}"
|
---|
165 | mv -v "${dstfile}.old" "${dstfile}"
|
---|
166 | return 0
|
---|
167 | else
|
---|
168 | return 1
|
---|
169 | fi
|
---|
170 | }
|
---|
171 |
|
---|
172 | install() {
|
---|
173 | installFile "$win64_sys_path" "$dxvk_lib64" "$1"
|
---|
174 | inst64_ret="$?"
|
---|
175 |
|
---|
176 | inst32_ret=-1
|
---|
177 | if $wow64; then
|
---|
178 | installFile "$win32_sys_path" "$dxvk_lib32" "$1"
|
---|
179 | inst32_ret="$?"
|
---|
180 | fi
|
---|
181 |
|
---|
182 | if (( ($inst32_ret == 0) || ($inst64_ret == 0) )); then
|
---|
183 | overrideDll "$1"
|
---|
184 | fi
|
---|
185 | }
|
---|
186 |
|
---|
187 | uninstall() {
|
---|
188 | uninstallFile "$win64_sys_path" "$dxvk_lib64" "$1"
|
---|
189 | uninst64_ret="$?"
|
---|
190 |
|
---|
191 | uninst32_ret=-1
|
---|
192 | if $wow64; then
|
---|
193 | uninstallFile "$win32_sys_path" "$dxvk_lib32" "$1"
|
---|
194 | uninst32_ret="$?"
|
---|
195 | fi
|
---|
196 |
|
---|
197 | if (( ($uninst32_ret == 0) || ($uninst64_ret == 0) )); then
|
---|
198 | restoreDll "$1"
|
---|
199 | fi
|
---|
200 | }
|
---|
201 |
|
---|
202 | # skip dxgi during install if not explicitly
|
---|
203 | # enabled, but always try to uninstall it
|
---|
204 | if $with_dxgi || [ "$action" == "uninstall" ]; then
|
---|
205 | $action dxgi
|
---|
206 | fi
|
---|
207 |
|
---|
208 | $action d3d9
|
---|
209 |
|
---|
210 | if $with_d3d10 || [ "$action" == "uninstall" ]; then
|
---|
211 | $action d3d10
|
---|
212 | $action d3d10_1
|
---|
213 | fi
|
---|
214 |
|
---|
215 | $action d3d10core
|
---|
216 | $action d3d11
|
---|