Przeglądaj źródła

Bug 2014: Monitoring A: and B: drives

https://winscp.net/tracker/2014
(cherry picked from commit 7283d36b6332c6cd9ad055dd7bc445f5deac2b9e)

Source commit: 226a0722116150063b05880f726aeee8f3070442
Martin Prikryl 4 lat temu
rodzic
commit
9d7dfba37d

+ 4 - 4
source/packages/filemng/DriveView.pas

@@ -1377,12 +1377,12 @@ begin
             if (Directory <> '') and (Directory[1] = Drive) then
             begin
               if DriveInfo.IsRealDrive(Drive) then NewDrive := Drive[1]
-                else NewDrive := FirstFixedDrive;
+                else NewDrive := SystemDrive;
 
               repeat
-                if NewDrive < FirstFixedDrive then NewDrive := FirstFixedDrive
+                if NewDrive < SystemDrive then NewDrive := SystemDrive
                   else
-                if NewDrive = FirstFixedDrive then NewDrive := LastDrive
+                if NewDrive = SystemDrive then NewDrive := LastDrive
                   else Dec(NewDrive);
                 DriveInfo.ReadDriveStatus(NewDrive, dsSize or dsImageIndex);
 
@@ -1400,7 +1400,7 @@ begin
 
               if not Assigned(Selected) then
               begin
-                Directory := NodePathName(GetDriveStatus(FirstFixedDrive).RootNode);
+                Directory := NodePathName(GetDriveStatus(SystemDrive).RootNode);
               end;
             end;
             Scanned := False;

+ 16 - 3
source/packages/filemng/IEDriveInfo.pas

@@ -41,7 +41,7 @@ const
   dsDisplayName = 4;  {Fetch drives displayname}
   dsAll = dsImageIndex or dsSize or dsDisplayName;
   FirstDrive          = 'A';
-  FirstFixedDrive     = 'C';
+  SystemDrive         = 'C';
   LastDrive           = 'Z';
   FirstSpecialFolder  = CSIDL_DESKTOP;
   LastSpecialFolder   = CSIDL_PRINTHOOD;
@@ -78,11 +78,13 @@ type
     FDesktop: IShellFolder;
     FFolders: array[TSpecialFolder] of TSpecialFolderRec;
     FHonorDrivePolicy: Boolean;
+    FUseABDrives: Boolean;
     FLoaded: Boolean;
     function GetFolder(Folder: TSpecialFolder): PSpecialFolderRec;
     procedure ReadDriveBasicStatus(Drive: string);
     procedure ResetDrive(Drive: string);
     procedure SetHonorDrivePolicy(Value: Boolean);
+    function GetFirstFixedDrive: Char;
     procedure NeedData;
     procedure Load;
     function AddDrive(Drive: string): TDriveInfoRec;
@@ -102,6 +104,9 @@ type
     function GetPrettyName(Drive: string): string;
     function ReadDriveStatus(Drive: string; Flags: Integer): Boolean;
     property HonorDrivePolicy: Boolean read FHonorDrivePolicy write SetHonorDrivePolicy;
+    property FirstFixedDrive: Char read GetFirstFixedDrive;
+    property UseABDrives: Boolean read FUseABDrives write FUseABDrives;
+
     constructor Create;
     destructor Destroy; override;
   end;
@@ -129,6 +134,7 @@ begin
   inherited;
 
   FHonorDrivePolicy := True;
+  FUseABDrives := True;
   FLoaded := False;
   FData := TObjectDictionary<string, TDriveInfoRec>.Create([doOwnsValues]);
 end; {TDriveInfo.Create}
@@ -152,7 +158,8 @@ function TDriveInfo.AnyValidPath: string;
 var
   Drive: TRealDrive;
 begin
-  for Drive := FirstFixedDrive to LastDrive do
+  // Fallback to A:/B: if no other drive is found?
+  for Drive := SystemDrive to LastDrive do
     if Get(Drive).Valid and
        (Get(Drive).DriveType = DRIVE_FIXED) and
        DirectoryExists(ApiPath(DriveInfo.GetDriveRoot(Drive))) then
@@ -160,7 +167,7 @@ begin
       Result := DriveInfo.GetDriveRoot(Drive);
       Exit;
     end;
