Commit 1eccf55f authored by Mikhail Tergoev's avatar Mikhail Tergoev

Merge branch 'steamAppIdToName' of github.com:alex2844/PortWINE into alex2844-steamAppIdToName

parents b7464e20 46aaca1e
...@@ -100,23 +100,30 @@ getAppId() { ...@@ -100,23 +100,30 @@ getAppId() {
getSteamId() { getSteamId() {
unset SteamAppId unset SteamAppId
local cache_file="${PORT_WINE_TMP_PATH:-/tmp}/steamid_cache.json" local cache_file="${PORT_WINE_TMP_PATH:-/tmp}/steamid_cache.json"
local applist_cache_file="${PORT_WINE_TMP_PATH:-/tmp}/steamapplist_cache.json"
[[ -n "${1:-}" ]] && NOSTAPPNAME="$1" [[ -n "${1:-}" ]] && NOSTAPPNAME="$1"
if [[ -z "${SteamIds:-}" ]] && [[ -f "${cache_file}" ]]; then if [[ -z "${SteamIds:-}" ]] && [[ -f "${cache_file}" ]]; then
SteamIds=$(<"${cache_file}") SteamIds=$(<"${cache_file}")
fi fi
if [[ -n "${SteamIds:-}" ]] && jq -e --arg key "$NOSTAPPNAME" 'has($key)' <<< "${SteamIds}" > /dev/null; then if [[ -n "${SteamIds:-}" ]] && jq -e --arg key "${NOSTAPPNAME}" 'has($key)' <<< "${SteamIds}" > /dev/null; then
SteamAppId=$(jq -r --arg key "${NOSTAPPNAME}" '.[$key]' <<< "${SteamIds}") SteamAppId=$(jq -r --arg key "${NOSTAPPNAME}" '.[$key]' <<< "${SteamIds}")
else else
if [[ -n "${1:-}" ]] && [[ "${USE_STEABGRIDDB:-1}" == "1" ]]; then if [[ -n "${1:-}" ]] && [[ "${USE_STEAMGRIDDB:-1}" == "1" ]]; then
getSteamGridDBId "${NOSTAPPNAME}" > /dev/null getSteamGridDBId "${NOSTAPPNAME}" > /dev/null
fi fi
if [[ $SteamGridDBTypeSteam == true ]]; then if [[ ${SteamGridDBTypeSteam} == true ]]; then
SRES=$(curl -Ls --connect-timeout 5 -m 10 -e "https://www.steamgriddb.com/game/${SteamGridDBId}" "https://www.steamgriddb.com/api/public/game/${SteamGridDBId}") SRES=$(curl -Ls --connect-timeout 5 -m 10 -e "https://www.steamgriddb.com/game/${SteamGridDBId}" "https://www.steamgriddb.com/api/public/game/${SteamGridDBId}")
if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then
SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")" SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")"
fi fi
elif [[ "${USE_STEABGRIDDB:-1}" == "0" ]]; then elif [[ "${USE_STEAMGRIDDB:-1}" == "0" ]]; then
SteamAppId="$(curl -s --connect-timeout 5 -m 10 "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | jq --arg name "${NOSTAPPNAME}" '.applist.apps[] | select(.name == $name) | .appid')" if [[ ! -f "${applist_cache_file}" ]] || [[ $(find "${applist_cache_file}" -mmin +1440) ]]; then
applist_data=$(curl -s --connect-timeout 5 "https://api.steampowered.com/ISteamApps/GetAppList/v2/")
[[ -n "${applist_data}" ]] && echo "${applist_data}" > "${applist_cache_file}"
else
applist_data=$(<"${applist_cache_file}")
fi
[[ -n "${applist_data}" ]] && SteamAppId=$(jq --arg name "${NOSTAPPNAME,,}" '.applist.apps[] | select(.name == $name) | .appid' <<< "${applist_data,,}")
fi fi
SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}") SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}")
echo "${SteamIds}" > "${cache_file}" echo "${SteamIds}" > "${cache_file}"
...@@ -129,7 +136,7 @@ getSteamId() { ...@@ -129,7 +136,7 @@ getSteamId() {
getSteamGridDBId() { getSteamGridDBId() {
unset SteamGridDBId unset SteamGridDBId
NOSTAPPNAME="$1" NOSTAPPNAME="$1"
if [[ "${USE_STEABGRIDDB:-1}" == "1" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs --connect-timeout 5 -m 10 -o /dev/null "${BASESTEAMGRIDDBAPI}"; then if [[ "${USE_STEAMGRIDDB:-1}" == "1" ]] && [[ -n "${SGDBAPIKEY}" ]] && [[ -n "${BASESTEAMGRIDDBAPI}" ]] && curl -fs --connect-timeout 5 -m 10 -o /dev/null "${BASESTEAMGRIDDBAPI}"; then
SGDBRES=$(curl -Ls --connect-timeout 5 -m 10 -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}") SGDBRES=$(curl -Ls --connect-timeout 5 -m 10 -H "Authorization: Bearer ${SGDBAPIKEY}" "${BASESTEAMGRIDDBAPI}/search/autocomplete/${NOSTAPPNAME// /_}")
if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then if jq -e ".success == true and (.data | length > 0)" <<< "${SGDBRES}" > /dev/null 2>&1; then
if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then if jq -e '.data[0].types | contains(["steam"])' <<< "${SGDBRES}" > /dev/null; then
...@@ -141,7 +148,7 @@ getSteamGridDBId() { ...@@ -141,7 +148,7 @@ getSteamGridDBId() {
echo "${SteamGridDBId}" echo "${SteamGridDBId}"
fi fi
else else
USE_STEABGRIDDB="0" USE_STEAMGRIDDB="0"
fi fi
} }
...@@ -204,10 +211,12 @@ listInstalledSteamGames() { ...@@ -204,10 +211,12 @@ listInstalledSteamGames() {
jq -n '[]' jq -n '[]'
else else
for manifest_file in "${manifests[@]}"; do for manifest_file in "${manifests[@]}"; do
name="$(grep -Po '"name"\s+"\K[^"]+' "$manifest_file")"; name="$(grep -Po '"name"\s+"\K[^"]+' "${manifest_file}")";
if [[ ! "${name}" =~ ^(Proton |Steam Linux Runtime|Steamworks Common) ]]; then stateflags="$(grep -Po '"StateFlags"\s+"\K\d+' "${manifest_file}")"
# if [[ ! "${name}" =~ ^(Proton |Steam Linux Runtime|Steamworks Common) ]]; then
if ((stateflags & 4)) && grep -q '"SharedDepots"' "${manifest_file}"; then
jq -n \ jq -n \
--arg id "$(grep -Po '"appid"\s+"\K\d+' "$manifest_file")" \ --arg id "$(grep -Po '"appid"\s+"\K\d+' "${manifest_file}")" \
--arg name "${name}" \ --arg name "${name}" \
'{id: $id, name: $name}' '{id: $id, name: $name}'
fi fi
...@@ -216,36 +225,47 @@ listInstalledSteamGames() { ...@@ -216,36 +225,47 @@ listInstalledSteamGames() {
} }
listNonSteamGames() { listNonSteamGames() {
getSteamShortcutHex | while read -r SCVDFE; do getSteamShortcutHex | while read -r SCVDFE; do
jq -n \ jq -n \
--arg id "$(parseSteamShortcutEntryAppID "${SCVDFE}")" \ --arg id "$(parseSteamShortcutEntryAppID "${SCVDFE}")" \
--arg name "$(parseSteamShortcutEntryAppName "${SCVDFE}")" \ --arg name "$(parseSteamShortcutEntryAppName "${SCVDFE}")" \
--arg exe "$(parseSteamShortcutEntryExe "${SCVDFE}")" \ --arg exe "$(parseSteamShortcutEntryExe "${SCVDFE}")" \
--arg dir "$(parseSteamShortcutEntryStartDir "${SCVDFE}")" \ --arg dir "$(parseSteamShortcutEntryStartDir "${SCVDFE}")" \
--arg icon "$(parseSteamShortcutEntryIcon "${SCVDFE}")" \ --arg icon "$(parseSteamShortcutEntryIcon "${SCVDFE}")" \
--arg args "$(parseSteamShortcutEntryLaunchOptions "${SCVDFE}")" \ --arg args "$(parseSteamShortcutEntryLaunchOptions "${SCVDFE}")" \
'{id: $id, name: $name, exe: $exe, dir: $dir, icon: $icon, args: $args}' '{id: $id, name: $name, exe: $exe, dir: $dir, icon: $icon, args: $args}'
done | jq -s '.' done | jq -s '.'
} }
listSteamGames() { listSteamGames() {
( (
jq -r 'map({AppId: .id, SteamAppId: .id, SteamGameId: .id, Name: .name}) | .[] | tostring' <<< "$(listInstalledSteamGames)" jq -r 'map({AppId: .id, SteamAppId: .id, SteamGameId: .id, Name: .name}) | .[] | tostring' <<< "$(listInstalledSteamGames)"
jq -r '.[] | tostring' <<< "$(listNonSteamGames)" | while read -r game; do jq -r '.[] | tostring' <<< "$(listNonSteamGames)" | while read -r game; do
id=$(jq -r '.id' <<< "${game}") id=$(jq -r '.id' <<< "${game}")
name=$(jq -r '.name' <<< "${game}") name=$(jq -r '.name' <<< "${game}")
jq -r \ exe=$(jq -r '.exe' <<< "${game}")
--arg SteamAppId "$(getSteamId "${name}")" \ if [[ "${name}" =~ ^[0-9]+$ ]] && [[ "${exe}" =~ .sh$ ]]; then
--arg SteamGameId "$(getSteamGameId $id)" \ appid="${name}"
'{AppId: .id, SteamAppId: ($SteamAppId | if . == "" then "0" else . end), SteamGameId: $SteamGameId, Name: .name} | tostring' <<< "${game}" name=$(basename "${exe}" .sh)
else
appid="$(getSteamId "${name}")"
[[ -z "${appid}" ]] && appid="0"
fi
gid="$(getSteamGameId $id)"
jq -n \
--arg id "${id}" \
--arg appid "${appid}" \
--arg gid "${gid}" \
--arg name "${name}" \
'{AppId: $id, SteamAppId: $appid, SteamGameId: $gid, Name: $name}'
done done
) | jq -s '.' ) | jq -s '.'
} }
convertSteamShortcutAppID() { convertSteamShortcutAppID() {
SHORTCUTAPPIDHEX="$1" SHORTCUTAPPIDHEX="$1"
SHORTCUTAPPIDLITTLEENDIAN="$( echo "${SHORTCUTAPPIDHEX}" | tac -rs .. | tr -d '\n' )" SHORTCUTAPPIDLITTLEENDIAN="$( echo "${SHORTCUTAPPIDHEX}" | tac -rs .. | tr -d '\n' )"
echo "$((16#${SHORTCUTAPPIDLITTLEENDIAN}))" echo "$((16#${SHORTCUTAPPIDLITTLEENDIAN}))"
} }
convertSteamShortcutHex() { convertSteamShortcutHex() {
...@@ -350,8 +370,8 @@ downloadImageSteamGridDB() { ...@@ -350,8 +370,8 @@ downloadImageSteamGridDB() {
} }
addGrids() { addGrids() {
getSteamGridDBId "${name_desktop}" > /dev/null [[ -z "${SteamGridDBId}" ]] && getSteamGridDBId "${name_desktop}" > /dev/null
if [[ "${USE_STEABGRIDDB:-1}" == "0" ]]; then if [[ -z "${SteamAppId}" ]] && [[ "${USE_STEAMGRIDDB:-1}" == "0" ]]; then
getSteamId > /dev/null getSteamId > /dev/null
fi fi
if [[ -n "${SteamGridDBId}" ]] || [[ -n "${SteamAppId}" ]]; then if [[ -n "${SteamGridDBId}" ]] || [[ -n "${SteamAppId}" ]]; then
...@@ -474,8 +494,8 @@ addNonSteamGame() { ...@@ -474,8 +494,8 @@ addNonSteamGame() {
fi fi
NOSTICONPATH="${PORT_WINE_PATH}/data/img/${name_desktop_png}.png" NOSTICONPATH="${PORT_WINE_PATH}/data/img/${name_desktop_png}.png"
NOSTAIDVDF="$(generateShortcutVDFAppId "${NOSTAPPNAME}${NOSTEXEPATH}")" # signed integer AppID, stored in the VDF as hexidecimal - ex: -598031679 NOSTAIDVDF="$(generateShortcutVDFAppId "${NOSTAPPNAME}${NOSTEXEPATH}")" # signed integer AppID, stored in the VDF as hexidecimal - ex: -598031679
NOSTAIDVDFHEX="$(generateShortcutVDFHexAppId "$NOSTAIDVDF")" # 4byte little-endian hexidecimal of above 32bit signed integer, which we write out to the binary VDF - ex: c1c25adc NOSTAIDVDFHEX="$(generateShortcutVDFHexAppId "${NOSTAIDVDF}")" # 4byte little-endian hexidecimal of above 32bit signed integer, which we write out to the binary VDF - ex: c1c25adc
NOSTAPPID="$(extractSteamId32 "$NOSTAIDVDF")" # unsigned 32bit ingeger version of "$NOSTAIDVDF", which is used as the AppID for Steam artwork ("grids"), as well as for our shortcuts NOSTAPPID="$(extractSteamId32 "${NOSTAIDVDF}")" # unsigned 32bit ingeger version of "$NOSTAIDVDF", which is used as the AppID for Steam artwork ("grids"), as well as for our shortcuts
create_new_dir "${STEAM_SCRIPTS}" create_new_dir "${STEAM_SCRIPTS}"
cat <<-EOF > "${NOSTSHPATH}" cat <<-EOF > "${NOSTSHPATH}"
...@@ -491,9 +511,15 @@ addNonSteamGame() { ...@@ -491,9 +511,15 @@ addNonSteamGame() {
cp "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null cp "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
fi fi
if [[ "${USE_STEAMAPPID_AS_NAME:-0}" == "1" ]]; then
SteamAppId=$(getSteamId "${NOSTAPPNAME}")
[[ -n "${SteamAppId}" ]] && NOSTAPPNAME="${SteamAppId}"
fi
addEntry addEntry
if [[ "${DOWNLOAD_STEAM_GRID}" == "1" ]] ; then if [[ "${DOWNLOAD_STEAM_GRID}" == "1" ]] ; then
NOSTAPPNAME="${name_desktop}"
pw_start_progress_bar_block "${translations[Please wait. downloading covers for]} ${NOSTAPPNAME}" pw_start_progress_bar_block "${translations[Please wait. downloading covers for]} ${NOSTAPPNAME}"
addGrids addGrids
pw_stop_progress_bar pw_stop_progress_bar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment