forked from Linux-Gaming/PortProtonQt
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46078d72a3
|
No files matched your search
@@ -30,7 +30,6 @@
|
||||
- В настройки добавлена загрузка Wine/Proton в Steam `compatibilitytools.d`
|
||||
|
||||
### Changed
|
||||
- Бейджи источников (Steam и PortProton) теперь отображаются при любом фильтре библиотеки
|
||||
- Обложки к играм из Steam теперь полностью локальные
|
||||
- Улучшен механизм кеширования данных
|
||||
- Тип геймпада `Xbox` `PS` теперь выбирается автоматически
|
||||
@@ -49,7 +48,6 @@
|
||||
- Автоустановки теперь можно остановить
|
||||
- Префиксы `DEFAULT`, `DOTNET` и `PROGRAMS` теперь всегда отображаются вверху списков префиксов
|
||||
- Из лога удалена версия скриптов, так как скрипты теперь внутри PortProtonQt
|
||||
- Из downloader удалена отдельная проверка сети через Yandex и Google
|
||||
|
||||
### Fixed
|
||||
- Исправлено определение `PW_USE_RUNTIME` в debug-логе
|
||||
@@ -67,7 +65,6 @@
|
||||
- Исправлено управление геймпадом в диалоге выбора файла для загрузки PPDB
|
||||
- Исправлен повторный вывод одинаковых Vulkan GPU в `vk_gpu_info`
|
||||
- Исправлена работа клавиатурного управления при раскладке, отличной от английской
|
||||
- Исправлена загрузка данных HowLongToBeat
|
||||
|
||||
### Contributors
|
||||
- @Dervart
|
||||
|
||||
@@ -57,7 +57,7 @@ PortProtonQt использует код и зависимости от след
|
||||
|
||||
- [Icoextract](https://github.com/jlu5/icoextract) — библиотека для извлечения иконок, лицензия [MIT](https://github.com/jlu5/icoextract/blob/master/LICENSE).
|
||||
- [HowLongToBeat Python API](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI) — библиотека для взаимодействия с HowLongToBeat, лицензия [MIT](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/blob/master/LICENSE.md).
|
||||
- [iat](https://sourceforge.net/projects/iat.berlios) — библиотека для конвертации mdf в iso, лицензия GPLv3
|
||||
- [mdf2iso](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI) — библиотека для конвертации mdf в iso, лицензия [GPLv2](https://salsa.debian.org/debian/mdf2iso/-/blob/master/gpl.txt).
|
||||
Полный текст лицензий см. в файле [LICENSE](LICENSE).
|
||||
|
||||
> [!WARNING]
|
||||
|
||||
@@ -88,7 +88,7 @@ EOM
|
||||
# Disable locale noextract
|
||||
sed -i -E 's@[[:space:]]*usr/share/locale/\*@@g; s@[[:space:]]+@ @g; s@[[:space:]]+$@@' /etc/pacman.conf
|
||||
|
||||
pacman -Syyu --noconfirm --disable-download-timeout
|
||||
pacman -Syy
|
||||
|
||||
echo "Building PortProtonQt from PKGBUILD..."
|
||||
echo "---------------------------------------------------------------"
|
||||
|
||||
@@ -37,8 +37,9 @@ fi
|
||||
# Qt libs have to be passed manually due to the app being a python script
|
||||
./quick-sharun \
|
||||
/usr/bin/portprotonqt* \
|
||||
/usr/lib/libQt6*.so* \
|
||||
/usr/lib/libSDL2*.so* \
|
||||
/usr/lib/libQt6Core.so* \
|
||||
/usr/lib/libQt6Gui.so* \
|
||||
/usr/lib/libQt6Network.so* \
|
||||
/usr/lib/libudev.so*
|
||||
|
||||
# Turn AppDir into AppImage
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ arch=('any')
|
||||
url="https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt"
|
||||
license=('GPL-3.0')
|
||||
depends=('python-requests' 'python-babel' 'python-evdev' 'python-pygame' 'python-orjson'
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-beautifulsoup4' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
depends_aarch64=('muvm')
|
||||
makedepends=('meson' 'ninja' 'vulkan-headers' 'gettext')
|
||||
source=("git+https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt#tag=v$pkgver")
|
||||
|
||||
@@ -6,7 +6,7 @@ arch=('any')
|
||||
url="https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt"
|
||||
license=('GPL-3.0')
|
||||
depends=('python-requests' 'python-babel' 'python-evdev' 'python-pygame' 'python-orjson'
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-beautifulsoup4' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
depends_aarch64=('muvm')
|
||||
makedepends=('meson' 'ninja' 'vulkan-headers' 'gettext')
|
||||
source=("git+https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt.git")
|
||||
@@ -18,7 +18,7 @@ pkgver() {
|
||||
}
|
||||
|
||||
build() {
|
||||
arch-meson PortProtonQt build -Dnightly=true
|
||||
arch-meson PortProtonQt build
|
||||
meson compile -C build
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ Requires: python3-tqdm
|
||||
Requires: python3-vdf
|
||||
Requires: python3-pefile
|
||||
Requires: python3-pillow
|
||||
Requires: python3-beautifulsoup4
|
||||
Requires: python3-rapidfuzz
|
||||
Requires: python3-libarchive-c
|
||||
Requires: perl-Image-ExifTool
|
||||
@@ -96,7 +97,6 @@ git clone https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt.git
|
||||
%build
|
||||
cd %{oname}
|
||||
%meson \
|
||||
-Dnightly=true \
|
||||
-Dpython_purelibdir=%{python3_sitelib} \
|
||||
-Dudev_rulesdir=%{_udevrulesdir}
|
||||
%meson_build
|
||||
@@ -120,8 +120,6 @@ install -Dpm 0644 ./completions/_portprotonqt -t %{buildroot}%{zsh_completions_d
|
||||
%{_datadir}/polkit-1/rules.d/ru.linux_gaming.PortProtonQt.rules
|
||||
%{_datadir}/applications/ru.linux_gaming.PortProtonQt.desktop
|
||||
%{_datadir}/portproton/scripts/
|
||||
%{_datadir}/portproton/conf/
|
||||
%{_datadir}/portproton/img/
|
||||
%{bash_completions_dir}/portprotonqt
|
||||
%{fish_completions_dir}/portprotonqt.fish
|
||||
%{zsh_completions_dir}/_portprotonqt
|
||||
|
||||
@@ -36,6 +36,7 @@ Requires: python3-tqdm
|
||||
Requires: python3-vdf
|
||||
Requires: python3-pefile
|
||||
Requires: python3-pillow
|
||||
Requires: python3-beautifulsoup4
|
||||
Requires: python3-rapidfuzz
|
||||
Requires: python3-libarchive-c
|
||||
Requires: perl-Image-ExifTool
|
||||
@@ -118,8 +119,6 @@ install -Dpm 0644 ./completions/_portprotonqt -t %{buildroot}%{zsh_completions_d
|
||||
%{_datadir}/polkit-1/rules.d/ru.linux_gaming.PortProtonQt.rules
|
||||
%{_datadir}/applications/ru.linux_gaming.PortProtonQt.desktop
|
||||
%{_datadir}/portproton/scripts/
|
||||
%{_datadir}/portproton/conf/
|
||||
%{_datadir}/portproton/img/
|
||||
%{bash_completions_dir}/portprotonqt
|
||||
%{fish_completions_dir}/portprotonqt.fish
|
||||
%{zsh_completions_dir}/_portprotonqt
|
||||
|
||||
@@ -145,7 +145,7 @@ pw_enable_idle_inhibit() {
|
||||
return
|
||||
fi
|
||||
|
||||
PW_INHIBIT_SLR="python3 -m portprotonqt.idle_inhibit"
|
||||
PW_INHIBIT_SLR="python3 -m portprotonqt.scripts_utils.idle_inhibit"
|
||||
print_info "Screensaver will be inhibited using D-Bus"
|
||||
}
|
||||
|
||||
@@ -1195,7 +1195,7 @@ init_wine_ver () {
|
||||
if [[ -d "${PORT_DATA_PATH}/data/dist" ]] ; then
|
||||
IFS=$'\n'
|
||||
for dist_dir in $(lsbash "${PORT_DATA_PATH}/data/dist") ; do
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e 's/[[:blank:]]*-[[:blank:]]*/-/g' -e 's/[[:blank:]]/_/g')
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e s/[[:blank:]]/_/g)
|
||||
if [[ ! -d "${PORT_DATA_PATH}/data/dist/${dist_dir_new^^}" ]] ; then
|
||||
mv -- "${PORT_DATA_PATH}/data/dist/$dist_dir" "${PORT_DATA_PATH}/data/dist/${dist_dir_new^^}"
|
||||
fi
|
||||
@@ -2251,15 +2251,12 @@ pw_create_gui_png () {
|
||||
if [[ -z $name_desktop_png ]] ; then
|
||||
basename_PW_EXE_FILE="$(basename "${PW_EXE_FILE}")"
|
||||
if echo "$basename_PW_EXE_FILE" | grep -ie 'setup\|install\|\.msi$' &>/dev/null ; then
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/setup.png"
|
||||
export name_desktop_png="setup"
|
||||
return 0
|
||||
elif echo "$basename_PW_EXE_FILE" | grep -ie '\.reg$' &>/dev/null ; then
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/reg.png"
|
||||
export name_desktop_png="reg"
|
||||
return 0
|
||||
elif echo "$basename_PW_EXE_FILE"| grep -ie '\.bat$' &>/dev/null ; then
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/bat.png"
|
||||
export name_desktop_png="bat"
|
||||
return 0
|
||||
fi
|
||||
@@ -2304,7 +2301,7 @@ pw_create_gui_png () {
|
||||
fi
|
||||
fi
|
||||
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}" "48" "128"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}"
|
||||
|
||||
PORTPROTON_NAME_PNG="${PORTPROTON_NAME// /_}"
|
||||
if [[ $PORTPROTON_NAME_PNG =~ [\!\%\$\&\<] ]] ; then
|
||||
@@ -2313,15 +2310,9 @@ pw_create_gui_png () {
|
||||
PORTPROTON_NAME_PNG="${PORTPROTON_NAME_PNG//$i/}"
|
||||
done
|
||||
fi
|
||||
if [[ -z "${PW_ICON_FOR_YAD}" ]] ; then
|
||||
if [[ -n "$(file "${PORT_DATA_PATH}/data/img/${PORTPROTON_NAME_PNG}.png" | grep "${PW_RESIZE_TO} x ${PW_RESIZE_TO}")" ]] ; then
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/${PORTPROTON_NAME_PNG}.png"
|
||||
else
|
||||
export PW_ICON_FOR_YAD="${PW_GUI_ICON_PATH}/port_proton.png"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
pw_create_unique_exe () {
|
||||
BASEDIR_GAME="$(dirname "$PW_EXE_FILE")"
|
||||
if [[ -d "$BASEDIR_GAME" ]] ; then
|
||||
@@ -4436,11 +4427,11 @@ pw_gamescope_process () {
|
||||
|
||||
# RESIZE PNG FILE
|
||||
resize_png () {
|
||||
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]] ; then
|
||||
if [[ -z "$1" ]] || [[ -z "$2" ]] ; then
|
||||
print_error "no argument specified for resize_png"
|
||||
return 1
|
||||
else
|
||||
local RESIZE_FILE RESIZE_NAME_PNG resize_to resize_to_helper
|
||||
local RESIZE_FILE RESIZE_NAME_PNG
|
||||
RESIZE_FILE="$1"
|
||||
RESIZE_NAME_PNG="${2// /_}"
|
||||
fi
|
||||
@@ -4449,44 +4440,26 @@ resize_png () {
|
||||
then RESIZE_NAME_PNG=${RESIZE_NAME_PNG/*ru.linux_gaming.PortProton\/data\/img\//}
|
||||
fi
|
||||
|
||||
for resize_to in "${@:3}" ; do
|
||||
if [[ $resize_to == 128 ]]
|
||||
then resize_to_helper=""
|
||||
else resize_to_helper="_$resize_to"
|
||||
fi
|
||||
if [[ $RESIZE_NAME_PNG =~ [\!\%\$\&\<] ]] ; then
|
||||
local ICON_NAME_REGEX=(\! % \$ \& \<)
|
||||
for i in "${ICON_NAME_REGEX[@]}" ; do
|
||||
RESIZE_NAME_PNG="${RESIZE_NAME_PNG//$i/}"
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $RESIZE_NAME_PNG =~ [\!\%\$\&\<] ]] ; then
|
||||
local ICON_NAME_REGEX=(\! % \$ \& \<)
|
||||
for i in "${ICON_NAME_REGEX[@]}" ; do
|
||||
RESIZE_NAME_PNG="${RESIZE_NAME_PNG//$i/}"
|
||||
done
|
||||
fi
|
||||
if [[ -f "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}.png" ]] \
|
||||
|| [[ ! -f "${RESIZE_FILE}" ]] \
|
||||
|| [[ ! ${RESIZE_FILE,,} =~ .exe$ ]]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}${resize_to_helper}.png" ]] \
|
||||
|| [[ ! -f "${RESIZE_FILE}" ]] \
|
||||
|| [[ ! ${RESIZE_FILE,,} =~ .exe$ ]]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/launcher.png"
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/Launcher.png"
|
||||
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/launcher.png"
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/Launcher.png"
|
||||
|
||||
if check_flatpak ; then
|
||||
if ! timeout 3 \
|
||||
exe-thumbnailer --force-resize -s "$resize_to" "$(readlink -f "${RESIZE_FILE}")" "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}${resize_to_helper}.png" \
|
||||
&& [[ "$ALPINE_FP" != "1" ]]
|
||||
then
|
||||
print_error "exe-thumbnailer - broken!"
|
||||
fi
|
||||
else
|
||||
print_warning "use portable exe-thumbnailer"
|
||||
env PYTHONPATH="${PW_PLUGINS_PATH}/portable/lib/python3.9/site-packages/" \
|
||||
LD_LIBRARY_PATH="${PW_PLUGINS_PATH}/portable/lib/lib64" \
|
||||
"${PW_WINELIB}/runtime/files/bin/python3.9" \
|
||||
"${PW_PLUGINS_PATH}/portable/bin/exe-thumbnailer" --force-resize -s "$resize_to" "$(readlink -f "${RESIZE_FILE}")" "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}${resize_to_helper}.png"
|
||||
fi
|
||||
done
|
||||
python3 -m portprotonqt.scripts_utils.shortcut_tools thumbnail \
|
||||
"$(readlink -f "${RESIZE_FILE}")" \
|
||||
"${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}.png"
|
||||
}
|
||||
|
||||
portwine_create_shortcut () {
|
||||
@@ -4520,19 +4493,12 @@ portwine_output_yad_shortcut () {
|
||||
export name_desktop="$PW_NAME_DESKTOP_PROXY"
|
||||
fi
|
||||
|
||||
echo "[Desktop Entry]" > "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
echo "Name=${name_desktop}" >> "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
if check_flatpak
|
||||
then echo "Exec=flatpak run ${FLATPAK_ID} --silent \"${PW_EXE_FILE}\"" >> "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
else echo "Exec=portprotonqt --silent \"${PW_EXE_FILE}\"" >> "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
if ! python3 -m portprotonqt.scripts_utils.shortcut_tools shortcut \
|
||||
"${PW_EXE_FILE}" \
|
||||
"${name_desktop}"
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
{
|
||||
echo "Type=Application"
|
||||
echo "Categories=Game"
|
||||
echo "StartupNotify=true"
|
||||
echo "Icon=${PORT_DATA_PATH}/data/img/${name_desktop_png}.png"
|
||||
} >> "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
chmod +x "${PORT_DATA_PATH}/${name_desktop}.desktop"
|
||||
|
||||
if [[ "${PW_SHORTCUT_MENU}" == "TRUE" ]] ; then
|
||||
try_remove_file "${HOME}/.local/share/applications/${name_desktop}.desktop"
|
||||
@@ -4602,7 +4568,7 @@ pw_auto_create_shortcut () {
|
||||
pw_init_db
|
||||
export PW_NO_RESTART_PPDB="1"
|
||||
edit_db_from_gui PW_PREFIX_NAME LAUNCH_URI
|
||||
unset PW_ICON_FOR_YAD name_desktop_png
|
||||
unset name_desktop_png
|
||||
portwine_create_shortcut
|
||||
fi
|
||||
fi
|
||||
@@ -4636,9 +4602,9 @@ pw_auto_create_shortcut () {
|
||||
fi
|
||||
print_info "Created link for: $link_name"
|
||||
PORTPROTON_NAME="$link_name"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}" "48" "128"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}"
|
||||
export PW_NO_RESTART_PPDB=1
|
||||
unset PW_ICON_FOR_YAD name_desktop_png
|
||||
unset name_desktop_png
|
||||
portwine_create_shortcut
|
||||
done
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ export PW_VULKAN_USE="0"
|
||||
export PW_WINE_USE="PROTON_LG"
|
||||
export PW_PREFIX_NAME="STUDENT"
|
||||
export PW_DISABLED_CREATE_DB="1"
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/setup.png"
|
||||
export PW_USE_FSYNC="0"
|
||||
export PW_USE_ESYNC="0"
|
||||
export PW_DLL_INSTALL=""
|
||||
|
||||
@@ -6,7 +6,6 @@ export PW_VULKAN_USE="0"
|
||||
export PW_WINE_USE="PROTON_LG"
|
||||
export PW_PREFIX_NAME="TEACHER"
|
||||
export PW_DISABLED_CREATE_DB="1"
|
||||
export PW_ICON_FOR_YAD="${PORT_DATA_PATH}/data/img/setup.png"
|
||||
export PW_USE_FSYNC="0"
|
||||
export PW_USE_ESYNC="0"
|
||||
export PW_DLL_INSTALL=""
|
||||
|
||||
@@ -112,7 +112,7 @@ create_new_dir "${HOME}/.local/share/applications"
|
||||
create_new_dir "${PORT_DATA_PATH}/data/dist"
|
||||
IFS=$'\n'
|
||||
for dist_dir in $(lsbash "${PORT_DATA_PATH}/data/dist/") ; do
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e 's/[[:blank:]]*-[[:blank:]]*/-/g' -e 's/[[:blank:]]/_/g')
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e s/[[:blank:]]/_/g)
|
||||
if [[ ! -d "${PORT_DATA_PATH}/data/dist/${dist_dir_new^^}" ]] ; then
|
||||
mv -- "${PORT_DATA_PATH}/data/dist/$dist_dir" "${PORT_DATA_PATH}/data/dist/${dist_dir_new^^}"
|
||||
fi
|
||||
|
||||
@@ -87,12 +87,12 @@ def bump_meson(path: Path, old: str, new: str) -> bool:
|
||||
|
||||
def bump_app_py(path: Path, old: str, new: str) -> bool:
|
||||
"""
|
||||
Update APP_VERSION fallback in app.py
|
||||
Update __app_version__ in app.py
|
||||
"""
|
||||
if not path.exists():
|
||||
return False
|
||||
text = path.read_text(encoding='utf-8')
|
||||
pattern = re.compile(r"(?m)^(\s*APP_VERSION\s*=\s*)\"" + re.escape(old) + r"\"$")
|
||||
pattern = re.compile(r"(?m)^(\s*__app_version__\s*=\s*)\"" + re.escape(old) + r"\"$")
|
||||
new_text, count = pattern.subn(lambda m: m.group(1) + f'"{new}"', text)
|
||||
if count:
|
||||
path.write_text(new_text, encoding='utf-8')
|
||||
|
||||
@@ -679,8 +679,7 @@ def get_files_from_meson_build(meson_file_path):
|
||||
'install_headers', # Header files installation
|
||||
'install_man', # Manual pages installation
|
||||
'install_symlink', # Symlinks installation
|
||||
'install_emptydir', # Empty directories installation
|
||||
'configure_file', # Files generated and potentially installed
|
||||
'install_emptydir' # Empty directories installation
|
||||
]
|
||||
|
||||
# Process each install function
|
||||
|
||||
-25
@@ -12,20 +12,6 @@ python3 = import('python').find_installation('python3')
|
||||
conf = configuration_data()
|
||||
conf.set('PYTHON', python3.full_path())
|
||||
|
||||
version_conf = configuration_data()
|
||||
version_conf.set_quoted('APP_VERSION', meson.project_version())
|
||||
version_conf.set_quoted('APP_COMMIT', '')
|
||||
|
||||
if get_option('nightly')
|
||||
git = find_program('git', required: false)
|
||||
if git.found()
|
||||
git_commit = run_command(git, 'rev-parse', '--short', 'HEAD', check: false)
|
||||
if git_commit.returncode() == 0
|
||||
version_conf.set_quoted('APP_COMMIT', git_commit.stdout().strip())
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# Directories
|
||||
prefix = get_option('prefix')
|
||||
datadir = prefix / get_option('datadir')
|
||||
@@ -39,17 +25,6 @@ pkgdatadir = pythondir / meson.project_name()
|
||||
# C compiler for vk_gpu_info
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
configured_version = configure_file(
|
||||
input: 'portprotonqt/_version.py.in',
|
||||
output: '_version.py',
|
||||
configuration: version_conf,
|
||||
)
|
||||
|
||||
install_data(
|
||||
configured_version,
|
||||
install_dir: pythondir / meson.project_name(),
|
||||
)
|
||||
|
||||
# Install Python package
|
||||
subdir('portprotonqt')
|
||||
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
|
||||
option('python_purelibdir', type: 'string', value: '', description: 'Python pure library installation directory (overrides purelib)')
|
||||
option('udev_rulesdir', type: 'string', value: '', description: 'Udev rules installation directory (overrides default)')
|
||||
option('nightly', type: 'boolean', value: false, description: 'Include git commit in application version')
|
||||
@@ -1,2 +0,0 @@
|
||||
APP_VERSION = @APP_VERSION@
|
||||
APP_COMMIT = @APP_COMMIT@
|
||||
+1
-14
@@ -1,22 +1,12 @@
|
||||
import sys
|
||||
import os
|
||||
import importlib
|
||||
import subprocess
|
||||
import shutil
|
||||
from logging import Logger
|
||||
|
||||
__app_id__ = "ru.linux_gaming.PortProtonQt"
|
||||
__app_name__ = "PortProtonQt"
|
||||
|
||||
try:
|
||||
version_module = importlib.import_module("portprotonqt._version")
|
||||
APP_COMMIT = version_module.APP_COMMIT
|
||||
APP_VERSION = version_module.APP_VERSION
|
||||
except ImportError:
|
||||
APP_COMMIT = ""
|
||||
APP_VERSION = "0.1.12"
|
||||
|
||||
__app_version__ = APP_VERSION
|
||||
__app_version__ = "0.1.12"
|
||||
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
|
||||
@@ -46,9 +36,6 @@ from portprotonqt.cli import (
|
||||
from portprotonqt.localization import _, get_steam_language
|
||||
|
||||
def get_version():
|
||||
if APP_COMMIT:
|
||||
return f"{__app_version__} ({APP_COMMIT})"
|
||||
|
||||
try:
|
||||
commit = subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
|
||||
@@ -19,6 +19,14 @@ logger = get_logger(__name__)
|
||||
_portproton_start_command: list[str] | None = None
|
||||
|
||||
|
||||
def _sanitize_icon_name(name: str) -> str:
|
||||
"""Convert a game name to a safe icon file name."""
|
||||
sanitized_name = name.replace(" ", "_")
|
||||
for char in ("!", "%", "$", "&", "<"):
|
||||
sanitized_name = sanitized_name.replace(char, "")
|
||||
return sanitized_name
|
||||
|
||||
|
||||
class PortProtonConfig(BaseConfig):
|
||||
"""PortProton location configuration."""
|
||||
|
||||
@@ -356,8 +364,8 @@ def find_game_by_exe(exe_path: str) -> configparser.SectionProxy | None:
|
||||
def create_desktop_file(
|
||||
exe_path: str,
|
||||
game_name: str | None = None,
|
||||
) -> tuple[str, str] | None:
|
||||
"""Create desktop entry content and destination path for a game."""
|
||||
) -> tuple[str, str, str] | None:
|
||||
"""Create desktop entry content, destination path and icon path for a game."""
|
||||
portproton_path = get_portproton_location()
|
||||
if not os.path.isfile(exe_path):
|
||||
logger.error("Executable not found: %s", exe_path)
|
||||
@@ -369,7 +377,8 @@ def create_desktop_file(
|
||||
if not game_name:
|
||||
game_name = os.path.splitext(os.path.basename(exe_path))[0]
|
||||
base_path = os.path.join(portproton_path, "data")
|
||||
icon_path = os.path.join(base_path, "img", f"{game_name}.png")
|
||||
icon_name = _sanitize_icon_name(game_name)
|
||||
icon_path = os.path.join(base_path, "img", f"{icon_name}.png")
|
||||
desktop_path = os.path.join(portproton_path, f"{game_name}.desktop")
|
||||
os.makedirs(os.path.dirname(icon_path), exist_ok=True)
|
||||
|
||||
@@ -391,4 +400,4 @@ def create_desktop_file(
|
||||
"StartupNotify=true\n"
|
||||
f"Icon={icon_path}\n"
|
||||
)
|
||||
return desktop_entry, desktop_path
|
||||
return desktop_entry, desktop_path, icon_path
|
||||
@@ -18,7 +18,8 @@ from portprotonqt.steam_api import (
|
||||
is_game_in_steam,
|
||||
remove_from_steam,
|
||||
)
|
||||
from portprotonqt.dialogs import AddGameDialog, generate_thumbnail
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs import AddGameDialog
|
||||
from portprotonqt.dialogs.base import DraggableDialog
|
||||
from portprotonqt.theme_manager import ThemeManager
|
||||
from portprotonqt.logger import get_logger
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Environment variables and configuration utilities."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from portprotonqt.logger import get_logger
|
||||
@@ -12,9 +11,8 @@ logger = get_logger(__name__)
|
||||
|
||||
|
||||
def _normalize_dist_name(value: str) -> str:
|
||||
# Keep spaced hyphen separators readable before replacing blanks with "_".
|
||||
normalized = re.sub(r"\s*-\s*", "-", value.strip())
|
||||
return "_".join(normalized.split()).upper()
|
||||
# Match scripts behavior: trim, normalize whitespace, replace blanks with "_", uppercase.
|
||||
return "_".join(value.split()).upper()
|
||||
|
||||
|
||||
def get_file_content(file_path: str, default: str = "") -> str:
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from portprotonqt.debug_utils.env_utils import _normalize_dist_name
|
||||
|
||||
def _normalize_dist_name(value: str) -> str:
|
||||
# Match scripts behavior: trim, normalize whitespace, replace blanks with "_", uppercase.
|
||||
return "_".join(value.split()).upper()
|
||||
|
||||
|
||||
def _strip_pw_wine_use_path(line: str) -> str:
|
||||
|
||||
@@ -21,7 +21,6 @@ from portprotonqt.detail_pages.widgets import (
|
||||
create_back_button,
|
||||
create_content_frame,
|
||||
setup_adaptive_layout,
|
||||
apply_adaptive_layout,
|
||||
create_cover_frame,
|
||||
create_protondb_badge,
|
||||
create_steam_badge,
|
||||
@@ -196,17 +195,19 @@ class DetailPageManager:
|
||||
return size, size
|
||||
|
||||
def _create_game_badges(self, parent: QWidget, game_data: dict) -> list:
|
||||
from portprotonqt.config import game_config
|
||||
|
||||
if self._is_compact_detail_layout():
|
||||
return []
|
||||
|
||||
display_filter = game_config.get_display_filter()
|
||||
game_source = str(game_data.get("game_source", "")).lower()
|
||||
appid = game_data.get("appid", "")
|
||||
name = game_data.get("name", "")
|
||||
exec_line = game_data.get("exec_line", "")
|
||||
|
||||
steam_visible = game_source == "steam"
|
||||
portproton_visible = game_source == "portproton"
|
||||
steam_visible = game_source == "steam" and display_filter in ("all", "favorites")
|
||||
portproton_visible = game_source == "portproton" and display_filter in ("all", "favorites")
|
||||
|
||||
badges = []
|
||||
protondb_badge = self._create_protondb_badge(parent, game_data)
|
||||
@@ -322,19 +323,6 @@ class DetailPageManager:
|
||||
|
||||
if has_data:
|
||||
game_info_layout.addLayout(hltb_layout)
|
||||
QTimer.singleShot(0, self._refresh_current_detail_page_layout)
|
||||
|
||||
def _refresh_current_detail_page_layout(self) -> None:
|
||||
"""Refresh layout after asynchronous detail content changes."""
|
||||
if not self._detail_page_active or not self._current_detail_page:
|
||||
return
|
||||
|
||||
content_frame_layout = self._get_content_frame_layout(self._current_detail_page)
|
||||
if content_frame_layout:
|
||||
content_frame_layout.invalidate()
|
||||
apply_adaptive_layout(self._current_detail_page, content_frame_layout)
|
||||
|
||||
self._current_detail_page.updateGeometry()
|
||||
|
||||
def _add_hltb_times(
|
||||
self, game: GameEntry, hltb: HowLongToBeat, hltb_layout: QHBoxLayout
|
||||
|
||||
@@ -107,33 +107,30 @@ def setup_adaptive_layout(
|
||||
"""Setup adaptive layout switching on resize."""
|
||||
|
||||
def on_detail_page_resize(event) -> None:
|
||||
apply_adaptive_layout(detail_page, content_frame_layout)
|
||||
if detail_page.property("force_compact_detail_layout"):
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
QWidget.resizeEvent(detail_page, event)
|
||||
return
|
||||
|
||||
required_width = _get_required_horizontal_width(content_frame_layout)
|
||||
if detail_page.width() < required_width:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.TopToBottom:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
else:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.LeftToRight:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.LeftToRight)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
QWidget.resizeEvent(detail_page, event)
|
||||
|
||||
detail_page.resizeEvent = on_detail_page_resize
|
||||
|
||||
|
||||
def apply_adaptive_layout(detail_page: QWidget, content_frame_layout: QBoxLayout) -> None:
|
||||
"""Apply detail page adaptive layout for current size hints."""
|
||||
if detail_page.property("force_compact_detail_layout"):
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
return
|
||||
|
||||
required_width = _get_required_horizontal_width(content_frame_layout)
|
||||
if detail_page.width() < required_width:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.TopToBottom:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
elif content_frame_layout.direction() != QBoxLayout.Direction.LeftToRight:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.LeftToRight)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
|
||||
|
||||
def _get_required_horizontal_width(content_frame_layout: QBoxLayout) -> int:
|
||||
"""Calculate minimal width for horizontal content layout."""
|
||||
item_count = content_frame_layout.count()
|
||||
|
||||
@@ -5,10 +5,10 @@ New code should import directly from portprotonqt.dialogs package.
|
||||
"""
|
||||
|
||||
# Re-export all dialog classes for backward compatibility
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs.base import (
|
||||
GameLaunchDialog,
|
||||
AddGameDialog,
|
||||
generate_thumbnail,
|
||||
FileSelectedSignal,
|
||||
)
|
||||
from portprotonqt.dialogs.file_explorer import FileExplorer
|
||||
|
||||
@@ -5,7 +5,8 @@ from portprotonqt.dialogs.file_explorer import FileExplorer
|
||||
from portprotonqt.dialogs.winetricks_dialog import WinetricksDialog
|
||||
from portprotonqt.dialogs.settings_dialog import ExeSettingsDialog
|
||||
from portprotonqt.dialogs.proton_manager import ProtonManager
|
||||
from portprotonqt.dialogs.base import GameLaunchDialog, AddGameDialog, generate_thumbnail, FileSelectedSignal
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs.base import GameLaunchDialog, AddGameDialog, FileSelectedSignal
|
||||
|
||||
__all__ = [
|
||||
'create_dialog_hints_widget',
|
||||
|
||||
@@ -9,7 +9,6 @@ from PySide6.QtWidgets import (
|
||||
QProgressBar, QSizePolicy, QWidget, QCheckBox
|
||||
)
|
||||
from PySide6.QtCore import Qt, QObject, Signal, QTimer, QStandardPaths, QSize
|
||||
from PIL import Image
|
||||
import psutil
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -23,80 +22,13 @@ from portprotonqt.downloader import Downloader
|
||||
from portprotonqt.virtual_keyboard import VirtualKeyboard
|
||||
from portprotonqt.localization import _
|
||||
from portprotonqt.image_utils import COVER_IMAGE_EXTENSIONS, set_animated_cover
|
||||
from portprotonqt.icon_extractor import IconExtractor, IconExtractorError
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
|
||||
logger = get_logger(__name__)
|
||||
theme_manager = ThemeManager()
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf")
|
||||
|
||||
|
||||
def generate_thumbnail(inputfile, outfile, size=128, force_resize=True):
|
||||
"""
|
||||
Generates a thumbnail for an .exe file.
|
||||
|
||||
inputfile: the input file path (%i)
|
||||
outfile: output filename (%o)
|
||||
size: determines the thumbnail output size (%s)
|
||||
"""
|
||||
logger.debug(f"Starting thumbnail generation: {inputfile} → {outfile}, size={size}, force={force_resize}")
|
||||
|
||||
try:
|
||||
extractor = IconExtractor(inputfile)
|
||||
logger.debug("IconExtractor created successfully.")
|
||||
except (RuntimeError, IconExtractorError) as e:
|
||||
logger.warning(f"Failed to create IconExtractor: {e}")
|
||||
return False
|
||||
|
||||
try:
|
||||
data = extractor.get_icon()
|
||||
if data is None:
|
||||
return False
|
||||
im = Image.open(data)
|
||||
logger.debug(f"Extracted icon size {im.size}, formats: {im.format}, frames: {getattr(im, 'n_frames', 1)}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error extracting icon: {e}")
|
||||
return False
|
||||
|
||||
if force_resize:
|
||||
logger.debug(f"Forcing icon resize to {size}x{size}")
|
||||
im = im.resize((size, size), Image.Resampling.LANCZOS)
|
||||
else:
|
||||
if size > 256:
|
||||
logger.warning('Requested size larger than 256, set to 256')
|
||||
size = 256
|
||||
elif size not in (128, 256):
|
||||
logger.warning(f'Unsupported size {size}, set to 128')
|
||||
size = 128
|
||||
|
||||
if size == 256:
|
||||
logger.debug("Saving icon without resize (256x256)")
|
||||
im.save(outfile, "PNG")
|
||||
logger.info(f"Icon saved to {outfile}")
|
||||
return True
|
||||
|
||||
frames = getattr(im, 'n_frames', 1)
|
||||
try:
|
||||
for frame in range(frames):
|
||||
im.seek(frame)
|
||||
if im.size == (size, size):
|
||||
logger.debug(f"Found frame with size {size}x{size}")
|
||||
break
|
||||
except EOFError:
|
||||
logger.debug("Frames ended before finding required size.")
|
||||
|
||||
if im.size != (size, size):
|
||||
logger.debug(f"Resizing from {im.size} to {size}x{size}")
|
||||
im = im.resize((size, size))
|
||||
|
||||
try:
|
||||
im.save(outfile, "PNG")
|
||||
logger.info(f"Thumbnail successfully saved to {outfile}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error saving thumbnail: {e}")
|
||||
return False
|
||||
|
||||
|
||||
class FileSelectedSignal(QObject):
|
||||
"""Signal class for file selection."""
|
||||
file_selected = Signal(str)
|
||||
@@ -538,9 +470,7 @@ class AddGameDialog(DraggableDialog):
|
||||
result = create_desktop_file(exe_path, name)
|
||||
if not result:
|
||||
return None, None
|
||||
desktop_entry, desktop_path = result
|
||||
base_path = os.path.join(os.path.dirname(desktop_path), "data")
|
||||
icon_path = os.path.join(base_path, "img", f"{name}.png")
|
||||
desktop_entry, desktop_path, icon_path = result
|
||||
|
||||
if not self.last_cover_path and not generate_thumbnail(launch_path, icon_path, size=128):
|
||||
logger.error(f"Failed to generate thumbnail from exe: {launch_path}")
|
||||
|
||||
@@ -21,7 +21,8 @@ from portprotonqt.theme_manager import ThemeManager
|
||||
from portprotonqt.custom_widgets import AutoSizeButton
|
||||
from portprotonqt.localization import _
|
||||
from portprotonqt.dialogs.dialog_utils import create_dialog_hints_widget, update_dialog_hints
|
||||
from portprotonqt.dialogs.base import DraggableDialog, generate_thumbnail, FileSelectedSignal
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs.base import DraggableDialog, FileSelectedSignal
|
||||
from portprotonqt.image_utils import COVER_IMAGE_EXTENSIONS
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -94,15 +94,15 @@ class WinetricksDialog(DraggableDialog):
|
||||
|
||||
def update_winetricks(self):
|
||||
"""Update the winetricks script."""
|
||||
if not self.downloader.has_internet():
|
||||
logger.warning("No internet connection, skipping winetricks update")
|
||||
return
|
||||
|
||||
url = "https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks"
|
||||
temp_path = os.path.join(self.tmp_path, "winetricks_temp")
|
||||
|
||||
try:
|
||||
if not self.downloader.download(url, temp_path):
|
||||
logger.warning("Failed to download external winetricks version")
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
return
|
||||
self.downloader.download(url, temp_path)
|
||||
with open(temp_path) as f:
|
||||
ext_content = f.read()
|
||||
ext_ver_match = re.search(r'WINETRICKS_VERSION\s*=\s*[\'"]?([^\'"\s]+)', ext_content)
|
||||
|
||||
@@ -5,7 +5,6 @@ import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import shlex
|
||||
from typing import BinaryIO
|
||||
from portprotonqt.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -13,14 +12,6 @@ logger = get_logger(__name__)
|
||||
SYNC_HEADER = b'\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00'
|
||||
SYNC_HEADER_MDF = b'\x80\xc0\x80\x80\x80\x80\x80\xc0\x80\x80\x80\x80'
|
||||
ISO_9660_SIG = b'\x01\x43\x44\x30\x30\x31\x01\x00'
|
||||
DISC_BLOCK_SIZES = (2048, 2336, 2352, 2368, 2448)
|
||||
SVCD_SUB_HEADERS = (
|
||||
b"\x00\x00\x08\x00\x00\x00\x08\x00",
|
||||
b"\x00\x00\x09\x00\x00\x00\x09\x00",
|
||||
b"\x00\x00\x88\x00\x00\x00\x88\x00",
|
||||
b"\x00\x00\x89\x00\x00\x00\x89\x00",
|
||||
)
|
||||
UDF_SIGNATURES = (b"BEA01", b"BOOT2", b"CD001", b"CDW02", b"NSR02", b"NSR03", b"TEA01")
|
||||
|
||||
|
||||
class DiscImageManager:
|
||||
@@ -61,126 +52,58 @@ class DiscImageManager:
|
||||
logger.error("Failed to read ISO 9660 signature for %s: %s", file_path, e)
|
||||
return False
|
||||
|
||||
def _is_svcd_sub_header(self, header: bytes) -> bool:
|
||||
"""Return True if header matches known SVCD subheader bytes."""
|
||||
return header[:8] in SVCD_SUB_HEADERS
|
||||
|
||||
def _calculate_disc_layout(self, source: BinaryIO) -> tuple[int, int]:
|
||||
"""Return pregap and block size using the iat detection rules."""
|
||||
source.seek(0, os.SEEK_END)
|
||||
image_size = source.tell()
|
||||
cd_id_start = -1
|
||||
cd_id_end = 0
|
||||
header_size = 0
|
||||
|
||||
for offset in range(32768, image_size):
|
||||
source.seek(offset)
|
||||
header = source.read(12)
|
||||
if header == SYNC_HEADER:
|
||||
header_size = self._add_header_size(header_size, 16)
|
||||
continue
|
||||
if self._is_svcd_sub_header(header):
|
||||
header_size = self._add_header_size(header_size, 8)
|
||||
continue
|
||||
if header[:5] in UDF_SIGNATURES:
|
||||
if cd_id_start < 0:
|
||||
cd_id_start = offset
|
||||
else:
|
||||
cd_id_end = offset
|
||||
break
|
||||
|
||||
if cd_id_start < 0 or cd_id_end <= cd_id_start:
|
||||
return self._detect_sector_layout(source)
|
||||
|
||||
block_size = self._calculate_block_size(cd_id_end - cd_id_start)
|
||||
pregap = cd_id_start - (block_size * 16) - header_size - 1
|
||||
return max(pregap, 0), block_size
|
||||
|
||||
def _add_header_size(self, header_size: int, value: int) -> int:
|
||||
"""Add a detected header size once, matching iat's mixed header logic."""
|
||||
if header_size in (value, 24):
|
||||
return header_size
|
||||
return header_size + value
|
||||
|
||||
def _calculate_block_size(self, block_delta: int) -> int:
|
||||
"""Return closest iat-supported block size for descriptor spacing."""
|
||||
for block_size in DISC_BLOCK_SIZES[:-1]:
|
||||
if block_delta % block_size == 0:
|
||||
return block_size
|
||||
return DISC_BLOCK_SIZES[-1]
|
||||
|
||||
def _detect_sector_layout(self, source: BinaryIO) -> tuple[int, int]:
|
||||
"""Fallback sector layout detection for images without two descriptors."""
|
||||
source.seek(0)
|
||||
h0 = source.read(12)
|
||||
source.seek(2352)
|
||||
h2352 = source.read(12)
|
||||
if h0 == SYNC_HEADER and h2352 == SYNC_HEADER_MDF:
|
||||
return 0, 2448
|
||||
if h0 == SYNC_HEADER:
|
||||
return 0, 2352
|
||||
return 0, 2352
|
||||
|
||||
def _write_sync_sector_data(self, target: BinaryIO, sector: bytes) -> None:
|
||||
"""Write ISO user data from a sector with a sync header."""
|
||||
mode = sector[15]
|
||||
if mode == 0:
|
||||
target.write(sector[16:2352])
|
||||
elif mode == 1:
|
||||
target.write(sector[16:2064])
|
||||
elif mode == 2:
|
||||
self._write_mode_two_sector_data(target, sector)
|
||||
else:
|
||||
raise ValueError(f"Unknown MDF sector mode {mode}")
|
||||
|
||||
def _write_mode_two_sector_data(self, target: BinaryIO, sector: bytes) -> None:
|
||||
"""Write ISO user data from a Mode 2 sector."""
|
||||
sub_header = sector[16:24]
|
||||
if sub_header[:4] != sub_header[4:8]:
|
||||
target.write(sector[16:2352])
|
||||
return
|
||||
if sub_header[2] & 0x20:
|
||||
target.write(sector[24:2348])
|
||||
return
|
||||
target.write(sector[24:2072])
|
||||
|
||||
def _write_headerless_sector_data(self, target: BinaryIO, sector: bytes) -> bool:
|
||||
"""Write ISO user data from a 2336-byte headerless sector."""
|
||||
sub_header = sector[:8]
|
||||
if sub_header[:4] != sub_header[4:8]:
|
||||
return False
|
||||
if self._is_svcd_sub_header(sub_header):
|
||||
target.write(sector[8:2332])
|
||||
else:
|
||||
target.write(sector[8:2056])
|
||||
return True
|
||||
|
||||
def _write_iso_from_mdf(self, mdf_path: str, iso_path: str) -> None:
|
||||
"""Convert MDF to ISO using iat-compatible sector extraction."""
|
||||
"""Convert MDF to ISO using logic from test.py or legacy fallback."""
|
||||
with open(mdf_path, "rb") as source:
|
||||
source.seek(0)
|
||||
h0 = source.read(12)
|
||||
source.seek(2352)
|
||||
h2352 = source.read(12)
|
||||
|
||||
if h0 == SYNC_HEADER:
|
||||
if h2352 == SYNC_HEADER_MDF:
|
||||
sector_size = 2448
|
||||
elif h2352 == SYNC_HEADER:
|
||||
sector_size = 2352
|
||||
else:
|
||||
raise ValueError(f"Unknown SYNC format for {mdf_path}")
|
||||
|
||||
source.seek(0, os.SEEK_END)
|
||||
num_sectors = source.tell() // sector_size
|
||||
source.seek(0)
|
||||
with open(iso_path, "wb") as target:
|
||||
for _ in range(num_sectors):
|
||||
sector_start = source.tell()
|
||||
header = source.read(16)
|
||||
if len(header) < 16:
|
||||
break
|
||||
mode = header[15]
|
||||
data_offset = 24 if mode == 2 else 16
|
||||
source.seek(sector_start + data_offset)
|
||||
data = source.read(2048)
|
||||
if len(data) < 2048:
|
||||
break
|
||||
target.write(data)
|
||||
source.seek(sector_start + sector_size)
|
||||
return
|
||||
|
||||
# Legacy fallback
|
||||
with open(mdf_path, "rb") as source, open(iso_path, "wb") as target:
|
||||
pregap, block_size = self._calculate_disc_layout(source)
|
||||
image_size = os.path.getsize(mdf_path)
|
||||
source.seek(pregap)
|
||||
sector_index = pregap
|
||||
while sector_index < image_size:
|
||||
sector = source.read(block_size)
|
||||
sector_index = 0
|
||||
while True:
|
||||
sector = source.read(2352)
|
||||
if not sector:
|
||||
return
|
||||
if len(sector) != block_size:
|
||||
if len(sector) != 2352:
|
||||
raise ValueError(f"Truncated MDF sector at {sector_index}")
|
||||
if sector.startswith(SYNC_HEADER):
|
||||
self._write_sync_sector_data(target, sector)
|
||||
elif block_size == 2336 and not self._write_headerless_sector_data(target, sector):
|
||||
sector_index += 1
|
||||
source.seek(sector_index)
|
||||
continue
|
||||
elif block_size == 2048:
|
||||
target.write(sector)
|
||||
mode = sector[15]
|
||||
if mode == 1:
|
||||
target.write(sector[16:2064])
|
||||
elif mode == 2:
|
||||
target.write(sector[24:2072])
|
||||
else:
|
||||
sector_index += 1
|
||||
source.seek(sector_index)
|
||||
continue
|
||||
sector_index += block_size
|
||||
raise ValueError(f"Unknown MDF sector mode {mode} at {sector_index}")
|
||||
sector_index += 1
|
||||
|
||||
def _convert_mdf_to_iso(self, mdf_path: str) -> str | None:
|
||||
"""Convert raw 2352-byte sector MDF to temporary ISO."""
|
||||
|
||||
@@ -2,6 +2,7 @@ from PySide6.QtCore import QObject, Signal, QThread
|
||||
import threading
|
||||
import os
|
||||
import requests
|
||||
import socket
|
||||
from pathlib import Path
|
||||
from tqdm import tqdm
|
||||
from collections.abc import Callable
|
||||
@@ -64,12 +65,54 @@ class Downloader(QObject):
|
||||
self._locks = {}
|
||||
self._active_threads: list[QThread] = []
|
||||
self._global_lock = threading.Lock()
|
||||
self._has_internet = None
|
||||
self.callback_requested.connect(self._run_callback)
|
||||
|
||||
def _run_callback(self, callback, result):
|
||||
if callback:
|
||||
callback(result)
|
||||
|
||||
def has_internet(self, timeout=3):
|
||||
if self._has_internet is None:
|
||||
errors = []
|
||||
# Primary: Yandex
|
||||
try:
|
||||
socket.create_connection(("77.88.8.8", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Yandex DNS (77.88.8.8): {e}")
|
||||
try:
|
||||
socket.create_connection(("77.88.8.1", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Yandex DNS (77.88.8.1): {e}")
|
||||
try:
|
||||
requests.get("https://ya.ru", timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"ya.ru: {e}")
|
||||
|
||||
# Fallback: Google (if Yandex failed)
|
||||
if errors:
|
||||
logger.debug("Yandex check failed, trying Google fallback")
|
||||
try:
|
||||
socket.create_connection(("8.8.8.8", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Google DNS (8.8.8.8): {e}")
|
||||
try:
|
||||
socket.create_connection(("8.8.4.4", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Google DNS (8.8.4.4): {e}")
|
||||
try:
|
||||
requests.get("https://www.google.com", timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"google.com: {e}")
|
||||
|
||||
if errors:
|
||||
logger.warning("Internet unavailable:\n" + "\n".join(errors))
|
||||
self._has_internet = False
|
||||
else:
|
||||
self._has_internet = True
|
||||
return self._has_internet
|
||||
|
||||
|
||||
def _get_url_lock(self, url):
|
||||
with self._global_lock:
|
||||
if url not in self._locks:
|
||||
@@ -176,6 +219,9 @@ class Downloader(QObject):
|
||||
return results
|
||||
|
||||
def download(self, url, local_path, timeout=5):
|
||||
if not self.has_internet():
|
||||
logger.warning(f"No internet, skipping download {url}")
|
||||
return None
|
||||
with self._global_lock:
|
||||
if url in self._last_error:
|
||||
logger.warning(f"Previous download error for {url}, skipping")
|
||||
@@ -213,6 +259,14 @@ class Downloader(QObject):
|
||||
max_workers=None,
|
||||
on_result: Callable[[str, str | None], None] | None = None,
|
||||
):
|
||||
if not self.has_internet():
|
||||
logger.warning("No internet, skipping parallel download")
|
||||
results = dict.fromkeys(urls)
|
||||
if on_result:
|
||||
for url, result in results.items():
|
||||
on_result(url, result)
|
||||
return results
|
||||
|
||||
filtered_urls = []
|
||||
filtered_paths = []
|
||||
emitted_urls = set()
|
||||
|
||||
@@ -89,8 +89,8 @@ class GameCard(QFrame):
|
||||
self.portproton_api = PortProtonAPI(self.downloader)
|
||||
self.missing_executable_path = self._get_missing_executable_path()
|
||||
|
||||
self.steam_visible = (str(game_source).lower() == "steam" and not self.economy_mode)
|
||||
self.portproton_visible = (str(game_source).lower() == "portproton" and not self.economy_mode)
|
||||
self.steam_visible = (str(game_source).lower() == "steam" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.portproton_visible = (str(game_source).lower() == "portproton" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
|
||||
self.base_extra_margin = 8 if self.list_layout else 20
|
||||
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
@@ -486,8 +486,8 @@ class GameCard(QFrame):
|
||||
|
||||
self.display_filter = display_filter
|
||||
self.economy_mode = ui_config.get_economy_mode()
|
||||
self.steam_visible = (str(self.game_source).lower() == "steam" and not self.economy_mode)
|
||||
self.portproton_visible = (str(self.game_source).lower() == "portproton" and not self.economy_mode)
|
||||
self.steam_visible = (str(self.game_source).lower() == "steam" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.portproton_visible = (str(self.game_source).lower() == "portproton" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
protondb_visible = bool(self.getProtonDBText(self.protondb_tier)) and not self.economy_mode
|
||||
anticheat_visible = bool(self.getAntiCheatText(self.anticheat_status)) and not self.economy_mode
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import orjson
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
from difflib import SequenceMatcher
|
||||
from threading import Thread
|
||||
import requests
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
from portprotonqt.config import proxy_config
|
||||
from portprotonqt.time_utils import format_playtime
|
||||
from portprotonqt.logger import get_logger
|
||||
@@ -15,22 +17,66 @@ logger = get_logger(__name__)
|
||||
@dataclass
|
||||
class GameEntry:
|
||||
"""Game information from HowLongToBeat."""
|
||||
game_id: int = -1
|
||||
game_name: str | None = None
|
||||
main_story: float | None = None
|
||||
main_extra: float | None = None
|
||||
completionist: float | None = None
|
||||
similarity: float = -1.0
|
||||
raw_data: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
@dataclass
|
||||
class SearchConfig:
|
||||
"""Search configuration."""
|
||||
token: str
|
||||
hp_key: str
|
||||
hp_val: str
|
||||
api_key: str | None = None
|
||||
search_url: str | None = None
|
||||
|
||||
class APIKeyExtractor:
|
||||
"""Extract API key and search URL from site scripts."""
|
||||
@staticmethod
|
||||
def extract_from_script(script_content: str) -> SearchConfig:
|
||||
config = SearchConfig()
|
||||
config.api_key = APIKeyExtractor._extract_api_key(script_content)
|
||||
config.search_url = APIKeyExtractor._extract_search_url(script_content, config.api_key)
|
||||
return config
|
||||
|
||||
@staticmethod
|
||||
def _extract_api_key(script_content: str) -> str | None:
|
||||
user_id_pattern = r'users\s*:\s*{\s*id\s*:\s*"([^"]+)"'
|
||||
matches = re.findall(user_id_pattern, script_content)
|
||||
if matches:
|
||||
return ''.join(matches)
|
||||
concat_pattern = r'\/api\/\w+\/"(?:\.concat\("[^"]*"\))+'
|
||||
matches = re.findall(concat_pattern, script_content)
|
||||
if matches:
|
||||
parts = str(matches).split('.concat')
|
||||
cleaned_parts = [re.sub(r'["\(\)\[\]\']', '', part) for part in parts[1:]]
|
||||
return ''.join(cleaned_parts)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _extract_search_url(script_content: str, api_key: str | None) -> str | None:
|
||||
if not api_key:
|
||||
return None
|
||||
pattern = re.compile(
|
||||
r'fetch\(\s*["\'](\/api\/[^"\']*)["\']'
|
||||
r'((?:\s*\.concat\(\s*["\']([^"\']*)["\']\s*\))+)'
|
||||
r'\s*,',
|
||||
re.DOTALL
|
||||
)
|
||||
for match in pattern.finditer(script_content):
|
||||
endpoint = match.group(1)
|
||||
concat_calls = match.group(2)
|
||||
concat_strings = re.findall(r'\.concat\(\s*["\']([^"\']*)["\']\s*\)', concat_calls)
|
||||
concatenated_str = ''.join(concat_strings)
|
||||
if concatenated_str == api_key:
|
||||
return endpoint
|
||||
return None
|
||||
|
||||
class HTTPClient:
|
||||
"""HTTP client for HowLongToBeat API."""
|
||||
BASE_URL = 'https://howlongtobeat.com/'
|
||||
AUTH_URL = BASE_URL + "api/bleed/init"
|
||||
SEARCH_URL = BASE_URL + "api/bleed"
|
||||
SEARCH_URL = BASE_URL + "api/s/"
|
||||
|
||||
def __init__(self, timeout: int = 60):
|
||||
self.timeout = timeout
|
||||
@@ -43,55 +89,67 @@ class HTTPClient:
|
||||
if proxy_settings:
|
||||
self.session.proxies.update(proxy_settings)
|
||||
|
||||
def get_search_config(self) -> SearchConfig | None:
|
||||
def get_search_config(self, parse_all_scripts: bool = False) -> SearchConfig | None:
|
||||
try:
|
||||
response = self.session.get(
|
||||
self.AUTH_URL,
|
||||
params={"t": int(time.time() * 1000)},
|
||||
timeout=self.timeout
|
||||
)
|
||||
response = self.session.get(self.BASE_URL, timeout=self.timeout)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except (requests.RequestException, ValueError):
|
||||
return None
|
||||
if not data.get("token") or not data.get("hpKey") or not data.get("hpVal"):
|
||||
return None
|
||||
return SearchConfig(
|
||||
token=data["token"],
|
||||
hp_key=data["hpKey"],
|
||||
hp_val=data["hpVal"]
|
||||
)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
scripts = soup.find_all('script', src=True)
|
||||
script_urls = []
|
||||
for script in scripts:
|
||||
if isinstance(script, Tag):
|
||||
src = script.get('src')
|
||||
if src is not None and isinstance(src, str):
|
||||
if parse_all_scripts or '_app-' in src:
|
||||
script_urls.append(src)
|
||||
for script_url in script_urls:
|
||||
full_url = self.BASE_URL + script_url
|
||||
script_response = self.session.get(full_url, timeout=self.timeout)
|
||||
if script_response.status_code == 200:
|
||||
config = APIKeyExtractor.extract_from_script(script_response.text)
|
||||
if config.api_key:
|
||||
return config
|
||||
except requests.RequestException:
|
||||
pass
|
||||
return None
|
||||
|
||||
def search_games(self, game_name: str, page: int = 1, config: SearchConfig | None = None) -> str | None:
|
||||
if not config:
|
||||
config = self.get_search_config()
|
||||
if not config:
|
||||
if not config:
|
||||
config = self.get_search_config(parse_all_scripts=True)
|
||||
if not config or not config.api_key:
|
||||
return None
|
||||
for retry in range(2):
|
||||
payload = self._build_search_payload(game_name, page, config)
|
||||
headers = {
|
||||
'content-type': 'application/json',
|
||||
'accept': '*/*',
|
||||
'x-auth-token': config.token,
|
||||
'x-hp-key': config.hp_key,
|
||||
'x-hp-val': config.hp_val
|
||||
}
|
||||
try:
|
||||
response = self.session.post(
|
||||
self.SEARCH_URL,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
except requests.RequestException:
|
||||
return None
|
||||
search_url = self.SEARCH_URL
|
||||
if config.search_url:
|
||||
search_url = self.BASE_URL + config.search_url.lstrip('/')
|
||||
payload = self._build_search_payload(game_name, page, config)
|
||||
headers = {
|
||||
'content-type': 'application/json',
|
||||
'accept': '*/*'
|
||||
}
|
||||
try:
|
||||
response = self.session.post(
|
||||
search_url + config.api_key,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
if response.status_code != 403 or retry:
|
||||
return None
|
||||
config = self.get_search_config()
|
||||
if not config:
|
||||
return None
|
||||
except requests.RequestException:
|
||||
pass
|
||||
try:
|
||||
response = self.session.post(
|
||||
search_url,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
except requests.RequestException:
|
||||
pass
|
||||
return None
|
||||
|
||||
def _build_search_payload(self, game_name: str, page: int, config: SearchConfig) -> dict[str, Any]:
|
||||
@@ -113,7 +171,8 @@ class HTTPClient:
|
||||
'genre': "",
|
||||
"difficulty": ""
|
||||
},
|
||||
'rangeYear': {'max': "", 'min': ""}
|
||||
'rangeYear': {'max': "", 'min': ""},
|
||||
'modifier': "" # Hardcoded to empty string for SearchModifiers.NONE
|
||||
},
|
||||
'users': {'sortCategory': "postcount"},
|
||||
'lists': {'sortCategory': "follows"},
|
||||
@@ -122,26 +181,42 @@ class HTTPClient:
|
||||
'randomizer': 0
|
||||
},
|
||||
'useCache': True,
|
||||
'fields': ["comp_main", "comp_plus", "comp_100"]
|
||||
'fields': ["game_id", "game_name", "comp_main", "comp_plus", "comp_100"] # Request only needed fields
|
||||
}
|
||||
payload[config.hp_key] = config.hp_val
|
||||
if config.api_key:
|
||||
payload['searchOptions']['users']['id'] = config.api_key
|
||||
return payload
|
||||
|
||||
class ResultParser:
|
||||
"""Search results parser."""
|
||||
def parse_results(self, json_response: str) -> list[GameEntry]:
|
||||
def __init__(self, search_query: str, minimum_similarity: float = 0.4, case_sensitive: bool = True):
|
||||
self.search_query = search_query
|
||||
self.minimum_similarity = minimum_similarity
|
||||
self.case_sensitive = case_sensitive
|
||||
self.search_numbers = self._extract_numbers(search_query)
|
||||
|
||||
def parse_results(self, json_response: str, target_game_id: int | None = None) -> list[GameEntry]:
|
||||
try:
|
||||
data = orjson.loads(json_response)
|
||||
games = []
|
||||
# Only process the first result
|
||||
if data.get("data"):
|
||||
game_data = data["data"][0]
|
||||
games.append(self._parse_game_entry(game_data))
|
||||
game = self._parse_game_entry(game_data)
|
||||
if target_game_id is not None:
|
||||
if game.game_id == target_game_id:
|
||||
games.append(game)
|
||||
elif self.minimum_similarity == 0.0 or game.similarity >= self.minimum_similarity:
|
||||
games.append(game)
|
||||
return games
|
||||
except (orjson.JSONDecodeError, KeyError, IndexError):
|
||||
return []
|
||||
|
||||
def _parse_game_entry(self, game_data: dict[str, Any]) -> GameEntry:
|
||||
game = GameEntry()
|
||||
game.game_id = game_data.get("game_id", -1)
|
||||
game.game_name = game_data.get("game_name")
|
||||
game.raw_data = game_data
|
||||
time_fields = [
|
||||
("comp_main", "main_story"),
|
||||
("comp_plus", "main_extra"),
|
||||
@@ -153,8 +228,35 @@ class ResultParser:
|
||||
time_seconds = game_data[json_field]
|
||||
time_hours = None if all_zero else round(time_seconds / 3600, 2)
|
||||
setattr(game, attr_name, time_hours)
|
||||
game.similarity = self._calculate_similarity(game)
|
||||
return game
|
||||
|
||||
def _calculate_similarity(self, game: GameEntry) -> float:
|
||||
return self._compare_strings(self.search_query, game.game_name)
|
||||
|
||||
def _compare_strings(self, a: str | None, b: str | None) -> float:
|
||||
if not a or not b:
|
||||
return 0.0
|
||||
if self.case_sensitive:
|
||||
similarity = SequenceMatcher(None, a, b).ratio()
|
||||
else:
|
||||
similarity = SequenceMatcher(None, a.lower(), b.lower()).ratio()
|
||||
if self.search_numbers and not self._contains_numbers(b, self.search_numbers):
|
||||
similarity -= 0.1
|
||||
return max(0.0, similarity)
|
||||
|
||||
@staticmethod
|
||||
def _extract_numbers(text: str) -> list[str]:
|
||||
return [word for word in text.split() if word.isdigit()]
|
||||
|
||||
@staticmethod
|
||||
def _contains_numbers(text: str, numbers: list[str]) -> bool:
|
||||
if not numbers:
|
||||
return True
|
||||
cleaned_text = re.sub(r'([^\s\w]|_)+', '', text)
|
||||
text_numbers = [word for word in cleaned_text.split() if word.isdigit()]
|
||||
return any(num in text_numbers for num in numbers)
|
||||
|
||||
|
||||
class HowLongToBeat(QObject):
|
||||
"""Main class for HowLongToBeat API."""
|
||||
@@ -171,13 +273,15 @@ class HowLongToBeat(QObject):
|
||||
return self.cache_manager.load_text(f"hltb_{game_name}")
|
||||
|
||||
def _save_to_cache(self, game_name: str, json_response: str):
|
||||
"""Save data to cache, storing only first game times."""
|
||||
"""Save data to cache, storing only first game and required fields."""
|
||||
try:
|
||||
data = orjson.loads(json_response)
|
||||
if data.get("data"):
|
||||
first_game = data["data"][0]
|
||||
simplified_data = {
|
||||
"data": [{
|
||||
"game_id": first_game.get("game_id", -1),
|
||||
"game_name": first_game.get("game_name"),
|
||||
"comp_main": first_game.get("comp_main", 0),
|
||||
"comp_plus": first_game.get("comp_plus", 0),
|
||||
"comp_100": first_game.get("comp_100", 0)
|
||||
@@ -194,8 +298,25 @@ class HowLongToBeat(QObject):
|
||||
cached_response = self._load_from_cache(game_name)
|
||||
if cached_response:
|
||||
try:
|
||||
parser = ResultParser()
|
||||
return parser.parse_results(cached_response)
|
||||
cached_data = orjson.loads(cached_response)
|
||||
full_json = {
|
||||
"data": [
|
||||
{
|
||||
"game_id": game["game_id"],
|
||||
"game_name": game["game_name"],
|
||||
"comp_main": game["comp_main"],
|
||||
"comp_plus": game["comp_plus"],
|
||||
"comp_100": game["comp_100"]
|
||||
}
|
||||
for game in cached_data.get("data", [])
|
||||
]
|
||||
}
|
||||
parser = ResultParser(
|
||||
game_name,
|
||||
self.minimum_similarity,
|
||||
case_sensitive
|
||||
)
|
||||
return parser.parse_results(orjson.dumps(full_json).decode('utf-8'))
|
||||
except orjson.JSONDecodeError:
|
||||
pass
|
||||
# If not in cache, make request
|
||||
@@ -204,7 +325,11 @@ class HowLongToBeat(QObject):
|
||||
return None
|
||||
# Save only first game to cache
|
||||
self._save_to_cache(game_name, json_response)
|
||||
parser = ResultParser()
|
||||
parser = ResultParser(
|
||||
game_name,
|
||||
self.minimum_similarity,
|
||||
case_sensitive
|
||||
)
|
||||
return parser.parse_results(json_response)
|
||||
|
||||
def format_game_time(self, game_entry: GameEntry, time_field: str = "main_story") -> str | None:
|
||||
|
||||
@@ -12,6 +12,36 @@ RT_ICON = 3
|
||||
RT_GROUP_ICON = 14
|
||||
THUMBNAIL_SIZE = 128
|
||||
|
||||
|
||||
def generate_thumbnail(inputfile: str, outfile: str, size: int = 128, force_resize: bool = True) -> bool:
|
||||
"""
|
||||
Generates a thumbnail for an .exe file.
|
||||
|
||||
inputfile: the input file path
|
||||
outfile: output filename
|
||||
size: determines the thumbnail output size
|
||||
"""
|
||||
logger.debug("Starting thumbnail generation: %s → %s, size=%s, force=%s", inputfile, outfile, size, force_resize)
|
||||
|
||||
try:
|
||||
extractor = IconExtractor(inputfile)
|
||||
data = extractor.get_icon()
|
||||
if data is None:
|
||||
return False
|
||||
|
||||
im = Image.open(data)
|
||||
if force_resize or im.size != (size, size):
|
||||
logger.debug("Resizing icon to %sx%s", size, size)
|
||||
im = im.resize((size, size), Image.Resampling.LANCZOS)
|
||||
|
||||
im.save(outfile, "PNG")
|
||||
logger.info("Thumbnail successfully saved to %s", outfile)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Error generating thumbnail: %s", e)
|
||||
return False
|
||||
|
||||
|
||||
class IconExtractorError(Exception):
|
||||
"""Base exception for icon extraction errors."""
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ import subprocess
|
||||
import psutil
|
||||
import re
|
||||
from portprotonqt.logger import get_logger
|
||||
from portprotonqt.dialogs import AddGameDialog, FileExplorer, WinetricksDialog, ExeSettingsDialog, generate_thumbnail
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs import AddGameDialog, FileExplorer, WinetricksDialog, ExeSettingsDialog
|
||||
from portprotonqt.game_card import GameCard
|
||||
from portprotonqt.animations import DetailPageAnimations
|
||||
from portprotonqt.custom_widgets import ClickableLabel, AutoSizeButton, NavLabel, FlowLayout
|
||||
|
||||
@@ -12,7 +12,6 @@ install_data(
|
||||
'game_card.py',
|
||||
'game_library_manager.py',
|
||||
'howlongtobeat_api.py',
|
||||
'idle_inhibit.py',
|
||||
'image_utils.py',
|
||||
'icon_extractor.py',
|
||||
'input_manager.py',
|
||||
@@ -24,10 +23,10 @@ install_data(
|
||||
'portproton_api.py',
|
||||
'preloader.py',
|
||||
'search_utils.py',
|
||||
'settings_manager.py',
|
||||
'theme_manager.py',
|
||||
'theme_security.py',
|
||||
'time_utils.py',
|
||||
'settings_manager.py',
|
||||
'theme_manager.py',
|
||||
'theme_security.py',
|
||||
'time_utils.py',
|
||||
'tray_manager.py',
|
||||
'version_utils.py',
|
||||
'virtual_keyboard.py'],
|
||||
@@ -118,6 +117,15 @@ install_data(
|
||||
install_dir: pythondir / meson.project_name() / 'debug_utils',
|
||||
)
|
||||
|
||||
# Install scripts_utils package
|
||||
install_data(
|
||||
['scripts_utils/__init__.py',
|
||||
'scripts_utils/idle_inhibit.py',
|
||||
'scripts_utils/shortcut_tools.py',
|
||||
],
|
||||
install_dir: pythondir / meson.project_name() / 'scripts_utils',
|
||||
)
|
||||
|
||||
# Install config package
|
||||
install_data(
|
||||
['config/__init__.py',
|
||||
|
||||
@@ -31,8 +31,6 @@ logger = get_logger(__name__)
|
||||
AUTOINSTALL_CACHE_DURATION = 3600 # 1 hour for autoinstall cache
|
||||
HEAD_FAILURE_RETRY_DELAY = 60 # 1 minute cooldown for failed HEAD checks
|
||||
HEAD_CACHE_DURATION = 24 * 60 * 60
|
||||
HEAD_CACHE_NAME = "head_cache"
|
||||
HEAD_CACHE_OLD_PATTERN = "head_*.json"
|
||||
|
||||
|
||||
def _create_bootstrap_file_explorer_parent() -> tuple[QObject | None, Any]:
|
||||
@@ -118,7 +116,6 @@ class PortProtonAPI:
|
||||
self._head_positive_cache: set[str] = set()
|
||||
self._head_negative_cache: set[str] = set()
|
||||
self._head_failure_cache: dict[str, float] = {}
|
||||
self._head_disk_cache_cleaned = False
|
||||
self._pending_asset_notifier: QObject | None = None
|
||||
self._pending_asset_batch_thread: QThread | None = None
|
||||
|
||||
@@ -127,38 +124,6 @@ class PortProtonAPI:
|
||||
os.makedirs(game_dir, exist_ok=True)
|
||||
return game_dir
|
||||
|
||||
def _load_head_cache_entry(self, cache_manager: CacheManager, cache_key: str) -> bool | None:
|
||||
cached = cache_manager.load_json(HEAD_CACHE_NAME)
|
||||
if not isinstance(cached, dict):
|
||||
return None
|
||||
entry = cached.get(cache_key)
|
||||
if not isinstance(entry, dict):
|
||||
return None
|
||||
timestamp = entry.get("timestamp")
|
||||
if not isinstance(timestamp, int | float):
|
||||
return None
|
||||
if time.time() - timestamp > HEAD_CACHE_DURATION:
|
||||
return None
|
||||
return entry.get("exists") is True
|
||||
|
||||
def _save_head_cache_entry(self, cache_manager: CacheManager, cache_key: str, exists: bool) -> None:
|
||||
cached = cache_manager.load_json(HEAD_CACHE_NAME)
|
||||
if not isinstance(cached, dict):
|
||||
cached = {}
|
||||
cached[cache_key] = {"exists": exists, "timestamp": time.time()}
|
||||
cache_manager.save_json(HEAD_CACHE_NAME, cached)
|
||||
self._remove_old_head_cache_files(cache_manager)
|
||||
|
||||
def _remove_old_head_cache_files(self, cache_manager: CacheManager) -> None:
|
||||
if self._head_disk_cache_cleaned:
|
||||
return
|
||||
for cache_file in cache_manager.cache_dir.glob(HEAD_CACHE_OLD_PATTERN):
|
||||
try:
|
||||
cache_file.unlink()
|
||||
except OSError as e:
|
||||
logger.debug("Failed to remove old HEAD cache %s: %s", cache_file, e)
|
||||
self._head_disk_cache_cleaned = True
|
||||
|
||||
def _check_file_exists(self, url: str, timeout: int = 5) -> bool:
|
||||
if url in self._head_negative_cache:
|
||||
return False
|
||||
@@ -169,10 +134,11 @@ class PortProtonAPI:
|
||||
return False
|
||||
|
||||
cache_manager = CacheManager()
|
||||
cache_key = hashlib.sha256(url.encode('utf-8')).hexdigest()
|
||||
cached_exists = self._load_head_cache_entry(cache_manager, cache_key)
|
||||
if cached_exists is not None:
|
||||
return cached_exists
|
||||
cache_key = f"head_{hashlib.sha256(url.encode('utf-8')).hexdigest()}"
|
||||
if cache_manager.is_fresh(cache_key, HEAD_CACHE_DURATION):
|
||||
cached = cache_manager.load_json(cache_key)
|
||||
if isinstance(cached, dict):
|
||||
return cached.get("exists") is True
|
||||
|
||||
try:
|
||||
session = get_requests_session()
|
||||
@@ -181,13 +147,13 @@ class PortProtonAPI:
|
||||
self._head_negative_cache.add(url)
|
||||
self._head_positive_cache.discard(url)
|
||||
self._head_failure_cache.pop(url, None)
|
||||
self._save_head_cache_entry(cache_manager, cache_key, False)
|
||||
cache_manager.save_json(cache_key, {"exists": False})
|
||||
return False
|
||||
response.raise_for_status()
|
||||
if response.status_code == 200:
|
||||
self._head_positive_cache.add(url)
|
||||
self._head_failure_cache.pop(url, None)
|
||||
self._save_head_cache_entry(cache_manager, cache_key, True)
|
||||
cache_manager.save_json(cache_key, {"exists": True})
|
||||
return True
|
||||
return False
|
||||
except requests.RequestException as e:
|
||||
|
||||
Whitespace-only changes.
File renamed without changes.
@@ -0,0 +1,89 @@
|
||||
"""Entry point for shortcut and thumbnail generation tools."""
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from portprotonqt.cli import normalize_launch_path
|
||||
|
||||
|
||||
def create_shortcut(exe_path: str, game_name: str | None = None) -> bool:
|
||||
"""Create a PortProtonQt desktop shortcut for an executable."""
|
||||
from portprotonqt.config import create_desktop_file
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
normalized_path = normalize_launch_path(exe_path)
|
||||
result = create_desktop_file(normalized_path, game_name)
|
||||
if not result:
|
||||
return False
|
||||
|
||||
desktop_entry, desktop_path, icon_path = result
|
||||
|
||||
if not generate_thumbnail(normalized_path, icon_path, size=128):
|
||||
logger.error("Failed to generate thumbnail from exe: %s", normalized_path)
|
||||
desktop_entry = desktop_entry.replace(f"Icon={icon_path}\n", "Icon=\n")
|
||||
|
||||
try:
|
||||
Path(desktop_path).write_text(desktop_entry, encoding="utf-8")
|
||||
os.chmod(desktop_path, 0o755)
|
||||
except OSError as error:
|
||||
logger.error("Failed to save desktop file %s: %s", desktop_path, error)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def create_thumbnail(exe_path: str, output_path: str) -> bool:
|
||||
"""Create a PNG thumbnail for an executable."""
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
normalized_path = normalize_launch_path(exe_path)
|
||||
if not normalized_path or not output_path:
|
||||
return False
|
||||
|
||||
try:
|
||||
output_dir = os.path.dirname(output_path)
|
||||
if output_dir:
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
except OSError as error:
|
||||
logger.error("Failed to prepare thumbnail directory %s: %s", output_path, error)
|
||||
return False
|
||||
|
||||
if not generate_thumbnail(normalized_path, output_path, size=128):
|
||||
logger.error("Failed to generate thumbnail: %s", normalized_path)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""Parse arguments for shortcut tools."""
|
||||
parser = argparse.ArgumentParser(description="PortProtonQt shortcut tools")
|
||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
shortcut_parser = subparsers.add_parser("shortcut", help="Create a desktop shortcut")
|
||||
shortcut_parser.add_argument("exe_path", help="Path to the executable")
|
||||
shortcut_parser.add_argument("game_name", help="Name of the game")
|
||||
|
||||
thumbnail_parser = subparsers.add_parser("thumbnail", help="Create a PNG thumbnail")
|
||||
thumbnail_parser.add_argument("exe_path", help="Path to the executable")
|
||||
thumbnail_parser.add_argument("output_path", help="Path to the output PNG file")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Main entry point for shortcut tools."""
|
||||
args = parse_args()
|
||||
if args.command == "shortcut":
|
||||
return 0 if create_shortcut(args.exe_path, args.game_name) else 1
|
||||
if args.command == "thumbnail":
|
||||
return 0 if create_thumbnail(args.exe_path, args.output_path) else 1
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -15,7 +15,7 @@ import websocket
|
||||
|
||||
from portprotonqt.logger import get_logger
|
||||
from portprotonqt.downloader import Downloader
|
||||
from portprotonqt.dialogs import generate_thumbnail
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.config import (
|
||||
extract_exec_target_path,
|
||||
get_portproton_location,
|
||||
|
||||
+2
-1
@@ -24,7 +24,9 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"babel>=2.18.0",
|
||||
"beautifulsoup4>=4.14.3",
|
||||
"evdev>=1.9.3",
|
||||
"icoextract>=0.2.0",
|
||||
"libarchive-c>=5.3",
|
||||
"orjson>=3.11.8",
|
||||
"pillow>=12.2.0",
|
||||
@@ -38,7 +40,6 @@ dependencies = [
|
||||
"websocket-client>=1.9.0",
|
||||
"dbus-fast>=4.0.4",
|
||||
"pygame>=2.6.1",
|
||||
"pefile>=2024.8.26",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -15,6 +15,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/77/f5/21d2de20e8b8b0408f0681956ca2c69f1320a3848ac50e6e7f39c6159675/babel-2.18.0-py3-none-any.whl", hash = "sha256:e2b422b277c2b9a9630c1d7903c2a00d0830c409c59ac8cae9081c92f1aeba35", size = 10196845, upload-time = "2026-02-01T12:30:53.445Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "beautifulsoup4"
|
||||
version = "4.14.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "soupsieve" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c3/b0/1c6a16426d389813b48d95e26898aff79abbde42ad353958ad95cc8c9b21/beautifulsoup4-4.14.3.tar.gz", hash = "sha256:6292b1c5186d356bba669ef9f7f051757099565ad9ada5dd630bd9de5fa7fb86", size = 627737, upload-time = "2025-11-30T15:08:26.084Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/1a/39/47f9197bdd44df24d67ac8893641e16f386c984a0619ef2ee4c51fbbc019/beautifulsoup4-4.14.3-py3-none-any.whl", hash = "sha256:0918bfe44902e6ad8d57732ba310582e98da931428d231a5ecb9e7c703a735bb", size = 107721, upload-time = "2025-11-30T15:08:24.087Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.11.12"
|
||||
@@ -194,6 +207,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e3/7f/a1a97644e39e7316d850784c642093c99df1290a460df4ede27659056834/filelock-3.20.1-py3-none-any.whl", hash = "sha256:15d9e9a67306188a44baa72f569d2bfd803076269365fdea0934385da4dc361a", size = 16666, upload-time = "2025-12-15T23:54:26.874Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icoextract"
|
||||
version = "0.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pefile" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cc/a9/4653791ae2356f981ea3597a1ace0d04fef622071209a4613bf56abd0264/icoextract-0.2.0.tar.gz", hash = "sha256:e7b4770c9a927a48ecfccc4ecd35afe477c2565a71449f92a95bdc92a0d10043", size = 10949, upload-time = "2025-06-03T04:17:37.464Z" }
|
||||
|
||||
[[package]]
|
||||
name = "identify"
|
||||
version = "2.6.15"
|
||||
@@ -433,11 +455,12 @@ version = "0.1.12"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "babel" },
|
||||
{ name = "beautifulsoup4" },
|
||||
{ name = "dbus-fast" },
|
||||
{ name = "evdev" },
|
||||
{ name = "icoextract" },
|
||||
{ name = "libarchive-c" },
|
||||
{ name = "orjson" },
|
||||
{ name = "pefile" },
|
||||
{ name = "pillow" },
|
||||
{ name = "psutil" },
|
||||
{ name = "pygame" },
|
||||
@@ -460,11 +483,12 @@ dev = [
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "babel", specifier = ">=2.18.0" },
|
||||
{ name = "beautifulsoup4", specifier = ">=4.14.3" },
|
||||
{ name = "dbus-fast", specifier = ">=4.0.4" },
|
||||
{ name = "evdev", specifier = ">=1.9.3" },
|
||||
{ name = "icoextract", specifier = ">=0.2.0" },
|
||||
{ name = "libarchive-c", specifier = ">=5.3" },
|
||||
{ name = "orjson", specifier = ">=3.11.8" },
|
||||
{ name = "pefile", specifier = ">=2024.8.26" },
|
||||
{ name = "pillow", specifier = ">=12.2.0" },
|
||||
{ name = "psutil", specifier = ">=7.2.2" },
|
||||
{ name = "pygame", specifier = ">=2.6.1" },
|
||||
@@ -830,6 +854,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/fb/99/6e5ee21db2d6af84bbbd7d871d441dafeb069c6de5667b1aa49891a77c66/shiboken6-6.11.0-cp310-abi3-win_arm64.whl", hash = "sha256:3bd76cf56105ab2d62ecaff630366f11264f69b88d488f10f048da9a065781f4", size = 1783186, upload-time = "2026-03-23T12:47:11.832Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "soupsieve"
|
||||
version = "2.8.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/89/23/adf3796d740536d63a6fbda113d07e60c734b6ed5d3058d1e47fc0495e47/soupsieve-2.8.1.tar.gz", hash = "sha256:4cf733bc50fa805f5df4b8ef4740fc0e0fa6218cf3006269afd3f9d6d80fd350", size = 117856, upload-time = "2025-12-18T13:50:34.655Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/48/f3/b67d6ea49ca9154453b6d70b34ea22f3996b9fa55da105a79d8732227adc/soupsieve-2.8.1-py3-none-any.whl", hash = "sha256:a11fe2a6f3d76ab3cf2de04eb339c1be5b506a8a47f2ceb6d139803177f85434", size = 36710, upload-time = "2025-12-18T13:50:33.267Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tqdm"
|
||||
version = "4.67.3"
|
||||
|
||||
Reference in new issue
Block a user