-  for Drive := FirstFixedDrive to LastDrive do
+  for Drive := SystemDrive to LastDrive do
     if Get(Drive).Valid and
        (Get(Drive).DriveType = DRIVE_REMOTE) and
        DirectoryExists(ApiPath(DriveInfo.GetDriveRoot(Drive))) then
@@ -267,6 +274,12 @@ begin
   end;
 end;
 
+function TDriveInfo.GetFirstFixedDrive: Char;
+begin
+  if UseABDrives then Result := FirstDrive
+    else Result := SystemDrive;
+end;
+
 procedure TDriveInfo.ReadDriveBasicStatus(Drive: string);
 begin
   Assert(FData.ContainsKey(Drive));

+ 1 - 1
source/windows/GUITools.cpp

@@ -352,7 +352,7 @@ TObjectList * StartCreationDirectoryMonitorsOnEachDrive(unsigned int Filter, TFi
       TDriveInfoRec * DriveInfoRec = DriveInfo->Get(Drive);
       if (DriveInfoRec->Valid &&
           (DriveInfoRec->DriveType != DRIVE_CDROM) &&
-          ((DriveInfoRec->DriveType != DRIVE_REMOVABLE) || (Drive >= FirstFixedDrive)))
+          ((DriveInfoRec->DriveType != DRIVE_REMOVABLE) || (Drive >= DriveInfo->FirstFixedDrive)))
       {
         Drives->Add(Drive);
       }

+ 16 - 0
source/windows/WinConfiguration.cpp

@@ -616,6 +616,7 @@ void __fastcall TWinConfiguration::Default()
   FLockedInterface = false;
 
   HonorDrivePolicy = true;
+  UseABDrives = true;
   TimeoutShellOperations = true;
   TimeoutShellIconRetrieval = false;
   UseIconUpdateThread = true;
@@ -1021,6 +1022,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(String,   FileColors); \
     KEY(Integer,  RunsSinceLastTip); \
     KEY(Bool,     HonorDrivePolicy); \
+    KEY(Bool,     UseABDrives); \
     KEY(Integer,  LastMachineInstallations); \
     KEY(String,   FExtensionsDeleted); \
     KEY(String,   FExtensionsOrder); \
@@ -2335,6 +2337,20 @@ void __fastcall TWinConfiguration::SetHonorDrivePolicy(bool value)
   }
 }
 //---------------------------------------------------------------------------
+bool __fastcall TWinConfiguration::GetUseABDrives()
+{
+  return DriveInfo->UseABDrives;
+}
+//---------------------------------------------------------------------------
+void __fastcall TWinConfiguration::SetUseABDrives(bool value)
+{
+  if (UseABDrives != value)
+  {
+    DriveInfo->UseABDrives = value;
+    Changed();
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
 {
   DebugAssert(FCustomCommandList);

+ 3 - 0
source/windows/WinConfiguration.h

@@ -565,6 +565,8 @@ private:
   void __fastcall SetRunsSinceLastTip(int value);
   bool __fastcall GetHonorDrivePolicy();
   void __fastcall SetHonorDrivePolicy(bool value);
+  bool __fastcall GetUseABDrives();
+  void __fastcall SetUseABDrives(bool value);
   bool __fastcall GetIsBeta();
   TStrings * __fastcall GetCustomCommandOptions();
   void __fastcall SetCustomCommandOptions(TStrings * value);
@@ -758,6 +760,7 @@ public:
   __property UnicodeString FileColors = { read = FFileColors, write = SetFileColors };
   __property int RunsSinceLastTip = { read = FRunsSinceLastTip, write = SetRunsSinceLastTip };
   __property bool HonorDrivePolicy = { read = GetHonorDrivePolicy, write = SetHonorDrivePolicy };
+  __property bool UseABDrives = { read = GetUseABDrives, write = SetUseABDrives };
   __property TMasterPasswordPromptEvent OnMasterPasswordPrompt = { read = FOnMasterPasswordPrompt, write = FOnMasterPasswordPrompt };
   __property TStrings * CustomCommandOptions = { read = GetCustomCommandOptions, write = SetCustomCommandOptions };
   __property bool LockedInterface = { read = FLockedInterface, write = SetLockedInterface };