forked from Linux-Gaming/PortProtonQt
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46078d72a3
|
No files matched your search
+1
-1
@@ -23,7 +23,7 @@
|
||||
- В скриптах добавлена поддержка внешних Proton из каталогов Steam `steamapps` и `compatibilitytools.d`
|
||||
- Добавлена классическая тема, приближенная по внешнему виду к PortProton для облегчения перехода на PortProtonQt
|
||||
- Для обложек добавлена поддержка APNG, animated WebP, GIF и JXL
|
||||
- Добавлена поддержка запуска `.mdf`, `.nrg`, `.bin` и `.img`
|
||||
- Добавлена поддержка запуска `.mdf`
|
||||
- Добавлена приостановка фоновой активности при потере фокуса окна
|
||||
- При запуске теперь генерируются отсутствующие изображения в `data/img` для найденных `.exe`
|
||||
- Для игр из Steam добавлено создание ярлыков на рабочем столе и в меню
|
||||
|
||||
@@ -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, nrg, bin и img в 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]
|
||||
|
||||
@@ -18,7 +18,7 @@ pkgver() {
|
||||
}
|
||||
|
||||
build() {
|
||||
arch-meson PortProtonQt build -Dnightly=true
|
||||
arch-meson PortProtonQt build
|
||||
meson compile -C build
|
||||
}
|
||||
|
||||
|
||||
@@ -97,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
|
||||
@@ -121,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
|
||||
|
||||
@@ -119,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
|
||||
|
||||
@@ -11,4 +11,4 @@ Terminal=false
|
||||
Icon=ru.linux_gaming.PortProtonQt
|
||||
StartupWMClass=ru.linux_gaming.PortProtonQt
|
||||
Categories=Game;Utility;
|
||||
MimeType=x-scheme-handler/portproton;application/x-ms-dos-exec;application/x-executable;application/x-dosexec;application/x-iso9660-image;application/x-cd-image;application/x-raw-disk-image;application/x-mdf;application/x-mds-disk;application/x-nrg;
|
||||
MimeType=x-scheme-handler/portproton;application/x-ms-dos-exec;application/x-executable;application/x-dosexec;application/x-iso9660-image;application/x-cd-image;application/x-raw-disk-image;application/x-mdf;application/x-mds-disk;
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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=""
|
||||
|
||||
@@ -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"],
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
|
||||
from portprotonqt.steam_api import get_steam_home
|
||||
|
||||
LAUNCH_FILE_EXTENSIONS = ('.exe', '.iso', '.mdf', '.nrg', '.bin', '.img')
|
||||
LAUNCH_FILE_EXTENSIONS = ('.exe', '.iso', '.mdf')
|
||||
|
||||
|
||||
def parse_args():
|
||||
@@ -65,7 +65,7 @@ def parse_args():
|
||||
parser.add_argument(
|
||||
'file_or_url',
|
||||
nargs='?',
|
||||
help="Launch file path (.exe/.iso/.mdf/.nrg/.bin/.img) or portproton:// URL"
|
||||
help="Launch file path (.exe/.iso/.mdf) or portproton:// URL"
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -319,7 +327,7 @@ def extract_exec_target_path(exec_value: str | list[str]) -> str | None:
|
||||
return None
|
||||
|
||||
for part in reversed(parts):
|
||||
if part.lower().endswith((".exe", ".iso", ".mdf", ".nrg", ".bin", ".img")):
|
||||
if part.lower().endswith((".exe", ".iso", ".mdf")):
|
||||
return os.path.expanduser(part)
|
||||
|
||||
if parts[0] in ("env", "flatpak"):
|
||||
@@ -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
|
||||
|
||||
@@ -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,78 +22,11 @@ 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", ".nrg", ".bin", ".img")
|
||||
|
||||
|
||||
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
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf")
|
||||
|
||||
|
||||
class FileSelectedSignal(QObject):
|
||||
@@ -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,12 +21,13 @@ 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__)
|
||||
theme_manager = ThemeManager()
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf", ".nrg", ".bin", ".img")
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf")
|
||||
THUMBNAIL_PRELOAD_ROWS = 5
|
||||
THUMBNAIL_QUEUE_LIMIT = 24
|
||||
THUMBNAIL_SCROLL_DELAY_MS = 80
|
||||
|
||||
@@ -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,15 +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")
|
||||
CONVERTIBLE_DISC_EXTENSIONS = (".mdf", ".nrg", ".bin", ".img")
|
||||
|
||||
|
||||
class DiscImageManager:
|
||||
@@ -62,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."""
|
||||
@@ -301,10 +223,7 @@ class DiscImageManager:
|
||||
logger.error("7zz or 7z is required to extract MDF set %s", mdf_path)
|
||||
return None
|
||||
|
||||
if normalized_mdf.lower().endswith(".mdf"):
|
||||
mdf_sources = self._get_mdf_sources(normalized_mdf)
|
||||
else:
|
||||
mdf_sources = [normalized_mdf]
|
||||
mdf_sources = self._get_mdf_sources(normalized_mdf)
|
||||
source_stamp = self._get_disc_source_stamp(mdf_sources)
|
||||
if not source_stamp:
|
||||
return None
|
||||
@@ -342,7 +261,7 @@ class DiscImageManager:
|
||||
def sync_iso_to_rw(self, iso_path: str) -> str | None:
|
||||
"""Extract disc image content to writable runtime directory if source changed."""
|
||||
normalized_iso = os.path.abspath(os.path.expanduser(iso_path))
|
||||
if normalized_iso.lower().endswith(CONVERTIBLE_DISC_EXTENSIONS):
|
||||
if normalized_iso.lower().endswith(".mdf"):
|
||||
return self._sync_mdf_set_to_rw(normalized_iso)
|
||||
rw_root = self._iso_rw_paths.get(normalized_iso, self._get_iso_rw_root(normalized_iso))
|
||||
os.makedirs(rw_root, exist_ok=True)
|
||||
|
||||
@@ -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
|
||||
@@ -69,7 +70,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import datetime
|
||||
|
||||
logger = get_logger(__name__)
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf", ".nrg", ".bin", ".img")
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf")
|
||||
|
||||
class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWindowWorkersMixin, QMainWindow):
|
||||
games_loaded = Signal(list)
|
||||
|
||||
@@ -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',
|
||||
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user