mirror of
https://github.com/winscp/winscp.git
synced 2026-10-24 02:28:55 +03:00
Factoring out universal path utility functions that will also be used Issue 2020
Source commit: ecc9f746b50cf7f0203dcb08b1db627375cf5295
This commit is contained in:
@@ -3883,20 +3883,9 @@ bool __fastcall TFTPFileSystem::HandleAsynchRequestOverwrite(
|
||||
UnicodeString TargetFileName = FileName1;
|
||||
DebugAssert(UserData.FileName == TargetFileName);
|
||||
|
||||
UnicodeString SourceFullFileName = Path2;
|
||||
UnicodeString TargetFullFileName = Path1;
|
||||
if (OperationProgress->Side == osLocal)
|
||||
{
|
||||
SourceFullFileName = IncludeTrailingBackslash(SourceFullFileName);
|
||||
TargetFullFileName = UnixIncludeTrailingBackslash(TargetFullFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
SourceFullFileName = UnixIncludeTrailingBackslash(SourceFullFileName);
|
||||
TargetFullFileName = IncludeTrailingBackslash(TargetFullFileName);
|
||||
}
|
||||
SourceFullFileName += FileName2;
|
||||
TargetFullFileName += FileName1;
|
||||
bool Local = (OperationProgress->Side == osLocal);
|
||||
UnicodeString SourceFullFileName = UniversalIncludeTrailingBackslash(!Local, Path2) + FileName2;
|
||||
UnicodeString TargetFullFileName = UniversalIncludeTrailingBackslash(Local, Path1) + FileName1;
|
||||
|
||||
TOverwriteMode OverwriteMode = omOverwrite;
|
||||
TOverwriteFileParams FileParams;
|
||||
|
||||
@@ -35,6 +35,11 @@ UnicodeString __fastcall UnixIncludeTrailingBackslash(const UnicodeString & Path
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
UnicodeString UniversalIncludeTrailingBackslash(bool Unix, const UnicodeString & Path)
|
||||
{
|
||||
return Unix ? UnixIncludeTrailingBackslash(Path) : IncludeTrailingBackslash(Path);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Keeps "/" for root path
|
||||
UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString & Path, bool Simple)
|
||||
{
|
||||
@@ -51,6 +56,11 @@ UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString & Path
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
UnicodeString UniversalExcludeTrailingBackslash(bool Unix, const UnicodeString & Path)
|
||||
{
|
||||
return Unix ? UnixExcludeTrailingBackslash(Path) : ExcludeTrailingBackslash(Path);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
UnicodeString __fastcall SimpleUnixExcludeTrailingBackslash(const UnicodeString & Path)
|
||||
{
|
||||
return UnixExcludeTrailingBackslash(Path, true);
|
||||
@@ -67,6 +77,11 @@ UnicodeString __fastcall UnixCombinePaths(const UnicodeString & Path1, const Uni
|
||||
return UnixCombinePathsForce(Path1, Path2);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
UnicodeString UniversalCombinePaths(bool Unix, const UnicodeString & Path1, const UnicodeString & Path2)
|
||||
{
|
||||
return Unix ? UnixCombinePaths(Path1, Path2) : CombinePaths(Path1, Path2);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Eventually make UnixCombinePaths do this,
|
||||
// once we verify that no use of UnixCombinePaths relies on it adding backslash even for empty second arg
|
||||
UnicodeString UnixCombinePathsSmart(const UnicodeString & Path1, const UnicodeString & Path2)
|
||||
|
||||
@@ -572,11 +572,14 @@ private:
|
||||
bool __fastcall IsUnixStyleWindowsPath(const UnicodeString & Path);
|
||||
bool __fastcall UnixIsAbsolutePath(const UnicodeString & Path);
|
||||
UnicodeString __fastcall UnixIncludeTrailingBackslash(const UnicodeString & Path);
|
||||
UnicodeString UniversalIncludeTrailingBackslash(bool Unix, const UnicodeString & Path);
|
||||
UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString & Path, bool Simple = false);
|
||||
UnicodeString UniversalExcludeTrailingBackslash(bool Unix, const UnicodeString & Path);
|
||||
UnicodeString __fastcall SimpleUnixExcludeTrailingBackslash(const UnicodeString & Path);
|
||||
UnicodeString __fastcall UnixCombinePaths(const UnicodeString & Path1, const UnicodeString & Path2);
|
||||
UnicodeString UnixCombinePathsForce(const UnicodeString & Path1, const UnicodeString & Path2);
|
||||
UnicodeString UnixCombinePathsSmart(const UnicodeString & Path1, const UnicodeString & Path2);
|
||||
UnicodeString UniversalCombinePaths(bool Unix, const UnicodeString & Path1, const UnicodeString & Path2);
|
||||
UnicodeString __fastcall UnixExtractFileDir(const UnicodeString & Path);
|
||||
UnicodeString __fastcall UnixExtractFilePath(const UnicodeString & Path);
|
||||
UnicodeString __fastcall UnixExtractFileName(const UnicodeString & Path);
|
||||
|
||||
@@ -1850,15 +1850,7 @@ UnicodeString __fastcall TScript::SynchronizeFileRecord(
|
||||
{
|
||||
const TSynchronizeChecklist::TItem::TFileInfo & FileInfo =
|
||||
Local ? Item->Local : Item->Remote;
|
||||
UnicodeString Path;
|
||||
if (Local)
|
||||
{
|
||||
Path = IncludeTrailingBackslash(FileInfo.Directory) + FileInfo.FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Path = UnixIncludeTrailingBackslash(FileInfo.Directory) + FileInfo.FileName;
|
||||
}
|
||||
UnicodeString Path = UniversalCombinePaths(!Local, FileInfo.Directory, FileInfo.FileName);
|
||||
|
||||
if (SameText(RootDirectory, Path.SubString(1, RootDirectory.Length())))
|
||||
{
|
||||
@@ -1869,14 +1861,7 @@ UnicodeString __fastcall TScript::SynchronizeFileRecord(
|
||||
UnicodeString Result;
|
||||
if (Item->IsDirectory)
|
||||
{
|
||||
if (Local)
|
||||
{
|
||||
Result = IncludeTrailingBackslash(Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = UnixIncludeTrailingBackslash(Path);
|
||||
}
|
||||
Result = UniversalIncludeTrailingBackslash(!Local, Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2360,15 +2345,8 @@ void __fastcall TManagementScript::TerminalOperationProgress(
|
||||
{
|
||||
bool DoPrint = false;
|
||||
bool First = false;
|
||||
UnicodeString ProgressFileName = ProgressData.FileName;
|
||||
if (ProgressData.Side == osLocal)
|
||||
{
|
||||
ProgressFileName = ExcludeTrailingBackslash(ProgressFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgressFileName = UnixExcludeTrailingBackslash(ProgressFileName);
|
||||
}
|
||||
UnicodeString ProgressFileName =
|
||||
UniversalExcludeTrailingBackslash((ProgressData.Side != osLocal), ProgressData.FileName);
|
||||
|
||||
if (ProgressFileName != FLastProgressFile)
|
||||
{
|
||||
|
||||
@@ -896,15 +896,7 @@ void TParallelOperation::Done(
|
||||
FDirectories.erase(DirectoryIterator);
|
||||
if (FFileList->Count > FListIndex)
|
||||
{
|
||||
UnicodeString FileNameWithSlash;
|
||||
if (FSide == osLocal)
|
||||
{
|
||||
FileNameWithSlash = IncludeTrailingBackslash(FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileNameWithSlash = UnixIncludeTrailingBackslash(FileName);
|
||||
}
|
||||
UnicodeString FileNameWithSlash = UniversalIncludeTrailingBackslash((FSide == osRemote), FileName);
|
||||
|
||||
// It can actually be a different list than the one the directory was taken from,
|
||||
// but that does not matter that much. It should not happen anyway, as more lists should be in scripting only.
|
||||
@@ -1173,15 +1165,7 @@ int TParallelOperation::GetNext(
|
||||
{
|
||||
DebugAssert(!OnlyFileName.IsEmpty());
|
||||
TDirectoryData DirectoryData;
|
||||
if (FSide == osLocal)
|
||||
{
|
||||
DirectoryData.OppositePath = UnixCombinePaths(TargetDir, OnlyFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryData.OppositePath = CombinePaths(TargetDir, OnlyFileName);
|
||||
}
|
||||
|
||||
DirectoryData.OppositePath = UniversalCombinePaths((FSide == osLocal), TargetDir, OnlyFileName);
|
||||
DirectoryData.Exists = false;
|
||||
|
||||
FDirectories.insert(std::make_pair(FileName, DirectoryData));
|
||||
|
||||
@@ -326,8 +326,7 @@ void __fastcall TCopyDialog::SetDirectory(UnicodeString value)
|
||||
{
|
||||
if (!value.IsEmpty())
|
||||
{
|
||||
value = RemotePaths() ?
|
||||
UnicodeString(UnixIncludeTrailingBackslash(value)) : IncludeTrailingBackslash(value);
|
||||
value = UniversalIncludeTrailingBackslash(RemotePaths(), value);
|
||||
}
|
||||
DirectoryEdit->Text = value + GetFileMask();
|
||||
}
|
||||
@@ -340,18 +339,14 @@ UnicodeString __fastcall TCopyDialog::GetDirectory()
|
||||
if (RemotePaths())
|
||||
{
|
||||
Result = UnixExtractFilePath(Result);
|
||||
if (!Result.IsEmpty())
|
||||
{
|
||||
Result = UnixIncludeTrailingBackslash(Result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = ExtractFilePath(Result);
|
||||
if (!Result.IsEmpty())
|
||||
{
|
||||
Result = IncludeTrailingBackslash(Result);
|
||||
}
|
||||
}
|
||||
if (!Result.IsEmpty())
|
||||
{
|
||||
Result = UniversalIncludeTrailingBackslash(RemotePaths(), Result);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
@@ -602,20 +602,13 @@ UnicodeString __fastcall TGenerateUrlDialog::GenerateAssemblyCode(UnicodeString
|
||||
L")." + RtfLibraryMethod(L"OperationResultBase", L"Check", true) + L"()" +
|
||||
StatementSeparator + RtfPara;
|
||||
|
||||
UnicodeString SourcePath = UniversalIncludeTrailingBackslash(!FToRemote, FSourcePath);
|
||||
if (FFilesSelected == fsList)
|
||||
{
|
||||
for (int Index = 0; Index < FPaths->Count; Index++)
|
||||
{
|
||||
UnicodeString FileName = FPaths->Strings[Index];
|
||||
UnicodeString Path;
|
||||
if (!FToRemote)
|
||||
{
|
||||
Path = UnixIncludeTrailingBackslash(FSourcePath) + FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Path = IncludeTrailingBackslash(FSourcePath) + FileName;
|
||||
}
|
||||
UnicodeString Path = SourcePath + FileName;
|
||||
UnicodeString PathCode = AssemblyString(Language, Path);
|
||||
if (!FToRemote && (FileName != EscapeFileMask(FileName)))
|
||||
{
|
||||
@@ -628,15 +621,6 @@ UnicodeString __fastcall TGenerateUrlDialog::GenerateAssemblyCode(UnicodeString
|
||||
}
|
||||
else
|
||||
{
|
||||
UnicodeString SourcePath = FSourcePath;
|
||||
if (FToRemote)
|
||||
{
|
||||
SourcePath = IncludeTrailingBackslash(SourcePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
SourcePath = UnixIncludeTrailingBackslash(SourcePath);
|
||||
}
|
||||
SourcePath += AllFilesMask;
|
||||
Code += TransferMethodCallStart + AssemblyString(Language, SourcePath) + TransferMethodCallEnd;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user