Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing icons to .local/share/icons for Linux #74

Open
rehhouari opened this issue Mar 6, 2024 · 1 comment
Open

Add missing icons to .local/share/icons for Linux #74

rehhouari opened this issue Mar 6, 2024 · 1 comment

Comments

@rehhouari
Copy link

SGDBoop doesn't add any icon to .local/share/icons/hicolor meaning even if I apply an icon it would still show the steam default one in the desktop or application menus. Regardless if I apply the sgd icon before I install the game or after.**

I think this feature would be be so helpful and thank you for this app!

System: arch, steam runtime (not flatpak), sdgboop: flatpak

@jimmon89
Copy link

jimmon89 commented Dec 17, 2024

I would like to second this.
SGDBoop doesn't perform the single feature I downloaded it for while thinking it did it.

--Edit--

Explination of what i did prior to creating the script further down.

in the spirit of "I'll do it myself", after doing "Apply with BOOP" on all of my games that were missing icons.
then i found where steam stores its icons for games, which is
$HOME/steam/steam/appcache/librarycache/
saw that the icons are named *appid here*_icon.jpg
and there were a lot more _icon.jpg files than the number of games i've ever had installed at once, likely icons for my whole library
so i copied all of those files to a new folder and opened a terminal there
using imagemagik, i ran find -name '*.jpg' -print0 | xargs -0 -r mogrify -format png to loop through all of the .jpg files in that directory and convert them to .png format
then i noticed a bunch of missing .png files along with this error being repeated with a single variation with each instance
mogrify: Not a JPEG file: starts with 0x00 0x00 './*appid here*_icon.jpg' @ error/jpeg.c/JPEGErrorHandler/356.
and upon further investigation, the appids seemed to match up with the games i recently BOOPed
so i tried opening one of the erroring JPGs with gimp, which also threw an error
so i tried renaming it to .ico and then opening it in gimp, SUCCESS
the file was a .ico file
so i renamed all of the erroring JPGs to .ico
and then ran find -name '*.ico' -print0 | xargs -0 -r mogrify -format png
which gave me a handful of similarly named .png files per .ico
like *appid here*_icon-*incremental number starting at 0*.png
and then checking a few of the .png files for a single appid, i see that they're all different sizes, like 64x64, 128x128, and 256x256
so then i went and decided the fastest thing would be to rename the .ico files before converting them to the multiple .png files each
so i deleted the .png files from the .ico files
then renamed the .ico files to add steam_icon_ before the appids
and also removed _icon from after the appids, so we have a bunch of files named like
steam_icon_*appid here*.ico
then reran find -name '*.ico' -print0 | xargs -0 -r mogrify -format png
and now i'm going through and finding the size of each .png file from the .ico files
moving each one individually to the appropriate folder and removing the number and dash after the appid, for example
say steam_icon_*appid here*-0.png was 256x256
i move it to
$HOME/.local/share/icons/hicolor/256x256/apps/
and then rename it to steam_icon_*appid here*.png

--TL;DR--

Now someone needs to write a script that does the following:

  1. gets steam to recognize the existence of the fresh .png files in the icons directory

--Script-Progress--

i think i nailed it.
the only problem is that steam still seems to be unaware that these files now exist even the for me KDE most definately is aware.
forcing me to change the icon of the .desktop file manually

Shell Script
#!/usr/bin/env bash
shopt -s nullglob

OVERWRITE_EXISTING_ICONS="false"
STEAM_ASSET_PATH="$HOME/.local/share/Steam/appcache/librarycache/"
TMPFILE_PATH="/tmp/IMAGES_TO_MODIFY/"

if ! command -v basename >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if ! command -v identify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if ! command -v mogrify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if [ "$UTIL_EXISTS" == "0" ]
then	
	if exists apt
	then
		PACKAGE_MANAGER="apt"
	elif exists dnf
	then
		PACKAGE_MANAGER="dnf"
	elif exists yum
	then
		PACKAGE_MANAGER="yum"
	elif exists pacman
	then
		PACKAGE_MANAGER="pacman"
	fi

	echo "WARNING: Missing 'imagemagick' and/or 'coreutils', attempting to detect system package manager and then install the missing packages..."
	case "$PACKAGE_MANAGER" in
		"apt")
			echo "Detected apt..."
			sudo apt update
			sudo apt install coreutils imagemagick
			;;
		"dnf")
			echo "Detected dnf..."
			sudo dnf upgrade
			sudo dnf install coreutils ImageMagick
			;;
		"yum")
			echo "Detected yum..."
			sudo yum update
			sudo yum install coreutils ImageMagick
			;;
		"pacman")
			echo "Detected pacman..."
			sudo pacman -Syu
			sudo pacman -Sy imagemagick coreutils
			;;
		*)
			echo "ERROR: Unable to detect package manager..."
			echo "please find and install 'basename', possibly a part of 'coreutils' and, 'identify' and 'mogrify', possibly a part of 'imagemagick', according to your distributions instructions"
			exit 1
			;;
	esac
	if ! command -v basename >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'basename' and/or 'coreutils', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	if ! command -v identify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'identify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	if ! command -v mogrify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'mogrify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
