Changeset 1474 for branches/eraser6/6.0


Ignore:
Timestamp:
1/6/2010 5:11:47 AM (5 years ago)
Author:
lowjoel
Message:

No need to call GetLastError? to get the error code for SfcIsFileProtected?: the last error code is not set by the function. Fixes #286.

Location:
branches/eraser6/6.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/6.0

  • branches/eraser6/6.0/Eraser.Util/File.cs

    r1360 r1474  
    150150        public static bool IsProtectedSystemFile(string filePath) 
    151151        { 
    152             if (filePath.Length > 255) 
    153                 return false; 
    154             if (SfcIsFileProtected(IntPtr.Zero, filePath)) 
    155                 return true; 
    156  
    157             switch (Marshal.GetLastWin32Error()) 
    158             { 
    159                 case 0: //ERROR_SUCCESS 
    160                 case 2: //ERROR_FILE_NOT_FOUND 
    161                     return false; 
    162  
    163                 default: 
    164                     throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 
    165             } 
     152            return SfcIsFileProtected(IntPtr.Zero, filePath); 
    166153        } 
    167154 
     
    223210        /// <param name="RpcHandle">This parameter must be NULL.</param> 
    224211        /// <param name="ProtFileName">The name of the file.</param> 
    225         /// <returns>If the file is protected, the return value is true. 
    226         ///  
    227         /// If the file is not protected, the return value is false and 
    228         /// Marshal.GetLastWin32Error() returns ERROR_FILE_NOT_FOUND. If the 
    229         /// function fails, Marshal.GetLastWin32Error() will return a different 
    230         /// error code.</returns> 
    231         [DllImport("Sfc.dll", SetLastError = true, CharSet = CharSet.Unicode)] 
     212        /// <returns>If the file is protected, the return value is true.</returns> 
     213        [DllImport("Sfc.dll", CharSet = CharSet.Unicode)] 
    232214        [return: MarshalAs(UnmanagedType.Bool)] 
    233215        private static extern bool SfcIsFileProtected(IntPtr RpcHandle, 
Note: See TracChangeset for help on using the changeset viewer.