FIX: Bug [0000160] "Support address start with \\" and related bugs

This commit is contained in:
Alexander Koblov 2011-11-12 17:44:18 +00:00
commit 84db68aed3
8 changed files with 106 additions and 38 deletions

View file

@ -656,7 +656,7 @@ uses
uFileSourceOperationTypes, uFileSourceCopyOperation, uFileSourceMoveOperation,
fFileOpDlg, uFileSourceProperty, uFileSourceExecuteOperation, uArchiveFileSource,
uShellExecute, fSymLink, fHardLink, uExceptions, uUniqueInstance, Clipbrd,
uFileSourceOperationOptionsUI, uDebug, uHotkeyManager
uFileSourceOperationOptionsUI, uDebug, uHotkeyManager, uFileSourceUtil
{$IFDEF LCLQT}
, qtwidgets
{$ENDIF}
@ -4141,16 +4141,16 @@ begin
sDir:= IncludeTrailingBackslash(sDir);
sDir:= ReplaceTilde(sDir);
end;
logWrite('Chdir to: ' + sDir);
if not mbSetCurrentDir(sDir) then
// Choose FileSource by path
ChooseFileSource(ActiveFrame, sDir);
if not SameText(ActiveFrame.CurrentPath, sDir) then
begin
msgWarning(Format(rsMsgChDirFailed, [sDir]));
end
else
begin
sDir := mbGetCurrentDir;
ActiveFrame.CurrentPath := sDir;
DCDebug(sDir);
if gTermWindow and Assigned(Cons) then
Cons.Terminal.SetCurrentDir(sDir);
end;

View file

@ -238,6 +238,11 @@ type
var theNewProperties: TFileProperties): TFileSourceOperation; virtual;
function GetOperationClass(OperationType: TFileSourceOperationType): TFileSourceOperationClass;
{en
Returns @true if the given path is supported by the file source,
@false otherwise.
}
class function IsSupportedPath(const Path: String): Boolean; virtual;
{en
Returns @true if the given path is the root path of the file source,
@false otherwise.
@ -668,6 +673,11 @@ begin
Result := FOperationsClasses[OperationType];
end;
class function TFileSource.IsSupportedPath(const Path: String): Boolean;
begin
Result:= True;
end;
function TFileSource.GetConnection(Operation: TFileSourceOperation): TFileSourceConnection;
begin
// By default connections are not supported.
@ -911,4 +921,4 @@ finalization
FreeAndNil(FileSourceManager);
end.

View file

@ -21,7 +21,9 @@ procedure ChooseFile(aFileView: TFileView; aFile: TFile);
@returns @true if the file matched any rules and a new file source was created,
@false otherwise, which means no action was taken.
}
function ChooseFileSource(aFileView: TFileView; aFile: TFile): Boolean;
function ChooseFileSource(aFileView: TFileView; aFile: TFile): Boolean; overload;
function ChooseFileSource(aFileView: TFileView; const Path: UTF8String): Boolean; overload;
function ChooseArchive(aFileView: TFileView; aFile: TFile; bForce: Boolean = False): Boolean;
@ -172,6 +174,23 @@ begin
end;
end;
function ChooseFileSource(aFileView: TFileView; const Path: UTF8String): Boolean;
var
aFileSource: TFileSource;
begin
Result:= True;
aFileSource:= gVfsModuleList.GetFileSource(Path);
if Assigned(aFileSource) then
aFileView.AddFileSource(aFileSource, Path)
else
begin
if mbDirectoryExists(Path) then
Result:= mbSetCurrentDir(Path);
if Result then
aFileView.CurrentPath:= Path;
end;
end;
function ChooseArchive(aFileView: TFileView; aFile: TFile; bForce: Boolean): Boolean;
var
FileSource: IFileSource;

View file

@ -56,7 +56,7 @@ type
implementation
uses
LCLType, uDCUtils, uOSUtils, fMain;
LCLType, uDCUtils, uOSUtils, fMain, uFileSourceUtil;
{ TFileViewHeader }
@ -85,10 +85,10 @@ begin
NewPath:= NormalizePathDelimiters(FPathEdit.Text);
NewPath:= ReplaceEnvVars(ReplaceTilde(NewPath));
if not mbFileExists(NewPath) then
FFileView.CurrentPath := NewPath
ChooseFileSource(FFileView, NewPath)
else
begin
FFileView.CurrentPath := ExtractFileDir(NewPath);
ChooseFileSource(FFileView, ExtractFileDir(NewPath));
FFileView.SetActiveFile(ExtractFileName(NewPath));
end;
FPathEdit.Visible := False;

