Project: Convert to .NET 5.0

This commit is contained in:
Gus
2021-02-08 17:50:27 +01:00
parent 8630a89553
commit 0ea33ff35c
10 changed files with 136 additions and 1068 deletions
+6 -6
View File
@@ -375,18 +375,18 @@ namespace WPinternals
HasChanged = true;
}
if ((NewPartition.PartitionGuid == null) || (NewPartition.PartitionGuid != CurrentPartition.PartitionGuid))
if ((NewPartition.PartitionGuid != Guid.Empty) || (NewPartition.PartitionGuid != CurrentPartition.PartitionGuid))
HasChanged = true;
if (NewPartition.PartitionGuid != null)
if (NewPartition.PartitionGuid != Guid.Empty)
CurrentPartition.PartitionGuid = NewPartition.PartitionGuid;
if (CurrentPartition.PartitionGuid == null)
if (CurrentPartition.PartitionGuid != Guid.Empty)
CurrentPartition.PartitionGuid = Guid.NewGuid();
if ((NewPartition.PartitionTypeGuid == null) || (NewPartition.PartitionTypeGuid != CurrentPartition.PartitionTypeGuid))
if ((NewPartition.PartitionTypeGuid != Guid.Empty) || (NewPartition.PartitionTypeGuid != CurrentPartition.PartitionTypeGuid))
HasChanged = true;
if (NewPartition.PartitionTypeGuid != null)
if (NewPartition.PartitionTypeGuid != Guid.Empty)
CurrentPartition.PartitionTypeGuid = NewPartition.PartitionTypeGuid;
if (CurrentPartition.PartitionTypeGuid == null)
if (CurrentPartition.PartitionTypeGuid != Guid.Empty)
CurrentPartition.PartitionTypeGuid = Guid.NewGuid();
for (int i = this.Partitions.Count - 1; i >= 0; i--)
+11 -3
View File
@@ -92,6 +92,8 @@ namespace WPinternals
private Stream stream;
private bool LeaveOpen;
private Thread WorkThread;
private CancellationTokenSource source;
private CancellationToken token;
public LZMACompressionStream(Stream stream, CompressionMode mode, bool LeaveOpen, int DictionarySize, int PosStateBits,
int LitContextBits, int LitPosBits, int Algorithm, int NumFastBytes, string MatchFinder, bool EndMarker)
@@ -99,6 +101,8 @@ namespace WPinternals
this.stream = stream;
this.LeaveOpen = LeaveOpen;
BufferStream = new PumpStream();
source = new CancellationTokenSource();
token = source.Token;
if (mode == CompressionMode.Compress)
{
@@ -130,14 +134,14 @@ namespace WPinternals
private void Encode()
{
Encoder.Code(BufferStream, stream, -1, -1, null);
Encoder.Code(BufferStream, stream, -1, -1, null, token);
if (LeaveOpen == false)
stream.Close();
}
private void Decode()
{
Decoder.Code(stream, BufferStream, -1, -1, null);
Decoder.Code(stream, BufferStream, -1, -1, null, token);
BufferStream.Close();
if (LeaveOpen == false)
stream.Close();
@@ -148,7 +152,11 @@ namespace WPinternals
if (Encoder != null)
BufferStream.Close();
else if (WorkThread.IsAlive)
WorkThread.Abort();
{
if (source != null)
source.Cancel();
WorkThread.Join();
}
}
public override int Read(byte[] buffer, int offset, int count)
+1 -12
View File
@@ -118,14 +118,12 @@ namespace WPinternals
[DllImport(
KERNEL32,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern bool CloseHandle(IntPtr handle);
[DllImport(
ADVAPI32,
CharSet = CharSet.Unicode,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern bool AdjustTokenPrivileges(
[In] SafeTokenHandle TokenHandle,
[In] bool DisableAllPrivileges,
@@ -138,7 +136,6 @@ namespace WPinternals
ADVAPI32,
CharSet = CharSet.Auto,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool RevertToSelf();
@@ -147,7 +144,6 @@ namespace WPinternals
EntryPoint = "LookupPrivilegeValueW",
CharSet = CharSet.Auto,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool LookupPrivilegeValue(
[In] string lpSystemName,
@@ -158,7 +154,6 @@ namespace WPinternals
KERNEL32,
CharSet = CharSet.Auto,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
IntPtr GetCurrentProcess();
@@ -166,7 +161,6 @@ namespace WPinternals
KERNEL32,
CharSet = CharSet.Auto,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
IntPtr GetCurrentThread();
@@ -174,7 +168,6 @@ namespace WPinternals
ADVAPI32,
CharSet = CharSet.Unicode,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool OpenProcessToken(
[In] IntPtr ProcessToken,
@@ -185,7 +178,6 @@ namespace WPinternals
(ADVAPI32,
CharSet = CharSet.Unicode,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool OpenThreadToken(
[In] IntPtr ThreadToken,
@@ -197,7 +189,6 @@ namespace WPinternals
(ADVAPI32,
CharSet = CharSet.Unicode,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool DuplicateTokenEx(
[In] SafeTokenHandle ExistingToken,
@@ -211,7 +202,6 @@ namespace WPinternals
(ADVAPI32,
CharSet = CharSet.Unicode,
SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern
bool SetThreadToken(
[In] IntPtr Thread,
@@ -301,8 +291,7 @@ namespace WPinternals
}
[DllImport(NativeMethods.KERNEL32, SetLastError = true),
SuppressUnmanagedCodeSecurity,
ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
SuppressUnmanagedCodeSecurity]
private static extern bool CloseHandle(IntPtr handle);
override protected bool ReleaseHandle()
-20
View File
@@ -20,8 +20,6 @@
using System;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Threading;
@@ -93,7 +91,6 @@ namespace WPinternals
// of privilege names to luids
//
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
private static Luid LuidFromPrivilege(string privilege)
{
Luid luid;
@@ -104,8 +101,6 @@ namespace WPinternals
// Look up the privilege LUID inside the cache
//
RuntimeHelpers.PrepareConstrainedRegions();
try
{
privilegeLock.AcquireReaderLock(Timeout.Infinite);
@@ -206,8 +201,6 @@ namespace WPinternals
}
}
RuntimeHelpers.PrepareConstrainedRegions();
try
{
// Open the thread token; if there is no thread token,
@@ -382,19 +375,16 @@ namespace WPinternals
#endregion
#region Public methods and properties
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public void Enable()
{
this.ToggleState(true);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public void Disable()
{
this.ToggleState(false);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public void Revert()
{
int error = 0;
@@ -413,8 +403,6 @@ namespace WPinternals
// This code must be eagerly prepared and non-interruptible.
RuntimeHelpers.PrepareConstrainedRegions();
try
{
// The payload is entirely in the finally block
@@ -492,8 +480,6 @@ namespace WPinternals
Privilege p = new Privilege(privilege);
RuntimeHelpers.PrepareConstrainedRegions();
try
{
if (enabled)
@@ -520,7 +506,6 @@ namespace WPinternals
#endregion
#region Private implementation
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
private void ToggleState(bool enable)
{
int error = 0;
@@ -542,8 +527,6 @@ namespace WPinternals
// Need to make this block of code non-interruptible so that it would preserve
// consistency of thread oken state even in the face of catastrophic exceptions
RuntimeHelpers.PrepareConstrainedRegions();
try
{
// The payload is entirely in the finally block
@@ -635,11 +618,8 @@ namespace WPinternals
}
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private void Reset()
{
RuntimeHelpers.PrepareConstrainedRegions();
try
{
// Payload is in the finally block