Wine 安装与中文字体乱码修复记录
AI

Wine 安装与中文字体乱码修复记录

TomHanck4
2026-05-18 / 0 评论 / 0 阅读 / 正在检测是否收录...

Wine 安装与中文字体乱码修复记录

适用环境:Ubuntu 24.04 / amd64 / Wine 9.0。

1. 安装 Wine 和 winetricks

启用 32 位架构并安装 Wine:

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install -y --install-recommends wine winetricks

验证安装:

wine --version
winetricks --version

本机验证结果:

wine-9.0 (Ubuntu 9.0~repack-4build3)
winetricks 20240105

2. 处理 winetricks 反复弹窗

如果出现类似提示:

Running /usr/bin/wineserver -w. This will hang until all wine processes in prefix=/home/fsy/.wine terminate

并且窗口一直弹出,可以终止重复启动的 Wine / winetricks 进程:

pkill -u "$USER" -f '[w]inetricks' || true
pkill -u "$USER" -f '[w]ineserver' || true
pkill -u "$USER" -f '[w]ineboot|[w]inedevice\.exe|[s]ervices\.exe|[e]xplorer\.exe' || true

3. 确认中文字体

Ubuntu 24.04 通常已安装 fonts-noto-cjk。确认字体是否可用:

fc-match 'Noto Sans CJK SC'

期望输出类似:

NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"

如果没有该字体,可安装中文字体包:

sudo apt install -y fonts-noto-cjk fonts-wqy-microhei fonts-wqy-zenhei

4. 修复 Wine 中文菜单方块/乱码

当前 Wine 前缀为:

/home/fsy/.wine

执行以下命令,把常见 Windows 字体替换为 Noto Sans CJK SC:

export WINEPREFIX="${WINEPREFIX:-$HOME/.wine}"
export WINEDEBUG=-all

pkill -u "$USER" -f '[P]otPlayer|[p]otplayer' || true
wineserver -k || true
sleep 1

wine reg add 'HKCU\Software\Wine\Fonts\Replacements' /f >/dev/null

for name in \
  Tahoma \
  'MS Sans Serif' \
  'Microsoft Sans Serif' \
  Arial \
  'Arial Unicode MS' \
  SimSun \
  NSimSun \
  SimHei \
  FangSong \
  KaiTi \
  'Microsoft YaHei' \
  'Microsoft JhengHei' \
  'MS UI Gothic' \
  'MS Gothic' \
  Gulim \
  Dotum \
  Batang
 do
  wine reg add 'HKCU\Software\Wine\Fonts\Replacements' \
    /v "$name" \
    /t REG_SZ \
    /d 'Noto Sans CJK SC' \
    /f >/dev/null
 done

wine reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes' \
  /v 'MS Shell Dlg' \
  /t REG_SZ \
  /d 'Noto Sans CJK SC' \
  /f >/dev/null

wine reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes' \
  /v 'MS Shell Dlg 2' \
  /t REG_SZ \
  /d 'Noto Sans CJK SC' \
  /f >/dev/null

wineboot -u
wineserver -w

验证替换项:

wine reg query 'HKCU\Software\Wine\Fonts\Replacements'

应能看到类似内容:

Arial                 REG_SZ    Noto Sans CJK SC
Microsoft Sans Serif  REG_SZ    Noto Sans CJK SC
Microsoft YaHei       REG_SZ    Noto Sans CJK SC
MS Sans Serif         REG_SZ    Noto Sans CJK SC
Tahoma                REG_SZ    Noto Sans CJK SC

5. 启动中文程序

如果程序仍有局部乱码,建议显式使用中文 locale 启动:

LANG=zh_CN.UTF-8 wine /path/to/app.exe

例如 PotPlayer:

LANG=zh_CN.UTF-8 wine "$HOME/.wine/drive_c/Program Files/DAUM/PotPlayer/PotPlayerMini64.exe"

6. 说明

  • 主界面中文正常但菜单是方块,通常是菜单字体仍使用 Tahoma、MS Sans Serif 等无中文字体。
  • 上面的注册表替换会让 Wine 菜单和常见 Windows 字体回退到 Noto Sans CJK SC。
  • 如果仍然乱码,优先检查程序自身语言设置、Wine 前缀区域设置,以及是否需要安装更兼容的中文字体包。

7. 把 Wine 里的 PotPlayer 加到右键“打开方式”

Wine 安装的 Windows 程序默认不一定会出现在 Linux 文件管理器的“打开方式”列表里。可以手动创建一个 Linux 启动包装脚本和 .desktop 入口。

本机 NAS 视频位于:

smb://mynas.local/jellyfin/

文件管理器访问 SMB 时通常会通过 GVFS 挂载到:

/run/user/1000/gvfs/smb-share:server=mynas.local,share=jellyfin

PotPlayer 在 Wine 下直接接收这种 GVFS 长路径时不稳定。当前包装脚本做了三层处理:

  • 把 file:// 和 smb:// URI 转换成本机路径。
  • 把 NAS 共享根目录映射为 Wine 的 Y: 盘。
  • 双击具体视频时,把视频所在目录临时映射为 Wine 的 P: 盘,只传 P:\文件名.mp4 这种短路径给 PotPlayer。
  • 使用 /current 参数把文件投递到当前 PotPlayer 实例。

7.1 创建启动包装脚本

文件路径:

/home/fsy/.local/bin/potplayer-wine

内容:

#!/usr/bin/env bash
set -uo pipefail

export WINEPREFIX="${WINEPREFIX:-$HOME/.wine}"
export LANG="${LANG:-zh_CN.UTF-8}"
export WINEDEBUG="${WINEDEBUG:--all}"

