forked from Linux-Gaming/PortProtonQt
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
290211e0cb
|
||
|
|
54271548ec
|
||
|
|
a9552a3c1b
|
||
|
|
88c30025de
|
||
|
|
1aac62b647
|
||
|
|
08131ea53f
|
||
|
|
2666159375
|
||
|
|
3515ad0ac5
|
||
|
|
0875896e45
|
||
|
|
4f406cc966
|
||
|
|
f9e0081fd6
|
||
|
|
bc4ba2169d
|
||
|
|
cfc05c2017
|
||
|
|
55fba9260e
|
No files matched your search
@@ -30,6 +30,7 @@
|
||||
- В настройки добавлена загрузка Wine/Proton в Steam `compatibilitytools.d`
|
||||
|
||||
### Changed
|
||||
- Бейджи источников (Steam и PortProton) теперь отображаются при любом фильтре библиотеки
|
||||
- Обложки к играм из Steam теперь полностью локальные
|
||||
- Улучшен механизм кеширования данных
|
||||
- Тип геймпада `Xbox` `PS` теперь выбирается автоматически
|
||||
@@ -48,6 +49,7 @@
|
||||
- Автоустановки теперь можно остановить
|
||||
- Префиксы `DEFAULT`, `DOTNET` и `PROGRAMS` теперь всегда отображаются вверху списков префиксов
|
||||
- Из лога удалена версия скриптов, так как скрипты теперь внутри PortProtonQt
|
||||
- Из downloader удалена отдельная проверка сети через Yandex и Google
|
||||
|
||||
### Fixed
|
||||
- Исправлено определение `PW_USE_RUNTIME` в debug-логе
|
||||
@@ -65,6 +67,7 @@
|
||||
- Исправлено управление геймпадом в диалоге выбора файла для загрузки 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).
|
||||
- [mdf2iso](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI) — библиотека для конвертации mdf в iso, лицензия [GPLv2](https://salsa.debian.org/debian/mdf2iso/-/blob/master/gpl.txt).
|
||||
- [iat](https://sourceforge.net/projects/iat.berlios) — библиотека для конвертации mdf в iso, лицензия GPLv3
|
||||
Полный текст лицензий см. в файле [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 -Syy
|
||||
pacman -Syyu --noconfirm --disable-download-timeout
|
||||
|
||||
echo "Building PortProtonQt from PKGBUILD..."
|
||||
echo "---------------------------------------------------------------"
|
||||
|
||||
@@ -37,9 +37,8 @@ fi
|
||||
# Qt libs have to be passed manually due to the app being a python script
|
||||
./quick-sharun \
|
||||
/usr/bin/portprotonqt* \
|
||||
/usr/lib/libQt6Core.so* \
|
||||
/usr/lib/libQt6Gui.so* \
|
||||
/usr/lib/libQt6Network.so* \
|
||||
/usr/lib/libQt6*.so* \
|
||||
/usr/lib/libSDL2*.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-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')
|
||||
'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')
|
||||
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-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')
|
||||
'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')
|
||||
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
|
||||
arch-meson PortProtonQt build -Dnightly=true
|
||||
meson compile -C build
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ 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
|
||||
@@ -97,6 +96,7 @@ 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,6 +120,8 @@ 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,7 +36,6 @@ 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
|
||||
@@ -119,6 +118,8 @@ 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
|
||||
|
||||
@@ -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:]]/_/g)
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e 's/[[:blank:]]*-[[:blank:]]*/-/g' -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
|
||||
|
||||
@@ -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:]]/_/g)
|
||||
dist_dir_new=$(echo "${dist_dir}" | awk '$1=$1' | sed -e 's/[[:blank:]]*-[[:blank:]]*/-/g' -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__ in app.py
|
||||
Update APP_VERSION fallback 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,7 +679,8 @@ 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
|
||||
'install_emptydir', # Empty directories installation
|
||||
'configure_file', # Files generated and potentially installed
|
||||
]
|
||||
|
||||
# Process each install function
|
||||
|
||||
+25
@@ -12,6 +12,20 @@ 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')
|
||||
@@ -25,6 +39,17 @@ 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,3 +2,4 @@
|
||||
|
||||
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')
|
||||
@@ -0,0 +1,2 @@
|
||||
APP_VERSION = @APP_VERSION@
|
||||
APP_COMMIT = @APP_COMMIT@
|
||||
+14
-1
@@ -1,12 +1,22 @@
|
||||
import sys
|
||||
import os
|
||||
import importlib
|
||||
import subprocess
|
||||
import shutil
|
||||
from logging import Logger
|
||||
|
||||
__app_id__ = "ru.linux_gaming.PortProtonQt"
|
||||
__app_name__ = "PortProtonQt"
|
||||
__app_version__ = "0.1.12"
|
||||
|
||||
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
|
||||
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
|
||||
@@ -36,6 +46,9 @@ 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"],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Environment variables and configuration utilities."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from portprotonqt.logger import get_logger
|
||||
@@ -11,8 +12,9 @@ logger = get_logger(__name__)
|
||||
|
||||
|
||||
def _normalize_dist_name(value: str) -> str:
|
||||
# Match scripts behavior: trim, normalize whitespace, replace blanks with "_", uppercase.
|
||||
return "_".join(value.split()).upper()
|
||||
# Keep spaced hyphen separators readable before replacing blanks with "_".
|
||||
normalized = re.sub(r"\s*-\s*", "-", value.strip())
|
||||
return "_".join(normalized.split()).upper()
|
||||
|
||||
|
||||
def get_file_content(file_path: str, default: str = "") -> str:
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def _normalize_dist_name(value: str) -> str:
|
||||
# Match scripts behavior: trim, normalize whitespace, replace blanks with "_", uppercase.
|
||||
return "_".join(value.split()).upper()
|
||||
from portprotonqt.debug_utils.env_utils import _normalize_dist_name
|
||||
|
||||
|
||||
def _strip_pw_wine_use_path(line: str) -> str:
|
||||
|
||||
@@ -21,6 +21,7 @@ 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,
|
||||
@@ -195,19 +196,17 @@ 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" and display_filter in ("all", "favorites")
|
||||
portproton_visible = game_source == "portproton" and display_filter in ("all", "favorites")
|
||||
steam_visible = game_source == "steam"
|
||||
portproton_visible = game_source == "portproton"
|
||||
|
||||
badges = []
|
||||
protondb_badge = self._create_protondb_badge(parent, game_data)
|
||||
@@ -323,6 +322,19 @@ 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,30 +107,33 @@ def setup_adaptive_layout(
|
||||
"""Setup adaptive layout switching on resize."""
|
||||
|
||||
def on_detail_page_resize(event) -> None:
|
||||
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
|
||||
)
|
||||
apply_adaptive_layout(detail_page, content_frame_layout)
|
||||
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()
|
||||
|
||||
@@ -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:
|
||||
self.downloader.download(url, temp_path)
|
||||
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
|
||||
with open(temp_path) as f:
|
||||
ext_content = f.read()
|
||||
ext_ver_match = re.search(r'WINETRICKS_VERSION\s*=\s*[\'"]?([^\'"\s]+)', ext_content)
|
||||
|
||||
@@ -5,6 +5,7 @@ import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import shlex
|
||||
from typing import BinaryIO
|
||||
from portprotonqt.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -12,6 +13,14 @@ 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:
|
||||
@@ -52,58 +61,126 @@ class DiscImageManager:
|
||||
logger.error("Failed to read ISO 9660 signature for %s: %s", file_path, e)
|
||||
return False
|
||||
|
||||
def _write_iso_from_mdf(self, mdf_path: str, iso_path: str) -> None:
|
||||
"""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)
|
||||
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
|
||||
|
||||
if h0 == SYNC_HEADER:
|
||||
if h2352 == SYNC_HEADER_MDF:
|
||||
sector_size = 2448
|
||||
elif h2352 == SYNC_HEADER:
|
||||
sector_size = 2352
|
||||
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:
|
||||
raise ValueError(f"Unknown SYNC format for {mdf_path}")
|
||||
cd_id_end = offset
|
||||
break
|
||||
|
||||
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
|
||||
if cd_id_start < 0 or cd_id_end <= cd_id_start:
|
||||
return self._detect_sector_layout(source)
|
||||
|
||||
# Legacy fallback
|
||||
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."""
|
||||
with open(mdf_path, "rb") as source, open(iso_path, "wb") as target:
|
||||
sector_index = 0
|
||||
while True:
|
||||
sector = source.read(2352)
|
||||
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)
|
||||
if not sector:
|
||||
return
|
||||
if len(sector) != 2352:
|
||||
if len(sector) != block_size:
|
||||
raise ValueError(f"Truncated MDF sector at {sector_index}")
|
||||
mode = sector[15]
|
||||
if mode == 1:
|
||||
target.write(sector[16:2064])
|
||||
elif mode == 2:
|
||||
target.write(sector[24:2072])
|
||||
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)
|
||||
else:
|
||||
raise ValueError(f"Unknown MDF sector mode {mode} at {sector_index}")
|
||||
sector_index += 1
|
||||
sector_index += 1
|
||||
source.seek(sector_index)
|
||||
continue
|
||||
sector_index += block_size
|
||||
|
||||
def _convert_mdf_to_iso(self, mdf_path: str) -> str | None:
|
||||
"""Convert raw 2352-byte sector MDF to temporary ISO."""
|
||||
|
||||
@@ -2,7 +2,6 @@ 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
|
||||
@@ -65,54 +64,12 @@ 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:
|
||||
@@ -219,9 +176,6 @@ 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")
|
||||
@@ -259,14 +213,6 @@ 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 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.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.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 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)
|
||||
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)
|
||||
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,11 +1,9 @@
|
||||
import orjson
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
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
|
||||
@@ -17,66 +15,22 @@ 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."""
|
||||
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
|
||||
token: str
|
||||
hp_key: str
|
||||
hp_val: str
|
||||
|
||||
class HTTPClient:
|
||||
"""HTTP client for HowLongToBeat API."""
|
||||
BASE_URL = 'https://howlongtobeat.com/'
|
||||
SEARCH_URL = BASE_URL + "api/s/"
|
||||
AUTH_URL = BASE_URL + "api/bleed/init"
|
||||
SEARCH_URL = BASE_URL + "api/bleed"
|
||||
|
||||
def __init__(self, timeout: int = 60):
|
||||
self.timeout = timeout
|
||||
@@ -89,67 +43,55 @@ class HTTPClient:
|
||||
if proxy_settings:
|
||||
self.session.proxies.update(proxy_settings)
|
||||
|
||||
def get_search_config(self, parse_all_scripts: bool = False) -> SearchConfig | None:
|
||||
def get_search_config(self) -> SearchConfig | None:
|
||||
try:
|
||||
response = self.session.get(self.BASE_URL, timeout=self.timeout)
|
||||
response = self.session.get(
|
||||
self.AUTH_URL,
|
||||
params={"t": int(time.time() * 1000)},
|
||||
timeout=self.timeout
|
||||
)
|
||||
response.raise_for_status()
|
||||
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
|
||||
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"]
|
||||
)
|
||||
|
||||
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:
|
||||
config = self.get_search_config(parse_all_scripts=True)
|
||||
if not config or not config.api_key:
|
||||
if not config:
|
||||
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
|
||||
)
|
||||
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
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
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
|
||||
if response.status_code != 403 or retry:
|
||||
return None
|
||||
config = self.get_search_config()
|
||||
if not config:
|
||||
return None
|
||||
return None
|
||||
|
||||
def _build_search_payload(self, game_name: str, page: int, config: SearchConfig) -> dict[str, Any]:
|
||||
@@ -171,8 +113,7 @@ class HTTPClient:
|
||||
'genre': "",
|
||||
"difficulty": ""
|
||||
},
|
||||
'rangeYear': {'max': "", 'min': ""},
|
||||
'modifier': "" # Hardcoded to empty string for SearchModifiers.NONE
|
||||
'rangeYear': {'max': "", 'min': ""}
|
||||
},
|
||||
'users': {'sortCategory': "postcount"},
|
||||
'lists': {'sortCategory': "follows"},
|
||||
@@ -181,42 +122,26 @@ class HTTPClient:
|
||||
'randomizer': 0
|
||||
},
|
||||
'useCache': True,
|
||||
'fields': ["game_id", "game_name", "comp_main", "comp_plus", "comp_100"] # Request only needed fields
|
||||
'fields': ["comp_main", "comp_plus", "comp_100"]
|
||||
}
|
||||
if config.api_key:
|
||||
payload['searchOptions']['users']['id'] = config.api_key
|
||||
payload[config.hp_key] = config.hp_val
|
||||
return payload
|
||||
|
||||
class ResultParser:
|
||||
"""Search results parser."""
|
||||
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]:
|
||||
def parse_results(self, json_response: str) -> list[GameEntry]:
|
||||
try:
|
||||
data = orjson.loads(json_response)
|
||||
games = []
|
||||
# Only process the first result
|
||||
if data.get("data"):
|
||||
game_data = data["data"][0]
|
||||
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)
|
||||
games.append(self._parse_game_entry(game_data))
|
||||
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"),
|
||||
@@ -228,35 +153,8 @@ 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."""
|
||||
@@ -273,15 +171,13 @@ 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 and required fields."""
|
||||
"""Save data to cache, storing only first game times."""
|
||||
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)
|
||||
@@ -298,25 +194,8 @@ class HowLongToBeat(QObject):
|
||||
cached_response = self._load_from_cache(game_name)
|
||||
if cached_response:
|
||||
try:
|
||||
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'))
|
||||
parser = ResultParser()
|
||||
return parser.parse_results(cached_response)
|
||||
except orjson.JSONDecodeError:
|
||||
pass
|
||||
# If not in cache, make request
|
||||
@@ -325,11 +204,7 @@ class HowLongToBeat(QObject):
|
||||
return None
|
||||
# Save only first game to cache
|
||||
self._save_to_cache(game_name, json_response)
|
||||
parser = ResultParser(
|
||||
game_name,
|
||||
self.minimum_similarity,
|
||||
case_sensitive
|
||||
)
|
||||
parser = ResultParser()
|
||||
return parser.parse_results(json_response)
|
||||
|
||||
def format_game_time(self, game_entry: GameEntry, time_field: str = "main_story") -> str | None:
|
||||
|
||||
@@ -31,6 +31,8 @@ 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]:
|
||||
@@ -116,6 +118,7 @@ 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
|
||||
|
||||
@@ -124,6 +127,38 @@ 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
|
||||
@@ -134,11 +169,10 @@ class PortProtonAPI:
|
||||
return False
|
||||
|
||||
cache_manager = CacheManager()
|
||||
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
|
||||
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
|
||||
|
||||
try:
|
||||
session = get_requests_session()
|
||||
@@ -147,13 +181,13 @@ class PortProtonAPI:
|
||||
self._head_negative_cache.add(url)
|
||||
self._head_positive_cache.discard(url)
|
||||
self._head_failure_cache.pop(url, None)
|
||||
cache_manager.save_json(cache_key, {"exists": False})
|
||||
self._save_head_cache_entry(cache_manager, cache_key, 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)
|
||||
cache_manager.save_json(cache_key, {"exists": True})
|
||||
self._save_head_cache_entry(cache_manager, cache_key, True)
|
||||
return True
|
||||
return False
|
||||
except requests.RequestException as e:
|
||||
|
||||
+1
-2
@@ -24,9 +24,7 @@ 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",
|
||||
@@ -40,6 +38,7 @@ dependencies = [
|
||||
"websocket-client>=1.9.0",
|
||||
"dbus-fast>=4.0.4",
|
||||
"pygame>=2.6.1",
|
||||
"pefile>=2024.8.26",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -15,19 +15,6 @@ 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"
|
||||
@@ -207,15 +194,6 @@ 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"
|
||||
@@ -455,12 +433,11 @@ 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" },
|
||||
@@ -483,12 +460,11 @@ 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" },
|
||||
@@ -854,15 +830,6 @@ 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