fi

mkdir -p -v "$TMPFILE_PATH"
FILES=$(find "$STEAM_ASSET_PATH" -name "*_icon.*")
for F in $FILES
do
	IMG_FORMAT="$(file -i -b "$F" | sed -e 's/;.*//')"
	IMG_FORMAT="${IMG_FORMAT//image\/}"
	BASENAME_NO_EXT="$(basename "${F%.*}")"
	case "$IMG_FORMAT" in  
		"png")
			echo "$(basename "$F") is already in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then renaming it to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.png"
			;; 
		"jpeg")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			;; 
		"vnd.microsoft.icon")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			;;
		"x-tga")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			;;
		*)
			echo "$F has unknown image format $IMG_FORMAT"
			;; 
	esac
done

PNG_FILES=$(find "$TMPFILE_PATH" -name "*.png")
for P in $PNG_FILES
do
	IMG_WIDTH="$(identify -format '%w' "$P")"
	IMG_HEIGHT="$(identify -format '%h' "$P")"
	NO_DIGIT_FILENAME="$(basename "$P" | sed "s/-[[:digit:]]\+//")"
	NO_ICON_FILENAME="${NO_DIGIT_FILENAME//_icon/}"
	FULL_NEW_FILENAME="steam_icon_$NO_ICON_FILENAME"
	NEW_PATHNAME="$HOME/.local/share/icons/hicolor/${IMG_WIDTH}x${IMG_HEIGHT}/apps/"
	FINAL_FILENAME="${NEW_PATHNAME}${FULL_NEW_FILENAME}"
	echo "$(basename "$P") is ${IMG_WIDTH}x${IMG_HEIGHT}"
	if ! [ -e "$NEW_PATHNAME" ]
	then
		mkdir -p -v "$NEW_PATHNAME"
	fi
	echo "Moving $(basename "$P") to $NEW_PATHNAME"
	if [ "${OVERWRITE_EXISTING_ICONS,,}" == "false" ] || [ "${OVERWRITE_EXISTING_ICONS,,}" == "no" ] || [ "$OVERWRITE_EXISTING_ICONS" == "0" ]
	then
		mv -v -n "$P" "$FINAL_FILENAME"
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME already exists, skipping..."
			rm -v "$FINAL_FILENAME"
		fi
	elif [ "${OVERWRITE_EXISTING_ICONS,,}" != "false" ] && [ "${OVERWRITE_EXISTING_ICONS,,}" != "no" ] && [ "$OVERWRITE_EXISTING_ICONS" != "0" ]
	then
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME already exists, overwriting..."
		elif ! [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME doesnt exist, continuing..."
		fi
		mv -v -f "$P" "$FINAL_FILENAME"
	fi
done

rmdir -v "$TMPFILE_PATH"
if [ -e "$TMPFILE_PATH" ]
then
	rm -r -f -v "$TMPFILE_PATH"
fi 
Shell Script V2

has a hacky workaround that adds appropriate icons to already existing desktop files that feature the steam fallback icon on both the desktop folder and the user application folder under $HOME/.local/share/applications, but only tries if they are not symboolic links

#!/usr/bin/env bash
shopt -s nullglob

OVERWRITE_EXISTING_ICONS="false"
STEAM_ASSET_PATH="$HOME/.local/share/Steam/appcache/librarycache/"
TMPFILE_PATH="/tmp/IMAGES_TO_MODIFY/"

if ! command -v basename >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if ! command -v identify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if ! command -v mogrify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi
if [ "$UTIL_EXISTS" == "0" ]
then	
	if exists apt
	then
		PACKAGE_MANAGER="apt"
	elif exists dnf
	then
		PACKAGE_MANAGER="dnf"
	elif exists yum
	then
		PACKAGE_MANAGER="yum"
	elif exists pacman
	then
		PACKAGE_MANAGER="pacman"
	fi

	echo "WARNING: Missing 'imagemagick' and/or 'coreutils', attempting to detect system package manager and then install the missing packages..."
	case "$PACKAGE_MANAGER" in
		"apt")
			echo "Detected apt..."
			sudo apt update
			sudo apt install coreutils imagemagick
			;;
		"dnf")
			echo "Detected dnf..."
			sudo dnf upgrade
			sudo dnf install coreutils ImageMagick
			;;
		"yum")
			echo "Detected yum..."
			sudo yum update
			sudo yum install coreutils ImageMagick
			;;
		"pacman")
			echo "Detected pacman..."
			sudo pacman -Syu
			sudo pacman -Sy imagemagick coreutils
			;;
		*)
			echo "ERROR: Unable to detect package manager..."
			echo "please find and install 'basename', possibly a part of 'coreutils' and, 'identify' and 'mogrify', possibly a part of 'imagemagick', according to your distributions instructions"
			exit 1
			;;
	esac
	if ! command -v basename >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'basename' and/or 'coreutils', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	if ! command -v identify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'identify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	if ! command -v mogrify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'mogrify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
