forked from Linux-Gaming/PortProtonQt
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dce7c9683
|
||
|
|
cdeb74fd10
|
No files matched your search
@@ -145,7 +145,7 @@ pw_enable_idle_inhibit() {
|
||||
return
|
||||
fi
|
||||
|
||||
PW_INHIBIT_SLR="python3 -m portprotonqt.scripts_utils.idle_inhibit"
|
||||
PW_INHIBIT_SLR="python3 -m portprotonqt.idle_inhibit"
|
||||
print_info "Screensaver will be inhibited using D-Bus"
|
||||
}
|
||||
|
||||
@@ -1282,7 +1282,11 @@ init_wine_ver () {
|
||||
}
|
||||
|
||||
pw_init_runtime () {
|
||||
check_flatpak && export PW_USE_RUNTIME="0"
|
||||
if [[ ! -f "${PW_WINELIB}/runtime/files/bin/vkcube" ]] \
|
||||
|| [[ ! -f "${PW_WINELIB}/pressure-vessel/bin/pressure-vessel-wrap" ]]
|
||||
then
|
||||
export PW_USE_RUNTIME="0"
|
||||
fi
|
||||
if [[ "$PW_USE_RUNTIME" != "1" ]] \
|
||||
|| [[ "$PW_WINE_USE" == "USE_SYSTEM_WINE" ]]
|
||||
then
|
||||
@@ -2251,12 +2255,15 @@ 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
|
||||
@@ -2301,7 +2308,7 @@ pw_create_gui_png () {
|
||||
fi
|
||||
fi
|
||||
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}" "48" "128"
|
||||
|
||||
PORTPROTON_NAME_PNG="${PORTPROTON_NAME// /_}"
|
||||
if [[ $PORTPROTON_NAME_PNG =~ [\!\%\$\&\<] ]] ; then
|
||||
@@ -2310,9 +2317,15 @@ 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
|
||||
@@ -2506,7 +2519,7 @@ pw_enable_gamemode_basic () {
|
||||
start_portproton () {
|
||||
pw_check_and_download_plugins
|
||||
|
||||
if check_flatpak ; then
|
||||
if [[ "${PW_DISABLE_RUNTIME_DOWNLOAD}" == "1" ]] ; then
|
||||
try_remove_dir "${PORT_WINE_TMP_PATH}/libs${PW_LIBS_VER}"
|
||||
else
|
||||
pw_check_and_download_runtime
|
||||
@@ -4094,7 +4107,12 @@ gui_edit_db () {
|
||||
if [[ $PW_WINE_USE =~ (PROTON_LG|WINE_LG) ]] || [[ $PW_VULKAN_USE == "0" ]] ; then
|
||||
DISABLE_EDIT_DB_LIST+=" PW_USE_SUPPLIED_DXVK_VKD3D"
|
||||
fi
|
||||
check_flatpak && DISABLE_EDIT_DB_LIST+=" PW_USE_RUNTIME"
|
||||
|
||||
if [[ ! -f "${PW_WINELIB}/runtime/files/bin/vkcube" ]] \
|
||||
|| [[ ! -f "${PW_WINELIB}/pressure-vessel/bin/pressure-vessel-wrap" ]]
|
||||
then
|
||||
DISABLE_EDIT_DB_LIST+=" PW_USE_RUNTIME"
|
||||
fi
|
||||
|
||||
# GALLIUM NINE
|
||||
[[ ! -f "${PW_TMPFS_PATH}/gallium_nine.tmp" ]] && DISABLE_EDIT_DB_LIST+=" PW_USE_GALLIUM_NINE"
|
||||
@@ -4427,11 +4445,11 @@ pw_gamescope_process () {
|
||||
|
||||
# RESIZE PNG FILE
|
||||
resize_png () {
|
||||
if [[ -z "$1" ]] || [[ -z "$2" ]] ; then
|
||||
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]] ; then
|
||||
print_error "no argument specified for resize_png"
|
||||
return 1
|
||||
else
|
||||
local RESIZE_FILE RESIZE_NAME_PNG
|
||||
local RESIZE_FILE RESIZE_NAME_PNG resize_to resize_to_helper
|
||||
RESIZE_FILE="$1"
|
||||
RESIZE_NAME_PNG="${2// /_}"
|
||||
fi
|
||||
@@ -4440,26 +4458,44 @@ resize_png () {
|
||||
then RESIZE_NAME_PNG=${RESIZE_NAME_PNG/*ru.linux_gaming.PortProton\/data\/img\//}
|
||||
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
|
||||
for resize_to in "${@:3}" ; do
|
||||
if [[ $resize_to == 128 ]]
|
||||
then resize_to_helper=""
|
||||
else resize_to_helper="_$resize_to"
|
||||
fi
|
||||
|
||||
if [[ -f "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}.png" ]] \
|
||||
|| [[ ! -f "${RESIZE_FILE}" ]] \
|
||||
|| [[ ! ${RESIZE_FILE,,} =~ .exe$ ]]
|
||||
then
|
||||
return 0
|
||||
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
|
||||
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/launcher.png"
|
||||
try_remove_file "${PORT_DATA_PATH}/data/img/Launcher.png"
|
||||
if [[ -f "${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}${resize_to_helper}.png" ]] \
|
||||
|| [[ ! -f "${RESIZE_FILE}" ]] \
|
||||
|| [[ ! ${RESIZE_FILE,,} =~ .exe$ ]]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
python3 -m portprotonqt.scripts_utils.shortcut_tools thumbnail \
|
||||
"$(readlink -f "${RESIZE_FILE}")" \
|
||||
"${PORT_DATA_PATH}/data/img/${RESIZE_NAME_PNG}.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
|
||||
}
|
||||
|
||||
portwine_create_shortcut () {
|
||||
@@ -4493,12 +4529,19 @@ portwine_output_yad_shortcut () {
|
||||
export name_desktop="$PW_NAME_DESKTOP_PROXY"
|
||||
fi
|
||||
|
||||
if ! python3 -m portprotonqt.scripts_utils.shortcut_tools shortcut \
|
||||
"${PW_EXE_FILE}" \
|
||||
"${name_desktop}"
|
||||
then
|
||||
return 1
|
||||
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"
|
||||
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"
|
||||
@@ -4568,7 +4611,7 @@ pw_auto_create_shortcut () {
|
||||
pw_init_db
|
||||
export PW_NO_RESTART_PPDB="1"
|
||||
edit_db_from_gui PW_PREFIX_NAME LAUNCH_URI
|
||||
unset name_desktop_png
|
||||
unset PW_ICON_FOR_YAD name_desktop_png
|
||||
portwine_create_shortcut
|
||||
fi
|
||||
fi
|
||||
@@ -4602,9 +4645,9 @@ pw_auto_create_shortcut () {
|
||||
fi
|
||||
print_info "Created link for: $link_name"
|
||||
PORTPROTON_NAME="$link_name"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}"
|
||||
resize_png "$PW_EXE_FILE" "${PORTPROTON_NAME}" "48" "128"
|
||||
export PW_NO_RESTART_PPDB=1
|
||||
unset name_desktop_png
|
||||
unset PW_ICON_FOR_YAD name_desktop_png
|
||||
portwine_create_shortcut
|
||||
done
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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,6 +6,7 @@ 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=""
|
||||
|
||||
@@ -37,6 +37,11 @@ if [[ -z "$PORT_DATA_PATH" ]] ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "$HOME/.config/PortProtonQt.conf" ]] \
|
||||
&& grep "disable_runtime_download = True" "$HOME/.config/PortProtonQt.conf" ; then
|
||||
export PW_DISABLE_RUNTIME_DOWNLOAD=1
|
||||
fi
|
||||
|
||||
export PORT_SCRIPTS_PATH PORT_IMG_PATH PORT_DATA_PATH PORT_CONF_PATH
|
||||
export PW_LOG_FILE="${PORT_DATA_PATH}/PortProton.log"
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ def main():
|
||||
portproton_location = get_portproton_location()
|
||||
if portproton_location:
|
||||
os.environ["PORT_DATA_PATH"] = portproton_location
|
||||
ui_config.get_disable_runtime_download()
|
||||
|
||||
# Check if running as Steam compatibility tool (STEAM_COMPAT=1).
|
||||
is_steam_compat = os.environ.get("STEAM_COMPAT") == "1"
|
||||
|
||||
@@ -19,14 +19,6 @@ 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."""
|
||||
|
||||
@@ -364,8 +356,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, str] | None:
|
||||
"""Create desktop entry content, destination path and icon path for a game."""
|
||||
) -> tuple[str, str] | None:
|
||||
"""Create desktop entry content and destination path for a game."""
|
||||
portproton_path = get_portproton_location()
|
||||
if not os.path.isfile(exe_path):
|
||||
logger.error("Executable not found: %s", exe_path)
|
||||
@@ -377,8 +369,7 @@ 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_name = _sanitize_icon_name(game_name)
|
||||
icon_path = os.path.join(base_path, "img", f"{icon_name}.png")
|
||||
icon_path = os.path.join(base_path, "img", f"{game_name}.png")
|
||||
desktop_path = os.path.join(portproton_path, f"{game_name}.desktop")
|
||||
os.makedirs(os.path.dirname(icon_path), exist_ok=True)
|
||||
|
||||
@@ -400,4 +391,4 @@ def create_desktop_file(
|
||||
"StartupNotify=true\n"
|
||||
f"Icon={icon_path}\n"
|
||||
)
|
||||
return desktop_entry, desktop_path, icon_path
|
||||
return desktop_entry, desktop_path
|
||||
@@ -11,6 +11,7 @@ from portprotonqt.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
THEME_VARIANTS = ("dark", "light", "auto")
|
||||
DOWNLOADS_SECTION = "Downloads"
|
||||
|
||||
|
||||
def _get_theme_base_name(theme_name: str) -> str:
|
||||
@@ -244,21 +245,64 @@ class UIConfig(BaseConfig):
|
||||
|
||||
def get_economy_mode(self) -> bool:
|
||||
"""Get economy mode setting."""
|
||||
return self._get_bool("economy_mode", False)
|
||||
return self._get_download_bool("economy_mode", False)
|
||||
|
||||
def set_economy_mode(self, enabled: bool):
|
||||
"""Set economy mode setting."""
|
||||
validate_bool(enabled, "economy_mode")
|
||||
self._save_value("economy_mode", enabled, "bool")
|
||||
self._save_download_value("economy_mode", enabled)
|
||||
|
||||
def _get_download_bool(self, option: str, default: bool) -> bool:
|
||||
cp = self._read_config()
|
||||
if cp is None:
|
||||
return self._save_download_value(option, default)
|
||||
|
||||
try:
|
||||
if cp.has_option(DOWNLOADS_SECTION, option):
|
||||
return cp.getboolean(DOWNLOADS_SECTION, option, fallback=default)
|
||||
if cp.has_option(self._section, option):
|
||||
return cp.getboolean(self._section, option, fallback=default)
|
||||
except ValueError as e:
|
||||
logger.warning("Error reading %s: %s", option, e)
|
||||
return self._save_download_value(option, default)
|
||||
except configparser.Error as e:
|
||||
logger.warning("Error reading %s: %s", option, e)
|
||||
return self._save_download_value(option, default)
|
||||
|
||||
return self._save_download_value(option, default)
|
||||
|
||||
def _save_download_value(self, option: str, value: bool) -> bool:
|
||||
validate_bool(value, option)
|
||||
cp = self._read_config() or configparser.ConfigParser()
|
||||
if DOWNLOADS_SECTION not in cp:
|
||||
cp[DOWNLOADS_SECTION] = {}
|
||||
|
||||
cp[DOWNLOADS_SECTION][option] = str(value)
|
||||
if cp.has_section(self._section):
|
||||
cp.remove_option(self._section, option)
|
||||
self._save_config(cp)
|
||||
return value
|
||||
|
||||
def get_download_wine_to_steam(self) -> bool:
|
||||
"""Get Steam compatibility tools download setting."""
|
||||
return self._get_bool("download_wine_to_steam", False)
|
||||
return self._get_download_bool("download_wine_to_steam", False)
|
||||
|
||||
def set_download_wine_to_steam(self, enabled: bool) -> None:
|
||||
"""Set Steam compatibility tools download setting."""
|
||||
validate_bool(enabled, "download_wine_to_steam")
|
||||
self._save_value("download_wine_to_steam", enabled, "bool")
|
||||
self._save_download_value("download_wine_to_steam", enabled)
|
||||
|
||||
def get_disable_runtime_download(self) -> bool:
|
||||
"""Get PortProton runtime download setting."""
|
||||
default = bool(os.getenv("FLATPAK_ID"))
|
||||
return self._get_download_bool("disable_runtime_download", default)
|
||||
|
||||
def set_disable_runtime_download(self, enabled: bool) -> None:
|
||||
"""Set PortProton runtime download setting."""
|
||||
if os.getenv("FLATPAK_ID"):
|
||||
enabled = True
|
||||
validate_bool(enabled, "disable_runtime_download")
|
||||
self._save_download_value("disable_runtime_download", enabled)
|
||||
|
||||
|
||||
def load_theme_metainfo(theme_name: str) -> dict:
|
||||
|
||||
@@ -18,8 +18,7 @@ from portprotonqt.steam_api import (
|
||||
is_game_in_steam,
|
||||
remove_from_steam,
|
||||
)
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs import AddGameDialog
|
||||
from portprotonqt.dialogs import AddGameDialog, generate_thumbnail
|
||||
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,8 +5,7 @@ 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.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs.base import GameLaunchDialog, AddGameDialog, FileSelectedSignal
|
||||
from portprotonqt.dialogs.base import GameLaunchDialog, AddGameDialog, generate_thumbnail, FileSelectedSignal
|
||||
|
||||
__all__ = [
|
||||
'create_dialog_hints_widget',
|
||||
|
||||
@@ -9,6 +9,7 @@ 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:
|
||||
@@ -22,13 +23,80 @@ 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 generate_thumbnail
|
||||
from portprotonqt.icon_extractor import IconExtractor, IconExtractorError
|
||||
|
||||
logger = get_logger(__name__)
|
||||
theme_manager = ThemeManager()
|
||||
DISC_IMAGE_EXTENSIONS = (".iso", ".mdf")
|
||||
|
||||
|
||||
def generate_thumbnail(inputfile, outfile, size=128, force_resize=True):
|
||||
"""
|
||||
Generates a thumbnail for an .exe file.
|
||||
|
||||
inputfile: the input file path (%i)
|
||||
outfile: output filename (%o)
|
||||
size: determines the thumbnail output size (%s)
|
||||
"""
|
||||
logger.debug(f"Starting thumbnail generation: {inputfile} → {outfile}, size={size}, force={force_resize}")
|
||||
|
||||
try:
|
||||
extractor = IconExtractor(inputfile)
|
||||
logger.debug("IconExtractor created successfully.")
|
||||
except (RuntimeError, IconExtractorError) as e:
|
||||
logger.warning(f"Failed to create IconExtractor: {e}")
|
||||
return False
|
||||
|
||||
try:
|
||||
data = extractor.get_icon()
|
||||
if data is None:
|
||||
return False
|
||||
im = Image.open(data)
|
||||
logger.debug(f"Extracted icon size {im.size}, formats: {im.format}, frames: {getattr(im, 'n_frames', 1)}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error extracting icon: {e}")
|
||||
return False
|
||||
|
||||
if force_resize:
|
||||
logger.debug(f"Forcing icon resize to {size}x{size}")
|
||||
im = im.resize((size, size), Image.Resampling.LANCZOS)
|
||||
else:
|
||||
if size > 256:
|
||||
logger.warning('Requested size larger than 256, set to 256')
|
||||
size = 256
|
||||
elif size not in (128, 256):
|
||||
logger.warning(f'Unsupported size {size}, set to 128')
|
||||
size = 128
|
||||
|
||||
if size == 256:
|
||||
logger.debug("Saving icon without resize (256x256)")
|
||||
im.save(outfile, "PNG")
|
||||
logger.info(f"Icon saved to {outfile}")
|
||||
return True
|
||||
|
||||
frames = getattr(im, 'n_frames', 1)
|
||||
try:
|
||||
for frame in range(frames):
|
||||
im.seek(frame)
|
||||
if im.size == (size, size):
|
||||
logger.debug(f"Found frame with size {size}x{size}")
|
||||
break
|
||||
except EOFError:
|
||||
logger.debug("Frames ended before finding required size.")
|
||||
|
||||
if im.size != (size, size):
|
||||
logger.debug(f"Resizing from {im.size} to {size}x{size}")
|
||||
im = im.resize((size, size))
|
||||
|
||||
try:
|
||||
im.save(outfile, "PNG")
|
||||
logger.info(f"Thumbnail successfully saved to {outfile}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error saving thumbnail: {e}")
|
||||
return False
|
||||
|
||||
|
||||
class FileSelectedSignal(QObject):
|
||||
"""Signal class for file selection."""
|
||||
file_selected = Signal(str)
|
||||
@@ -470,7 +538,9 @@ class AddGameDialog(DraggableDialog):
|
||||
result = create_desktop_file(exe_path, name)
|
||||
if not result:
|
||||
return None, None
|
||||
desktop_entry, desktop_path, icon_path = result
|
||||
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")
|
||||
|
||||
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,8 +21,7 @@ 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.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs.base import DraggableDialog, FileSelectedSignal
|
||||
from portprotonqt.dialogs.base import DraggableDialog, generate_thumbnail, FileSelectedSignal
|
||||
from portprotonqt.image_utils import COVER_IMAGE_EXTENSIONS
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -12,36 +12,6 @@ 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."""
|
||||
|
||||
|
||||
File renamed without changes.
@@ -6,8 +6,7 @@ import subprocess
|
||||
import psutil
|
||||
import re
|
||||
from portprotonqt.logger import get_logger
|
||||
from portprotonqt.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs import AddGameDialog, FileExplorer, WinetricksDialog, ExeSettingsDialog
|
||||
from portprotonqt.dialogs import AddGameDialog, FileExplorer, WinetricksDialog, ExeSettingsDialog, generate_thumbnail
|
||||
from portprotonqt.game_card import GameCard
|
||||
from portprotonqt.animations import DetailPageAnimations
|
||||
from portprotonqt.custom_widgets import ClickableLabel, AutoSizeButton, NavLabel, FlowLayout
|
||||
@@ -2365,6 +2364,23 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
hide_autoinstall_layout.addStretch()
|
||||
uiForm.addRow(hide_autoinstall_layout)
|
||||
|
||||
disable_runtime_download_layout = None
|
||||
if not os.getenv("FLATPAK_ID"):
|
||||
self.disableRuntimeDownloadCheckBox = QCheckBox()
|
||||
self.disableRuntimeDownloadCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE)
|
||||
self.disableRuntimeDownloadCheckBox.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
self.disableRuntimeDownloadTitle = QLabel(_("Disable PortProton runtime download"))
|
||||
self.disableRuntimeDownloadTitle.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
self.disableRuntimeDownloadTitle.setStyleSheet(self.theme.SETTINGS_TITLE_CHECKBOX_STYLE)
|
||||
self.disableRuntimeDownloadTitle.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
self.disableRuntimeDownloadCheckBox.setChecked(ui_config.get_disable_runtime_download())
|
||||
disable_runtime_download_layout = QHBoxLayout()
|
||||
disable_runtime_download_layout.setContentsMargins(0, 0, 0, 0)
|
||||
disable_runtime_download_layout.addWidget(self.disableRuntimeDownloadCheckBox)
|
||||
disable_runtime_download_layout.addWidget(self.disableRuntimeDownloadTitle)
|
||||
disable_runtime_download_layout.addStretch()
|
||||
|
||||
download_wine_to_steam_layout = None
|
||||
self.steamCompatCheckBox = QCheckBox()
|
||||
self.steamCompatCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE)
|
||||
self.steamCompatCheckBox.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
@@ -2395,7 +2411,6 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
download_wine_to_steam_layout.addWidget(self.downloadWineToSteamCheckBox)
|
||||
download_wine_to_steam_layout.addWidget(self.downloadWineToSteamTitle)
|
||||
download_wine_to_steam_layout.addStretch()
|
||||
uiForm.addRow(download_wine_to_steam_layout)
|
||||
|
||||
self.economyModeCheckBox = QCheckBox()
|
||||
self.economyModeCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE)
|
||||
@@ -2419,7 +2434,6 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
economy_mode_layout.addWidget(self.economyModeCheckBox)
|
||||
economy_mode_layout.addWidget(self.economyModeTitle)
|
||||
economy_mode_layout.addStretch()
|
||||
uiForm.addRow(economy_mode_layout)
|
||||
|
||||
self.forceSystemDpiCheckBox = QCheckBox()
|
||||
self.forceSystemDpiCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE)
|
||||
@@ -2437,7 +2451,20 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
force_system_dpi_layout.addStretch()
|
||||
uiForm.addRow(force_system_dpi_layout)
|
||||
|
||||
# 3. Gamepad Settings Section
|
||||
# 3. Download Settings Section
|
||||
downloadFrame, downloadForm = create_section(_("Download Settings"), self.theme)
|
||||
downloadForm.setRowWrapPolicy(QFormLayout.RowWrapPolicy.DontWrapRows)
|
||||
scrollLayout.addWidget(downloadFrame)
|
||||
|
||||
if disable_runtime_download_layout is not None:
|
||||
downloadForm.addRow(disable_runtime_download_layout)
|
||||
|
||||
if download_wine_to_steam_layout is not None:
|
||||
downloadForm.addRow(download_wine_to_steam_layout)
|
||||
|
||||
downloadForm.addRow(economy_mode_layout)
|
||||
|
||||
# 4. Gamepad Settings Section
|
||||
padFrame, padForm = create_section(_("Gamepad Settings"), self.theme)
|
||||
padForm.setRowWrapPolicy(QFormLayout.RowWrapPolicy.DontWrapRows)
|
||||
scrollLayout.addWidget(padFrame)
|
||||
@@ -2458,7 +2485,7 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
auto_fullscreen_layout.addStretch()
|
||||
padForm.addRow(auto_fullscreen_layout)
|
||||
|
||||
# 4. Hardware Settings Section
|
||||
# 5. Hardware Settings Section
|
||||
hwFrame, hwForm = create_section(_("Hardware Settings"), self.theme)
|
||||
hwForm.setRowWrapPolicy(QFormLayout.RowWrapPolicy.DontWrapRows)
|
||||
scrollLayout.addWidget(hwFrame)
|
||||
@@ -2493,7 +2520,7 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
else:
|
||||
hwForm.addRow(QLabel(_("No GPUs found")), QLabel(""))
|
||||
|
||||
# 5. Proxy Settings Section
|
||||
# 6. Proxy Settings Section
|
||||
proxyFrame, proxyForm = create_section(_("Proxy Settings"), self.theme)
|
||||
proxyForm.setRowWrapPolicy(QFormLayout.RowWrapPolicy.DontWrapRows)
|
||||
scrollLayout.addWidget(proxyFrame)
|
||||
@@ -2681,6 +2708,11 @@ class MainWindow(MainWindowControlHintsMixin, MainWindowSystemTabMixin, MainWind
|
||||
if hasattr(self, 'downloadWineToSteamCheckBox'):
|
||||
ui_config.set_download_wine_to_steam(self.downloadWineToSteamCheckBox.isChecked())
|
||||
|
||||
if hasattr(self, 'disableRuntimeDownloadCheckBox'):
|
||||
ui_config.set_disable_runtime_download(self.disableRuntimeDownloadCheckBox.isChecked())
|
||||
else:
|
||||
ui_config.get_disable_runtime_download()
|
||||
|
||||
# Save GPU selection to user.conf (only if the combo box exists)
|
||||
if hasattr(self, 'gpuCombo'):
|
||||
selected_gpu = self.gpuCombo.currentText()
|
||||
|
||||
@@ -12,6 +12,7 @@ install_data(
|
||||
'game_card.py',
|
||||
'game_library_manager.py',
|
||||
'howlongtobeat_api.py',
|
||||
'idle_inhibit.py',
|
||||
'image_utils.py',
|
||||
'icon_extractor.py',
|
||||
'input_manager.py',
|
||||
@@ -23,10 +24,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'],
|
||||
@@ -117,15 +118,6 @@ 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.
@@ -1,89 +0,0 @@
|
||||
"""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.icon_extractor import generate_thumbnail
|
||||
from portprotonqt.dialogs import generate_thumbnail
|
||||
from portprotonqt.config import (
|
||||
extract_exec_target_path,
|
||||
get_portproton_location,
|
||||
|
||||
Reference in new issue
Block a user