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
+4
-26
@@ -36,6 +36,7 @@
|
||||
|
||||
// FileTransferV2 is in the same directory (common/)
|
||||
#include "FileTransferV2.h"
|
||||
#include "UnixPath.h"
|
||||
|
||||
// External declaration of clientID (defined in main.cpp/main.mm)
|
||||
extern uint64_t g_myClientID;
|
||||
@@ -186,34 +187,11 @@ private:
|
||||
// /:\ -> /
|
||||
// /: -> /
|
||||
// C:\Users\file.txt -> /Users/file.txt
|
||||
// %USERPROFILE%\Desktop\ -> /home/user/Desktop/ (or the XDG desktop folder)
|
||||
static std::string winPathToLinux(const char* winPath)
|
||||
{
|
||||
if (!winPath || !*winPath) return "/";
|
||||
|
||||
std::string p(winPath);
|
||||
// 1. Backslash -> forward slash
|
||||
for (auto& c : p) {
|
||||
if (c == '\\') c = '/';
|
||||
}
|
||||
// 2. Remove "X:/" or "X:" prefix (handles both /: and C: style)
|
||||
if (p.size() >= 3 && p[1] == ':' && p[2] == '/') {
|
||||
p = p.substr(3);
|
||||
} else if (p.size() >= 2 && p[1] == ':') {
|
||||
p = p.substr(2);
|
||||
}
|
||||
// 3. Ensure starts with /
|
||||
if (p.empty() || p[0] != '/') {
|
||||
p = "/" + p;
|
||||
}
|
||||
// 4. Merge consecutive slashes
|
||||
std::string result;
|
||||
result.reserve(p.size());
|
||||
for (size_t i = 0; i < p.size(); i++) {
|
||||
if (i > 0 && p[i] == '/' && p[i - 1] == '/')
|
||||
continue;
|
||||
result += p[i];
|
||||
}
|
||||
return result.empty() ? "/" : result;
|
||||
// 展开 %USERPROFILE% 等变量并把路径风格转成 Unix(见 UnixPath.h)
|
||||
return UnixPath::ToUnixPath(winPath ? winPath : "");
|
||||
}
|
||||
|
||||
// ---- Linux path -> Windows path (for sending to server) ----
|
||||
|
||||
Reference in new issue
Block a user