So i run most if not all of my GOG and Itch Games via Lutris which i am quite happy with :D
But sadly i just get the “Stock” Executeable Icon instead of the Games Icon :(
Also yes due to the my Icon Theme Set it does look different but eitherway is that not the Correct Icon for the Game :(
Is there a better Way than downloading and changing the Icon for each Game manually? :(

  • cecilkorik@piefed.ca
    link
    fedilink
    English
    arrow-up
    1
    ·
    5 days ago

    If you don’t want to do it manually, make a script to do it. :) Create a text file named something like fix-icon.sh, put it somewhere that’s on your $PATH like /usr/local/bin (with sudo) or ~/bin (if that’s on your path):

    #!/bin/bash
    set -e
    
    # Give it a path to the *.desktop file on the command line, and it will be set here from $1
    DESKTOP_FILE=${1:?"You need to specify the .desktop file as a command line argument"}
    # The icon will go into your local ~/.icons folder
    ICON_DESTINATION="${HOME}/.icons"
    # Make sure ~/.icons exists
    mkdir -p "${ICON_DESTINATION}"
    # The icon will be named whatever the desktop file is named
    ICON_NAME=$(basename -s.desktop "${DESKTOP_FILE}")
    # The icon will use this name (both .ico and .png)
    ICON_FILE="${ICON_DESTINATION}/${ICON_NAME}"
    # The EXE file should be detected from the "Exec=" line of the .desktop file
    EXE_CMD=$(grep '^Exec=.*' ${DESKTOP_FILE} | sed 's/Exec=//')
    # Use python to break down the command to get just the EXE file
    EXE_FILE=$(which $(python -c "import shlex; print(shlex.split(r'${EXE_CMD}')[0])"))
    
    if [[ -e "${ICON_FILE}.ico" || -e "${ICON_FILE}.png" ]]; then
        echo "Error: An icon at ${ICON_FILE} already exists, not overwriting"
        exit 1
    fi
    
    # Extract the icon with wrestool from icoutils or however you prefer to do it
    wrestool -x -t 14 "${EXE_FILE}" > "${ICON_FILE}.ico"
    
    # Convert ico to png with imagemagick
    convert "${ICON_FILE}.ico[0]" "${ICON_FILE}.png"
    
    # Cleanup ico file we don't need anymore
    rm "${ICON_FILE}.ico"
    
    # Embed png icon into desktop file
    sed -i "s/Icon=.*/Icon=${ICON_NAME}/" "${DESKTOP_FILE}"
    

    Then chmod u+x /path/to/fix-icon.sh and do fix-icon.sh /path/to/whatever.desktop Should do the trick in most cases. I used some advanced magic in some of the variables to make it hopefully not fail for you if it runs into weird issues, but it doesn’t actually need to be that complicated usually I just wanted to make sure it could handle some weird formats pretty safely. You can easily loop it on all .desktop files in a path if you want:

    for DESKTOP_FILE in *.desktop; do fix-icon.sh "${DESKTOP_FILE}"; done

    I love bash. :) python, coreutils, grep should be on pretty much any system by default. But you will need imagemagick, and icoutils installed for it to work.

    Let me know if you have any trouble with it. I tested it on my system and it seems fine but I don’t have any lutris desktop files so I can’t test it properly. Good luck!