-
-
Save Gfurst/c3ebc114b57cb0792db7ba0430eb9150 to your computer and use it in GitHub Desktop.
General use Eroge script for HRPG in wine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###UserConfig### | |
#This section is for variables that the user can modify to change the behaviour of this script | |
#Set the language to ja_JP.UTF-8, put it into a comment to use system default | |
#default: ja_JP.UTF-8 | |
export LC_ALL="ja_JP.UTF-8" | |
#The foldername for wine, in case you want to use a different one for experimenting with winetricks | |
#default: wine | |
export WINEDIR="wine" | |
#Launcher path | |
#default: ~/".local/share/applications" | |
LAUNCHER_PATH=~/".local/share/applications" | |
#Set the standard Category name for the desktop file | |
STANDARD_CATEGORY_NAME="LEWD" | |
#1 = Autostart fluidsynth | |
#0 = Don't autostart fluidsynth | |
AUTOSTART_FLUIDSYNTH="0" | |
#Loudness of fluidsynth [min=0.000, max=10.000, def=0.200] it gets distorted with higher values | |
#default: 0.5 | |
FLUIDSYNTH_GAIN="0.5" | |
###EndUserConfig### | |
###ScriptEssentials### | |
#This section is for variables the user should only modify if they are content with breaking this script | |
#Number of cores used for fluidsynth synth and parallel converting | |
CPUS=$(nproc) | |
DIVIDE=$((CPUS/2)) | |
if [ "$DIVIDE" != "0" ] | |
then | |
export CONVERT_MAXJOBS=$DIVIDE | |
else | |
export CONVERT_MAXJOBS=1 | |
fi | |
#Detect running soundsystem for fluidsynth | |
if [ "$(pidof pulseaudio)" ] | |
then | |
AUDIO_DRIVER="pulseaudio" | |
else | |
AUDIO_DRIVER="alsa" | |
fi | |
#Soundsystem for fluidsynth: see "fluidsynth -a help" for available ones | |
#AUDIO_DRIVER="jack" | |
#Options for fluidsynth, gets passed to both the running server and the converter | |
export FLUIDSYNTH_OPTIONS="--gain ${FLUIDSYNTH_GAIN} --chorus no --reverb no --audio-driver=${AUDIO_DRIVER} --midi-driver=alsa_seq --sample-rate=44100 -o synth.cpu-cores=${CONVERT_MAXJOBS}" | |
#Define variable to not stop after executing the script, used so the arguments can set a stop signal. | |
STOP_IT="" | |
#Define argument variables just in case they are inherited from something outside of this shell | |
GET_HELP="" | |
GET_TIPS="" | |
GET_PROBLEMS="" | |
SCRIPT_GENERATE="" | |
LAUNCHER_GENERATE="" | |
LAUNCHER_BATCH_MODE="" | |
CONVERT_MIDI="" | |
SETUP_INSTALLATION="" | |
START_SOURCE="" | |
EXE_FILES="./found_exe_files" | |
#Needed to make sure the exe files were initially created by this script | |
EXE_FILES_IDENTIFIER="#####Don't delete this line and the \"|\", the batch function will not work without them!#####" | |
#If the script is called without argument, display help | |
if [[ -z "${@}" ]] | |
then | |
GET_HELP="1" | |
fi | |
#Check if required programs are available | |
command -v wine > /dev/null 2>&1 || { echo >&2 "You need wine. Aborting."; exit 1; } | |
if [[ ${AUTOSTART_FLUIDSYNTH} == "1" ]] | |
then | |
command -v fluidsynth > /dev/null 2>&1 || { echo >&2 "You need fluidsynth. Aborting."; exit 1; } | |
fi | |
command -v megadl > /dev/null 2>&1 && { MEGADL=1; } | |
#setting $DIR variable to script directory | |
SOURCE="${BASH_SOURCE[0]}" | |
DIR="$( dirname "${SOURCE}" )" | |
while [ -h "${SOURCE}" ] | |
do | |
SOURCE="$(readlink "${SOURCE}")" | |
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" | |
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" | |
done | |
export DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" | |
#Set prefix for wine | |
export WINEPREFIX="${DIR}/.${WINEDIR}" | |
#Set soundfont location, change it to the one you want | |
export SOUNDFONT="${WINEPREFIX}/gm.sf2" | |
###EndScriptEssentials### | |
#Create the options | |
while getopts ":h?tpis:l:bc:" opt; do | |
case ${opt} in | |
h|\?) | |
GET_HELP="1" | |
;; | |
t) | |
GET_TIPS="1" | |
;; | |
p) | |
GET_PROBLEMS="1" | |
;; | |
s) | |
SCRIPT_GENERATE="1" | |
SCRIPTARG="${OPTARG}" | |
shift $((OPTIND-1)) | |
[ "${1}" = "--" ] && shift | |
;; | |
l) | |
LAUNCHER_GENERATE="1" | |
shift $((OPTIND-2)) | |
[ "${1}" = "--" ] && shift | |
;; | |
b) | |
LAUNCHER_GENERATE="1" | |
LAUNCHER_BATCH_MODE="1" | |
;; | |
c) | |
CONVERT_MIDI="1" | |
CONVERTARG="${OPTARG}" | |
shift $((OPTIND-1)) | |
[ "${1}" = "--" ] && shift | |
;; | |
i) | |
SETUP_INSTALLATION="1" | |
;; | |
:) | |
echo "Option -${OPTARG} requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
if [[ -n "${GET_HELP}" ]] | |
then | |
echo "" | |
echo "Usage:" | |
echo "This script needs to be placed to the base folder of the games." | |
echo "" | |
echo "$ ${0} -i" | |
echo "$ ${0} wine Game.exe" | |
echo "" | |
echo "Add ../ at the beginning depending how deep the folder hierarchy is." | |
echo "" | |
echo "Options (Only one at a time):" | |
echo " -h -? Display this message" | |
echo " -t Display Tips and Tricks" | |
echo " -p Display known problems, including workarounds" | |
echo "" | |
echo " -i" | |
echo " ^ Setup the initial installation, without it some things will not work" | |
echo " ^ This needs to be run again if the path to the game directory changes" | |
echo " ^ It optionally supports 'megatools' to download and setup almost everything" | |
echo "" | |
echo ' -s "Game.exe"' | |
echo " ^ Generate a shell script in the current directory with \"${0} wine Game.exe\" (it will overwrite \"Game.sh\")" | |
echo "" | |
echo ' -l "Game.exe" "Optional Game Name" "Optional Category Name"' | |
echo ' ^ Generate a launcher for the start menu including an icon and custom category' | |
echo ' ^ Requires icoutils, will use existing "Game.sh" or creates the same as -s' | |
echo " ^ \"Game Name\" will be guessed when the argument is absent or empty" | |
echo " ^ \"Category Name\" can be changed in the script or temporary as shown above. Currently \"${STANDARD_CATEGORY_NAME}\"" | |
echo " ^ The launcherpath can be changed in the script by editing LAUNCHER_PATH. Currently \"${LAUNCHER_PATH}\"" | |
echo "" | |
echo " -b" | |
echo " ^ Batch mode creates ${EXE_FILES} with all \"*.exe\" files found recursively from this directory" | |
echo " ^ Edit that file to remove unwanted lines and add |Optional Game Name|Optional Category Name| seperated by |." | |
echo " ^ Run this mode again to create the same files as -l for each line in ${EXE_FILES}" | |
echo "" | |
echo ' -c "folder name"' | |
echo ' ^ Converts midi files inside the specified folder to ogg and moves them to "folder name/backup_midis"' | |
echo " ^ This can be used without the initial setup by changing the SOUNDFONT variable to an existing soundfont" | |
echo "" | |
echo "######################################################################################" | |
echo "" | |
echo "This script creates a wineprefix in the directory the script resides in." | |
echo "It's meant to be used as a base prefix for games in wine." | |
echo "It also autostarts its own fluidsynth process or uses an already running one." | |
echo "This behavior can be disabled by setting AUTOSTART_FLUIDSYNTH to 0" | |
echo "" | |
echo "The folder structure should look like this:" | |
echo "${DIR}" | |
echo "${DIR}/${0##*/}" | |
echo "${WINEPREFIX} (created with this script)" | |
echo "${DIR}/Game1/game.exe" | |
echo "${DIR}/Game2/game.exe" | |
echo "${DIR}/Game3/WHATAREYOUDOING/game.exe" | |
echo "" | |
echo "The wineprefix name can be changed by modifying the \"WINEDIR\" variable in this script," | |
echo "" | |
echo "######################################################################################" | |
echo "" | |
STOP_IT="1" | |
fi | |
if [[ -n "${GET_PROBLEMS}" ]] | |
then | |
echo "" | |
echo "Known Problems and Solutions:" | |
echo "" | |
echo "P: Some games show black screen but play sound / just get stuck before the menu or directly after the menu." | |
echo "S: It's most probably a problem displaying a video." | |
echo " It is often enough to just rename the culprit and the game should continue." | |
echo "" | |
echo "" | |
echo "P: Some RPGMaker titles can't play midi, RPGMaker XP for example." | |
echo "S: RPGMaker XP needs to have them in ogg." | |
echo " Browse to your rpgmaker installation, which is probably here for win64:" | |
echo " ${WINEPREFIX}/drive_c/Program Files (x86)/Common Files/Enterbrain/RGSS/Standard/Audio/" | |
echo " Execute the script with -c BGM and do the same for ME" | |
echo " Those things needs to be done in the games directory too, since some provide their own midis." | |
echo "" | |
echo "" | |
echo "P: The Gamepad has wrong buttons" | |
echo "S: $ ${0} wine control" | |
echo " Double click on \"Game Controllers\", check your gamepad and click disable." | |
echo " Antimicro is recommend to bind buttons to keyboard keys." | |
echo "" | |
echo "" | |
echo "P: Some games are corrupt or just don't work in fullscreen mode." | |
echo "S: Enable \"Emulate a virtual desktop\" under the tab \"Graphics\" in" | |
echo " $ ${0} winecfg" | |
echo "" | |
echo "P: Some games from unity don't have my native resolution." | |
echo "S: See the modeline section of -t" | |
echo " Some 16:10 monitors don't provide proper EDID information for compability for 4:3 and 16:9 resolutions" | |
echo " Add some yourself in that case" | |
echo "" | |
echo "######################################################################################" | |
echo "" | |
STOP_IT="1" | |
fi | |
if [[ -n "${GET_TIPS}" ]] | |
then | |
echo "" | |
echo "Tips and tricks:" | |
echo "" | |
echo "" | |
echo "To unzip japanese games correctly there must be SHIFT_JIS support in the locale file and unzip with natspec support." | |
echo "Other compression methods like rar or 7z don't need something special since they all have native unicode support." | |
echo "Execute the initial setup from this script to see how to add SHIFT_JIS support." | |
echo "After that unzip the zip file like this:" | |
echo "$ unzip -O SHIFT_JIS \"the zip file.zip\"" | |
echo "" | |
echo "" | |
echo "Keep the main wine profile from this script clean from winetricks, like d3d9x or ffmpeg." | |
echo "" | |
echo "If you absolutely need to have some d3d9 ddl or directmusic" | |
echo "then you should copy ${0}, rename it and" | |
echo "change the WINEDIR value to keep the winetricks things seperate." | |
echo "" | |
echo "" | |
echo "Try to use wine-staging since it has many experimental features that can help with compability." | |
echo "" | |
echo "" | |
echo "Keep in mind that you need to manually install many lib32 dependencies yourself" | |
echo "because most distros only provide the minimum." | |
echo "" | |
echo "Noteable ones:" | |
echo "lib32 pulseaudio" | |
echo "lib32 gstreamer and its plugins" | |
echo "" | |
echo "" | |
echo "If you want a fullscreen like effect, then you can use Modelines in your xorg config" | |
echo "to change your resolution to half of your real one (integerscale is best for quality)." | |
echo "See: \"https://en.wikipedia.org/wiki/Display_resolution\"" | |
echo "for a nice graphical way to pick a good resolution for your aspect ratio" | |
echo "" | |
echo "Example for a display with 1920x1200 and 60Hz refresh rate:" | |
echo "$ gtf horizontal vertical refresh_rate" | |
echo "$ gtf 960 600 60" | |
echo "" | |
echo "This is a example of /etc/X11/xorg.conf.d/10-custom.conf:" | |
echo "Section \"Monitor\"" | |
echo " Identifier \"DELL 2707WFP\"" | |
echo " Modeline \"1920x1080\" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync" | |
echo " Modeline \"1344x840\" 92.71 1344 1416 1560 1776 840 841 844 870 -hSync +vsync" | |
echo " ModeLine \"1280x800\" 83.50 1280 1352 1480 1680 800 803 809 831 -hsync +vsync" | |
echo " ModeLine \"1120x700\" 63.50 1120 1176 1288 1456 700 703 709 727 -hsync +vsync" | |
echo " Modeline \"1088x680\" 59.50 1088 1144 1248 1408 680 683 689 707 -hsync +vsync" | |
echo " Modeline \"1040x650\" 53.75 1040 1080 1184 1328 650 653 659 676 -hsync +vsync" | |
echo " ModeLine \"960x600\" 45.25 960 992 1088 1216 600 603 609 624 -hsync +vsync" | |
echo " Modeline \"768x480\" 28.75 768 792 864 960 480 483 489 500 -hsync +vsync" | |
echo " Option \"DPMS\" \"false\"" | |
echo "EndSection" | |
echo "" | |
echo "Only use your own values since they are generated with your monitor in mind." | |
echo "Check if xrandr displays those resolutions. If not then your driver is probably a propetary one from nvidia," | |
echo "you are on your own in this case." | |
echo "" | |
echo "######################################################################################" | |
echo "" | |
STOP_IT="1" | |
fi | |
if [[ -n "${STOP_IT}" ]] | |
then | |
exit 0 | |
fi | |
if [[ -n "${SETUP_INSTALLATION}" ]] | |
then | |
#detect localesettings | |
if ! locale -a | grep ja_JP.utf8 >/dev/null || ! locale -a | grep ja_JP.shiftjis >/dev/null | |
then | |
echo "" | |
echo "You need ja_JP.UTF-8 locale to use japanese programs." | |
echo "ja_JP.SHIFT_JIS SHIFT_JIS is used for unzip with natspec support to extract zip files without garbage characters." | |
echo "Example:" | |
echo "$ unzip -O SHIFT_JIS zipfile.zip" | |
echo "" | |
if [[ $(command -v sudo) ]] | |
then | |
echo "Should this script add them for you?" | |
PS3="Select 1 or 2: " | |
select opt in Yes No; do | |
if [ "$opt" = "Yes" ]; then | |
echo 'ja_JP.UTF-8 UTF-8' | sudo tee -a /etc/locale.gen > /dev/null | |
echo 'ja_JP.SHIFT_JIS SHIFT_JIS' | sudo tee -a /etc/locale.gen > /dev/null | |
sudo locale-gen | |
echo "" | |
break | |
elif [ "$opt" = "No" ]; then | |
echo "" | |
echo "$ su" | |
echo "$ nano /etc/locale.gen" | |
echo "comment out or add it yourself (don't remove or change the other ones):" | |
echo "ja_JP.UTF-8 UTF-8" | |
echo "ja_JP.SHIFT_JIS SHIFT_JIS" | |
echo "execute:" | |
echo "$ locale-gen" | |
echo "" | |
exit 1 | |
else | |
echo "" | |
echo "Use 1 or 2!" | |
echo "" | |
fi | |
done | |
else | |
echo "$ su" | |
echo "$ nano /etc/locale.gen" | |
echo "comment out or add it yourself (don't remove or change the other ones):" | |
echo "ja_JP.UTF-8 UTF-8" | |
echo "ja_JP.SHIFT_JIS SHIFT_JIS" | |
echo "execute:" | |
echo "$ locale-gen" | |
echo "" | |
exit 1 | |
fi | |
fi | |
#create the wineprefix if needed | |
if [[ ! -d "${WINEPREFIX}" ]] | |
then | |
echo "Create WINEPREFIX and initial dll overwrite" | |
wineboot -u > /dev/null 2>&1 | |
cat > "/tmp/winemenubuilder.reg" <<-EOF | |
[HKEY_CURRENT_USER\Software\Wine\DllOverrides] | |
"winemenubuilder.exe"="" | |
EOF | |
regedit /tmp/winemenubuilder.reg > /dev/null 2>&1 | |
rm /tmp/winemenubuilder.reg > /dev/null 2>&1 | |
# Make sure wine doesn't put files outside the prefix | |
winetricks sandbox | |
echo "link Z: to game directory, some installers can't deal with longer paths." | |
rm -v "${WINEPREFIX}/dosdevices/z:" > /dev/null 2>&1 | |
ln -s ../../ "${WINEPREFIX}/dosdevices/z:" > /dev/null 2>&1 | |
#create link to root for compability with files outside of game directory | |
ln -s / "${WINEPREFIX}/dosdevices/y:" > /dev/null 2>&1 | |
fi | |
#setup the midi file | |
if [[ ! -f "${SOUNDFONT}" ]] | |
then | |
if [[ "${MEGADL}" ]] | |
then | |
echo "Downloading \"${SOUNDFONT}\"..." | |
megadl --path="${SOUNDFONT}" 'https://mega.co.nz/#!Gw9URQLR!auDQl3pDDYK9Ot2loDGsxMEHak_ZGfdqAwEM9P_6ego' | |
else | |
echo "" | |
echo "You need to have ${SOUNDFONT}" | |
echo "otherwise you will not get midi sound working." | |
echo "" | |
echo "Try installing 'megatools' package and this script will download it for you." | |
echo "" | |
echo "If you can't / don't want to then you can do it manually too:" | |
echo "You can get the file by converting gm.dls to gm.sf2 from a windows installation" | |
echo "or download it here:" | |
echo "https://mega.co.nz/#!Gw9URQLR!auDQl3pDDYK9Ot2loDGsxMEHak_ZGfdqAwEM9P_6ego" | |
echo "" | |
echo "It is also possible to use a completely different one:" | |
echo 'Search the script for export SOUNDFONT="${WINEPREFIX}/gm.sf2"' | |
echo "and change the SOUNDFONT variable to the one you want." | |
echo "" | |
exit 1 | |
fi | |
fi | |
#setup fonts | |
if ! fc-list | grep -i msgothic.ttc >/dev/null | |
then | |
if [[ "${MEGADL}" ]] | |
then | |
#workaround for megadl, it can't deal with ~/ | |
MEGADL_FONT_PATH=$(echo ~/.local/share/fonts/msgothic) | |
mkdir -p "${MEGADL_FONT_PATH}" > /dev/null 2>&1 | |
echo "Downloading \"${MEGADL_FONT_PATH}\"..." | |
megadl --path="${MEGADL_FONT_PATH}" 'https://mega.co.nz/#!21NjXLqZ!TohZQC1_eBcBKWQQpRZkJNrmLbgSfiTozcQ7T--x_5I' && | |
fc-cache -vf | |
else | |
echo "" | |
echo "You need \"MS PGothic\" which can be found in msgothic.ttc from a windows installation" | |
echo "or download it here:" | |
echo "https://mega.co.nz/#!21NjXLqZ!TohZQC1_eBcBKWQQpRZkJNrmLbgSfiTozcQ7T--x_5I" | |
echo "" | |
echo "Try installing 'megatools' package and this script will download and install it for you." | |
echo "" | |
echo "If you can't / don't want to then you can do it manually too:" | |
echo "Install it by putting the file into ~/.local/share/fonts/somedir or" | |
echo "/usr/share/fonts/somedir (with correct permission chmod 0444 or 0555)" | |
echo "After that execute:" | |
echo "$ fc-cache -vf" | |
echo "" | |
exit 1 | |
fi | |
fi | |
echo "" | |
echo "\"${WINEPREFIX}\" is now fine to use." | |
echo "You can now use the following to start your games:" | |
echo "$ ${0} wine Game.exe" | |
echo "" | |
exit 0 | |
fi | |
create_start_script(){ | |
SCRIPTNAME="${1%.*}.sh" | |
#Check if script will get overwritten for custom message | |
if [[ -f "${SCRIPTNAME}" ]] | |
then | |
SCRIPT_EXIST=1 | |
fi | |
#check for proper launch command | |
if [[ ! ${START_SOURCE} ]] | |
then | |
START_SOURCE=${0} | |
fi | |
cat > "${SCRIPTNAME}" <<-EOF | |
#!/bin/bash | |
#setting \$DIR variable to script directory | |
SOURCE="\${BASH_SOURCE[0]}" | |
DIR="\$( dirname "\${SOURCE}" )" | |
while [ -h "\${SOURCE}" ] | |
do | |
SOURCE="\$(readlink "\${SOURCE}")" | |
[[ \${SOURCE} != /* ]] && SOURCE="\${DIR}/\${SOURCE}" | |
DIR="\$( cd -P "\$( dirname "\${SOURCE}" )" && pwd )" | |
done | |
DIR="\$( cd -P "\$( dirname "\${SOURCE}" )" && pwd )" | |
cd "\${DIR}" | |
"${START_SOURCE}" wine "${1}" | |
EOF | |
#make the script executable | |
chmod +x "${SCRIPTNAME}" > /dev/null 2>&1 | |
if [[ $SCRIPT_EXIST == "1" ]] | |
then | |
echo -e "\e[33;1mOverwritten \"${SCRIPTNAME}\"\e[0m" | |
else | |
echo -e "\e[92mCreated \"${SCRIPTNAME}\"\e[0m" | |
fi | |
} | |
export -f create_start_script | |
check_start_script(){ | |
if [[ -f ${1} ]] | |
then | |
create_start_script "${@}" | |
exit 0 | |
else | |
echo -e "\e[31m${1} does not exist, make sure you are in the same directory as it.\e[0m" | |
exit 1 | |
fi | |
} | |
export -f check_start_script | |
if [[ -n "${SCRIPT_GENERATE}" ]] | |
then | |
check_start_script "${SCRIPTARG}">&2 | |
exit 0 | |
fi | |
if [[ -n "${LAUNCHER_GENERATE}" ]] | |
then | |
create_category(){ | |
cat > "${CATEGORY_NAME}.menu" <<EOF | |
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" | |
"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd"> | |
<Menu> | |
<Name>Applications</Name> | |
<Menu> | |
<Name>Games</Name> | |
<Menu> | |
<Name>${CATEGORY_NAME}</Name> | |
<Directory>${CATEGORY_NAME}.directory</Directory> | |
<Include> | |
<Category>X-${CATEGORY_NAME}</Category> | |
</Include> | |
</Menu> | |
<Exclude> | |
<And> | |
<Category>X-${CATEGORY_NAME}</Category> | |
</And> | |
</Exclude> | |
</Menu> | |
</Menu> | |
EOF | |
mkdir -p ~/".config/menus/applications-merged" > /dev/null 2>&1 | |
mv -v "${CATEGORY_NAME}.menu" ~/".config/menus/applications-merged/${CATEGORY_NAME}.menu" > /dev/null 2>&1 | |
echo -e "\e[92mCreated ~/\".config/menus/applications-merged/${CATEGORY_NAME}.menu\"\e[0m" | |
cat > "${CATEGORY_NAME}.directory" <<-EOF | |
[Desktop Entry] | |
Version=1.0 | |
Type=Directory | |
Icon=applications-games | |
Name=${CATEGORY_NAME} | |
Comment=${CATEGORY_NAME} | |
EOF | |
mkdir -p ~/".local/share/desktop-directories" > /dev/null 2>&1 | |
mv -v "${CATEGORY_NAME}.directory" ~/".local/share/desktop-directories/${CATEGORY_NAME}.directory" > /dev/null 2>&1 | |
echo -e "\e[92mCreated ~/\".local/share/desktop-directories/${CATEGORY_NAME}.directory\"\e[0m" | |
} | |
export -f create_category | |
create_desktop_file(){ | |
#check for empty name | |
if [[ -z ${2} ]] | |
then | |
#Extract Game Name from Path | |
DESKTOPNAME="$(pwd | sed "s|${DIR}/||" | sed "s|/.*||" )" | |
else | |
DESKTOPNAME="${2}" | |
fi | |
REALICONNAME="${1%.*}.png" | |
if [[ ! -f ${REALICONNAME} ]] | |
then | |
# Check the exe for extractable ico | |
if [[ $(wrestool --list "${1}") == *"--type=14"* ]] | |
then | |
# Hopefully catching the last errors wrestool could produce | |
ICO_OUTPUT=$(wrestool --extract --type=14 --output="${WORKDIR}"/. "${1}" 2>&1) | |
if [[ -z "${ICO_OUTPUT}" ]] | |
then | |
#find the biggest *.ico file | |
ICONNAME="$(find "${WORKDIR}"/ -maxdepth 1 -mindepth 1 -type f -iname "${1}*.ico" -print0 | xargs -0 ls -1S | head -n 1)" | |
#extract all icons out of the ico | |
icotool --icon --output="${WORKDIR}" -x "${ICONNAME}" > /dev/null 2>&1 | |
#rename the biggest png as "exename.png" | |
ICONNAME="$(find "${WORKDIR}"/ -maxdepth 1 -mindepth 1 -type f -iname "${1}*.png" -print0 | xargs -0 ls -1S | head -n 1)" | |
mv -v "${ICONNAME}" "${REALICONNAME}" > /dev/null 2>&1 | |
echo -e "\e[92mExtracted \"${REALICONNAME}\"\e[0m" | |
#Remove the work files | |
rm -rv "${WORKDIR}" > /dev/null 2>&1 | |
echo -e "\e[92mRenamed \"${ICONNAME}\" to \"${REALICONNAME}\"\e[0m" | |
echo -e "\e[92mReverse this if it looks wrong\e[0m" | |
else | |
echo "Something went wrong with wrestool, check the output and create your own ico file at:" | |
echo "\"${REALICONNAME}\"" | |
echo "${ICO_OUTPUT}" | |
fi | |
else | |
echo -e "\e[33;1mNo icon in the exe found." | |
echo -e "Place your own in the folder named:" | |
echo -e "\"${REALICONNAME}\"\e[0m" | |
fi | |
fi | |
#create the desktop file | |
DESKTOPFILE="${DESKTOPNAME}.desktop" | |
cat > "${DESKTOPFILE}" <<-EOF | |
#!/usr/bin/env xdg-open | |
[Desktop Entry] | |
Exec=bash "$(pwd)/${1%.*}.sh" | |
Icon=$(pwd)/${REALICONNAME} | |
Name=${DESKTOPNAME} | |
Path=$(pwd) | |
Terminal=false | |
Type=Application | |
Categories=Game;X-${CATEGORY_NAME}; | |
EOF | |
#make the script executable | |
chmod +x "${DESKTOPFILE}" > /dev/null 2>&1 | |
#install it to the local user | |
if [[ -f "${LAUNCHER_PATH}/${DESKTOPNAME}.desktop" ]] | |
then | |
LAUNCHER_EXIST="1" | |
fi | |
mkdir -p "${LAUNCHER_PATH}" > /dev/null 2>&1 | |
mv -v "${DESKTOPFILE}" "${LAUNCHER_PATH}/${DESKTOPNAME}.desktop" > /dev/null 2>&1 | |
if [[ ${LAUNCHER_EXIST} == "1" ]] | |
then | |
echo -e "\e[33;1mOverwritten \"${LAUNCHER_PATH}/${DESKTOPNAME}.desktop\" in category \"Game;${CATEGORY_NAME};\"\e[0m" | |
else | |
echo -e "\e[92mCreated \"${LAUNCHER_PATH}/${DESKTOPNAME}.desktop\" in category \"Game;${CATEGORY_NAME};\"\e[0m" | |
fi | |
} | |
export -f create_desktop_file | |
check_desktop_file(){ | |
if [[ -f ${1} ]] | |
then | |
WORKDIR="$(pwd)/._workdir" | |
mkdir -p "${WORKDIR}" > /dev/null 2>&1 | |
#check if a startscript exist, if not create it | |
if [[ ! -f "${1%.*}.sh" ]] | |
then | |
create_start_script "$@" | |
fi | |
#Check for Category name and set it accordingly | |
if [[ ! -z "${3}" ]] | |
then | |
CATEGORY_NAME="${3}" | |
else | |
CATEGORY_NAME="${STANDARD_CATEGORY_NAME}" | |
fi | |
#Make sure to not uselessly recreate the Categories | |
if [[ -f ~/".config/menus/applications-merged/${CATEGORY_NAME}.menu" ]] && [[ -f ~/".local/share/desktop-directories/${CATEGORY_NAME}.directory" ]] | |
then | |
create_desktop_file "${@}" | |
else | |
create_category "${@}" | |
create_desktop_file "${@}" | |
fi | |
else | |
echo -e "\e[31m${1} does not exist, make sure you are in the same directory as it.\e[0m" | |
exit 1 | |
fi | |
} | |
export -f check_desktop_file | |
prepare_batch() { | |
echo "Searching \"${PWD}\" recursively for \".exe\" files..." | |
find "${PWD}" -mindepth 1 \( -type d -name ".*" -prune \) -o \( -type f -name ".*" -prune \) -o \( -type f -iname "*.exe" \) | grep -v /\\. | sed -e 's/$/|/g' > "${EXE_FILES}" | |
if [[ ! -s "${EXE_FILES}" ]] | |
then | |
echo -e "\e[31m\"${EXE_FILES}\" contains no data.\e[0m" | |
echo -e "\e[31mThis is either a bug or it couldn't find any exe files.\e[0m" | |
exit 1 | |
fi | |
#Try guessing the game name from the folder name | |
while read LINE | |
do | |
#put the arguments into an array for easy processing | |
IFS='|' | |
read -r -a BATCH_ARGUMENTS <<< "$LINE" | |
unset IFS | |
#Extract the game name from the first folder relative to this script and add a category name as template | |
BATCH_ARGUMENTS[1]="$(echo "${BATCH_ARGUMENTS[0]}" | sed "s|${DIR}/||" | sed "s|/.*||" )" | |
BATCH_ARGUMENTS[2]="${STANDARD_CATEGORY_NAME}" | |
printf '%s|' "${BATCH_ARGUMENTS[@]}"; echo | |
done < "${EXE_FILES}" >> ".${EXE_FILES}" | |
mv ".${EXE_FILES}" "${EXE_FILES}" | |
echo "$(echo "${EXE_FILES_IDENTIFIER}" | cat - "${EXE_FILES}")" > "${EXE_FILES}" | |
echo -e "\e[92mCreated the file\e[0m \"${EXE_FILES}\"" | |
echo -e "\e[92mRemove the lines of the files you don't want and change\e[0m" | |
echo "/path/to/game name/Game.exe|Optional Game Name|Optional Category Name|" | |
echo -e "\e[92mto your pleasure, it works the same way as the -l option.\e[0m" | |
echo -e "\e[92mRun this script with -b again to finalize the creation of all launchers.\e[0m" | |
} | |
export -f prepare_batch | |
create_batch_launcher() { | |
if $(head -1 "${EXE_FILES}" | grep -q "${EXE_FILES_IDENTIFIER}") | |
then | |
#remove first line. | |
tail -n +2 "${EXE_FILES}" > "${EXE_FILES}_new" | |
mv "${EXE_FILES}_new" "${EXE_FILES}" | |
fi | |
while read LINE | |
do | |
#put the arguments into an array for easy processing | |
IFS='|' | |
read -r -a BATCH_ARGUMENTS <<< "$LINE" | |
unset IFS | |
#extract the relative path to the script | |
BATCH_PATH_COUNT=$(echo "${BATCH_ARGUMENTS[0]}" | sed "s|${DIR}/||" | grep -o "/" | wc -l) | |
BATCH_START_RELATIVE="" | |
COUNTER="0" | |
while [ $COUNTER -lt ${BATCH_PATH_COUNT} ] | |
do | |
BATCH_START_RELATIVE=${BATCH_START_RELATIVE}"../" | |
let COUNTER=COUNTER+1 | |
done | |
START_SOURCE="${BATCH_START_RELATIVE}$(basename "$0")" | |
cd "$(dirname "${BATCH_ARGUMENTS[0]}")" | |
#strip the path to the exe | |
BATCH_ARGUMENTS[0]=$(basename "${BATCH_ARGUMENTS[0]}") | |
check_desktop_file "${BATCH_ARGUMENTS[0]}" "${BATCH_ARGUMENTS[1]}" "${BATCH_ARGUMENTS[2]}" | |
done < "${EXE_FILES}" | |
echo -e "\e[92m\"${EXE_FILES}\" can be used to recreate the current setup. Add:\e[0m" | |
echo "${EXE_FILES_IDENTIFIER}" | |
echo -e "\e[92mat the beginning of the file to make it work with batch mode again\e[0m" | |
} | |
export -f create_batch_launcher | |
#check for icoutils | |
if [[ ! $(command -v wrestool) ]] | |
then | |
echo -e "\e[31mYou need to install 'icoutils' for this to work\e[0m" | |
exit 1 | |
fi | |
if [[ -n ${LAUNCHER_BATCH_MODE} ]] | |
then | |
if [[ -s "${EXE_FILES}" ]] | |
then | |
if $(head -1 "${EXE_FILES}" | grep -q "${EXE_FILES_IDENTIFIER}") | |
then | |
create_batch_launcher | |
else | |
echo -e "\e[31mThe file\e[0m \"${EXE_FILES}\"" | |
echo -e "\e[31mdoes not contain the required first line:\e[0m" | |
echo -e "${EXE_FILES_IDENTIFIER}" | |
exit 1 | |
fi | |
else | |
prepare_batch | |
fi | |
else | |
check_desktop_file "${1}" "${2}" "${3}" | |
fi | |
exit 0 | |
fi | |
if [[ -n "${CONVERT_MIDI}" ]] | |
then | |
command -v fluidsynth > /dev/null 2>&1 || { echo >&2 "You need fluidsynth. Aborting."; exit 1; } | |
#check for the soundfont | |
if [[ ! -f "${SOUNDFONT}" ]] | |
then | |
echo "" | |
echo "To convert midis you need to specify a soundfont!" | |
echo "Do it by running the initial setup first:" | |
echo "$ ${0} -i" | |
echo "" | |
echo 'OR search the script for export SOUNDFONT="${WINEPREFIX}/gm.sf2"' | |
echo "and change the SOUNDFONT variable to the one you want." | |
echo "" | |
exit 1 | |
fi | |
#convert the midi files and move them to the backup directory | |
do_midi_convert() { | |
for arg | |
do | |
fluidsynth ${FLUIDSYNTH_OPTIONS} -nli -T oga -F "${@%.*}.ogg" "${SOUNDFONT}" "${@}" > /dev/null 2>&1 | |
mv "${@}" "backup_midis/" | |
done | |
} | |
export -f do_midi_convert | |
#create backupdirectory and search for midi files | |
check_midi_convert(){ | |
cd "${1}" | |
mkdir -p "backup_midis" > /dev/null 2>&1 | |
find . -maxdepth 1 -mindepth 1 -type f -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P ${CONVERT_MAXJOBS} bash -c 'do_midi_convert "$@"' -- | |
} | |
export -f check_midi_convert | |
check_midi_convert "${CONVERTARG}">&2 | |
exit 0 | |
fi | |
if [[ -d "${WINEPREFIX}" ]] | |
then | |
if [[ ${AUTOSTART_FLUIDSYNTH} == "1" ]] | |
then | |
#check if fluidsynth is already running, if not start it | |
if [ ! "$(pidof fluidsynth)" ] | |
then | |
fluidsynth ${FLUIDSYNTH_OPTIONS} --server --no-shell "${SOUNDFONT}" > /dev/null 2>&1 & | |
FLUIDSYNTH_PID=${!} | |
fi | |
fi | |
#execute whatever this script is given as parameter | |
"${@}" | |
#wait until no wine program is running | |
wineserver -w | |
#check if a fluidsynth instance is from this script, if yes terminate it | |
if [[ "${FLUIDSYNTH_PID}" ]] | |
then | |
kill ${FLUIDSYNTH_PID} | |
fi | |
else | |
echo "" | |
echo "You need to use the initial setup first:" | |
echo "$ ${0} -i" | |
echo "" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment