-
Notifications
You must be signed in to change notification settings - Fork 1
/
tuhustp
executable file
·88 lines (86 loc) · 2.91 KB
/
tuhustp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# fix echo
echo () { printf %s\\n "$*" ; }
# search for executables from home directory
echo "searching for touhou executables"
find "$HOME" -name 'th[0-9]*[0-9]\.exe' > PathsFound
# number of games found saved to variable
NumPaths=$(find "$HOME" -name 'th[0-9]*[0-9]\.exe' | wc -l)
# number of icons found saved to variable
IconPaths=$(find "$HOME" -name 'Icon_th[0-9]*[0-9]\.png' | wc -l)
if [ ! "$IconPaths" = "$NumPaths" ]; then
echo "some games lack icons"
LacksIcon=1
# check if tool to create icons exists
command -v extresso > /dev/null && CanCreateIcon=1 || CanCreateIcon=0
[ 1 = $CanCreateIcon ] && echo "missing icons will be created" || echo "missing icons can't be created please install icoutils and re-run"
else
LacksIcon=0
fi
# start counter
NumLine=1
while [ $NumLine -le "$NumPaths" ];
do
# cd to dir of nth game found
cd "$(sed 's/th[0-9]*[0-9].exe$//;'$NumLine'q;d' PathsFound)" || exit
# read the numbers from the exe filename
TouhouNum=$(echo th*[!e].exe|cut -c 3-|head --bytes -5)
# check if an additional patched exe exists
if [ -f th"$TouhouNum"e.exe ]; then
# set the name of the additional patched exe for the run script
TouhouNumE="${TouhouNum}e"
else
# set the name of the only exe for the run script
TouhouNumE=$TouhouNum
fi
# create missing icons if the tools are avaible
if [ ! -f Icon_th"$TouhouNum".png ]; then
if [ $LacksIcon = 1 ] && [ $CanCreateIcon = 1 ]; then
echo "creating icon for th$TouhouNum"
wrestool -x -t 14 th"$TouhouNum".exe > out.ico
icotool -x -o . out.ico
mv out*.png Icon_th"$TouhouNum".png
rm out.ico
fi
fi
CurrentDirPath="$(pwd)"
echo "creating runscript for th$TouhouNum"
# create run script
touch touhou-"$TouhouNum"
# write contents of run script
echo "#!/bin/sh
# go to executable directory" > touhou-"$TouhouNum"
# write path of the exe to script
echo "cd $CurrentDirPath/" >> touhou-"$TouhouNum"
# write rest of run script
echo "#run executable
wine th$TouhouNumE.exe" >> touhou-"$TouhouNum"
# install run script
install touhou-"$TouhouNum" "$HOME"/.local/bin/touhou-"$TouhouNum"
# remove run script from current directory
rm -f touhou-"$TouhouNum"
echo "creating launcher for th$TouhouNum"
# create .desktop launcher
touch th"$TouhouNum".desktop
# write contents of .desktop
echo "#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false" > th"$TouhouNum".desktop
# insert icon declaration and icon name
echo "Icon=$CurrentDirPath/Icon_th$TouhouNum.png" >> th"$TouhouNum".desktop
# write rest of .desktop
echo "Exec=$HOME/.local/bin/touhou-$TouhouNum
Categories=Game;
Name=Touhou ~ $TouhouNum" >> th"$TouhouNum".desktop
# instal .desktop launcher
install th"$TouhouNum".desktop "$HOME"/.local/share/applications/th"$TouhouNum".desktop
# remove .desktop from current directory
rm -f th"$TouhouNum".desktop
NumLine=$((NumLine + 1))
cd "$HOME" || exit
done
cd "$HOME" || exit
rm PathsFound
echo "finished"