瀏覽代碼

Setting SetErrorMode only centrally

Source commit: 1309ebec90375e31b12717ca8f3550011f19e9f0
Martin Prikryl 2 天之前
父節點
當前提交
5c1ef4aa35
共有 3 個文件被更改,包括 19 次插入35 次删除
  1. 17 31
      source/packages/filemng/IEDriveInfo.pas
  2. 0 3
      source/windows/Setup.cpp
  3. 2 1
      source/windows/WinInterface.cpp

+ 17 - 31
source/packages/filemng/IEDriveInfo.pas

@@ -607,7 +607,6 @@ end;
 
 procedure TDriveInfo.DoReadDriveStatus(Drive: string; Flags: Integer);
 var
-  ErrorMode: Word;
   FileInfo: TShFileInfo;
   DriveRoot: string;
   DriveID: string;
@@ -653,35 +652,28 @@ begin
       {Read driveStatus:}
       if (Flags and dsSize) <> 0 then
       begin
-        { turn off critical errors }
-        ErrorMode := SetErrorMode(SEM_FailCriticalErrors or SEM_NOOPENFILEERRORBOX);
-        try
-          DriveReady := GetDiskFreeSpaceEx(PChar(DriveRoot), FreeSpace, Size, nil);
-          if DriveReady then
+        DriveReady := GetDiskFreeSpaceEx(PChar(DriveRoot), FreeSpace, Size, nil);
+        if DriveReady then
+        begin
+          {Access the physical drive:}
+          if GetVolumeInformation(PChar(DriveRoot), nil, 0,
+               @DriveSerial, MaxFileNameLength, FileSystemFlags,
+               nil, 0) then
           begin
-            {Access the physical drive:}
-            if GetVolumeInformation(PChar(DriveRoot), nil, 0,
-                 @DriveSerial, MaxFileNameLength, FileSystemFlags,
-                 nil, 0) then
-            begin
-            end
-              else
-            begin
-              DriveSerial := 0;
-            end;
           end
             else
           begin
             DriveSerial := 0;
           end;
-          // Particularly when removing drive fails (as other app has it locked), we end up with not monitoring the
-          // drive. When the drive is visited again in panel, it calls into here, and we take the opportunity
-          // to resume monitoring
-          UpdateDriveNotifications(Drive);
-        finally
-          { restore old error mode }
-          SetErrorMode(ErrorMode);
+        end
+          else
+        begin
+          DriveSerial := 0;
         end;
+        // Particularly when removing drive fails (as other app has it locked), we end up with not monitoring the
+        // drive. When the drive is visited again in panel, it calls into here, and we take the opportunity
+        // to resume monitoring
+        UpdateDriveNotifications(Drive);
       end;
 
       {DisplayName:}
@@ -1053,15 +1045,9 @@ end;
 function GetShellFileName(PIDL: PItemIDList): string;
 var
   SFI: TSHFileInfo;
-  E: Integer;
 begin
-  E := SetErrorMode(SEM_FAILCRITICALERRORS);
-  try
-    if SHGetFileInfo(PChar(PIDL), 0, SFI, SizeOf(TSHFileInfo), SHGFI_PIDL or SHGFI_DISPLAYNAME) <> 0 then
-      Result := SFI.szDisplayName;
-  finally
-    SetErrorMode(E);
-  end;
+  if SHGetFileInfo(PChar(PIDL), 0, SFI, SizeOf(TSHFileInfo), SHGFI_PIDL or SHGFI_DISPLAYNAME) <> 0 then
+    Result := SFI.szDisplayName;
 end; {GetShellFileName}
 
 function GetNetWorkName(Drive: string): string;

+ 0 - 3
source/windows/Setup.cpp

@@ -1944,8 +1944,6 @@ void __fastcall UpdateJumpList(TStrings * SessionNames, TStrings * WorkspaceName
 {
   ICustomDestinationList * DestinationList = NULL;
   TStringList * Removed = NULL;
-  int OldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
   try
   {
     if (SUCCEEDED(CoCreateInstance(CLSID_DestinationList, NULL,
@@ -1994,7 +1992,6 @@ void __fastcall UpdateJumpList(TStrings * SessionNames, TStrings * WorkspaceName
   }
   __finally
   {
-    SetErrorMode(OldErrMode);
     if (DestinationList != NULL)
     {
       DestinationList->Release();

+ 2 - 1
source/windows/WinInterface.cpp

@@ -1481,7 +1481,8 @@ void __fastcall WinInitialize()
     CallstackThread->Start();
   }
 
-  SetErrorMode(SEM_FAILCRITICALERRORS);
+  // SEM_NOOPENFILEERRORBOX should affect OpenFile only, which we probably never use
+  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
   OnApiPath = ApiPath;
   MainThread = GetCurrentThreadId();
   Application->OnGetMainFormHandle = MakeMethod<TGetHandleEvent>(NULL, AppGetMainFormHandle);