summarylogtreecommitdiffstats
path: root/bgb
blob: c0eda5a25c4352b0ba0f0f3e19a98f75cc0526c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
#
# run the gameboy emulator "bgb" in wine
#
# environment variables:
#	BGB_CONFIG_PATH=...		override the path of the bgb.ini file
#	BGB_SAVE_CONFIG=false		skip saving GUI configuration changes
#	BGB_EXE_PATH=...		override the path to bgb.exe
#	BGB_DEBUGMSG_DIR=...		override the path where debugmsg*.txt will be saved
#	BGB_SAVE_DEBUGMSG=false		skip saving debugmsg*.txt files
set -e

if [ -z "$BGB_EXE_PATH" ]; then
	BGB_EXE_PATH=/usr/lib/bgb/bgb.exe
fi

if [ -z "$BGB_CONFIG_PATH" ]; then
	BGB_CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/bgb/bgb.ini"
fi

if [ -z "$BGB_DEBUGMSG_DIR" ]; then
	BGB_DEBUGMSG_DIR=.
fi

tmp="$(mktemp -d)"
cp "$BGB_EXE_PATH" "$tmp/bgb.exe"

if [ -e "$BGB_CONFIG_PATH" ]; then
	cp "$BGB_CONFIG_PATH" "$tmp/bgb.ini"
fi

wine "$tmp/bgb.exe" "$@"

if [ "$BGB_SAVE_DEBUGMSG" != false ]; then
	mkdir -p "$(dirname "$BGB_DEBUGMSG_DIR")"
	cp -t "$BGB_DEBUGMSG_DIR" "$tmp"/debugmsg*.txt || true
fi

if [ "$BGB_SAVE_CONFIG" != false ] && [ -e "$tmp/bgb.ini" ]; then
	mkdir -p "$(dirname "$BGB_CONFIG_PATH")"
	cp "$tmp/bgb.ini" "$BGB_CONFIG_PATH"
fi

rm -r "$tmp"