Remove all unnecessary usings

This commit is contained in:
Caelan Sayler
2024-02-02 12:35:57 +00:00
parent 2caa7852d3
commit a3828fc6a6
66 changed files with 92 additions and 361 deletions

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading; using Avalonia.Threading;

View File

@@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace AvaloniaCrossPlat; namespace AvaloniaCrossPlat;

View File

@@ -1,6 +1,4 @@
using System.Configuration; using System.Windows;
using System.Data;
using System.Windows;
namespace VeloWpfSample namespace VeloWpfSample
{ {

View File

@@ -1,13 +1,5 @@
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack; using Velopack;

View File

@@ -1,8 +1,4 @@
using System; using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace VeloWpfSample namespace VeloWpfSample

View File

@@ -1,10 +1,4 @@
using System; using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Velopack; using Velopack;

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.NET.HostModel.AppHost namespace Microsoft.NET.HostModel.AppHost
{ {
/// <summary> /// <summary>

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
namespace Microsoft.NET.HostModel.AppHost namespace Microsoft.NET.HostModel.AppHost
{ {
internal static class ElfUtils internal static class ElfUtils

View File

@@ -1,11 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Microsoft.NET.HostModel namespace Microsoft.NET.HostModel
{ {
/// <summary> /// <summary>

View File

@@ -1,10 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
namespace Microsoft.NET.HostModel.AppHost namespace Microsoft.NET.HostModel.AppHost

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.NET.HostModel.AppHost namespace Microsoft.NET.HostModel.AppHost
{ {
/// <summary> /// <summary>

View File

@@ -1,12 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Text;
using System.Threading;
namespace Microsoft.NET.HostModel namespace Microsoft.NET.HostModel
{ {
/// <summary> /// <summary>

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle
{ {
/// <summary> /// <summary>

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle
{ {
/// <summary> /// <summary>

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle
{ {
/// <summary> /// <summary>

View File

@@ -1,10 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle

View File

@@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.NET.HostModel.AppHost; using Microsoft.NET.HostModel.AppHost;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle

View File

@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Microsoft.NET.HostModel.Bundle namespace Microsoft.NET.HostModel.Bundle
{ {
/// <summary> /// <summary>

View File

@@ -1,8 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Microsoft.NET.HostModel namespace Microsoft.NET.HostModel
@@ -18,16 +17,14 @@ namespace Microsoft.NET.HostModel
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Debug.Assert(IsCodesignAvailable()); Debug.Assert(IsCodesignAvailable());
var psi = new ProcessStartInfo() var psi = new ProcessStartInfo() {
{
Arguments = $"{args} \"{appHostPath}\"", Arguments = $"{args} \"{appHostPath}\"",
FileName = CodesignPath, FileName = CodesignPath,
RedirectStandardError = true, RedirectStandardError = true,
UseShellExecute = false, UseShellExecute = false,
}; };
using (var p = Process.Start(psi)) using (var p = Process.Start(psi)) {
{
p.WaitForExit(); p.WaitForExit();
return (p.ExitCode, p.StandardError.ReadToEnd()); return (p.ExitCode, p.StandardError.ReadToEnd());
} }

View File

@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -21,12 +20,12 @@ namespace Microsoft.NET.HostModel
// Native methods for updating resources // Native methods for updating resources
// //
[DllImport(nameof(Kernel32), CharSet = CharSet.Unicode, SetLastError=true)] [DllImport(nameof(Kernel32), CharSet = CharSet.Unicode, SetLastError = true)]
public static extern SafeUpdateHandle BeginUpdateResource(string pFileName, public static extern SafeUpdateHandle BeginUpdateResource(string pFileName,
[MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources); [MarshalAs(UnmanagedType.Bool)] bool bDeleteExistingResources);
// Update a resource with data from an IntPtr // Update a resource with data from an IntPtr
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateResource(SafeUpdateHandle hUpdate, public static extern bool UpdateResource(SafeUpdateHandle hUpdate,
IntPtr lpType, IntPtr lpType,
@@ -36,33 +35,33 @@ namespace Microsoft.NET.HostModel
uint cbData); uint cbData);
// Update a resource with data from a managed byte[] // Update a resource with data from a managed byte[]
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateResource(SafeUpdateHandle hUpdate, public static extern bool UpdateResource(SafeUpdateHandle hUpdate,
IntPtr lpType, IntPtr lpType,
IntPtr lpName, IntPtr lpName,
ushort wLanguage, ushort wLanguage,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=5)] byte[] lpData, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] byte[] lpData,
uint cbData); uint cbData);
// Update a resource with data from a managed byte[] // Update a resource with data from a managed byte[]
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateResource(SafeUpdateHandle hUpdate, public static extern bool UpdateResource(SafeUpdateHandle hUpdate,
string lpType, string lpType,
IntPtr lpName, IntPtr lpName,
ushort wLanguage, ushort wLanguage,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=5)] byte[] lpData, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] byte[] lpData,
uint cbData); uint cbData);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndUpdateResource(SafeUpdateHandle hUpdate, public static extern bool EndUpdateResource(SafeUpdateHandle hUpdate,
bool fDiscard); bool fDiscard);
// The IntPtr version of this dllimport is used in the // The IntPtr version of this dllimport is used in the
// SafeHandle implementation // SafeHandle implementation
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndUpdateResource(IntPtr hUpdate, public static extern bool EndUpdateResource(IntPtr hUpdate,
bool fDiscard); bool fDiscard);
@@ -81,12 +80,12 @@ namespace Microsoft.NET.HostModel
LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020 LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020
} }
[DllImport(nameof(Kernel32), CharSet = CharSet.Unicode, SetLastError=true)] [DllImport(nameof(Kernel32), CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadLibraryEx(string lpFileName, public static extern IntPtr LoadLibraryEx(string lpFileName,
IntPtr hReservedNull, IntPtr hReservedNull,
LoadLibraryFlags dwFlags); LoadLibraryFlags dwFlags);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(IntPtr hModule); public static extern bool FreeLibrary(IntPtr hModule);
@@ -107,20 +106,20 @@ namespace Microsoft.NET.HostModel
ushort wLang, ushort wLang,
IntPtr lParam); IntPtr lParam);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumResourceTypes(IntPtr hModule, public static extern bool EnumResourceTypes(IntPtr hModule,
EnumResTypeProc lpEnumFunc, EnumResTypeProc lpEnumFunc,
IntPtr lParam); IntPtr lParam);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumResourceNames(IntPtr hModule, public static extern bool EnumResourceNames(IntPtr hModule,
IntPtr lpType, IntPtr lpType,
EnumResNameProc lpEnumFunc, EnumResNameProc lpEnumFunc,
IntPtr lParam); IntPtr lParam);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumResourceLanguages(IntPtr hModule, public static extern bool EnumResourceLanguages(IntPtr hModule,
IntPtr lpType, IntPtr lpType,
@@ -128,25 +127,25 @@ namespace Microsoft.NET.HostModel
EnumResLangProc lpEnumFunc, EnumResLangProc lpEnumFunc,
IntPtr lParam); IntPtr lParam);
public const int UserStoppedResourceEnumerationHRESULT = unchecked((int)0x80073B02); public const int UserStoppedResourceEnumerationHRESULT = unchecked((int) 0x80073B02);
public const int ResourceDataNotFoundHRESULT = unchecked((int)0x80070714); public const int ResourceDataNotFoundHRESULT = unchecked((int) 0x80070714);
// Querying and loading resources // Querying and loading resources
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
public static extern IntPtr FindResourceEx(IntPtr hModule, public static extern IntPtr FindResourceEx(IntPtr hModule,
IntPtr lpType, IntPtr lpType,
IntPtr lpName, IntPtr lpName,
ushort wLanguage); ushort wLanguage);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
public static extern IntPtr LoadResource(IntPtr hModule, public static extern IntPtr LoadResource(IntPtr hModule,
IntPtr hResInfo); IntPtr hResInfo);
[DllImport(nameof(Kernel32))] // does not call SetLastError [DllImport(nameof(Kernel32))] // does not call SetLastError
public static extern IntPtr LockResource(IntPtr hResData); public static extern IntPtr LockResource(IntPtr hResData);
[DllImport(nameof(Kernel32), SetLastError=true)] [DllImport(nameof(Kernel32), SetLastError = true)]
public static extern uint SizeofResource(IntPtr hModule, public static extern uint SizeofResource(IntPtr hModule,
IntPtr hResInfo); IntPtr hResInfo);
@@ -188,29 +187,23 @@ namespace Microsoft.NET.HostModel
public static bool IsSupportedOS() public static bool IsSupportedOS()
{ {
#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER #if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
{
return false; return false;
} }
#endif #endif
try try {
{
// On Nano Server 1709+, `BeginUpdateResource` is exported but returns a null handle with a zero error // On Nano Server 1709+, `BeginUpdateResource` is exported but returns a null handle with a zero error
// Try to call `BeginUpdateResource` with an invalid parameter; the error should be non-zero if supported // Try to call `BeginUpdateResource` with an invalid parameter; the error should be non-zero if supported
// On Nano Server 20213, `BeginUpdateResource` fails with ERROR_CALL_NOT_IMPLEMENTED // On Nano Server 20213, `BeginUpdateResource` fails with ERROR_CALL_NOT_IMPLEMENTED
using (var handle = Kernel32.BeginUpdateResource("", false)) using (var handle = Kernel32.BeginUpdateResource("", false)) {
{
int lastWin32Error = Marshal.GetLastWin32Error(); int lastWin32Error = Marshal.GetLastWin32Error();
if (handle.IsInvalid && (lastWin32Error == 0 || lastWin32Error == Kernel32.ERROR_CALL_NOT_IMPLEMENTED)) if (handle.IsInvalid && (lastWin32Error == 0 || lastWin32Error == Kernel32.ERROR_CALL_NOT_IMPLEMENTED)) {
{
return false; return false;
} }
} }
} } catch (EntryPointNotFoundException) {
catch (EntryPointNotFoundException)
{
// BeginUpdateResource isn't exported from Kernel32 // BeginUpdateResource isn't exported from Kernel32
return false; return false;
} }
@@ -230,8 +223,7 @@ namespace Microsoft.NET.HostModel
public ResourceUpdater(string peFile) public ResourceUpdater(string peFile)
{ {
hUpdate = Kernel32.BeginUpdateResource(peFile, false); hUpdate = Kernel32.BeginUpdateResource(peFile, false);
if (hUpdate.IsInvalid) if (hUpdate.IsInvalid) {
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
} }
@@ -245,8 +237,7 @@ namespace Microsoft.NET.HostModel
/// </summary> /// </summary>
public ResourceUpdater AddResourcesFromPEImage(string peFile) public ResourceUpdater AddResourcesFromPEImage(string peFile)
{ {
if (hUpdate.IsInvalid) if (hUpdate.IsInvalid) {
{
ThrowExceptionForInvalidUpdate(); ThrowExceptionForInvalidUpdate();
} }
@@ -256,8 +247,7 @@ namespace Microsoft.NET.HostModel
IntPtr hModule = Kernel32.LoadLibraryEx(peFile, IntPtr.Zero, IntPtr hModule = Kernel32.LoadLibraryEx(peFile, IntPtr.Zero,
Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE |
Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE); Kernel32.LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE);
if (hModule == IntPtr.Zero) if (hModule == IntPtr.Zero) {
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
@@ -266,23 +256,17 @@ namespace Microsoft.NET.HostModel
GCHandle errorInfoHandle = GCHandle.Alloc(errorInfo); GCHandle errorInfoHandle = GCHandle.Alloc(errorInfo);
var errorInfoPtr = GCHandle.ToIntPtr(errorInfoHandle); var errorInfoPtr = GCHandle.ToIntPtr(errorInfoHandle);
try try {
{ if (!Kernel32.EnumResourceTypes(hModule, enumTypesCallback, errorInfoPtr)) {
if (!Kernel32.EnumResourceTypes(hModule, enumTypesCallback, errorInfoPtr)) if (Marshal.GetHRForLastWin32Error() != Kernel32.ResourceDataNotFoundHRESULT) {
{
if (Marshal.GetHRForLastWin32Error() != Kernel32.ResourceDataNotFoundHRESULT)
{
CaptureEnumResourcesErrorInfo(errorInfoPtr); CaptureEnumResourcesErrorInfo(errorInfoPtr);
errorInfo.ThrowException(); errorInfo.ThrowException();
} }
} }
} } finally {
finally
{
errorInfoHandle.Free(); errorInfoHandle.Free();
if (!Kernel32.FreeLibrary(hModule)) if (!Kernel32.FreeLibrary(hModule)) {
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
} }
@@ -292,7 +276,7 @@ namespace Microsoft.NET.HostModel
internal static bool IsIntResource(IntPtr lpType) internal static bool IsIntResource(IntPtr lpType)
{ {
return ((uint)lpType >> 16) == 0; return ((uint) lpType >> 16) == 0;
} }
/// <summary> /// <summary>
@@ -303,18 +287,15 @@ namespace Microsoft.NET.HostModel
/// </summary> /// </summary>
public ResourceUpdater AddResource(byte[] data, IntPtr lpType, IntPtr lpName) public ResourceUpdater AddResource(byte[] data, IntPtr lpType, IntPtr lpName)
{ {
if (hUpdate.IsInvalid) if (hUpdate.IsInvalid) {
{
ThrowExceptionForInvalidUpdate(); ThrowExceptionForInvalidUpdate();
} }
if (!IsIntResource(lpType) || !IsIntResource(lpName)) if (!IsIntResource(lpType) || !IsIntResource(lpName)) {
{
throw new ArgumentException("AddResource can only be used with integer resource types"); throw new ArgumentException("AddResource can only be used with integer resource types");
} }
if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, Kernel32.LangID_LangNeutral_SublangNeutral, data, (uint)data.Length)) if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, Kernel32.LangID_LangNeutral_SublangNeutral, data, (uint) data.Length)) {
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
@@ -329,18 +310,15 @@ namespace Microsoft.NET.HostModel
/// </summary> /// </summary>
public ResourceUpdater AddResource(byte[] data, string lpType, IntPtr lpName) public ResourceUpdater AddResource(byte[] data, string lpType, IntPtr lpName)
{ {
if (hUpdate.IsInvalid) if (hUpdate.IsInvalid) {
{
ThrowExceptionForInvalidUpdate(); ThrowExceptionForInvalidUpdate();
} }
if (!IsIntResource(lpName)) if (!IsIntResource(lpName)) {
{
throw new ArgumentException("AddResource can only be used with integer resource names"); throw new ArgumentException("AddResource can only be used with integer resource names");
} }
if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, Kernel32.LangID_LangNeutral_SublangNeutral, data, (uint)data.Length)) if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, Kernel32.LangID_LangNeutral_SublangNeutral, data, (uint) data.Length)) {
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
@@ -355,20 +333,15 @@ namespace Microsoft.NET.HostModel
/// </summary> /// </summary>
public void Update() public void Update()
{ {
if (hUpdate.IsInvalid) if (hUpdate.IsInvalid) {
{
ThrowExceptionForInvalidUpdate(); ThrowExceptionForInvalidUpdate();
} }
try try {
{ if (!Kernel32.EndUpdateResource(hUpdate, false)) {
if (!Kernel32.EndUpdateResource(hUpdate, false))
{
ThrowExceptionForLastWin32Error(); ThrowExceptionForLastWin32Error();
} }
} } finally {
finally
{
hUpdate.SetHandleAsInvalid(); hUpdate.SetHandleAsInvalid();
} }
} }
@@ -376,8 +349,7 @@ namespace Microsoft.NET.HostModel
private bool EnumAndUpdateTypesCallback(IntPtr hModule, IntPtr lpType, IntPtr lParam) private bool EnumAndUpdateTypesCallback(IntPtr hModule, IntPtr lpType, IntPtr lParam)
{ {
var enumNamesCallback = new Kernel32.EnumResNameProc(EnumAndUpdateNamesCallback); var enumNamesCallback = new Kernel32.EnumResNameProc(EnumAndUpdateNamesCallback);
if (!Kernel32.EnumResourceNames(hModule, lpType, enumNamesCallback, lParam)) if (!Kernel32.EnumResourceNames(hModule, lpType, enumNamesCallback, lParam)) {
{
CaptureEnumResourcesErrorInfo(lParam); CaptureEnumResourcesErrorInfo(lParam);
return false; return false;
} }
@@ -387,8 +359,7 @@ namespace Microsoft.NET.HostModel
private bool EnumAndUpdateNamesCallback(IntPtr hModule, IntPtr lpType, IntPtr lpName, IntPtr lParam) private bool EnumAndUpdateNamesCallback(IntPtr hModule, IntPtr lpType, IntPtr lpName, IntPtr lParam)
{ {
var enumLanguagesCallback = new Kernel32.EnumResLangProc(EnumAndUpdateLanguagesCallback); var enumLanguagesCallback = new Kernel32.EnumResLangProc(EnumAndUpdateLanguagesCallback);
if (!Kernel32.EnumResourceLanguages(hModule, lpType, lpName, enumLanguagesCallback, lParam)) if (!Kernel32.EnumResourceLanguages(hModule, lpType, lpName, enumLanguagesCallback, lParam)) {
{
CaptureEnumResourcesErrorInfo(lParam); CaptureEnumResourcesErrorInfo(lParam);
return false; return false;
} }
@@ -398,8 +369,7 @@ namespace Microsoft.NET.HostModel
private bool EnumAndUpdateLanguagesCallback(IntPtr hModule, IntPtr lpType, IntPtr lpName, ushort wLang, IntPtr lParam) private bool EnumAndUpdateLanguagesCallback(IntPtr hModule, IntPtr lpType, IntPtr lpName, ushort wLang, IntPtr lParam)
{ {
IntPtr hResource = Kernel32.FindResourceEx(hModule, lpType, lpName, wLang); IntPtr hResource = Kernel32.FindResourceEx(hModule, lpType, lpName, wLang);
if (hResource == IntPtr.Zero) if (hResource == IntPtr.Zero) {
{
CaptureEnumResourcesErrorInfo(lParam); CaptureEnumResourcesErrorInfo(lParam);
return false; return false;
} }
@@ -407,8 +377,7 @@ namespace Microsoft.NET.HostModel
// hResourceLoaded is just a handle to the resource, which // hResourceLoaded is just a handle to the resource, which
// can be used to get the resource data // can be used to get the resource data
IntPtr hResourceLoaded = Kernel32.LoadResource(hModule, hResource); IntPtr hResourceLoaded = Kernel32.LoadResource(hModule, hResource);
if (hResourceLoaded == IntPtr.Zero) if (hResourceLoaded == IntPtr.Zero) {
{
CaptureEnumResourcesErrorInfo(lParam); CaptureEnumResourcesErrorInfo(lParam);
return false; return false;
} }
@@ -417,13 +386,11 @@ namespace Microsoft.NET.HostModel
// pointer to the resource data. The pointer is valid // pointer to the resource data. The pointer is valid
// until the module is unloaded. // until the module is unloaded.
IntPtr lpResourceData = Kernel32.LockResource(hResourceLoaded); IntPtr lpResourceData = Kernel32.LockResource(hResourceLoaded);
if (lpResourceData == IntPtr.Zero) if (lpResourceData == IntPtr.Zero) {
{ ((EnumResourcesErrorInfo) GCHandle.FromIntPtr(lParam).Target).failedToLockResource = true;
((EnumResourcesErrorInfo)GCHandle.FromIntPtr(lParam).Target).failedToLockResource = true;
} }
if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, wLang, lpResourceData, Kernel32.SizeofResource(hModule, hResource))) if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, wLang, lpResourceData, Kernel32.SizeofResource(hModule, hResource))) {
{
CaptureEnumResourcesErrorInfo(lParam); CaptureEnumResourcesErrorInfo(lParam);
return false; return false;
} }
@@ -438,8 +405,7 @@ namespace Microsoft.NET.HostModel
public void ThrowException() public void ThrowException()
{ {
if (failedToLockResource) if (failedToLockResource) {
{
Debug.Assert(hResult == 0); Debug.Assert(hResult == 0);
throw new ResourceNotAvailableException("Failed to lock resource"); throw new ResourceNotAvailableException("Failed to lock resource");
} }
@@ -452,10 +418,9 @@ namespace Microsoft.NET.HostModel
private static void CaptureEnumResourcesErrorInfo(IntPtr errorInfoPtr) private static void CaptureEnumResourcesErrorInfo(IntPtr errorInfoPtr)
{ {
int hResult = Marshal.GetHRForLastWin32Error(); int hResult = Marshal.GetHRForLastWin32Error();
if (hResult != Kernel32.UserStoppedResourceEnumerationHRESULT) if (hResult != Kernel32.UserStoppedResourceEnumerationHRESULT) {
{
GCHandle errorInfoHandle = GCHandle.FromIntPtr(errorInfoPtr); GCHandle errorInfoHandle = GCHandle.FromIntPtr(errorInfoPtr);
var errorInfo = (EnumResourcesErrorInfo)errorInfoHandle.Target; var errorInfo = (EnumResourcesErrorInfo) errorInfoHandle.Target;
errorInfo.hResult = hResult; errorInfo.hResult = hResult;
} }
} }
@@ -485,8 +450,7 @@ namespace Microsoft.NET.HostModel
public void Dispose(bool disposing) public void Dispose(bool disposing)
{ {
if (disposing) if (disposing) {
{
hUpdate.Dispose(); hUpdate.Dispose();
} }
} }

View File

@@ -1,11 +1,5 @@
using System; using System.Runtime.Versioning;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack.Packaging.Exceptions;
namespace Velopack.Packaging.Unix; namespace Velopack.Packaging.Unix;

View File

@@ -1,9 +1,4 @@
using System; using System.Runtime.Versioning;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using ELFSharp.ELF; using ELFSharp.ELF;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack.Packaging.Abstractions; using Velopack.Packaging.Abstractions;

View File

@@ -1,9 +1,4 @@
using System; using Velopack.Packaging.Abstractions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging.Abstractions;
namespace Velopack.Packaging.Unix.Commands; namespace Velopack.Packaging.Unix.Commands;

View File

@@ -1,7 +1,4 @@
using System.ComponentModel; using System.Runtime.Versioning;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security; using System.Security;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;

View File

@@ -1,9 +1,4 @@
using System; using System.Runtime.Versioning;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Velopack.NuGet; using Velopack.NuGet;
namespace Velopack.Packaging.Windows; namespace Velopack.Packaging.Windows;

View File

@@ -1,6 +1,4 @@
using Microsoft.Extensions.Logging; namespace Velopack.Packaging.Abstractions;
namespace Velopack.Packaging.Abstractions;
public interface ICommand<TOpt> where TOpt : class public interface ICommand<TOpt> where TOpt : class
{ {

View File

@@ -1,6 +1,4 @@
using Microsoft.Extensions.Logging; namespace Velopack.Packaging.Abstractions;
namespace Velopack.Packaging.Abstractions;
public interface IFancyConsole public interface IFancyConsole
{ {

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Packaging.Abstractions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Abstractions;
public interface IOutputOptions public interface IOutputOptions
{ {

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Packaging.Abstractions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Abstractions;
public interface IPlatformOptions : IOutputOptions public interface IPlatformOptions : IOutputOptions
{ {

View File

@@ -1,10 +1,5 @@
using System; using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Exceptions; namespace Velopack.Packaging.Exceptions;

View File

@@ -1,9 +1,4 @@
using System; using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Exceptions; namespace Velopack.Packaging.Exceptions;

View File

@@ -1,9 +1,4 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging.Exceptions; using Velopack.Packaging.Exceptions;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -1,5 +1,4 @@
using System.Reflection; using System.Runtime.Versioning;
using System.Runtime.Versioning;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -2,7 +2,6 @@
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Json; using Velopack.Json;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Packaging.Exceptions;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -1,9 +1,4 @@
using System.IO.Compression; using NuGet.Versioning;
using System.Text;
using System.Xml;
using Microsoft.Extensions.Logging;
using NuGet.Versioning;
using Velopack.Compression;
using Velopack.NuGet; using Velopack.NuGet;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -1,11 +1,4 @@
using System; using Velopack.Packaging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.NET.HostModel.Bundle;
using Octokit;
using Velopack.Packaging;
namespace Velopack.Vpk.Commands; namespace Velopack.Vpk.Commands;

View File

@@ -1,7 +1,6 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Windows;
namespace Velopack.Vpk.Commands; namespace Velopack.Vpk.Commands;

View File

@@ -1,7 +1,5 @@
using System.ComponentModel; using Humanizer;
using Humanizer;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Velopack.Packaging.Abstractions;
namespace Velopack.Vpk.Commands; namespace Velopack.Vpk.Commands;

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Vpk.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Vpk.Logging;
public record DefaultPromptValueFactory(bool DefaultPromptValue) public record DefaultPromptValueFactory(bool DefaultPromptValue)
{ {

View File

@@ -1,9 +1,4 @@
using System; using Serilog.Events;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Serilog.Events;
namespace Velopack.Vpk.Logging; namespace Velopack.Vpk.Logging;

View File

@@ -1,9 +1,4 @@
using System; using Spectre.Console.Rendering;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spectre.Console.Rendering;
namespace Velopack.Vpk.Logging; namespace Velopack.Vpk.Logging;

View File

@@ -1,10 +1,4 @@
using System; using System.Threading;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Spectre.Console; using Spectre.Console;
using Velopack.Packaging.Abstractions; using Velopack.Packaging.Abstractions;

View File

@@ -1,11 +1,6 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;

View File

@@ -6,7 +6,6 @@ using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Sources;
namespace Velopack.Locators namespace Velopack.Locators
{ {

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Velopack.Json; using Velopack.Json;

View File

@@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Velopack.Json; using Velopack.Json;
namespace Velopack.Sources namespace Velopack.Sources

View File

@@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack namespace Velopack
{ {

View File

@@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack
{ {
/// <summary> /// <summary>
/// Options to customise the behaviour of <see cref="UpdateManager"/>. /// Options to customise the behaviour of <see cref="UpdateManager"/>.

View File

@@ -1,11 +1,5 @@
using System; using Velopack.Packaging.Exceptions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging.Exceptions;
using Velopack.Packaging.Windows; using Velopack.Packaging.Windows;
using Velopack.Packaging.Windows.Commands;
namespace Velopack.Packaging.Tests; namespace Velopack.Packaging.Tests;

View File

@@ -1,7 +1,4 @@
using System.Diagnostics; using Velopack.Deployment;
using Velopack.Deployment;
using Velopack.Packaging.Unix.Commands;
using Velopack.Packaging.Windows.Commands;
using Velopack.Sources; using Velopack.Sources;
using Octokit; using Octokit;
using Velopack.Packaging.Exceptions; using Velopack.Packaging.Exceptions;

View File

@@ -1,11 +1,5 @@
using System; using NuGet.Versioning;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NuGet.Versioning;
using Velopack.Deployment; using Velopack.Deployment;
using Velopack.Packaging.Exceptions;
using Velopack.Sources; using Velopack.Sources;
namespace Velopack.Packaging.Tests; namespace Velopack.Packaging.Tests;

View File

@@ -1,9 +1,4 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging.Unix.Commands; using Velopack.Packaging.Unix.Commands;
using Velopack.Packaging.Windows.Commands; using Velopack.Packaging.Windows.Commands;
using Velopack.Vpk.Logging; using Velopack.Vpk.Logging;

View File

@@ -1,7 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Win32; using Microsoft.Win32;
using NuGet.Packaging; using NuGet.Packaging;

View File

@@ -1,10 +1,5 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Tests; namespace Velopack.Tests;

View File

@@ -1,10 +1,5 @@
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Velopack.Locators; using Velopack.Locators;
using Velopack.Windows; using Velopack.Windows;

View File

@@ -1,10 +1,5 @@
using System; using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Json; using Velopack.Json;
using Velopack.Sources; using Velopack.Sources;

View File

@@ -1,7 +1,4 @@
using System; using System.Dynamic;
using System.Collections.Generic;
using System.Linq;
using System.Dynamic;
using System.Reflection; using System.Reflection;
// Lovingly stolen from http://exposedobject.codeplex.com/ // Lovingly stolen from http://exposedobject.codeplex.com/

View File

@@ -1,8 +1,4 @@
using System; using System.Dynamic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Dynamic;
using System.Reflection; using System.Reflection;
// Lovingly stolen from http://exposedobject.codeplex.com/ // Lovingly stolen from http://exposedobject.codeplex.com/

View File

@@ -1,7 +1,4 @@
using System; using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Dynamic; using System.Dynamic;
// Lovingly stolen from http://exposedobject.codeplex.com/ // Lovingly stolen from http://exposedobject.codeplex.com/

View File

@@ -1,8 +1,6 @@
using System.Diagnostics.Metrics; using System.Text;
using System.Text;
using System.Text.Json; using System.Text.Json;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Json;
using Velopack.Locators; using Velopack.Locators;
using Velopack.Sources; using Velopack.Sources;
using Velopack.Tests.TestHelpers; using Velopack.Tests.TestHelpers;