fi

mkdir -p -v "$TMPFILE_PATH"
FILES=$(find "$STEAM_ASSET_PATH" -name "*_icon.*")
for F in $FILES
do
	IMG_FORMAT="$(file -i -b "$F" | sed -e 's/;.*//')"
	IMG_FORMAT="${IMG_FORMAT//image\/}"
	BASENAME_NO_EXT="$(basename "${F%.*}")"
	case "$IMG_FORMAT" in  
		"png")
			echo "$(basename "$F") is already in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then renaming it to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.png"
			;; 
		"jpeg")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			;; 
		"vnd.microsoft.icon")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			;;
		"x-tga")
			echo "$(basename "$F") is not in .png format, moving it to ${TMPFILE_PATH}$(basename "$F") and then converting to .png"
			cp -v -T "$F" "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			;;
		*)
			echo "$F has unknown image format $IMG_FORMAT"
			;; 
	esac
done

PNG_FILES=$(find "$TMPFILE_PATH" -name "*.png")
for P in $PNG_FILES
do
	IMG_WIDTH="$(identify -format '%w' "$P")"
	IMG_HEIGHT="$(identify -format '%h' "$P")"
	NO_DIGIT_FILENAME="$(basename "$P" | sed "s/-[[:digit:]]\+//")"
	NO_ICON_FILENAME="${NO_DIGIT_FILENAME//_icon/}"
	FULL_NEW_FILENAME="steam_icon_$NO_ICON_FILENAME"
	NEW_PATHNAME="$HOME/.local/share/icons/hicolor/${IMG_WIDTH}x${IMG_HEIGHT}/apps/"
	FINAL_FILENAME="${NEW_PATHNAME}${FULL_NEW_FILENAME}"
	echo "$(basename "$P") is ${IMG_WIDTH}x${IMG_HEIGHT}"
	if ! [ -e "$NEW_PATHNAME" ]
	then
		mkdir -p -v "$NEW_PATHNAME"
	fi
	echo "Moving $(basename "$P") to $NEW_PATHNAME"
	if [ "${OVERWRITE_EXISTING_ICONS,,}" == "false" ] || [ "${OVERWRITE_EXISTING_ICONS,,}" == "no" ] || [ "$OVERWRITE_EXISTING_ICONS" == "0" ]
	then
		mv -v -n "$P" "$FINAL_FILENAME"
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME already exists, skipping..."
			rm -v "$FINAL_FILENAME"
		fi
	elif [ "${OVERWRITE_EXISTING_ICONS,,}" != "false" ] && [ "${OVERWRITE_EXISTING_ICONS,,}" != "no" ] && [ "$OVERWRITE_EXISTING_ICONS" != "0" ]
	then
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME already exists, overwriting..."
		elif ! [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME doesnt exist, continuing..."
		fi
		mv -v -f "$P" "$FINAL_FILENAME"
	fi
done

rmdir -v "$TMPFILE_PATH"
if [ -e "$TMPFILE_PATH" ]
then
	rm -r -f -v "$TMPFILE_PATH"
fi 

OIFS="$IFS"
IFS=$'\n'
fix_icons() {
	if [ ! -h "$1" ]; then
		NEW_VALUE='steam://rungameid/'
		for NEXT in `cat "$1"`
		do
			if [[ "$NEXT" == *"$NEW_VALUE"* ]]; then
				GAME_ID="$(echo "$NEXT" | sed 's,^Exec[[:space:]]*=[[:space:]]*steam[[:space:]]*steam://rungameid/,,i')"
				NO_SPACE_GAME_ID="${GAME_ID//_icon/}"
				NO_TAB_GAME_ID="${NO_SPACE_GAME_ID//	/}"
				echo "$1 is a shortcut to appid $NO_TAB_GAME_ID"
				sed -i "s/^Icon[[:space:]]*=[[:space:]]*steam$/Icon=steam_icon_${NO_TAB_GAME_ID}/i" "$1"
			fi
		done
	fi
}

DESKTOP_ENTRIES=$(find "$HOME/Desktop" -name "*.desktop")
for D in $DESKTOP_ENTRIES
do
	fix_icons "$D"
done
APPLICATION_ENTRIES=$(find "$HOME/.local/share/applications/" -name "*.desktop")
for A in $APPLICATION_ENTRIES
do
	fix_icons "$A"
done
IFS="$OIFS"
Shell Script V3 --WILL REMOVE ON REQUEST--

has all of the stuff from v2, as well as a help feature, a feature to download icons for steam games found as desktop shortcuts in $HOME/Desktop/ and $HOME/.local/share/applications/, and a feature to overwrite existing icons in $HOME/.local/share/icons/
the download and overwrite features are inactive by default
help can be seen by passing help as the 1st, 2nd, or 3rd argument when running the script
warning, help will just print the help text and then exit, without doing anything else
don't add help if you don't need it
download can be activated by passing download as the 1st or 2nd argument
and similarly overwrite, can be activated by passing overwrite as the 1st or 2nd argument

#!/usr/bin/env bash
shopt -s nullglob

STEAM_ASSET_PATH="$HOME/.local/share/Steam/appcache/librarycache/"
TMPFILE_PATH="/tmp/IMAGES_TO_MODIFY/"
DESKTOP_FILE_LOCATION="$HOME/Desktop/"
APPLICATION_FILE_LOCATION="$HOME/.local/share/applications/"
ICON_PATH="$HOME/.local/share/icons/"
HELP_ARGUMENT="help"
OVERWRITE_ARGUEMENT="overwrite"
DOWNLOAD_ARGUMENT="download"

OIFS="$IFS"
IFS=$'\n'
FIX_INVALID_NAME='.*].*$'
NO_MATCH_GAME_ID='^Icon[[:space:]]*=[[:space:]]*steam$'

if [ "${1,,}" == "help" ] || [ "${2,,}" == "help" ] || [ "${3,,}" == "help" ]
then
	echo "other than $HELP_ARGUMENT, this script accepts up to two other arguments simultaneously, notably $DOWNLOAD_ARGUMENT, and $OVERWRITE_ARGUEMENT"
	echo "however, $HELP_ARGUMENT will always print this message, and then exit without performing any other tasks"
	echo "$DOWNLOAD_ARGUMENT when set, will download and then process icons for steam games found as .desktop files on either $DESKTOP_FILE_LOCATION or $APPLICATION_FILE_LOCATION"
	echo "$DOWNLOAD_ARGUMENT when not set, will skip downloading icons, but those already found in $STEAM_ASSET_PATH will still be copied and then processed"
	echo "$OVERWRITE_ARGUEMENT when set, while processing icon files found in $STEAM_ASSET_PATH will then overwrite any icons of the same name that already exist in $ICON_PATH"
	echo "$OVERWRITE_ARGUEMENT when not set, will still process icons normally, but any icons with the same name as one that exists in $ICON_PATH will be ingored"
	exit 0
fi

read_ids() {
	if [ ! -h "$1" ] && ! [[ $1 =~ $FIX_INVALID_NAME ]]
	then
		while IFS= read -r line
		do
			if [[ "$line" =~ ^Exec[[:space:]]*=[[:space:]]*steam[[:space:]]*steam\:\/\/rungameid\/[0-9][0-9]*[[:space:]]*$ ]] && [[ "$line" =~ ^Exec[[:space:]]*=[[:space:]]*steam ]]
			then
				GAME_ID="$(echo "$line" | sed 's,^Exec[[:space:]]*=[[:space:]]*steam[[:space:]]*steam\:\/\/rungameid\/,,i')"
				export GAME_ID
				if [[ $GAME_ID =~ ^[0-9][0-9]*[[:space:]]* ]]
				then
					NO_SPACE_GAME_ID="$(echo "$GAME_ID" | sed 's/[[:space:]]*//i')"
					export NO_SPACE_GAME_ID
				fi
			fi
		done < "$1"
	fi
}

download_icons() {
	if [ -n "${NO_SPACE_GAME_ID}" ] && [[ "$NO_SPACE_GAME_ID" =~ ^[0-9][0-9]*$ ]] && ! [[ "$NO_SPACE_GAME_ID" =~ ^[[:space:]][[:space:]]*$ ]]
	then
		echo "Downloading icon for $NO_SPACE_GAME_ID"
		SGDBoop "sgdb://boop/steam/${NO_SPACE_GAME_ID}-clienticon-en"
	fi
	unset GAME_ID
	unset NO_SPACE_GAME_ID
}

set_icons() {
	if [ -n "${NO_SPACE_GAME_ID}" ] && [[ "$NO_SPACE_GAME_ID" =~ ^[0-9][0-9]*$ ]] && ! [[ "$NO_SPACE_GAME_ID" =~ ^[[:space:]][[:space:]]*$ ]]
	then
		if [[ "$1" =~ $NO_MATCH_GAME_ID ]]
		then
			echo "$1 has default icon, changing it to the one for $NO_SPACE_GAME_ID"
			sed -i "s/^Icon[[:space:]]*=[[:space:]]*steam$/Icon=steam_icon_${NO_SPACE_GAME_ID}/i" "$1"
		else
			echo "$1 already has the icon for $NO_SPACE_GAME_ID, skipping"
		fi
	fi
	unset GAME_ID
	unset NO_SPACE_GAME_ID
}

DESKTOP_ENTRIES=$(find "$DESKTOP_FILE_LOCATION" -name "*.desktop")
APPLICATION_ENTRIES=$(find "$APPLICATION_FILE_LOCATION" -name "*.desktop")]
STEAM_ASSETS=$(find "$STEAM_ASSET_PATH" -name "*_icon.*")

