View Issue Details

IDProjectCategoryView StatusLast Update
0001037Double CommanderGraphical user interfacepublic2018-10-27 22:10
Reporterondrejsv Assigned To 
PriorityhighSeverityblockReproducibilityalways
Status closedResolutionfixed 
ProjectionnoneETAnone 
Platformwin32OSWindowsOS Version8.0
Product Version0.6.0Product Build0.6.0 beta 
Summary0001037: App hangs after a network drive was disconnected
DescriptionDouble Commander hangs when a network shared folder is being browsed on a tab and this shared folder gets unavailable (by moving to a second physicial location with sleep/wake up cycle).
Steps To ReproduceStart the application and browse to a network share (e.g. on location one). Put the computer to sleep and move to a second location where the network share is no longer available. Wake up the computer and Double Commander now hangs.
TagsNo tags attached.
Fixed in Revision
Operating systemWindows
Widgetset
Architecture32-bit

Relationships

related to 0001837 resolvedAlexx2000 Freeze on entering unreachable network paths 

Activities

dmz73

2017-02-23 12:58

reporter   ~0002098

I use the following functions on Windows to quickly check if drive is available.
If DoubleCommander used something like this every time before it tried to access the drive or at least on startup it would avoid long pauses with frozen user interface.

function NetUseGetInfo(UncServerName: LPWSTR; UseName: LPWSTR; Level: DWORD; BufPtr: Pointer): DWORD; stdcall; external 'netapi32.dll' name 'NetUseGetInfo';
function NetApiBufferFree(Buffer: Pointer): DWORD; stdcall; external 'netapi32.dll' name 'NetApiBufferFree';

function NetworkDriveStatus(ADrive: char): integer;
type
  PUSEINFO1 = ^TUSEINFO1;
  TUSEINFO1 = packed record
    ui1_local: PChar;
    ui1_remote: PChar;
    ui1_password: PChar;
    ui1_status: DWORD;
    ui1_asg_type: DWORD;
    ui1_refcount: DWORD;
    ui1_usecount: DWORD;
  end;
var
  liER, liSZ: Cardinal;
  lpUI: PUSEINFO1;
  lsDrive, lsRemote: string;
begin
  result := -1;
  if ADrive = #0 then Exit;
  lsDrive := ADrive + ':';

  liER := NetUseGetInfo(nil, PChar(lsDrive), 1, @lpUI);
  if liER = 0 then
  begin
    result := lpUI.ui1_status;
    NetApiBufferFree(lpUI);
  end
  else
  begin
    liSZ := 2048;
    SetLength(lsRemote, liSZ);
    liER := WNetGetConnection(PChar(lsDrive), PChar(lsRemote), liSZ);
    result := liER;
  end;
end;

function DriveCharNo(Drive: Char): integer;
begin
  Result := -1;
  Drive := Drive.ToUpper;
  if not (CharInSet(Drive, ['A'..'Z'])) then exit;
  Result := Ord(Drive) - Ord('A') + 1;
end;

function DiskInDrive(Drive: Char): Boolean;
var
  ErrorMode: Word; DriveNo: integer;
begin
  Result := false;
  DriveNo := DriveCharNo(Drive);
  if (DriveNo < 1) then exit;
  // turn off critical errors
  ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    if DiskSize(DriveNo) = -1 then Result := false
    else Result := true;
  finally
    SetErrorMode(ErrorMode);
  end;
end;

function GetDriveLetter(const Path: string): char;
begin
  result := #0;
  if Path <> '' then
  begin
    if (Length(Path) > 5) and (Copy(Path, 1, 4) = '\\?\') and (Copy(Path, 6, 1) = ':') then
      result := Copy(Path, 5, 1)[1]
    else
    if (Length(Path) > 2) and (Path[2] = ':') then
      result := Path[1];
  end;
end;

function DriveAvailable(DriveLetter: char): boolean;
var
  lsDrive: string;
begin
  lsDrive := IncludeTrailingPathDelimiter(DriveLetter + ':');
  case GetDriveType(PChar(lsDrive)) of
    DRIVE_REMOVABLE, DRIVE_CDROM: result := DiskInDrive(DriveLetter);
    DRIVE_FIXED: result := SysUtils.DirectoryExists(lsDrive);
    DRIVE_REMOTE: result := NetworkDriveStatus(DriveLetter) = NO_ERROR;
    else result := false;
  end;
end;

Alexx2000

2018-10-27 22:09

administrator   ~0002843

Last edited: 2018-10-27 22:10

See comment in related issue.

Issue History

Date Modified Username Field Change
2015-03-10 13:07 ondrejsv New Issue
2017-02-23 12:58 dmz73 Note Added: 0002098
2018-09-24 09:46 Alexx2000 Relationship added related to 0001837
2018-10-27 22:09 Alexx2000 Note Added: 0002843
2018-10-27 22:09 Alexx2000 Status new => closed
2018-10-27 22:09 Alexx2000 Resolution open => fixed
2018-10-27 22:10 Alexx2000 Note Edited: 0002843