addEntry
This commit is contained in:
parent
df86ec0416
commit
23be9fc637
@ -210,19 +210,22 @@ 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}")" \
|
||||||
'{id: $id, name: $name, exe: $exe}'
|
--arg dir "$(parseSteamShortcutEntryStartDir "${SCVDFE}")" \
|
||||||
done | jq -s '.'
|
--arg icon "$(parseSteamShortcutEntryIcon "${SCVDFE}")" \
|
||||||
|
--arg args "$(parseSteamShortcutEntryLaunchOptions "${SCVDFE}")" \
|
||||||
|
'{id: $id, name: $name, exe: $exe, dir: $dir, icon: $icon, args: $args}'
|
||||||
|
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 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 \
|
jq -r \
|
||||||
@ -240,19 +243,22 @@ convertSteamShortcutAppID() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convertSteamShortcutHex() {
|
convertSteamShortcutHex() {
|
||||||
# printf "%s" "$1" | xxd -r -p | tr -d '\0'
|
|
||||||
LC_ALL=C perl -le 'print pack "H*", $ARGV[0]' "$1" | tr -d '\0'
|
LC_ALL=C perl -le 'print pack "H*", $ARGV[0]' "$1" | tr -d '\0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertStringToSteamShortcutHex() {
|
||||||
|
LC_ALL=C perl -e 'print unpack "H*", "$ARGV[0]" . "\x00"' "$(echo "$1" | tr -cd '[:alpha:]')"
|
||||||
|
}
|
||||||
|
|
||||||
parseSteamShortcutEntryHex() {
|
parseSteamShortcutEntryHex() {
|
||||||
SHORTCUTSVDFINPUTHEX="$1" # The hex block representing the shortcut
|
SHORTCUTSVDFINPUTHEX="$1" # The hex block representing the shortcut
|
||||||
SHORTCUTSVDFMATCHPATTERN="$2" # The pattern to match against in the block
|
SHORTCUTSVDFMATCHPATTERN="$2" # The pattern to match against in the block
|
||||||
convertSteamShortcutHex "$(getSteamShortcutEntryHex "${SHORTCUTSVDFINPUTHEX}" "${SHORTCUTSVDFMATCHPATTERN}")"
|
convertSteamShortcutHex "$(getSteamShortcutEntryHex "${SHORTCUTSVDFINPUTHEX}" "${SHORTCUTSVDFMATCHPATTERN}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSteamShortcutEntryExe() {
|
parseSteamShortcutEntryAppID() {
|
||||||
SHORTCUTVDFEXEHEXPAT="000145786500" # 'Exe' ('exe' is 6578650a if we ever need it)
|
SHORTCUTVDFAPPIDHEXPAT="617070696400" # 'appid'
|
||||||
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFEXEHEXPAT}" | tr -d '"'
|
convertSteamShortcutAppID "$(printf "%s" "$1" | grep -oP "${SHORTCUTVDFAPPIDHEXPAT}\K.{8}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSteamShortcutEntryAppName() {
|
parseSteamShortcutEntryAppName() {
|
||||||
@ -260,9 +266,24 @@ parseSteamShortcutEntryAppName() {
|
|||||||
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFNAMEHEXPAT}"
|
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFNAMEHEXPAT}"
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSteamShortcutEntryAppID() {
|
parseSteamShortcutEntryExe() {
|
||||||
SHORTCUTVDFAPPIDHEXPAT="617070696400" # 'appid'
|
SHORTCUTVDFEXEHEXPAT="000145786500" # 'Exe' ('exe' is 6578650a if we ever need it)
|
||||||
convertSteamShortcutAppID "$(printf "%s" "$1" | grep -oP "${SHORTCUTVDFAPPIDHEXPAT}\K.{8}")"
|
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFEXEHEXPAT}" | tr -d '"'
|
||||||
|
}
|
||||||
|
|
||||||
|
parseSteamShortcutEntryStartDir() {
|
||||||
|
SHORTCUTVDFSTARTDIRHEXPAT="0001537461727444697200"
|
||||||
|
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFSTARTDIRHEXPAT}" | tr -d '"'
|
||||||
|
}
|
||||||
|
|
||||||
|
parseSteamShortcutEntryIcon() {
|
||||||
|
SHORTCUTVDFICONHEXPAT="000169636f6e00"
|
||||||
|
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFICONHEXPAT}"
|
||||||
|
}
|
||||||
|
|
||||||
|
parseSteamShortcutEntryLaunchOptions() {
|
||||||
|
SHORTCUTVDFARGHEXPAT="00014c61756e63684f7074696f6e7300" # echo "0001$(convertStringToSteamShortcutHex "LaunchOptions")"
|
||||||
|
parseSteamShortcutEntryHex "$1" "${SHORTCUTVDFARGHEXPAT}" | tr '\002' '\n' | head -n 1 | tr -d '\000'
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSteamTargetExe() {
|
parseSteamTargetExe() {
|
||||||
@ -333,47 +354,90 @@ addGrids() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addEntry() {
|
||||||
|
if [[ -n "${SCPATH}" ]]; then
|
||||||
|
if [[ -f "${SCPATH}" ]] ; then
|
||||||
|
truncate -s-2 "${SCPATH}"
|
||||||
|
OLDSET="$(grep -aPo '\x00[0-9]\x00\x02appid' "${SCPATH}" | tail -n1 | tr -dc '0-9')"
|
||||||
|
NEWSET=$((OLDSET + 1))
|
||||||
|
else
|
||||||
|
printf '\x00%s\x00' "shortcuts" > "${SCPATH}"
|
||||||
|
NEWSET=0
|
||||||
|
fi
|
||||||
|
NOSTAIDVDFHEXFMT="\x$(awk '{$1=$1}1' FPAT='.{2}' OFS="\\\x" <<< "$NOSTAIDVDFHEX")" # binary-formatted string hex of the above which we actually write out - ex: \xc1\xc2\x5a\xdc
|
||||||
|
|
||||||
|
{
|
||||||
|
printf '\x00%s\x00' "${NEWSET}"
|
||||||
|
printf '\x02%s\x00%b' "appid" "${NOSTAIDVDFHEXFMT}"
|
||||||
|
printf '\x01%s\x00%s\x00' "AppName" "${NOSTAPPNAME}"
|
||||||
|
printf '\x01%s\x00%s\x00' "Exe" "\"${NOSTEXEPATH}\""
|
||||||
|
printf '\x01%s\x00%s\x00' "StartDir" "\"${NOSTSTDIR}\""
|
||||||
|
printf '\x01%s\x00%s\x00' "icon" "${NOSTICONPATH}"
|
||||||
|
printf '\x01%s\x00%s\x00' "ShortcutPath" ""
|
||||||
|
printf '\x01%s\x00%s\x00' "LaunchOptions" "${NOSTARGS:-}"
|
||||||
|
|
||||||
|
printf '\x02%s\x00%b\x00\x00\x00' "IsHidden" "\x00"
|
||||||
|
printf '\x02%s\x00%b\x00\x00\x00' "AllowDesktopConfig" "\x00"
|
||||||
|
|
||||||
|
# These values are now stored in localconfig.vdf under the "Apps" section,
|
||||||
|
# under a block using the Non-Steam Game Signed 32bit AppID. (i.e., -223056321)
|
||||||
|
# This is handled by `updateLocalConfigAppsValue` below
|
||||||
|
#
|
||||||
|
# Unsure if required, but still write these to the shortcuts.vdf file for consistency
|
||||||
|
printf '\x02%s\x00%b\x00\x00\x00' "AllowOverlay" "\x00"
|
||||||
|
printf '\x02%s\x00%b\x00\x00\x00' "OpenVR" "\x00"
|
||||||
|
|
||||||
|
printf '\x02%s\x00\x00\x00\x00\x00' "Devkit"
|
||||||
|
printf '\x01%s\x00\x00' "DevkitGameID"
|
||||||
|
printf '\x02%s\x00\x00\x00\x00\x00' "DevkitOverrideAppID"
|
||||||
|
printf '\x02%s\x00\x00\x00\x00\x00' "LastPlayTime"
|
||||||
|
printf '\x01%s\x00\x00' "FlatpakAppID"
|
||||||
|
printf '\x00%s\x00' "tags"
|
||||||
|
printf '\x08\x08\x08\x08'
|
||||||
|
} >> "${SCPATH}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
removeNonSteamGame() {
|
removeNonSteamGame() {
|
||||||
[[ -n "${1:-}" ]] && appid="$1"
|
[[ -n "$1" ]] && appid="$1"
|
||||||
[[ -n "${2:-}" ]] && NOSTSHPATH="$2"
|
|
||||||
[[ -z "${STUID}" ]] && STUID=$(getUserId)
|
[[ -z "${STUID}" ]] && STUID=$(getUserId)
|
||||||
[[ -z "${STCFGPATH}" ]] && STCFGPATH="$(getUserPath ${STUID})"
|
[[ -z "${STCFGPATH}" ]] && STCFGPATH="$(getUserPath ${STUID})"
|
||||||
if [[ -n "${STCFGPATH}" ]] && [[ -z "${SCPATH}" ]]; then
|
if [[ -n "${STCFGPATH}" ]] && [[ -z "${SCPATH}" ]]; then
|
||||||
SCPATH="${STCFGPATH}/shortcuts.vdf"
|
SCPATH="${STCFGPATH}/shortcuts.vdf"
|
||||||
fi
|
fi
|
||||||
if [[ -n "${appid}" ]] && [[ -n "${SCPATH}" ]] && [[ -f "${SCPATH}" ]]; then
|
if [[ -n "${appid}" ]]; then
|
||||||
[[ -z "${NOSTSHPATH}" ]] && NOSTSHPATH=$(getAppExe ${appid})
|
games=$(listNonSteamGames)
|
||||||
cp "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
|
NOSTSHPATH=$(jq -r --arg id "${appid}" 'map(select(.id == $id)) | first(.[].exe)' <<< "${games}")
|
||||||
NOSTAIDVDFHEX=$(bigToLittleEndian $(printf '%08x' "${appid}"))
|
if [[ -n "${NOSTSHPATH}" ]]; then
|
||||||
LC_ALL=C perl -pe '
|
mv "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
|
||||||
$hex = pack("H*", shift);
|
jq --arg id "${appid}" 'map(select(.id != $id))' <<< "${games}" | jq -c '.[]' | while read -r game; do
|
||||||
$pos = index($_, $hex);
|
NOSTAIDGRID=$(jq -r '.id' <<< "${game}")
|
||||||
if ($pos != -1) {
|
NOSTAPPNAME=$(jq -r '.name' <<< "${game}")
|
||||||
$start_pos = rindex($_, "\x00", $pos - 1);
|
NOSTEXEPATH=$(jq -r '.exe' <<< "${game}")
|
||||||
$end_pos = index($_, "ppid", $pos);
|
NOSTSTDIR=$(jq -r '.dir' <<< "${game}")
|
||||||
$end_pos = index($_, "\x08\x08", $pos) if $end_pos == -1;
|
NOSTICONPATH=$(jq -r '.icon' <<< "${game}")
|
||||||
if ($start_pos != -1 && $end_pos != -1) {
|
NOSTARGS=$(jq -r '.args' <<< "${game}")
|
||||||
$end_pos += 4;
|
NOSTAIDVDFHEX=$(bigToLittleEndian $(printf '%08x' "${NOSTAIDGRID}"))
|
||||||
$_ = substr($_, 0, $start_pos) . substr($_, $end_pos);
|
addEntry
|
||||||
}
|
done
|
||||||
}
|
rm -f "${STCFGPATH}/grid/${appid}.jpg" "${STCFGPATH}/grid/${appid}p.jpg" "${STCFGPATH}/grid/${appid}_hero.jpg" "${STCFGPATH}/grid/${appid}_logo.png"
|
||||||
' "${SCPATH}" "${NOSTAIDVDFHEX}" > "${SCPATH}~"
|
if [[ -f "${NOSTSHPATH}" ]]; then
|
||||||
mv "${SCPATH}~" "${SCPATH}"
|
isInstallGame=false
|
||||||
rm -f "${STCFGPATH}/grid/${appid}.jpg" "${STCFGPATH}/grid/${appid}p.jpg" "${STCFGPATH}/grid/${appid}_hero.jpg" "${STCFGPATH}/grid/${appid}_logo.png"
|
for STUIDCUR in $(getUserIds); do
|
||||||
fi
|
[[ "${STUIDCUR}" == "${STUID}" ]] && continue
|
||||||
if [[ -n "${STUID}" ]] && [[ -n "${NOSTSHPATH}" ]] && [[ -f "${NOSTSHPATH}" ]]; then
|
STCFGPATH="$(getUserPath ${STUIDCUR})"
|
||||||
isInstallGame=false
|
SCPATH="${STCFGPATH}/shortcuts.vdf"
|
||||||
for STUIDCUR in $(getUserIds); do
|
if [[ -n "$(getAppId "${NOSTSHPATH}")" ]]; then
|
||||||
[[ "${STUIDCUR}" == "${STUID}" ]] && continue
|
isInstallGame=true
|
||||||
STCFGPATH="$(getUserPath ${STUIDCUR})"
|
break
|
||||||
SCPATH="${STCFGPATH}/shortcuts.vdf"
|
fi
|
||||||
if [[ -n "$(getAppId "${NOSTSHPATH}")" ]]; then
|
done
|
||||||
isInstallGame=true
|
unset STCFGPATH SCPATH
|
||||||
break
|
if [[ ${isInstallGame} == false ]]; then
|
||||||
|
rm "${NOSTSHPATH}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
restartSteam
|
||||||
if [[ ${isInstallGame} == false ]]; then
|
|
||||||
rm "${NOSTSHPATH}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -390,14 +454,13 @@ addNonSteamGame() {
|
|||||||
NOSTSHPATH="${STEAM_SCRIPTS}/${name_desktop}.sh"
|
NOSTSHPATH="${STEAM_SCRIPTS}/${name_desktop}.sh"
|
||||||
NOSTAIDGRID=$(getAppId "${NOSTSHPATH}")
|
NOSTAIDGRID=$(getAppId "${NOSTSHPATH}")
|
||||||
if [[ -z "${NOSTAIDGRID}" ]]; then
|
if [[ -z "${NOSTAIDGRID}" ]]; then
|
||||||
NOSTEXEPATH="\"${NOSTSHPATH}\""
|
NOSTEXEPATH="${NOSTSHPATH}"
|
||||||
if [[ -z "${NOSTSTDIR}" ]]; then
|
if [[ -z "${NOSTSTDIR}" ]]; then
|
||||||
NOSTSTDIR="\"${STEAM_SCRIPTS}\""
|
NOSTSTDIR="${STEAM_SCRIPTS}"
|
||||||
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
|
||||||
NOSTAIDVDFHEXFMT="\x$(awk '{$1=$1}1' FPAT='.{2}' OFS="\\\x" <<< "$NOSTAIDVDFHEX")" # binary-formatted string hex of the above which we actually write out - ex: \xc1\xc2\x5a\xdc
|
|
||||||
NOSTAIDGRID="$(extractSteamId32 "$NOSTAIDVDF")" # unsigned 32bit ingeger version of "$NOSTAIDVDF", which is used as the AppID for Steam artwork ("grids"), as well as for our shortcuts
|
NOSTAIDGRID="$(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}"
|
||||||
@ -413,43 +476,9 @@ addNonSteamGame() {
|
|||||||
|
|
||||||
if [[ -f "${SCPATH}" ]] ; then
|
if [[ -f "${SCPATH}" ]] ; then
|
||||||
cp "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
|
cp "${SCPATH}" "${SCPATH//.vdf}_${PROGNAME}_backup.vdf" 2>/dev/null
|
||||||
truncate -s-2 "${SCPATH}"
|
|
||||||
OLDSET="$(grep -aPo '\x00[0-9]\x00\x02appid' "${SCPATH}" | tail -n1 | tr -dc '0-9')"
|
|
||||||
NEWSET=$((OLDSET + 1))
|
|
||||||
else
|
|
||||||
printf '\x00%s\x00' "shortcuts" > "${SCPATH}"
|
|
||||||
NEWSET=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{
|
addEntry
|
||||||
printf '\x00%s\x00' "${NEWSET}"
|
|
||||||
printf '\x02%s\x00%b' "appid" "${NOSTAIDVDFHEXFMT}"
|
|
||||||
printf '\x01%s\x00%s\x00' "AppName" "${NOSTAPPNAME}"
|
|
||||||
printf '\x01%s\x00%s\x00' "Exe" "${NOSTEXEPATH}"
|
|
||||||
printf '\x01%s\x00%s\x00' "StartDir" "${NOSTSTDIR}"
|
|
||||||
printf '\x01%s\x00%s\x00' "icon" "${NOSTICONPATH}"
|
|
||||||
printf '\x01%s\x00%s\x00' "ShortcutPath" ""
|
|
||||||
printf '\x01%s\x00%s\x00' "LaunchOptions" ""
|
|
||||||
|
|
||||||
printf '\x02%s\x00%b\x00\x00\x00' "IsHidden" "\x00"
|
|
||||||
printf '\x02%s\x00%b\x00\x00\x00' "AllowDesktopConfig" "\x00"
|
|
||||||
|
|
||||||
# These values are now stored in localconfig.vdf under the "Apps" section,
|
|
||||||
# under a block using the Non-Steam Game Signed 32bit AppID. (i.e., -223056321)
|
|
||||||
# This is handled by `updateLocalConfigAppsValue` below
|
|
||||||
#
|
|
||||||
# Unsure if required, but still write these to the shortcuts.vdf file for consistency
|
|
||||||
printf '\x02%s\x00%b\x00\x00\x00' "AllowOverlay" "\x00"
|
|
||||||
printf '\x02%s\x00%b\x00\x00\x00' "OpenVR" "\x00"
|
|
||||||
|
|
||||||
printf '\x02%s\x00\x00\x00\x00\x00' "Devkit"
|
|
||||||
printf '\x01%s\x00\x00' "DevkitGameID"
|
|
||||||
printf '\x02%s\x00\x00\x00\x00\x00' "DevkitOverrideAppID"
|
|
||||||
printf '\x02%s\x00\x00\x00\x00\x00' "LastPlayTime"
|
|
||||||
printf '\x01%s\x00\x00' "FlatpakAppID"
|
|
||||||
printf '\x00%s\x00' "tags"
|
|
||||||
printf '\x08\x08\x08\x08'
|
|
||||||
} >> "${SCPATH}"
|
|
||||||
|
|
||||||
# TODO: замень использование steamgriddb на steam так как сайт steamgriddb у многих без VPN не работает
|
# TODO: замень использование steamgriddb на steam так как сайт steamgriddb у многих без VPN не работает
|
||||||
# а пока просто блочим использование
|
# а пока просто блочим использование
|
||||||
|
Loading…
Reference in New Issue
Block a user