player="$WINEPREFIX/drive_c/Program Files/DAUM/PotPlayer/PotPlayerMini64.exe"
log_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
log_file="$log_dir/potplayer-wine.log"

gvfs_root="/run/user/$(id -u)/gvfs"
nas_server="mynas.local"
nas_share="jellyfin"
nas_gvfs="$gvfs_root/smb-share:server=$nas_server,share=$nas_share"

mkdir -p "$log_dir" "$WINEPREFIX/dosdevices"
if [[ -d "$nas_gvfs" ]]; then
  ln -sfn "$nas_gvfs" "$WINEPREFIX/dosdevices/y:"
fi

resolve_to_local_path() {
  local item="$1"

  python3 - "$item" "$gvfs_root" "$nas_server" "$nas_share" <<'PY'
import os
import sys
from urllib.parse import unquote, urlparse

item = sys.argv[1]
gvfs_root = sys.argv[2]
nas_server = sys.argv[3]
nas_share = sys.argv[4]

if item.startswith("file://"):
    print(unquote(urlparse(item).path))
    raise SystemExit

if item.startswith("smb://"):
    parsed = urlparse(item)
    server = (parsed.hostname or "").lower()
    parts = [unquote(part) for part in parsed.path.split("/") if part]
    if server == nas_server.lower() and parts and parts[0].lower() == nas_share.lower():
        base = os.path.join(gvfs_root, f"smb-share:server={nas_server},share={nas_share}")
        print(os.path.join(base, *parts[1:]) if len(parts) > 1 else base)
        raise SystemExit

print(item)
PY
}

args=()
for item in "$@"; do
  resolved="$(resolve_to_local_path "$item")"

  if [[ -e "$resolved" ]]; then
    parent_dir="$(dirname "$resolved")"
    file_name="$(basename "$resolved")"
    ln -sfn "$parent_dir" "$WINEPREFIX/dosdevices/p:"
    args+=("P:\\$file_name")
  else
    args+=("$resolved")
  fi
done

{
  printf '\n[%s] argv:' "$(date '+%F %T')"
  printf ' <%s>' "$@"
  printf '\n[%s] resolved:' "$(date '+%F %T')"
  printf ' <%s>' "${args[@]}"
  printf '\n'
  ls -l "$WINEPREFIX/dosdevices/p:" 2>/dev/null || true
} >>"$log_file"

nohup wine "$player" /current "${args[@]}" >>"$log_file" 2>&1 </dev/null &
exit 0

设置执行权限:

chmod +x /home/fsy/.local/bin/potplayer-wine

日志位置:

/home/fsy/.cache/potplayer-wine.log

7.2 创建桌面应用入口

文件路径:

/home/fsy/.local/share/applications/potplayer-wine.desktop

内容:

[Desktop Entry]
Type=Application
Name=PotPlayer (Wine)
Name[zh_CN]=PotPlayer (Wine)
Comment=Play videos with PotPlayer through Wine
Comment[zh_CN]=使用 Wine 运行 PotPlayer 播放视频
Exec=/home/fsy/.local/bin/potplayer-wine %U
Icon=4845_PotPlayerMini64.0
Terminal=false
NoDisplay=false
StartupNotify=false
StartupWMClass=potplayermini64.exe
X-GNOME-UsesNotifications=false
Categories=AudioVideo;Player;Video;
MimeType=video/mp4;video/x-matroska;video/x-msvideo;video/x-ms-wmv;video/mpeg;video/quicktime;video/x-flv;video/webm;video/ogg;video/3gpp;video/3gpp2;application/ogg;application/x-matroska;

StartupNotify=false 用于避免文件管理器一直显示“正在运行”。

7.3 刷新桌面数据库并关联视频类型

update-desktop-database /home/fsy/.local/share/applications 2>/dev/null || true

xdg-mime default potplayer-wine.desktop video/mp4
xdg-mime default potplayer-wine.desktop video/x-matroska
xdg-mime default potplayer-wine.desktop video/x-msvideo
xdg-mime default potplayer-wine.desktop video/x-ms-wmv
xdg-mime default potplayer-wine.desktop video/mpeg
xdg-mime default potplayer-wine.desktop video/quicktime
xdg-mime default potplayer-wine.desktop video/webm

验证 MP4 默认打开方式:

xdg-mime query default video/mp4

期望输出:

potplayer-wine.desktop

也可以检查 GNOME/GIO 关联:

gio mime video/mp4

7.4 当前双击 NAS 文件的实际路径转换

示例输入:

/run/user/1000/gvfs/smb-share:server=mynas.local,share=jellyfin/media/新建文件夹/001极品/1 (1).mp4

包装脚本会映射视频所在目录:

/home/fsy/.wine/dosdevices/p: -> /run/user/1000/gvfs/smb-share:server=mynas.local,share=jellyfin/media/新建文件夹/001极品

并传给 PotPlayer:

PotPlayerMini64.exe /current P:\1 (1).mp4

7.5 已确认的限制

当前现象:

  • 单个 .mp4 拖进已经打开的 PotPlayer 窗口可以播放。
  • 双击 NAS 上的 .mp4 会进入包装脚本,也能转换为 P:\文件名.mp4,但 PotPlayer/Wine 仍可能不播放。

这说明文件本身和 NAS 访问权限不是主要问题;失败点在 Wine/PotPlayer 通过命令行读取 GVFS SMB 路径这一层。

如果双击仍无法稳定打开,推荐最终方案是不要依赖文件管理器的 smb:// / GVFS 挂载,而是把 NAS 用内核 CIFS 挂载到固定本地目录,例如:

/home/fsy/NAS/jellyfin

之后让文件管理器从这个真实挂载目录打开视频,Wine 会收到普通本地路径,稳定性通常明显更好。

0

评论 (0)

取消