From 3ea9462025fe7f0933fcf0eeade5fe8af4c89824 Mon Sep 17 00:00:00 2001 From: Mikhail Tergoev Date: Mon, 26 May 2025 14:01:23 +0300 Subject: [PATCH] added launch of files in the native application (fnx @minergenon) --- winehelper | 58 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/winehelper b/winehelper index 2342c62..8502c57 100755 --- a/winehelper +++ b/winehelper @@ -744,14 +744,23 @@ get_and_set_reg_file () { case $name_type_reg in REG_DWORD) - name_for_find="\"$name_for_find\"=dword:" + if [[ $name_for_find != '@=' ]] + then name_for_find="\"$name_for_find\"=dword:" + else name_for_find="@=dword:" + fi name_for_set=$(convert_dec_and_hex --dec "$name_for_set") ;; REG_SZ) - name_for_find="\"$name_for_find\"=" + if [[ $name_for_find != '@=' ]] + then name_for_find="\"$name_for_find\"=" + else name_for_find="@=" + fi name_for_set="\"$name_for_set\"" ;; *) if [[ $name_add_or_del == --delete ]] ; then - name_for_find="\"$name_for_find\"" + if [[ $name_for_find != '@=' ]] + then name_for_find="\"$name_for_find\"" + else name_for_find="@=" + fi else print_error "не задан тип ветки реестра: $name_fatal" return 1 @@ -799,15 +808,15 @@ get_and_set_reg_file () { fi fi if [[ $find_check_file == 1 ]] ; then - print_info "Меняем $name_for_find_old в файле реестра" + print_info "Меняем $name_for_find_old в ветке реестра: $name_block" sed -i "${find_number_line}s|$name_for_find.*|$name_for_find$name_for_set|" "$find_file" else - print_info "Добавляем $name_for_find_old в файл реестра" + print_info "Добавляем $name_for_find_old в ветку реестра: $name_block" sed -i "$(( find_line + 1 ))a$name_for_find$name_for_set" "$find_file" fi elif [[ $name_add_or_del == --delete ]] ; then [[ $find_check_file != 1 ]] && return 0 - print_info "Удаляем $name_for_find_old из файла реестра" + print_info "Удаляем $name_for_find_old из ветки реестра: $name_block" sed -i "${find_number_line}d" "$find_file" fi } @@ -938,6 +947,43 @@ init_wineprefix () { get_and_set_reg_file --delete 'Software\Wine\X11 Driver' 'UseXVidMode' fi + # добавление ассоциаций файлов для запуска нативного приложения из wine + # пример переменной: WH_XDG_OPEN="txt doc pdf" + check_variables WH_XDG_OPEN "0" + local WRAPPER="${WH_TMP_DIR}/wh-xdg-open.sh" + local XDG_OPEN_REG="Software\Classes\xdg-open\shell\open\command" + if [[ $WH_XDG_OPEN != "0" ]] ; then + # проверяем на наличие запрещённых расширений + local forbidden_extensions="cpl dll exe lnk msi" + for ext in $WH_XDG_OPEN; do + if [[ "$forbidden_extensions" =~ $ext ]] ; then + fatal "Расширение .$ext запрещено для добавления!" + fi + done + + # создаем скрипт-обёртку + { + echo "#!/usr/bin/env bash" + echo "unix_path=\$(\"$WINELOADER\" winepath -u \"\$*\")" + echo "xdg-open \"\$unix_path\"" + } > "$WRAPPER" + chmod +x "$WRAPPER" + + # добавляем новую команду xdg-open в реестр + get_and_set_reg_file --add "$XDG_OPEN_REG" '@=' 'REG_SZ' "$WRAPPER %1" "system" + + # добавляем ассоциации файлов для запуска с помощью xdg-open + for ext in $WH_XDG_OPEN ; do + get_and_set_reg_file --add "Software\Classes\.$ext" '@=' 'REG_SZ' "xdg-open" "system" + done + print_info "Используется ассоциации с нативными приложениями для файлов: \"$WH_XDG_OPEN\"" + else + # удаление команды xdg-open из реестра + get_and_set_reg_file --delete "$XDG_OPEN_REG" '@=' + # удаяем скрипт-обёртку + try_remove_file "$WRAPPER" + fi + echo "# переменные последнего использования префикса:" > "$WINEPREFIX/last.conf" for var in WH_WINE_USE BASE_PFX WINEARCH WH_WINDOWS_VER WINEESYNC WINEFSYNC \ STAGING_SHARED_MEMORY WINE_LARGE_ADDRESS_AWARE WH_USE_SHADER_CACHE WH_USE_WINE_DXGI \