if [ "${1,,}" == "download" ] || [ "${2,,}" == "download" ]
then
	for D in $DESKTOP_ENTRIES
	do
		read_ids "$D"
		download_icons "$D"
	done

	for A in $APPLICATION_ENTRIES
	do
		read_ids "$A"
		download_icons "$A"
	done

elif ! [ "${1,,}" == "download" ] && ! [ "${2,,}" == "download" ]
then
	echo "download flag not set, skipping donwload of icons..."
elif [ "${1,,}" == "download" ] && [ "${2,,}" == "download" ]
then
	if ! command -v SGDBoop >/dev/null 2>&1
	then
		echo "ERROR: download flag set but 'SGDBoop' is missing, please disable the download flag or follow the instructions to install it at https://www.steamgriddb.com/boop"
		exit 1
	fi
fi

	echo "SGDBoop is missing"
if ! command -v basename >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi

if ! command -v identify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi

if ! command -v mogrify >/dev/null 2>&1
then
	UTIL_EXISTS="0"
fi

if [ "$UTIL_EXISTS" == "0" ]
then	
	if exists apt
	then
		PACKAGE_MANAGER="apt"
	elif exists dnf
	then
		PACKAGE_MANAGER="dnf"
	elif exists yum
	then
		PACKAGE_MANAGER="yum"
	elif exists pacman
	then
		PACKAGE_MANAGER="pacman"
	fi

	echo "WARNING: Missing 'imagemagick' and/or 'coreutils', attempting to detect system package manager and then install the missing packages..."
	case "$PACKAGE_MANAGER" in
		"apt")
			echo "Detected apt..."
			sudo apt update
			sudo apt install coreutils imagemagick
			;;
		"dnf")
			echo "Detected dnf..."
			sudo dnf upgrade
			sudo dnf install coreutils ImageMagick
			;;
		"yum")
			echo "Detected yum..."
			sudo yum update
			sudo yum install coreutils ImageMagick
			;;
		"pacman")
			echo "Detected pacman..."
			sudo pacman -Syu
			sudo pacman -Sy imagemagick coreutils
			;;
		*)
			echo "ERROR: Unable to detect package manager..."
			echo "please find and install 'basename', possibly a part of 'coreutils' and, 'identify' and 'mogrify', possibly a part of 'imagemagick', according to your distributions instructions"
			exit 1
			;;
	esac
	
	if ! command -v basename >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'basename' and/or 'coreutils', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	
	if ! command -v identify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'identify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
	
	if ! command -v mogrify >/dev/null 2>&1
	then
		echo "ERROR: Still missing 'mogrify' and/or 'imagemagick', please find the package containing it and use your system package manager to install the missing package..."
		exit 1
	fi
