mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Capability to show hidden shares
This commit is contained in:
parent
506951343c
commit
b577587f12
1 changed files with 83 additions and 23 deletions
|
|
@ -17,6 +17,9 @@ type
|
|||
TWinNetListOperation = class(TFileSourceListOperation)
|
||||
private
|
||||
FWinNetFileSource: IWinNetFileSource;
|
||||
private
|
||||
procedure ShareEnum;
|
||||
procedure WorkgroupEnum;
|
||||
public
|
||||
constructor Create(aFileSource: IFileSource; aPath: String); override;
|
||||
procedure MainExecute; override;
|
||||
|
|
@ -25,20 +28,13 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
LCLProc, uFile, Windows, JwaWinNetWk, DCStrUtils, uShowMsg,
|
||||
DCOSUtils, uOSUtils;
|
||||
LCLProc, uFile, Windows, JwaWinNetWk, JwaLmCons, JwaLmShare, JwaLmApiBuf,
|
||||
DCStrUtils, uShowMsg, DCOSUtils, uOSUtils;
|
||||
|
||||
type
|
||||
PNetResourceArray = ^TNetResource;
|
||||
|
||||
constructor TWinNetListOperation.Create(aFileSource: IFileSource; aPath: String);
|
||||
begin
|
||||
FFiles := TFiles.Create(aPath);
|
||||
FWinNetFileSource := aFileSource as IWinNetFileSource;
|
||||
inherited Create(aFileSource, aPath);
|
||||
end;
|
||||
|
||||
procedure TWinNetListOperation.MainExecute;
|
||||
procedure TWinNetListOperation.WorkgroupEnum;
|
||||
var
|
||||
I: DWORD;
|
||||
aFile: TFile;
|
||||
|
|
@ -51,7 +47,6 @@ var
|
|||
FilePath: UTF8String;
|
||||
FileName: WideString;
|
||||
begin
|
||||
FFiles.Clear;
|
||||
with FWinNetFileSource do
|
||||
try
|
||||
FillChar(nFile, SizeOf(TNetResource), #0);
|
||||
|
|
@ -62,17 +57,8 @@ begin
|
|||
if not IsPathAtRoot(Path) then
|
||||
begin
|
||||
FilePath:= ExcludeTrailingPathDelimiter(Path);
|
||||
// Workstation/Server
|
||||
if Pos('\\', FilePath) = 1 then
|
||||
begin
|
||||
FileName:= UTF8Decode(FilePath);
|
||||
nFile.lpRemoteName:= PWideChar(FileName);
|
||||
end
|
||||
else // Domain/Workgroup
|
||||
begin
|
||||
FileName:= UTF8Decode(ExcludeFrontPathDelimiter(FilePath));
|
||||
nFile.lpRemoteName:= PWideChar(FileName);
|
||||
end;
|
||||
FileName:= UTF8Decode(ExcludeFrontPathDelimiter(FilePath));
|
||||
nFile.lpRemoteName:= PWideChar(FileName);
|
||||
end;
|
||||
|
||||
dwResult := WNetOpenEnumW(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, @nFile, hEnum);
|
||||
|
|
@ -90,7 +76,7 @@ begin
|
|||
for I := 0 to dwCount - 1 do
|
||||
begin
|
||||
CheckOperationState;
|
||||
aFile := TWinNetFileSource.CreateFile(Path);
|
||||
aFile:= TWinNetFileSource.CreateFile(Path);
|
||||
aFile.FullPath:= UTF8Encode(WideString(nFileList^.lpRemoteName));
|
||||
aFile.CommentProperty.Value:= UTF8Encode(WideString(nFileList^.lpComment));
|
||||
if nFileList^.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE then
|
||||
|
|
@ -109,5 +95,79 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TWinNetListOperation.ShareEnum;
|
||||
var
|
||||
I: DWORD;
|
||||
aFile: TFile;
|
||||
ServerPath: WideString;
|
||||
dwResult: NET_API_STATUS;
|
||||
dwEntriesRead: DWORD = 0;
|
||||
dwTotalEntries: DWORD = 0;
|
||||
BufPtr, nFileList: PShareInfo1;
|
||||
begin
|
||||
ServerPath:= UTF8Decode(ExcludeTrailingPathDelimiter(Path));
|
||||
repeat
|
||||
// Call the NetShareEnum function
|
||||
dwResult:= NetShareEnum (PWideChar(ServerPath), 1, PByte(BufPtr), MAX_PREFERRED_LENGTH, @dwEntriesRead, @dwTotalEntries, nil);
|
||||
// If the call succeeds
|
||||
if (dwResult = ERROR_SUCCESS) or (dwResult = ERROR_MORE_DATA) then
|
||||
begin
|
||||
nFileList:= BufPtr;
|
||||
// Loop through the entries
|
||||
for I:= 1 to dwEntriesRead do
|
||||
begin
|
||||
CheckOperationState;
|
||||
aFile:= TWinNetFileSource.CreateFile(Path);
|
||||
aFile.Name:= UTF8Encode(WideString(nFileList^.shi1_netname));
|
||||
aFile.CommentProperty.Value:= UTF8Encode(WideString(nFileList^.shi1_remark));
|
||||
case (nFileList^.shi1_type and $FF) of
|
||||
STYPE_DISKTREE:
|
||||
aFile.Attributes:= FILE_ATTRIBUTE_DIRECTORY;
|
||||
STYPE_IPC:
|
||||
aFile.Attributes:= FILE_ATTRIBUTE_SYSTEM;
|
||||
end;
|
||||
// Mark special items as hidden
|
||||
if (nFileList^.shi1_type and STYPE_SPECIAL = STYPE_SPECIAL) then
|
||||
aFile.Attributes:= aFile.Attributes or FILE_ATTRIBUTE_HIDDEN;
|
||||
// Mark special items as hidden
|
||||
if (lstrcmpiW(nFileList^.shi1_netname, 'FAX$') = 0) then
|
||||
aFile.Attributes:= aFile.Attributes or FILE_ATTRIBUTE_HIDDEN;
|
||||
// Mark special items as hidden
|
||||
if (lstrcmpiW(nFileList^.shi1_netname, 'PRINT$') = 0) then
|
||||
aFile.Attributes:= aFile.Attributes or FILE_ATTRIBUTE_HIDDEN;
|
||||
FFiles.Add(aFile);
|
||||
Inc(nFileList);
|
||||
end;
|
||||
// Free the allocated buffer
|
||||
NetApiBufferFree(BufPtr);
|
||||
end;
|
||||
|
||||
// Continue to call NetShareEnum while there are more entries
|
||||
until (dwResult <> ERROR_MORE_DATA);
|
||||
|
||||
// Show error if failed
|
||||
if (dwResult <> ERROR_SUCCESS) then
|
||||
msgError(Thread, mbSysErrorMessage(dwResult));
|
||||
end;
|
||||
|
||||
constructor TWinNetListOperation.Create(aFileSource: IFileSource; aPath: String);
|
||||
begin
|
||||
FFiles := TFiles.Create(aPath);
|
||||
FWinNetFileSource := aFileSource as IWinNetFileSource;
|
||||
inherited Create(aFileSource, aPath);
|
||||
end;
|
||||
|
||||
procedure TWinNetListOperation.MainExecute;
|
||||
begin
|
||||
FFiles.Clear;
|
||||
with FWinNetFileSource do
|
||||
// Workstation/Server
|
||||
if (IsPathAtRoot(Path) = False) and (Pos('\\', Path) = 1) then
|
||||
ShareEnum
|
||||
// Root/Domain/Workgroup
|
||||
else
|
||||
WorkgroupEnum;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue