Merge branch 'improve_reg_func' of github.com:Htylol/PortWINE into Htylol-improve_reg_func

This commit is contained in:
Mikhail Tergoev
2024-11-08 17:15:04 +03:00
7 changed files with 139 additions and 61 deletions

View File

@ -1267,65 +1267,87 @@ combobox_fix () {
}
get_and_set_reg_file () {
local name_block name_for_find find_block find_file find_line count name_for_new_block
local line_reg find_number_line find_check_file name_for_set name_block_old
local name_block name_for_find find_block find_file find_line count name_for_new_block name_for_find_old
local line_reg find_number_line find_check_file name_for_set name_type_reg name_fatal name_add_or_del
name_add_or_del=$1
name_block=$2
name_block_old=$name_block
name_for_find=$3
name_for_set=$4
name_for_new_block=$5
name_block=${name_block//\\/\\\\}
name_block=${name_block//\[/\\[}
find_block=$(grep -n "${name_block//\]/\\]}" "${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/"*.reg)
name_type_reg=$4
name_for_set=$5
name_for_new_block=$6
name_for_find_old=$name_for_find
name_fatal="$name_block $name_for_find"
case $name_type_reg in
REG_DWORD)
name_for_find='"'"$name_for_find"'"'"=dword:"
name_for_set=$(convert_dec_and_hex --dec "$name_for_set") ;;
REG_SZ)
name_for_find='"'"$name_for_find"'"'"="
name_for_set='"'"$name_for_set"'"' ;;
*)
if [[ $name_add_or_del == --delete ]] ; then
name_for_find='"'"$name_for_find"'"'
else
print_error "Name type reg not set for $name_fatal"
return 1
fi ;;
esac
name_block=${name_block//\\/\\\\\\\\\\\\\\}
name_block=${name_block//*/\\[$name_block}
name_block="${name_block//*/${name_block//\\/\\\\}\\]}"
if [[ -n $name_for_new_block ]] ; then
find_block=$(grep -n "$name_block" "${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg")
else
find_block=$(grep -n "$name_block" "${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/"*.reg)
fi
if [[ -n $find_block ]] ; then
find_file=${find_block//:*/}
find_line=${find_block//$find_file:/}
find_line=${find_line//:*/}
if [[ -n $name_for_new_block ]] ; then
find_file="${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg"
find_line=${find_block//:*/}
else
find_file=${find_block//:*/}
find_line=${find_block//$find_file:/}
find_line=${find_line//:*/}
fi
count=-1
while IFS= read -r line_reg ; do
((count++))
if [[ $line_reg =~ $name_for_find ]] ; then
if [[ $line_reg == $name_for_find$name_for_set ]] ; then
# когда менять не нужно, потому что такое же
return 0
fi
find_number_line=$(( count + find_line ))
find_check_file=1
break
fi
[[ -z $line_reg ]] && break
done <<< $(sed -n "$find_line"',$p' $find_file)
done <<< "$(sed -n "$find_line"',$p' "$find_file")"
IFS="$orig_IFS"
fi
if [[ $1 == --add ]] ; then
if [[ $name_add_or_del == --add ]] ; then
if [[ -z $find_block ]] ; then
if [[ -n $name_for_new_block ]] ; then
sed -i '$a\\n'"${name_block_old//\\/\\\\}" "${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg"
find_file=${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg
sed -i '$a\\n'"$name_block\n" "${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg"
find_file="${PORT_WINE_PATH}/data/prefixes/${PW_PREFIX_NAME}/$name_for_new_block.reg"
find_line=$(wc -l "$find_file" | awk -F" " '{print $1}')
find_line=$(( find_line - 1 ))
else
print_error "$name_block_old not found in reg files"
print_error "$name_fatal not found in reg files"
return 1
fi
fi
if [[ $name_for_set =~ ^[0-9]+$ ]] ; then
name_for_set=$(convert_dec_and_hex --dec "$name_for_set")
fi
if [[ ! $name_for_set =~ ^[0-9]+$ ]] ; then
if [[ $find_check_file == 1 ]] ; then
sed -i "${find_number_line}s/$name_for_find.*/$name_for_find\"$name_for_set\"/" "$find_file"
else
print_info "Added ${name_for_find//=*} to reg file"
sed -i "$(( find_line + 1 ))"'a\\n'"$name_for_find\"$name_for_set\"" "$find_file"
fi
if [[ $find_check_file == 1 ]] ; then
print_info "Change $name_for_find_old to reg file"
sed -i "${find_number_line}s/$name_for_find.*/$name_for_find$name_for_set/" "$find_file"
else
if [[ $find_check_file == 1 ]] ; then
sed -i "${find_number_line}s/$name_for_find.*/$name_for_find$name_for_set/" "$find_file"
else
print_info "Added ${name_for_find//=*} to reg file"
sed -i "$(( find_line + 1 ))"'a\\n'"$name_for_find$name_for_set" "$find_file"
fi
print_info "Added $name_for_find_old to reg file"
sed -i "$(( find_line + 1 ))a$name_for_find$name_for_set" "$find_file"
fi
elif [[ $1 == --delete ]] ; then
elif [[ $name_add_or_del == --delete ]] ; then
[[ $find_check_file != 1 ]] && return 0
print_info "Delete ${name_for_find//=*} to reg file"
print_info "Delete $name_for_find_old to reg file"
sed -i "${find_number_line}d" "$find_file"
fi
}
@ -1337,7 +1359,7 @@ convert_dec_and_hex () {
case "$type" in
--dec)
# Преобразование из десятичного в шестнадцатеричный
echo -n $(printf "%08x" $num) ;;
echo -n "$(printf "%08x" "$num")" ;;
--hex)
# Преобразование из шестнадцатеричного в десятичный
echo $(( 0x$num )) ;;
@ -1346,6 +1368,32 @@ convert_dec_and_hex () {
esac
}
recommend_dpi () {
local height=$1
if [[ -z "$height" ]] ; then
echo "disabled"
return 1
fi
local dpi=$(( height / 9 ))
echo "$dpi"
}
fixes_after_update () {
local fixes_path line fixes_info IFS
fixes_info=$1
fixes_path="$PORT_WINE_TMP_PATH/fixes_apply"
[[ ! -f $fixes_path ]] && touch "$fixes_path"
while IFS= read -r line ; do
if [[ $line == "$fixes_info" ]] ; then
return 1
fi
done < "$fixes_path"
echo "$fixes_info" >> "$fixes_path"
return 0
}
restart_pp () {
case "$1" in
--userconf) export RESTART_PP_USED="userconf" ;;
@ -3758,28 +3806,33 @@ start_portwine () {
fi
if [[ "$PW_DINPUT_PROTOCOL" == "1" ]] ; then
get_and_set_reg_file --add '[System\\CurrentControlSet\\Services\\winebus]' '"DisableHidraw"=dword:' "0"
get_and_set_reg_file --add '[System\\CurrentControlSet\\Services\\winebus]' '"Enable SDL"=dword:' "0"
get_and_set_reg_file --add 'System\CurrentControlSet\Services\winebus' 'DisableHidraw' 'REG_DWORD' "0" "system"
get_and_set_reg_file --add 'System\CurrentControlSet\Services\winebus' 'Enable SDL' 'REG_DWORD' "0" "system"
else
get_and_set_reg_file --add '[System\\CurrentControlSet\\Services\\winebus]' '"DisableHidraw"=dword:' "1"
get_and_set_reg_file --add '[System\\CurrentControlSet\\Services\\winebus]' '"Enable SDL"=dword:' "1"
get_and_set_reg_file --add 'System\CurrentControlSet\Services\winebus' 'DisableHidraw' 'REG_DWORD' "1" "system"
get_and_set_reg_file --add 'System\CurrentControlSet\Services\winebus' 'Enable SDL' 'REG_DWORD' "1" "system"
fi
if [[ "$PW_WINE_DPI_VALUE" != "disabled" ]] ; then
get_and_set_reg_file --add '[Control Panel\\Desktop]' '"LogPixels"=dword:' "${PW_WINE_DPI_VALUE// (*/}"
if [[ "$PW_WINE_DPI_VALUE" == "recommended" ]] ; then
PW_RECOMMENDED_DPI=$(recommend_dpi "${PW_SCREEN_RESOLUTION:5:8}")
get_and_set_reg_file --add 'Control Panel\Desktop' 'LogPixels' 'REG_DWORD' "$PW_RECOMMENDED_DPI" "user"
else
get_and_set_reg_file --add 'Control Panel\Desktop' 'LogPixels' 'REG_DWORD' "$PW_WINE_DPI_VALUE" "user"
fi
fi
if [[ "$PW_USE_NATIVE_WAYLAND" == "1" ]] ; then
export PW_DISPLAY="env DISPLAY="
export PW_USE_RUNTIME="0"
get_and_set_reg_file --add '[Software\\Wine\\Drivers]' '"Graphics"=' "x11,wayland" "user"
get_and_set_reg_file --add 'Software\Wine\Drivers' 'Graphics' 'REG_SZ' "x11,wayland" "user"
else
unset PW_DISPLAY
get_and_set_reg_file --delete '[Software\\Wine\\Drivers]' '"Graphics"=' "x11,wayland"
get_and_set_reg_file --delete 'Software\Wine\Drivers' 'Graphics'
fi
if [[ "$PW_SOUND_DRIVER_USE" != "disabled" ]] ; then
get_and_set_reg_file --add '[Software\\Wine\\Drivers]' '"Audio"=' "$PW_SOUND_DRIVER_USE" "user"
get_and_set_reg_file --add 'Software\Wine\Drivers' 'Audio' 'REG_SZ' "$PW_SOUND_DRIVER_USE" "user"
fi
pw_stop_progress_bar
@ -5611,6 +5664,9 @@ gui_userconf () {
SORT_WITH_TIME="enabled"
fi
if [[ $PW_WINE_DPI_VALUE == "recommended" ]] ; then
PW_WINE_DPI_VALUE="${translations[Recommended value]}"
fi
if [[ -n "$PW_WINE_DPI_VALUE" ]] \
&& [[ "$PW_WINE_DPI_VALUE" != "disabled" ]]
then
@ -5619,10 +5675,10 @@ gui_userconf () {
YAD_DPI_VAR="disabled"
fi
"${pw_yad}" --plug=$KEY_USERCONF_GUI --tabnum="2" --form --columns=1 --separator="@" --homogeneous-row \
"${pw_yad}" --plug=$KEY_USERCONF_GUI --tabnum="2" --form --columns=1 --separator="%" --homogeneous-row \
--gui-type-text="$PANED_GUI_TYPE_TEXT_DOWN" --gui-type-layout="$PANED_GUI_TYPE_LAYOUT_DOWN" \
--field="${translations[Choose a graphics card to run the game]}!${translations[Select which video card will be used to run the game (used for all running games and programs in PortProton)]} :CB" "$(combobox_fix --disabled "$GPU_VAR" "$GET_GPU_NAMES")" \
--field="${translations[Force dpi for fonts]}!${translations[Here you can set forced dpi for fonts in wine]} :CB" "$(combobox_fix --disabled "$YAD_DPI_VAR" "96 (100%)!120 (125%)!144 (150%)!168 (175%)!192 (200%)!216 (225%)!240 (250%)!264 (275%)!288 (300%)")" \
--field="${translations[Force dpi]}!${translations[Here you can set forced dpi for applications wine]} :CB" "$(combobox_fix --disabled "$YAD_DPI_VAR" "${translations[Recommended value]}!96!120!144!168!192!216!240!264!288")" \
--field="${translations[Choice wine audio driver]}!${translations[Fixes sound popling if choice alsa]} :CB" "$(combobox_fix --disabled "$SOUND_DRIVER_VAR" "alsa!oss!pulse")" \
--field="${translations[Choice gui themes]}!${translations[Allows you to select a theme for PortProton]} :CB" "$(combobox_fix "$GUI_THEME" "default!compact!classic")" \
--field="${translations[Time display]}!${translations[Displays time spent in an application or game]} :CB" "$(combobox_fix --disabled "$DESKTOP_WITH_TIME" "enabled")" \
@ -5657,10 +5713,13 @@ gui_userconf () {
gui_open_user_conf
;;
166)
IFS='@' read -r -a PW_ADD_SETTINGS_UC <"${PW_TMPFS_PATH}/tmp_yad_userconf_set_cb"
IFS='%' read -r -a PW_ADD_SETTINGS_UC <"${PW_TMPFS_PATH}/tmp_yad_userconf_set_cb"
IFS="$orig_IFS"
PW_GPU_USE="${PW_ADD_SETTINGS_UC[0]}"
PW_WINE_DPI_VALUE="${PW_ADD_SETTINGS_UC[1]}"
if [[ $PW_WINE_DPI_VALUE == "${translations[Recommended value]}" ]] ; then
PW_WINE_DPI_VALUE="recommended"
fi
PW_SOUND_DRIVER_USE="${PW_ADD_SETTINGS_UC[2]}"
GUI_THEME="${PW_ADD_SETTINGS_UC[3]}"
DESKTOP_WITH_TIME="${PW_ADD_SETTINGS_UC[4]}"

View File

@ -18,7 +18,7 @@ then
pw_kill_autostart launcher.exe 3 &
pw_run "${PW_AUTOINSTALL_EXE}"
portwine_exe="${WINEPREFIX}/drive_c/users/$USER/AppData/Local/Crossout/launcher.exe"
pw_run reg add "HKEY_CURRENT_USER\Software\Wine\X11 Driver" /v "Decorated" /t REG_SZ /d "N" /f
get_and_set_reg_file --add 'Software\Wine\X11' 'Decorated' 'REG_SZ' "N" "user"
pw_create_unique_exe "crossout_launcher_pp"
try_remove_file "${PW_AUTOINSTALL_EXE}"
try_remove_file "${portwine_exe}.ppdb"

View File

@ -20,7 +20,7 @@ then
export PATH_TO_GAME="${PW_USER_TEMP}"
pw_run "${PW_AUTOINSTALL_EXE}"
export portwine_exe="$WINEPREFIX/drive_c/Program Files/HoYoPlay/launcher.exe"
pw_run reg add "HKEY_CURRENT_USER\Software\Wine\X11 Driver" /v "Decorated" /t REG_SZ /d "N" /f
get_and_set_reg_file --add 'Software\Wine\X11' 'Decorated' 'REG_SZ' "N" "user"
pw_create_unique_exe "hoyoplay_launcher_pp"
try_remove_file "${PW_AUTOINSTALL_EXE}"
try_remove_file "${portwine_exe}.ppdb"

View File

@ -248,6 +248,17 @@ if [[ ! $PW_GUI_START =~ (PANED|NOTEBOOK) ]] ; then
export PW_GUI_START="NOTEBOOK"
fi
# TODO:fixes_after_update
if fixes_after_update "2371: Reset PW_WINE_DPI_VALUE in user.conf" ; then
sed -i '/export PW_WINE_DPI_VALUE=/d' "$USER_CONF"
unset PW_WINE_DPI_VALUE
fi
# choose wine dpi default
if [[ -z $PW_WINE_DPI_VALUE ]] ; then
echo 'export PW_WINE_DPI_VALUE="recommended"' >> "$USER_CONF"
export PW_WINE_DPI_VALUE="recommended"
fi
if check_flatpak ; then
if check_gamescope_session
then PW_TERM="env LANG=C xterm -fullscreen -bg black -fg white -e"