fi

mkdir -p "$TMPFILE_PATH"

for S in $STEAM_ASSETS
do
	IMG_FORMAT="$(file -i -b "$S" | sed -e 's/;.*//')"
	IMG_FORMAT="${IMG_FORMAT//image\//}"
	BASENAME_NO_EXT="$(basename "${S%.*}")"
	case "$IMG_FORMAT" in  
		"png")
			echo "$S is already a .png, moving to ${TMPFILE_PATH} and renaming to ${BASENAME_NO_EXT}.png"
			cp -v -T "$S" "${TMPFILE_PATH}${BASENAME_NO_EXT}.png"
			;; 
		"jpeg")
			echo "$S is a .jpg, not a .png, moving to ${TMPFILE_PATH} and converting to ${BASENAME_NO_EXT}.png"
			cp -v -T "$S" "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.jpg"
			;; 
		"x-tga")
			echo "$S is a .tga, not a .png, moving to ${TMPFILE_PATH} and converting to ${BASENAME_NO_EXT}.png"
			cp -v -T "$S" "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.tga"
			;; 
		"vnd.microsoft.icon")
			echo "$S is a .ico, not a .png, moving to ${TMPFILE_PATH} and converting to ${BASENAME_NO_EXT}.png"
			cp -v -T "$S" "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			mogrify -quiet -auto-orient -format png "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			rm -v "${TMPFILE_PATH}${BASENAME_NO_EXT}.ico"
			;;
		*)
			echo "$S has unknown image format $IMG_FORMAT"
			;; 
	esac
