Changeset 1548
- Timestamp:
- 1/18/2010 4:51:59 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview/Eraser.Util
- Files:
-
- 1 added
- 2 edited
-
Eraser.Util.csproj (modified) (1 diff)
-
File.cs (modified) (7 diffs)
-
NativeMethods/Sfc.cs (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/Eraser.Util.csproj
r1543 r1548 83 83 </CodeAnalysisDictionary> 84 84 </ItemGroup> 85 <ItemGroup> 86 <Compile Include="NativeMethods\Sfc.cs" /> 87 </ItemGroup> 85 88 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 86 89 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/eraser6/CodeReview/Eraser.Util/File.cs
r1528 r1548 50 50 { 51 51 //Allocate the structures 52 N TApi.NativeMethods.FILE_STREAM_INFORMATION[] streams =53 NTApi.N ativeMethods.NtQueryInformationFile(streamHandle);54 55 foreach (N TApi.NativeMethods.FILE_STREAM_INFORMATION streamInfo in streams)52 NativeMethods.FILE_STREAM_INFORMATION[] streams = 53 NTApi.NtQueryInformationFile(streamHandle); 54 55 foreach (NativeMethods.FILE_STREAM_INFORMATION streamInfo in streams) 56 56 { 57 57 //Get the name of the stream. The raw value is :NAME:$DATA … … 77 77 public static string GetFileDescription(string path) 78 78 { 79 ShellApi.NativeMethods.SHFILEINFO shfi = new ShellApi.NativeMethods.SHFILEINFO();80 ShellApi.NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),81 ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_DISPLAYNAME);79 NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO(); 80 NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 81 NativeMethods.SHGetFileInfoFlags.SHGFI_DISPLAYNAME); 82 82 return shfi.szDisplayName; 83 83 } … … 93 93 public static Icon GetFileIcon(string path) 94 94 { 95 ShellApi.NativeMethods.SHFILEINFO shfi = new ShellApi.NativeMethods.SHFILEINFO();96 ShellApi.NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),97 ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_SMALLICON |98 ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_ICON);95 NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO(); 96 NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 97 NativeMethods.SHGetFileInfoFlags.SHGFI_SMALLICON | 98 NativeMethods.SHGetFileInfoFlags.SHGFI_ICON); 99 99 100 100 if (shfi.hIcon != IntPtr.Zero) … … 132 132 while (g.MeasureString(builder.ToString(), drawFont).Width > newWidth) 133 133 { 134 if (! ShellApi.NativeMethods.PathCompactPathEx(builder, longPath,134 if (!NativeMethods.PathCompactPathEx(builder, longPath, 135 135 (uint)charCount--, 0)) 136 136 { … … 150 150 public static bool IsProtectedSystemFile(string filePath) 151 151 { 152 return SfcIsFileProtected(IntPtr.Zero, filePath);152 return NativeMethods.SfcIsFileProtected(IntPtr.Zero, filePath); 153 153 } 154 154 … … 163 163 uint bytesReturned = 0; 164 164 165 using (FileStream strm = new FileStream( 166 KernelApi.NativeMethods.CreateFile(path, 167 KernelApi.NativeMethods.GENERIC_READ | KernelApi.NativeMethods.GENERIC_WRITE, 168 0, IntPtr.Zero, KernelApi.NativeMethods.OPEN_EXISTING, 169 KernelApi.NativeMethods.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero), FileAccess.Read)) 170 { 171 if (KernelApi.NativeMethods.DeviceIoControl(strm.SafeFileHandle, 172 KernelApi.NativeMethods.FSCTL_GET_COMPRESSION, IntPtr.Zero, 0, 165 using (FileStream strm = new FileStream(NativeMethods.CreateFile(path, 166 NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 167 0, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 168 NativeMethods.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero), FileAccess.Read)) 169 { 170 if (NativeMethods.DeviceIoControl(strm.SafeFileHandle, 171 NativeMethods.FSCTL_GET_COMPRESSION, IntPtr.Zero, 0, 173 172 out compressionStatus, sizeof(ushort), out bytesReturned, IntPtr.Zero)) 174 173 { 175 return compressionStatus != KernelApi.NativeMethods.COMPRESSION_FORMAT_NONE;174 return compressionStatus != NativeMethods.COMPRESSION_FORMAT_NONE; 176 175 } 177 176 } … … 188 187 { 189 188 ushort compressionStatus = compressed ? 190 KernelApi.NativeMethods.COMPRESSION_FORMAT_DEFAULT :191 KernelApi.NativeMethods.COMPRESSION_FORMAT_NONE;189 NativeMethods.COMPRESSION_FORMAT_DEFAULT : 190 NativeMethods.COMPRESSION_FORMAT_NONE; 192 191 uint bytesReturned = 0; 193 192 194 using (FileStream strm = new FileStream( 195 KernelApi.NativeMethods.CreateFile(path, 196 KernelApi.NativeMethods.GENERIC_READ | KernelApi.NativeMethods.GENERIC_WRITE, 197 0, IntPtr.Zero, KernelApi.NativeMethods.OPEN_EXISTING, 198 KernelApi.NativeMethods.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero), FileAccess.ReadWrite)) 199 { 200 return KernelApi.NativeMethods.DeviceIoControl(strm.SafeFileHandle, 201 KernelApi.NativeMethods.FSCTL_SET_COMPRESSION, ref compressionStatus, 193 using (FileStream strm = new FileStream(NativeMethods.CreateFile(path, 194 NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, 195 0, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 196 NativeMethods.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero), FileAccess.ReadWrite)) 197 { 198 return NativeMethods.DeviceIoControl(strm.SafeFileHandle, 199 NativeMethods.FSCTL_SET_COMPRESSION, ref compressionStatus, 202 200 sizeof(ushort), IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero); 203 201 } 204 202 } 205 206 /// <summary>207 /// Determines whether the specified file is protected. Applications208 /// should avoid replacing protected system files.209 /// </summary>210 /// <param name="RpcHandle">This parameter must be NULL.</param>211 /// <param name="ProtFileName">The name of the file.</param>212 /// <returns>If the file is protected, the return value is true.</returns>213 [DllImport("Sfc.dll", CharSet = CharSet.Unicode)]214 [return: MarshalAs(UnmanagedType.Bool)]215 private static extern bool SfcIsFileProtected(IntPtr RpcHandle,216 string ProtFileName);217 203 218 204 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.
