Everything moved to it's new file for now. Cleanup is well under way. Improved the unix2dos function.
This commit is contained in:
@ -22,6 +22,26 @@ check_requirements() {
|
||||
return 0
|
||||
}
|
||||
|
||||
clear_cache() {
|
||||
local answer
|
||||
if [[ ! -d "${cache}" ]]; then
|
||||
echo "No cache found at ${cache}."
|
||||
return
|
||||
fi
|
||||
while ! [[ "${answer,,}" =~ ^yes$|^no$ ]]; do
|
||||
echo "This will delete all contents of ${cache}. Are you sure you want to continue?"
|
||||
echo "Please type yes or no."
|
||||
echo
|
||||
read -r answer
|
||||
done
|
||||
if [[ "$answer" == "no" ]]; then
|
||||
return
|
||||
fi
|
||||
# All safety checks done. Delete the cache.
|
||||
rm -rfv "${cache}"
|
||||
echo "Cache deleted."
|
||||
}
|
||||
|
||||
download() {
|
||||
local source=($@)
|
||||
for i in "${source[@]}" ; do
|
||||
@ -83,6 +103,81 @@ download() {
|
||||
done
|
||||
}
|
||||
|
||||
get_installer() {
|
||||
trap "exit 0" SIGINT
|
||||
# If the file is in cache nothing else needs to be done.
|
||||
if [[ -f "${cache}/$1" ]]; then
|
||||
return
|
||||
fi
|
||||
# Create message for dialog.
|
||||
local message="Make sure $1 is available in either your Downloads or Desktop directory and press enter to continue."
|
||||
if [[ -n "$2" ]]; then
|
||||
message+="\n\nThe last good known URL for $game is:"
|
||||
message+="\n$2"
|
||||
fi
|
||||
if echo "$2" | xclip -selection clipboard 2> /dev/null ; then
|
||||
message+="\n\nThe URL has been copied to the clipboard."
|
||||
fi
|
||||
dialog --ok-label "Continue" \
|
||||
--backtitle "Audiogame Manager" \
|
||||
--msgbox "$message" -1 -1
|
||||
# Search the Desktop and Downloads directories for the installation file
|
||||
for i in ~/Downloads ~/Desktop ; do
|
||||
find $i -type f -name "$1" -exec cp -v {} "${cache}/" \;
|
||||
done
|
||||
# If the file is still not available abort.
|
||||
if [[ ! -f "${cache}/$1" ]]; then
|
||||
echo "couldn't find $1. Please download the file and try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_steam() {
|
||||
# Arguments: $1 id of item for download, $2 url for game
|
||||
trap "exit 0" SIGINT
|
||||
echo "manual intervention required."
|
||||
alert
|
||||
dialog --backtitle "Audiogame Manager" \
|
||||
--yes-label "Continue with Steam" \
|
||||
--no-label "Install manually" \
|
||||
--extra-button \
|
||||
--extra-label "Exit" \
|
||||
--yesno "To install the game manually, place files in \"${WINEPREFIX}/drive_c/Program Files/${game}\"" -1 -1 --stdout
|
||||
case $? in
|
||||
0) echo "The next steps will install through steamcmd." ;;
|
||||
1)
|
||||
mkdir -p "${WINEPREFIX}/drive_c/Program Files/${game}"
|
||||
dialog --backtitle "Audiogame Manager" \
|
||||
--msgbox "Place game files in \"${WINEPREFIX}/drive_c/Program Files/${game}\" and press enter to continue." -1 -1 --stdout
|
||||
return
|
||||
;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
# Check for steamcmd
|
||||
if ! command -v steamcmd &> /dev/null ; then
|
||||
dialog --backtitle "Audiogame Manager" \
|
||||
--infobox "This installer requires steamcmd. Please install steamcmd and try again." -1 -1
|
||||
exit 1
|
||||
fi
|
||||
# Create message for dialog.
|
||||
local message="Make sure ${game} is available in your Steam library and press enter to continue. The URL for ${game} is $2"
|
||||
if echo "$2" | xclip -selection clipboard 2> /dev/null ; then
|
||||
message+="\n\nThe URL has been copied to the clipboard."
|
||||
fi
|
||||
dialog --ok-label "Continue" \
|
||||
--backtitle "Audiogame Manager" \
|
||||
--msgbox "$message" -1 -1
|
||||
# Get Steam user name.
|
||||
steamUser="$(dialog --ok-label "Continue" \
|
||||
--backtitle "Audiogame Manager" \
|
||||
--inputbox "Please enter your Steam user name:" -1 -1 --stdout)"
|
||||
# Download the game
|
||||
mkdir -p "${WINEPREFIX}/drive_c/Program Files/${game}"
|
||||
steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir "${WINEPREFIX}/drive_c/Program Files/$game" +login "$steamUser" +app_update "$1" +quit || { dialog --backtitle "Audiogame Manager" \
|
||||
--infobox "Something went wrong. Please make sure you have a stable internet connection, and if the problem persists, contact audiogame-manager's developers." -1 -1
|
||||
exit 1; }
|
||||
}
|
||||
|
||||
# Function to open urls across OS.
|
||||
open_url() {
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
@ -91,3 +186,13 @@ open_url() {
|
||||
xdg-open "${*}" 2> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
unix2dos() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: unix2dos file(s)."
|
||||
exit 1
|
||||
fi
|
||||
for file in "$@"; do
|
||||
sed -i 's/\r\{0,\}$/\r/' "$file"
|
||||
done
|
||||
}
|
||||
|
Reference in New Issue
Block a user