Wine 应用调用系统 Dolphin 文件管理器

Wine 应用调用系统 Dolphin 文件管理器#

适用场景#

在 Wine 环境(如企业微信)中,点击"打开文件夹"或"打开文件所在位置"时,默认会调用 Windows 的 explorer.exe,在 Wine 下体验很差。本教程让 Wine 直接调用系统的 Dolphin 文件管理器,并正确转换 Windows 路径。

操作步骤#

1. 创建转换脚本#

mkdir -p ~/.local/bin

创建 ~/.local/bin/wine-dolphin.sh,内容如下:

#!/bin/bash
# Wine 路径转真实路径后调用 Dolphin
# 处理 Windows 传入的参数,如:
#   "C:\path\to\folder"
#   /select,"C:\path\to\file"
WINEPREFIX="$HOME/.local/wecom"

# 合并所有参数,去除多余空格和引号
raw="$*"
# 去除首尾空白
raw="${raw#"${raw%%[![:space:]]*}"}"
raw="${raw%"${raw##*[![:space:]]}"}"

# 检测 /select, 模式
select_mode=false
if [[ "$raw" =~ ^/select, ]]; then
    select_mode=true
    raw="${raw#/select,}"
    # 去掉可能存在的空格、引号
    raw="${raw#"${raw%%[![:space:]]*}"}"
    raw="${raw#"\'"}"
    raw="${raw%"\'"}"
    raw="${raw#\"}"
    raw="${raw%\"}"
fi

# 去掉外部引号
raw="${raw#\"}"
raw="${raw%\"}"

# winepath 转换
realpath=$(winepath -u "$raw" 2>/dev/null)
if [ -n "$realpath" ] && [ -d "$(dirname "$realpath" 2>/dev/null)" ]; then
    if $select_mode; then
        exec dolphin --select "$realpath"
    else
        exec dolphin "$realpath"
    fi
fi

# fallback: 手动转换 Windows 路径
fallback=$(echo "$raw" | sed 's|^[cC]:||;s|\\|/|g')
fulldir="$WINEPREFIX/drive_c$fallback"
if [ -d "$(dirname "$fulldir" 2>/dev/null)" ]; then
    if $select_mode; then
        exec dolphin --select "$fulldir"
    else
        exec dolphin "$fulldir"
    fi
fi

# 最差情况:直接传给 dolphin
exec dolphin "$raw"

添加可执行权限:

chmod +x ~/.local/bin/wine-dolphin.sh

2. 注册到 Wine 注册表#

对目标 Wine 前缀(本例为企业微信 ~/.local/wecom)执行:

# 让文件夹"打开"操作调用 Dolphin
WINEPREFIX=~/.local/wecom wine reg add "HKEY_CLASSES_ROOT\Folder\shell\open\command" /ve /d "/home/sa/.local/bin/wine-dolphin.sh \"%1\"" /f

# 让 explorer.exe 调用 Dolphin(兼容"打开文件所在位置"等操作)
WINEPREFIX=~/.local/wecom wine reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\explorer.exe" /ve "/home/sa/.local/bin/wine-dolphin.sh" /f

如果 Wine 前缀路径不同,将 ~/.local/wecom 替换为你的实际路径,并将脚本中的 WINEPREFIX 变量也同步修改。

3. 验证#

重启 Wine 应用(如企业微信),找到任意文件点击"打开文件夹"或"打开文件所在位置",应该会直接弹出系统的 Dolphin 文件管理器。

原理说明#

Windows 行为对应注册表路径脚本处理
右键文件夹 → 打开Folder\shell\open\command直接用 winepath -u 转换路径后打开
应用内"打开文件位置"App Paths\explorer.exe解析 /select,"路径" 参数,用 dolphin --select 打开并选中文件

脚本通过 winepath -u 将 Windows 路径(如 C:\Users\sa\Documents\...)转换为真实 Linux 路径(如 /home/sa/.local/wecom/drive_c/users/sa/Documents/...),再传给 Dolphin。

自定义其他 Wine 前缀#

如果需要为其他 Wine 应用也启用此功能,复制脚本并修改 WINEPREFIX 即可:

# 例如为另一个 Wine 前缀创建配置
cp ~/.local/bin/wine-dolphin.sh ~/.local/bin/wine-dolphin-wx.sh
# 编辑脚本,将 WINEPREFIX 改为对应路径

# 注册到对应的 Wine 前缀
WINEPREFIX=/path/to/other/wineprefix wine reg add ...