Fix: Resolve the Desktop, Downloads and home shortcuts on Unix clients
The file manager's remote shortcut buttons send "%USERPROFILE%\Desktop\" and friends, which the Windows client expands with ExpandEnvironmentStringsA. Unix clients had no such expansion, so the literal %USERPROFILE% was taken as a directory name: opendir() failed and the Desktop, Downloads and home buttons listed nothing at all. Add common/UnixPath.h, which expands the variables the server can send (%USERPROFILE%, %HOME%, %HOMEDRIVE%%HOMEPATH%, %USERNAME%) and maps $HOME/Desktop to the localized folder named in ~/.config/user-dirs.dirs (for example ~/桌面), falling back to the plain $HOME/<Name> path when that folder does not exist. Unknown %VAR% tokens are left untouched, so paths that really contain a percent sign behave as before. FileManager and the two Windows-to-Unix converters in FileTransferV2 now share that one conversion. Besides the listing itself, this fixes downloads into a shortcut directory, which used to be created under a literal %USERPROFILE% tree instead of the user's real desktop. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
6bfa4294cc
commit
106ac2ff0f
3 files changed
+227
-57
No files matched your search
+9
-31
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "commands.h"
|
||||
#include "file_upload.h"
|
||||
#include "UnixPath.h"
|
||||
#include "../client/IOCPClient.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -230,20 +231,11 @@ public:
|
||||
}
|
||||
savePath += relPath;
|
||||
} else {
|
||||
// 服务端传输:使用相对路径
|
||||
// 将 Windows 路径转换为 Linux 路径
|
||||
savePath = fileName;
|
||||
for (char& c : savePath) {
|
||||
if (c == '\\') c = '/';
|
||||
}
|
||||
// 移除盘符前缀 (如 C:/)——只认「字母 + 冒号」,否则 /:data 这类合法路径会被改写
|
||||
if (savePath.size() >= 3 && isalpha((unsigned char)savePath[0]) && savePath[1] == ':' && savePath[2] == '/') {
|
||||
savePath = savePath.substr(2);
|
||||
}
|
||||
// 确保以 / 开头
|
||||
if (savePath.empty() || savePath[0] != '/') {
|
||||
savePath = "/" + savePath;
|
||||
}
|
||||
// 服务端传输:用服务端下发的绝对路径。
|
||||
// 快捷按钮(桌面/下载/用户主页)下发的目标目录是 %USERPROFILE%\...,
|
||||
// 由 WinPathToLinux 展开(见 UnixPath.h),与 Windows 上
|
||||
// ExpandEnvironmentStringsA 的效果一致。
|
||||
savePath = WinPathToLinux(fileName);
|
||||
}
|
||||
|
||||
// 目录处理
|
||||
@@ -438,25 +430,11 @@ public:
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
// Windows 路径转 Linux 路径
|
||||
// Windows 路径转 Linux 路径。服务端对话框的快捷按钮(桌面/下载/用户主页)下发的是
|
||||
// %USERPROFILE%\Desktop\ 这类 Windows 变量路径,必须先展开(见 UnixPath.h)。
|
||||
static std::string WinPathToLinux(const std::string& winPath)
|
||||
{
|
||||
std::string p = winPath;
|
||||
// 1. 反斜杠 -> 正斜杠
|
||||
for (auto& c : p) {
|
||||
if (c == '\\') c = '/';
|
||||
}
|
||||
// 2. 移除 "X:/" 或 "X:" 前缀
|
||||
if (p.size() >= 3 && p[1] == ':' && p[2] == '/') {
|
||||
p = p.substr(3);
|
||||
} else if (p.size() >= 2 && p[1] == ':') {
|
||||
p = p.substr(2);
|
||||
}
|
||||
// 3. 确保以 / 开头
|
||||
if (p.empty() || p[0] != '/') {
|
||||
p = "/" + p;
|
||||
}
|
||||
return p;
|
||||
return UnixPath::ToUnixPath(winPath);
|
||||
}
|
||||
|
||||
// errno -> Win32 错误码:服务端 TOKEN_DOWNLOAD_ERROR 按 Win32 码分类
|
||||
|
||||
Reference in new issue
Block a user