done

PNG_FILES=$(find "$TMPFILE_PATH" -name "*.png")
for P in $PNG_FILES
do
	IMG_WIDTH="$(identify -format '%w' "$P")"
	IMG_HEIGHT="$(identify -format '%h' "$P")"
	NO_DIGIT_FILENAME="$(basename "$P" | sed "s/-[[:digit:]]\+//")"
	NO_ICON_FILENAME="${NO_DIGIT_FILENAME//_icon/}"
	FULL_NEW_FILENAME="steam_icon_$NO_ICON_FILENAME"
	NEW_PATHNAME="${ICON_PATH}hicolor/${IMG_WIDTH}x${IMG_HEIGHT}/apps/"
	FINAL_FILENAME="${NEW_PATHNAME}${FULL_NEW_FILENAME}"
	echo "image is ${IMG_WIDTH}x${IMG_HEIGHT}"
	if ! [ -e "$NEW_PATHNAME" ]
	then
		mkdir -v -p "$NEW_PATHNAME"
	fi
	
	if [ "${1,,}" == "overwrite" ] || [ "${2,,}" == "overwrite" ]
	then
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME exists, and overwrite flag is set... moving and overwriting..."
		elif ! [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME does not exist... moving..."
		fi
		mv -v -f "$P" "$FINAL_FILENAME"
	else
		if [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME exists, and overwrite flag is not set... ignoring..."
			rm -v "$FINAL_FILENAME"
		elif ! [ -e "$FINAL_FILENAME" ]
		then
			echo "$FINAL_FILENAME does not exist... moving..."
			mv -v -n "$P" "$FINAL_FILENAME"
		fi
	fi
done

rmdir "$TMPFILE_PATH"
if [ -e "$TMPFILE_PATH" ]
then
	rm -v -r -f "$TMPFILE_PATH"
fi

DESKTOP_ENTRIES_2=$(find "$DESKTOP_FILE_LOCATION" -name "*.desktop")
for D2 in $DESKTOP_ENTRIES_2
do
	read_ids "$D2"
	set_icons "$D2"
done

APPLICATION_ENTRIES_2=$(find "$APPLICATION_FILE_LOCATION" -name "*.desktop")]
for A2 in $APPLICATION_ENTRIES_2
do
	read_ids "$A2"
	set_icons "$A2"
done

IFS="$OIFS"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants