summarylogtreecommitdiffstats
path: root/plutonium
blob: 8753de29f138a58989b494ad54afd41e1f4a9c8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
set -euo pipefail

# --- Config -------------------------------------------------------------
PREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/plutonium-wine"
PLUTODIR="${XDG_DATA_HOME:-$HOME/.local/share}/plutonium"
EXE="/opt/plutonium/plutonium.exe"
STAMP="$PREFIX/.plutonium-setup.done"

# Prefer 64-bit prefix
export WINEARCH=win64
export WINEPREFIX="$PREFIX"

# Optional performance toggles (safe to leave on)
: "${WINEESYNC:=1}"
: "${WINEFSYNC:=1}"
export WINEESYNC WINEFSYNC

mkdir -p "$PREFIX" "$PLUTODIR"

# --- Helpers ------------------------------------------------------------
have() { command -v "$1" >/dev/null 2>&1; }
log()  { printf '%s\n' "$*" >&2; }

zenity_progress_start() {
  if have zenity && [ -t 0 ] && [ -t 1 ]; then
    # If launched from a desktop, stdin/stdout might not be a TTY; still try zenity.
    :
  fi
  if have zenity; then
    # Start a background zenity progress and write to its stdin via FD 3
    exec 3> >(
      zenity --progress \
        --title="Plutonium: First-time setup" \
        --text="Preparing..." \
        --percentage=0 --auto-close --no-cancel \
        2>/dev/null
    )
    ZENITY_ON=1
  else
    ZENITY_ON=0
  fi
}

zenity_progress_step() {
  # $1 = percent int, $2 = message
  if [ "${ZENITY_ON:-0}" -eq 1 ]; then
    echo "$1" >&3
    echo "# $2" >&3
  else
    log "[setup] $2 ($1%)"
  fi
}

zenity_progress_end() {
  if [ "${ZENITY_ON:-0}" -eq 1 ]; then
    # Close the fifo
    exec 3>&-
  fi
}

run_dxvk_install() {
  if have setup_dxvk.sh; then
    WINEPREFIX="$WINEPREFIX" setup_dxvk.sh install >/dev/null 2>&1 || true
  else
    winetricks -q dxvk || true
  fi
}

first_time_setup() {
  zenity_progress_start
  zenity_progress_step 5  "Creating Wine prefix"
  wineboot -u >/dev/null 2>&1 || true

  zenity_progress_step 20 "Installing .NET 4.8 (this may take a while)"
  # dotnet48 can be slow; allow failure message for user guidance
  if ! winetricks -q --force dotnet48; then
    zenity_progress_end
    log "dotnet48 installation failed. Try: WINEPREFIX=\"$WINEPREFIX\" winetricks dotnet48"
    exit 1
  fi

  zenity_progress_step 40 "Installing Visual C++ runtime"
  # Try 2019 first, fall back to 2022; both are fine
  winetricks -q vcrun2019 || winetricks -q vcrun2022 || true

  zenity_progress_step 55 "Installing audio and fonts"
  winetricks -q xact xact_x64 || true
  winetricks -q d3dcompiler_47 corefonts || true

  zenity_progress_step 70 "Enabling DXVK"
  run_dxvk_install

  zenity_progress_step 85 "Applying Windows 10 compatibility"
  winetricks -q win10 || true

  zenity_progress_step 95 "Finalizing"
  touch "$STAMP"
  zenity_progress_end
}

# --- Main ---------------------------------------------------------------
# Only do heavy setup once per prefix
if [ ! -f "$STAMP" ]; then
  log "[plutonium] First-time setup in: $WINEPREFIX"
  first_time_setup
else
  # Lightweight prefix sanity each run
  wineboot -u >/dev/null 2>&1 || true
fi

log "[plutonium] Launching Plutonium..."
exec wine "$EXE" "$@"