This commit is contained in:
2024-10-07 20:10:23 +05:00
parent 11dff46137
commit 38e880d3af
6 changed files with 143 additions and 110 deletions

View File

@ -186,6 +186,7 @@ eval_translations () {
}
create_translations () {
local po_file msgid msgstr
if [[ ! -d "${PW_CACHE_LANG_PATH}" ]] ; then
create_new_dir "${PW_CACHE_LANG_PATH}"
fi
@ -456,12 +457,13 @@ try_download () {
no_mirror=true
esac
local filename
if [[ -n "${PW_AUTOINSTALL_EXE}" ]] \
&& [[ "$no_mirror" == "true" ]]
then
local filename="$(basename "${PW_AUTOINSTALL_EXE}")"
filename="$(basename "${PW_AUTOINSTALL_EXE}")"
else
local filename="$(basename "$1")"
filename="$(basename "$1")"
fi
if [[ "${MIRROR}" == CLOUD ]] \
@ -778,6 +780,9 @@ debug_timer () {
# Поиск нужного .desktop файла по $portwine_exe
search_desktop_file () {
local count desktop_file desktop_file_new EXEC_DESKTOP EXEC_DESKTOP_NEW TIME_TOTAL i j df
unset TIME_CURRENT_ARRAY DESKTOP_FILES_ARRAY
count=0
for desktop_file in "$PORT_WINE_PATH"/* ; do
desktop_file_new="${desktop_file//"$PORT_WINE_PATH/"/}"
if [[ $desktop_file_new =~ .desktop ]] ; then
@ -789,89 +794,117 @@ search_desktop_file () {
else
EXEC_DESKTOP=${line//Exec=env \"$PORT_SCRIPTS_PATH\/start.sh\" /}
fi
EXEC_DESKTOP_NEW="${EXEC_DESKTOP//\"/}"
EXEC_DESKTOP_NEW=${EXEC_DESKTOP//\"/}
fi
if [[ $line =~ ^#Time= ]] ; then
if [[ $portwine_exe == "$EXEC_DESKTOP_NEW" ]] ; then
TIME_CURRENT=${line//#Time=/}
fi
if [[ $line =~ ^#Time= ]] && [[ $portwine_exe == "$EXEC_DESKTOP_NEW" ]] ; then
TIME_CURRENT=${line//#Time=/}
fi
done < "$desktop_file"
if [[ $portwine_exe == "$EXEC_DESKTOP_NEW" ]] ; then
if [[ ! $TIME_CURRENT =~ [0-9]+ ]] ; then
# Когда новый .desktop файл
if [[ $TIME_CURRENT == "" ]] ; then
echo "#NEW_DESKTOP" >> "$desktop_file"
TIME_CURRENT="0"
# Для битых #Time=
elif [[ ! $TIME_CURRENT == "" ]] && [[ ! $TIME_CURRENT =~ [0-9]+ ]] ; then
TIME_CURRENT="0"
sed -i '/^#Time=/d' "$desktop_file"
echo "#Time=0" >> "$desktop_file"
fi
if [[ -n $PW_TIME_IN_GAME ]] ; then
TIME_TOTAL=$(( TIME_CURRENT + PW_TIME_IN_GAME ))
sed -i '/^#Time=/d' "$desktop_file"
echo "#Time=$TIME_TOTAL" >> "$desktop_file"
fi
TIME_CURRENT_ARRAY+=($TIME_CURRENT)
unset TIME_CURRENT
DESKTOP_FILES_ARRAY["$count"]="$desktop_file"
(( count++ ))
fi
fi
fi
done
IFS="$orig_IFS"
# Если существуют .desktop файлы на один и тот же .exe файл, то среди них выбирается
# текущее время берётся из того .desktop файла, в котором проведено больше времени
# и запись этого большего времени будет потом записываться во все .desktop файлы
# у которых общий .exe файл, это нужно для того, чтобы в главном меню .desktop файлы
# упорядочивались нормально.
for i in "${!TIME_CURRENT_ARRAY[@]}" ; do
for j in "${!TIME_CURRENT_ARRAY[@]}" ; do
if (( ${TIME_CURRENT_ARRAY[$i]} > ${TIME_CURRENT_ARRAY[$j]} )) ; then
tmp=${TIME_CURRENT_ARRAY[$i]}
TIME_CURRENT_ARRAY[i]=${TIME_CURRENT_ARRAY[$j]}
TIME_CURRENT_ARRAY[j]=$tmp
fi
done
done
TIME_CURRENT="${TIME_CURRENT_ARRAY[0]}"
if [[ -n $PW_TIME_IN_GAME ]] ; then
TIME_TOTAL=$(( TIME_CURRENT + PW_TIME_IN_GAME ))
for df in "${DESKTOP_FILES_ARRAY[@]}" ; do
sed -i '/^#Time=/d' "$df"
echo "#Time=$TIME_TOTAL" >> "$df"
done
else
for df in "${DESKTOP_FILES_ARRAY[@]}" ; do
sed -i '/^#Time=/d' "$df"
echo "#Time=$TIME_CURRENT" >> "$df"
done
fi
}
# Конвертация секунд в дни, часы, минуты
seconds_to_time () {
[[ -z $1 ]] && return 0
local seconds=$1
local seconds days hours minutes
seconds=$1
local days=$((seconds / (60 * 60 * 24)))
local seconds=$((seconds % (60 * 60 * 24)))
days=$((seconds / (60 * 60 * 24)))
seconds=$((seconds % (60 * 60 * 24)))
local hours=$((seconds / (60 * 60)))
local seconds=$((seconds % (60 * 60)))
hours=$((seconds / (60 * 60)))
seconds=$((seconds % (60 * 60)))
local minutes=$((seconds / 60))
local seconds=$((seconds % 60))
minutes=$((seconds / 60))
seconds=$((seconds % 60))
if [[ $days =~ ^0$ ]] ; then
local days=
days=
elif [[ $days =~ ^1$ ]] ; then
local days="$days ${translations[day]}, "
days="$days ${translations[day]}, "
elif [[ $days =~ ^([2-9]1|[1-9][0-9]+1)$ ]] && [[ $LANGUAGE == ru ]] ; then
local days="$days ${translations[day]}, "
elif [[ $days =~ ^([2-4]|[2-9][2-4]|[1-9][0-9]+[2-4])$ ]] \
&& [[ $LANGUAGE == ru ]] ; then
local days="$days дня, "
days="$days ${translations[day]}, "
elif [[ $days =~ ^([2-4]|[2-9][2-4]|[1-9][0-9]+[2-4])$ ]] && [[ $LANGUAGE == ru ]] ; then
days="$days дня, "
else
local days="$days ${translations[days]}, "
days="$days ${translations[days]}, "
fi
if [[ $hours =~ ^0$ ]] ; then
local hours=
hours=
elif [[ $hours =~ ^1$ ]] ; then
local hours="$hours ${translations[hour]} ${translations[and]} "
hours="$hours ${translations[hour]} ${translations[and]} "
elif [[ $hours =~ ^([2-4]|2[2-4])$ ]] && [[ $LANGUAGE == ru ]] ; then
local hours="$hours часа ${translations[and]} "
hours="$hours часа ${translations[and]} "
elif [[ $hours =~ ^21$ ]] && [[ $LANGUAGE == ru ]] ; then
local hours="$hours ${translations[hour]} ${translations[and]} "
hours="$hours ${translations[hour]} ${translations[and]} "
else
local hours="$hours ${translations[hours]} ${translations[and]} "
hours="$hours ${translations[hours]} ${translations[and]} "
fi
if [[ $minutes =~ ^0$ ]] ; then
local hours=${hours//" ${translations[and]} "/}
local minutes=
hours=${hours//" ${translations[and]} "/}
minutes=
if [[ $days == "" ]] || [[ $hours == "" ]] ; then
local days=${days//","/}
days=${days//","/}
fi
if [[ $days == "" ]] && [[ $hours == "" ]] ; then
local minutes="${translations[not known yet]}"
minutes="${translations[less than a minute]}"
fi
elif [[ $minutes =~ ^1$ ]] ; then
local minutes="$minutes ${translations[minute]}"
minutes="$minutes ${translations[minute]}"
elif [[ $minutes =~ ^[2-5]1$ ]] && [[ $LANGUAGE == ru ]] ; then
local minutes="$minutes ${translations[minute]}"
minutes="$minutes ${translations[minute]}"
elif [[ $minutes =~ ^([2-4]|[2-5][2-4])$ ]] && [[ $LANGUAGE == ru ]] ; then
local minutes="$minutes минуты"
minutes="$minutes минуты"
else
local minutes="$minutes ${translations[minutes]}"
minutes="$minutes ${translations[minutes]}"
fi
echo -e "<b>\n${translations[Time spent]}: $days$hours$minutes</b>"
@ -882,32 +915,34 @@ combobox_fix () {
print_error "no argument specified for combobox_fix"
return 1
else
local name1 name2
if [[ "$1" == "--disabled" ]] ; then
if [[ -z "$3" ]] ; then
echo "disabled"
return 0
fi
local name1="$2"
local name2="$3"
name1="$2"
name2="$3"
elif [[ "$1" == "--empty" ]] ; then
if [[ -z "$3" ]] ; then
echo ""
return 0
fi
local name1="$2"
local name2="$3"
name1="$2"
name2="$3"
else
local name1="$1"
name1="$1"
if [[ -z "$2" ]] ; then
echo "${name1}"
return 0
fi
local name2="$2"
name2="$2"
fi
local name3="${name2//\!${name1}\!/\!}"
local name3="!${name3//${name1}\!/\!}"
local name3="${name3//\!\!/\!}"
local name4="${name3//*\!/}"
local name3 name4
name3="${name2//\!${name1}\!/\!}"
name3="!${name3//${name1}\!/\!}"
name3="${name3//\!\!/\!}"
name4="${name3//*\!/}"
if [[ ${name1} == "${name4}" ]] || [[ ${name1} == "\\${name4}" ]]
then name3="${name3%\!"${name1}"}"
fi
@ -2320,14 +2355,12 @@ pw_find_exe () {
--button="${translations[CANCEL]}"!"$PW_GUI_ICON_PATH/$BUTTON_SIZE.png":1 \
--button="${translations[OK]}"!"$PW_GUI_ICON_PATH/$BUTTON_SIZE.png":0 2>/dev/null)"
YAD_STATUS="$?"
if [[ "$YAD_STATUS" == "1" || "$YAD_STATUS" == "252" ]] ; then
if [[ -z "${PW_SET_FIND_EXE}" ]] ; then
print_info "Restarting..."
restart_pp
fi
exit 0
fi
IFS="$orig_IFS"
if [[ "$YAD_STATUS" == "1" || "$YAD_STATUS" == "252" ]] ; then
print_info "Restarting..."
restart_pp
fi
if [[ -n "${PW_SET_FIND_EXE}" ]] ; then
portwine_exe="${PW_PATH_FOR_FIND}$(echo "${PW_SET_FIND_EXE}" | awk -F'|' '{print $1}')"
@ -5483,6 +5516,7 @@ portwine_create_shortcut () {
fi
elif [[ "$PW_YAD_OUT" == "2" ]] ; then
print_info "Restarting PP..."
[[ -n $KEY_MENU ]] && unset portwine_exe
[[ "${PW_GUI_START}" == "NOTEBOOK" ]] && unset PW_YAD_FORM_TAB
restart_pp
fi
@ -5511,7 +5545,7 @@ pw_auto_create_shortcut () {
[[ -z "${LINKS[0]}" ]] && return 0
SORTED_LINKS=()
while IFS= read -r line ; do
SORTED_LINKS+=("$line");
SORTED_LINKS+=("$line")
done < <(echo ${LINKS[@]} | tr ' ' '\n' | sort -u)
IFS="$orig_IFS"
@ -5562,6 +5596,7 @@ pw_auto_create_shortcut () {
PORTPROTON_NAME="$link_name"
export portwine_exe="$exe_path"
resize_png "$portwine_exe" "${PORTPROTON_NAME}" "128"
export PW_NO_RESTART_PPDB=1
portwine_create_shortcut
fi
done
@ -6002,8 +6037,8 @@ button_click () {
kill -s SIGUSR1 $(pgrep -a yad | grep "\--key=${KEY_MENU}" | awk '{print $1}') > /dev/null 2>&1
PW_YAD_SET="${PORT_WINE_PATH}/${PW_YAD_SET//#@_@#/ }"
if [[ -n $PW_DESKTOP_FILES_REGEX ]] ; then
count=1
for y in ${PW_DESKTOP_FILES_REGEX[@]} ; do
local count=1
for y in "${PW_DESKTOP_FILES_REGEX[@]}" ; do
PW_YAD_SET="${PW_YAD_SET//#+_$count#/$y}"
(( count++ ))
done