diff --git a/home/stormux/.local/.functions/game_install_functions.sh b/home/stormux/.local/.functions/game_install_functions.sh index 4c9c9ad..f204975 100755 --- a/home/stormux/.local/.functions/game_install_functions.sh +++ b/home/stormux/.local/.functions/game_install_functions.sh @@ -317,9 +317,65 @@ prepare_wine_game_dirs() { done } +wine_dependency_state_dir() { + printf '%s\n' "${WINEPREFIX}/.stormux-installed-winetricks" +} + +wine_dependency_marker() { + local dependency="$1" + local safeDependency + + safeDependency="${dependency//[^[:alnum:]._-]/_}" + printf '%s/%s.done\n' "$(wine_dependency_state_dir)" "$safeDependency" +} + +wine_dependency_installed() { + local dependency="$1" + + [[ -f "$(wine_dependency_marker "$dependency")" ]] +} + +mark_wine_dependencies_installed() { + local dependency + local stateDir + + stateDir="$(wine_dependency_state_dir)" + mkdir -p "$stateDir" + for dependency in "$@"; do + : > "$(wine_dependency_marker "$dependency")" + done +} + +install_missing_wine_dependencies() { + local progressMessage="$1" + local forceWinetricks="${2:-false}" + local dependency + local missingDeps=() + + shift 2 + for dependency in "$@"; do + if ! wine_dependency_installed "$dependency"; then + missingDeps+=("$dependency") + fi + done + + if [[ "${#missingDeps[@]}" -eq 0 ]]; then + return 0 + fi + + if [[ "$forceWinetricks" == "true" ]]; then + WINETRICKS_FORCE=1 winetricks -q "${missingDeps[@]}" \ + | ui_progressbox "Wine Setup" "$progressMessage" + else + winetricks -q "${missingDeps[@]}" \ + | ui_progressbox "Wine Setup" "$progressMessage" + fi + mark_wine_dependencies_installed "${missingDeps[@]}" +} + install_wine_bottle() { local dep - local newBottle=false + local missingCommonDeps=() local regularDeps=() local needsSpeechsdk=false local winetricksOptions=() @@ -340,20 +396,23 @@ install_wine_bottle() { mkdir -p "$WINEPREFIX" if [[ ! -f "${WINEPREFIX}/system.reg" ]]; then - newBottle=true ui_progressbox "Wine Setup" "Initializing Wine bottle" < /dev/null DISPLAY="${DISPLAY:-}" wine wineboot -u fi prepare_wine_game_dirs - if [[ "$newBottle" == "true" ]]; then - winetricks -q isolate_home corefonts vcrun2019 win10 \ + for dep in isolate_home corefonts vcrun2019; do + if ! wine_dependency_installed "$dep"; then + missingCommonDeps+=("$dep") + fi + done + if [[ "${#missingCommonDeps[@]}" -gt 0 ]]; then + winetricks -q "${missingCommonDeps[@]}" win10 \ | ui_progressbox "Wine Setup" "Installing common Wine dependencies" - env DISPLAY="${DISPLAY:-:0}" WINETRICKS_FORCE=1 winetricks -q speechsdk \ - | ui_progressbox "Wine Setup" "Installing Wine speech support" - winetricks -q win10 \ - | ui_progressbox "Wine Setup" "Restoring Wine Windows version" + mark_wine_dependencies_installed "${missingCommonDeps[@]}" fi + install_missing_wine_dependencies "Installing Wine speech support" true speechsdk + install_missing_wine_dependencies "Restoring Wine Windows version" false win10 for dep in "$@"; do case "$dep" in @@ -361,9 +420,7 @@ install_wine_bottle() { needsSpeechsdk=true ;; corefonts|vcrun2019|isolate_home) - if [[ "$newBottle" != "true" ]]; then - regularDeps+=("$dep") - fi + regularDeps+=("$dep") ;; win7|win8|win10) : @@ -379,15 +436,25 @@ install_wine_bottle() { fi if [[ "${#regularDeps[@]}" -gt 0 ]]; then - winetricks -q isolate_home "${regularDeps[@]}" "${winetricksOptions[@]}" \ - | ui_progressbox "Wine Setup" "Installing Wine dependencies" + local missingRegularDeps=() + for dep in "${regularDeps[@]}"; do + if ! wine_dependency_installed "$dep"; then + missingRegularDeps+=("$dep") + fi + done + if [[ "${#missingRegularDeps[@]}" -gt 0 ]]; then + winetricks -q isolate_home "${missingRegularDeps[@]}" "${winetricksOptions[@]}" \ + | ui_progressbox "Wine Setup" "Installing Wine dependencies" + mark_wine_dependencies_installed isolate_home "${missingRegularDeps[@]}" + fi + elif [[ "${#winetricksOptions[@]}" -gt 0 ]]; then + winetricks -q "${winetricksOptions[@]}" \ + | ui_progressbox "Wine Setup" "Applying Wine settings" fi - if [[ "$needsSpeechsdk" == "true" && "$newBottle" != "true" ]]; then - env DISPLAY="${DISPLAY:-:0}" WINETRICKS_FORCE=1 winetricks -q speechsdk \ - | ui_progressbox "Wine Setup" "Installing Wine speech support" - winetricks -q win10 \ - | ui_progressbox "Wine Setup" "Restoring Wine Windows version" + if [[ "$needsSpeechsdk" == "true" ]]; then + install_missing_wine_dependencies "Installing Wine speech support" true speechsdk + install_missing_wine_dependencies "Restoring Wine Windows version" false win10 fi if [[ -n "${winVer:-}" ]]; then