Skip to content

Commit

Permalink
Bug 1486: When handling WebDAV file URL, use a display name for targe…
Browse files Browse the repository at this point in the history
…t local file

https://winscp.net/tracker/1486

Source commit: 91f8cc19d3626ee6dada21425121f77e2cd518a3
  • Loading branch information
martinprikryl committed Jan 27, 2018
1 parent 3b74f0b commit f679d63
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions source/core/RemoteFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ TRemoteFile * __fastcall TRemoteFile::Duplicate(bool Standalone) const
COPY_FP(ModificationFmt);
COPY_FP(Size);
COPY_FP(FileName);
COPY_FP(DisplayName);
COPY_FP(INodeBlocks);
COPY_FP(Modification);
COPY_FP(LastAccess);
Expand Down
2 changes: 2 additions & 0 deletions source/core/RemoteFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TRemoteFile : public TPersistent
TModificationFmt FModificationFmt;
__int64 FSize;
UnicodeString FFileName;
UnicodeString FDisplayName;
Integer FINodeBlocks;
TDateTime FModification;
TDateTime FLastAccess;
Expand Down Expand Up @@ -156,6 +157,7 @@ class TRemoteFile : public TPersistent
__property TRemoteToken Owner = { read = FOwner, write = FOwner };
__property TRemoteToken Group = { read = FGroup, write = FGroup };
__property UnicodeString FileName = { read = FFileName, write = FFileName };
__property UnicodeString DisplayName = { read = FDisplayName, write = FDisplayName };
__property int INodeBlocks = { read = FINodeBlocks };
__property TDateTime Modification = { read = FModification, write = SetModification };
__property UnicodeString ModificationStr = { read = GetModificationStr };
Expand Down
7 changes: 7 additions & 0 deletions source/core/WebDAVFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static const int HttpUnauthorized = 401;
#define PROP_QUOTA_USED "quota-used-bytes"
#define PROP_EXECUTABLE "executable"
#define PROP_OWNER "owner"
#define PROP_DISPLAY_NAME "displayname"
//---------------------------------------------------------------------------
static std::unique_ptr<TCriticalSection> DebugSection(TraceInitPtr(new TCriticalSection));
static std::set<TWebDAVFileSystem *> FileSystems;
Expand Down Expand Up @@ -1026,6 +1027,12 @@ void __fastcall TWebDAVFileSystem::ParsePropResultSet(TRemoteFile * File,
File->Owner.Name = Owner;
}

const char * DisplayName = GetProp(Results, PROP_DISPLAY_NAME);
if (DisplayName != NULL)
{
File->DisplayName = StrFromNeon(DisplayName);
}

const UnicodeString RightsDelimiter(L", ");
UnicodeString HumanRights;

Expand Down
36 changes: 27 additions & 9 deletions source/windows/WinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,10 @@ void __fastcall Upload(TTerminal * Terminal, TStrings * FileList, bool UseDefaul
void __fastcall Download(TTerminal * Terminal, const UnicodeString FileName,
bool UseDefaults)
{
UnicodeString TargetDirectory;
TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
TStrings * FileList = NULL;
TRemoteFile * File = NULL;

try
{
FileList = new TStringList();
Terminal->ExceptionOnFail = true;
try
{
Expand All @@ -130,21 +126,44 @@ void __fastcall Download(TTerminal * Terminal, const UnicodeString FileName,
Terminal->ExceptionOnFail = false;
}
File->FullFileName = FileName;
FileList->AddObject(FileName, File);
UnicodeString LocalDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
if (LocalDirectory.IsEmpty())
{
LocalDirectory = GetPersonalFolder();
}
TargetDirectory = IncludeTrailingBackslash(LocalDirectory);
UnicodeString TargetDirectory = IncludeTrailingBackslash(LocalDirectory);

TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
UnicodeString DisplayName = File->FileName;

bool CustomDisplayName =
!File->DisplayName.IsEmpty() &&
(File->DisplayName != DisplayName);
if (CustomDisplayName)
{
DisplayName = File->DisplayName;
}

UnicodeString FriendyFileName = UnixIncludeTrailingBackslash(UnixExtractFilePath(FileName)) + DisplayName;
std::unique_ptr<TStrings> FileListFriendly(new TStringList());
FileListFriendly->AddObject(FriendyFileName, File);

int Options = coDisableQueue;
int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Download;
if (UseDefaults ||
DoCopyDialog(false, false, FileList, TargetDirectory, &CopyParam,
DoCopyDialog(false, false, FileListFriendly.get(), TargetDirectory, &CopyParam,
Options, CopyParamAttrs, NULL, NULL))
{
Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam, 0);
if (CustomDisplayName)
{
// Set only now, so that it is not redundantly displayed on the copy dialog.
// We should escape the * and ?'s.
CopyParam.FileMask = DisplayName;
}

std::unique_ptr<TStrings> FileList(new TStringList());
FileList->AddObject(FileName, File);
Terminal->CopyToLocal(FileList.get(), TargetDirectory, &CopyParam, 0);
}

UnicodeString Directory = UnixExtractFilePath(FileName);
Expand All @@ -154,7 +173,6 @@ void __fastcall Download(TTerminal * Terminal, const UnicodeString FileName,
__finally
{
delete File;
delete FileList;
}
}
//---------------------------------------------------------------------------
Expand Down

0 comments on commit f679d63

Please sign in to comment.