View file

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, Dialogs,
uFileSourceProperty, uFileSourceOperationTypes,
uVirtualFileSource, uFileProperty, uFileSource,
uVirtualFileSource, uFileSystemFileSource, uFileProperty, uFileSource,
uFileSourceOperation, uFile;
type
@ -23,22 +23,24 @@ type
{ TWinNetFileSource }
TWinNetFileSource = class(TVirtualFileSource, IWinNetFileSource)
TWinNetFileSource = class(TFileSystemFileSource, IWinNetFileSource)
private
FProviderName: array[0..MAX_PATH-1] of WideChar;
function GetProviderName: WideString;
function IsNetworkPath(const Path: UTF8String): Boolean;
protected
function GetSupportedFileProperties: TFilePropertiesTypes; override;
function SetCurrentWorkingDirectory(NewDir: String): Boolean; override;
public
constructor Create; override;
class function IsSupportedPath(const Path: String): Boolean; override;
function GetParentDir(sPath : String): String; override;
class function CreateFile(const APath: String): TFile; override;
// Retrieve operations permitted on the source. = capabilities?
function GetOperationsTypes: TFileSourceOperationTypes; override;
function IsPathAtRoot(Path: String): Boolean; override;
function GetRootDir(sPath: String): String; override; overload;
function GetRootDir: String; override; overload;
// Retrieve some properties of the file source.
function GetProperties: TFileSourceProperties; override;
@ -90,25 +92,24 @@ begin
end;
end;
class function TWinNetFileSource.CreateFile(const APath: String): TFile;
function TWinNetFileSource.IsPathAtRoot(Path: String): Boolean;
begin
Result := TFile.Create(APath);
with Result do
begin
AttributesProperty := TNtfsFileAttributesProperty.Create;
CommentProperty:= TFileCommentProperty.Create;
end;
Result := (uDCUtils.GetParentDir(Path) = '');
end;
function TWinNetFileSource.GetOperationsTypes: TFileSourceOperationTypes;
function TWinNetFileSource.GetRootDir(sPath: String): String;
begin
Result := [fsoList, fsoExecute];
Result:= PathDelim;
end;
function TWinNetFileSource.GetRootDir: String;
begin
Result:= PathDelim;
end;
function TWinNetFileSource.GetProperties: TFileSourceProperties;
begin
Result := [fspVirtual];
Result := inherited GetProperties + [fspVirtual];
end;
function TWinNetFileSource.GetProviderName: WideString;
@ -116,10 +117,17 @@ begin
Result:= WideString(FProviderName);
end;
function TWinNetFileSource.GetSupportedFileProperties: TFilePropertiesTypes;
function TWinNetFileSource.IsNetworkPath(const Path: UTF8String): Boolean;
begin
Result := inherited GetSupportedFileProperties +
[fpAttributes, fpComment];
Result:= (NumCountChars(PathDelim, ExcludeTrailingPathDelimiter(Path)) < 3);
end;
function TWinNetFileSource.SetCurrentWorkingDirectory(NewDir: String): Boolean;
begin
if IsNetworkPath(NewDir) then
Result:= True
else
Result:= inherited SetCurrentWorkingDirectory(NewDir);
end;
constructor TWinNetFileSource.Create;
@ -132,12 +140,20 @@ begin
RaiseLastOSError;
end;
class function TWinNetFileSource.IsSupportedPath(const Path: String): Boolean;
begin
Result:= (Pos('\\', Path) = 1);
end;
function TWinNetFileSource.CreateListOperation(TargetPath: String): TFileSourceOperation;
var
TargetFileSource: IFileSource;
begin
TargetFileSource := Self;
Result := TWinNetListOperation.Create(TargetFileSource, TargetPath);
if IsNetworkPath(TargetPath) then
Result:= TWinNetListOperation.Create(TargetFileSource, TargetPath)
else
Result:= inherited CreateListOperation(TargetPath);
end;
function TWinNetFileSource.CreateExecuteOperation(var ExecutableFile: TFile; BasePath, Verb: String): TFileSourceOperation;
@ -145,7 +161,10 @@ var
TargetFileSource: IFileSource;
begin
TargetFileSource := Self;
Result:= TWinNetExecuteOperation.Create(TargetFileSource, ExecutableFile, BasePath, Verb);
if IsNetworkPath(BasePath) then
Result:= TWinNetExecuteOperation.Create(TargetFileSource, ExecutableFile, BasePath, Verb)
else
Result:= inherited CreateExecuteOperation(ExecutableFile, BasePath, Verb);
end;
end.

View file

@ -92,6 +92,8 @@ begin
aFile := TWinNetFileSource.CreateFile(Path);
aFile.FullPath:= UTF8Encode(WideString(nFileList^.lpRemoteName));
aFile.CommentProperty.Value:= UTF8Encode(WideString(nFileList^.lpComment));
if nFileList^.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE then
aFile.Attributes:= faFolder;
FFiles.Add(aFile);
Inc(nFileList);
end;

View file

@ -941,12 +941,13 @@ begin
if (aWatchPath = '') or (aWatcherEvent = nil) then
Exit(False);
{$IFDEF UNIX}
if aWatchPath <> PathDelim then
{$ENDIF}
aWatchPath := ExcludeTrailingPathDelimiter(aWatchPath);
{$IFDEF MSWINDOWS}
// Special check for network path
if (Pos(PathDelim, aWatchPath) = 1) and (NumCountChars(PathDelim, aWatchPath) < 3) then
Exit(False);
if gWatcherMode = fswmWholeDrive then
begin
RegisteredPath := aWatchPath;
@ -1390,4 +1391,4 @@ finalization
TFileSystemWatcher.DestroyFileSystemWatcher;
end.

View file

@ -26,6 +26,7 @@ type
function GetVfsModule(const S: String): TVfsModule;
public
destructor Destroy; override;
function GetFileSource(const Path: UTF8String): TFileSource;
property VfsModule[const S: String]: TVfsModule read GetVfsModule;
end;
@ -68,6 +69,22 @@ begin
inherited Destroy;
end;
function TVfsModuleList.GetFileSource(const Path: UTF8String): TFileSource;
var
I: Integer;
begin
Result:= nil;
for I:= 0 to Count - 1 do
with TVfsModule(Objects[I]) do
begin
if FileSourceClass.IsSupportedPath(Path) then
begin
Result:= FileSourceClass.Create;
Break;
end;
end;
end;
initialization
gVfsModuleList := TVfsModuleList.Create;
@ -75,4 +92,4 @@ finalization
FreeAndNil(gVfsModuleList);
end.