소스 검색

remove net46 support

JasonWang 6 년 전
부모
커밋
9826a8b8e1

+ 33 - 24
src/MineCase.Core/Chat.cs

@@ -96,7 +96,12 @@ namespace MineCase
     public class ChatClickEvent
     {
         private static readonly string[] _map = new string[4]
-        { "open_url", "run_command", "suggest_command", "change_page" };
+        {
+            "open_url",
+            "run_command",
+            "suggest_command",
+            "change_page"
+        };
 
         public ClickEventType Action { get; set; }
 
@@ -112,8 +117,8 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="ChatClickEvent"/> class with the specified parameters.
         /// </summary>
-        /// <param name="action">Action type</param>
-        /// <param name="value">The value of action</param>
+        /// <param name="action">Action type.</param>
+        /// <param name="value">The value of action.</param>
         public ChatClickEvent(ClickEventType action, JToken value)
         {
             Action = action;
@@ -134,7 +139,11 @@ namespace MineCase
     public class ChatHoverEvent
     {
         private static readonly string[] _map = new string[3]
-        { "show_text", "show_item", "show_entity" };
+        {
+            "show_text",
+            "show_item",
+            "show_entity"
+        };
 
         public HoverEventType Action { get; set; }
 
@@ -150,8 +159,8 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="ChatHoverEvent"/> class with the specified parameters.
         /// </summary>
-        /// <param name="action">Action type</param>
-        /// <param name="value">The value of action</param>
+        /// <param name="action">Action type.</param>
+        /// <param name="value">The value of action.</param>
         public ChatHoverEvent(HoverEventType action, JToken value)
         {
             Action = action;
@@ -187,9 +196,9 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="ChatScore"/> class with the specified parameters.
         /// </summary>
-        /// <param name="name">The name of the player</param>
-        /// <param name="objective">The scoreboard target to display the score</param>
-        /// <param name="value">The score to be displayed</param>
+        /// <param name="name">The name of the player.</param>
+        /// <param name="objective">The scoreboard target to display the score.</param>
+        /// <param name="value">The score to be displayed.</param>
         public ChatScore(string name, string objective, int? value = null)
         {
             Name = name;
@@ -331,7 +340,7 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="StringComponent"/> class with a string.
         /// </summary>
-        /// <param name="text">The text of StringComponent</param>
+        /// <param name="text">The text of StringComponent.</param>
         public StringComponent(string text)
         {
             Text = text;
@@ -347,7 +356,7 @@ namespace MineCase
     }
 
     /// <summary>
-    /// Translation component. Translates text into the current language
+    /// Translation component. Translates text into the current language.
     /// </summary>
     public class TranslationComponent : ChatComponent
     {
@@ -365,8 +374,8 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="TranslationComponent"/> class with a string and a List.
         /// </summary>
-        /// <param name="translate">Translates text</param>
-        /// <param name="with">Optional tag</param>
+        /// <param name="translate">Translates text.</param>
+        /// <param name="with">Optional tag.</param>
         public TranslationComponent(string translate = null, List<ChatComponent> with = null)
         {
             Translate = translate;
@@ -423,7 +432,7 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="KeybindComponent"/> class with the specified type.
         /// </summary>
-        /// <param name="type">The type of keybind</param>
+        /// <param name="type">The type of keybind.</param>
         public KeybindComponent(KeyBindType type)
         {
             Keybind = type;
@@ -455,7 +464,7 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="ScoreComponent"/> class ChatScore class.
         /// </summary>
-        /// <param name="score">A ChatScore class</param>
+        /// <param name="score">A ChatScore class.</param>
         public ScoreComponent(ChatScore score)
         {
             Score = score;
@@ -487,7 +496,7 @@ namespace MineCase
         /// <summary>
         /// Initializes a new instance of the <see cref="SelectorComponent"/> class with a string.
         /// </summary>
-        /// <param name="selector">Selector string</param>
+        /// <param name="selector">Selector string.</param>
         public SelectorComponent(string selector)
         {
             Selector = selector;
@@ -551,7 +560,7 @@ namespace MineCase
         /// Initializes a new instance of the <see cref="Chat"/> class with a string.
         /// It is convenient to initialize a Chat class with a StringComponent.
         /// </summary>
-        /// <param name="text">The text of the StringComponent</param>
+        /// <param name="text">The text of the StringComponent.</param>
         public Chat(string text)
         {
             Component = new StringComponent(text);
@@ -561,10 +570,10 @@ namespace MineCase
         /// Parses Chat from a JSON string.
         /// </summary>
         /// <exception>
-        /// Newtonsoft.Json.JsonException
+        /// Newtonsoft.Json.JsonException.
         /// </exception>
-        /// <param name="json">The JSON string</param>
-        /// <returns>A Chat object</returns>
+        /// <param name="json">The JSON string.</param>
+        /// <returns>A Chat object.</returns>
         public static Chat Parse(string json)
         {
             if (string.IsNullOrEmpty(json))
@@ -590,9 +599,9 @@ namespace MineCase
         /// Serializes this object to a JObject.
         /// </summary>
         /// <exception>
-        /// InvalidOperationException
+        /// InvalidOperationException.
         /// </exception>
-        /// <returns>A JObject</returns>
+        /// <returns>A JObject.</returns>
         public JObject ToJObject()
         {
             if (Component == null)
@@ -607,9 +616,9 @@ namespace MineCase
         /// Serializes this object to a string.
         /// </summary>
         /// <exception>
-        /// InvalidOperationException
+        /// InvalidOperationException.
         /// </exception>
-        /// <returns>A JSON string</returns>
+        /// <returns>A JSON string.</returns>
         public override string ToString()
         {
             return JsonConvert.SerializeObject(Component.ToJObject(), Formatting.None);

+ 2 - 1
src/MineCase.Core/CraftingRecipeLoader.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -214,7 +215,7 @@ namespace MineCase
 
         private static unsafe string ToString(ReadOnlySpan<char> span)
         {
-            return new string((char*)Unsafe.AsPointer(ref span.DangerousGetPinnableReference()), 0, span.Length);
+            return new string((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span)), 0, span.Length);
         }
     }
 

+ 2 - 1
src/MineCase.Core/FurnaceRecipeLoader.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -136,7 +137,7 @@ namespace MineCase
 
         private static unsafe string ToString(ReadOnlySpan<char> span)
         {
-            return new string((char*)Unsafe.AsPointer(ref span.DangerousGetPinnableReference()), 0, span.Length);
+            return new string((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span)), 0, span.Length);
         }
     }
 

+ 3 - 20
src/MineCase.Core/MineCase.Core.csproj

@@ -1,8 +1,8 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <RootNamespace>MineCase</RootNamespace>
-    <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
+    <TargetFrameworks>netstandard2.0</TargetFrameworks>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
@@ -12,16 +12,12 @@
     <DebugSymbols>true</DebugSymbols>
   </PropertyGroup>
   
-  <PropertyGroup Condition="'$(TargetFramework)' == 'net46'">
-    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
-    <FrameworkPathOverride>$(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6\1.0.1\lib\net46\</FrameworkPathOverride>
-  </PropertyGroup>
-  
   <ItemGroup>
     <ProjectReference Include="..\MineCase.Nbt\MineCase.Nbt.csproj" />
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="2.3.4" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
@@ -30,13 +26,6 @@
     <PackageReference Include="System.ValueTuple" Version="4.5.0" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
-    <PackageReference Include="System.ValueTuple" Version="4.4.0" />
-    <PackageReference Include="Microsoft.TargetingPack.NETFramework.v4.6" Version="1.0.1" ExcludeAssets="All" PrivateAssets="All" />
-
-    <Reference Include="System.Runtime" />
-  </ItemGroup>
-
   <ItemGroup>
     <AdditionalFiles Include="..\..\build\stylecop.json" />
   </ItemGroup>
@@ -45,10 +34,4 @@
     <Folder Include="Game\Entities\" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
-    <PackageReference Include="Microsoft.Orleans.Core.Abstractions">
-      <Version>2.3.4</Version>
-    </PackageReference>
-  </ItemGroup>
-
 </Project>

+ 2 - 17
src/MineCase.Nbt/MineCase.Nbt.csproj

@@ -1,7 +1,7 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
+    <TargetFrameworks>netstandard2.0</TargetFrameworks>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
     <Configurations>Debug;Release;Appveyor;TravisCI</Configurations>
@@ -9,21 +9,6 @@
     <DebugSymbols>true</DebugSymbols>
   </PropertyGroup>
 
-  <PropertyGroup Condition="'$(TargetFramework)' == 'net46'">
-    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
-    <FrameworkPathOverride>$(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6\1.0.1\lib\net46\</FrameworkPathOverride>
-  </PropertyGroup>
-
-  <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
-    <PackageReference Include="Microsoft.TargetingPack.NETFramework.v4.6" Version="1.0.1" ExcludeAssets="All" PrivateAssets="All" />
-    
-    <Reference Include="System" />
-    <Reference Include="System.Runtime" />
-    <Reference Include="System.ComponentModel" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-
   <ItemGroup>
     <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />

+ 1 - 18
src/MineCase.Protocol/MineCase.Protocol.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
+    <TargetFrameworks>netstandard2.0</TargetFrameworks>
     <RootNamespace>MineCase</RootNamespace>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -12,11 +12,6 @@
     <DebugSymbols>true</DebugSymbols>
   </PropertyGroup>
 
-  <PropertyGroup Condition="'$(TargetFramework)' == 'net46'">
-    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
-    <FrameworkPathOverride>$(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6\1.0.1\lib\net46\</FrameworkPathOverride>
-  </PropertyGroup>
-
   <ItemGroup>
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="System.Buffers" Version="4.5.0" />
@@ -27,12 +22,6 @@
     <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
-    <PackageReference Include="Microsoft.TargetingPack.NETFramework.v4.6" Version="1.0.1" ExcludeAssets="All" PrivateAssets="All" />
-
-    <Reference Include="System.Runtime" />
-  </ItemGroup>
-
   <ItemGroup>
     <AdditionalFiles Include="..\..\build\stylecop.json" />
   </ItemGroup>
@@ -42,10 +31,4 @@
     <ProjectReference Include="..\MineCase.Nbt\MineCase.Nbt.csproj" />
   </ItemGroup>
 
-  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
-    <PackageReference Include="Microsoft.Orleans.Core.Abstractions">
-      <Version>2.3.4</Version>
-    </PackageReference>
-  </ItemGroup>
-
 </Project>

+ 2 - 2
src/MineCase.Protocol/Protocol/PacketCompress.cs

@@ -20,7 +20,7 @@ namespace MineCase.Protocol
 
             targetPacket = targetPacket ?? new UncompressedPacket();
             using (var stream = new MemoryStream(packet.CompressedData))
-            using (var br = new BinaryReader(useCompression ? (Stream)new ZlibStream(stream, CompressionMode.Decompress, true) : stream))
+            using (var br = new BinaryReader(useCompression ? (Stream)new ZlibStream(stream, CompressionMode.Decompress, CompressionLevel.BestSpeed) : stream))
             {
                 targetPacket.PacketId = br.ReadAsVarInt(out var packetIdLen);
 
@@ -41,7 +41,7 @@ namespace MineCase.Protocol
                 bool useCompression = dataLength >= threshold;
                 targetPacket.DataLength = useCompression ? dataLength : 0;
 
-                using (var bw = new BinaryWriter(useCompression ? (Stream)new ZlibStream(stream, CompressionMode.Compress, true) : stream))
+                using (var bw = new BinaryWriter(useCompression ? (Stream)new ZlibStream(stream, CompressionMode.Compress, CompressionLevel.BestSpeed) : stream))
                 {
                     bw.WriteAsVarInt(packet.PacketId, out _);
                     bw.Write(packet.Data.Array, packet.Data.Offset, packet.Data.Count);

+ 41 - 3
src/MineCase.Protocol/ReadWriteExtensions.cs

@@ -4,13 +4,13 @@
 using System.Buffers;
 using System.Runtime;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
-using static System.Buffers.Binary.BinaryPrimitives;
 
 #pragma warning disable
 
 namespace System.IO.Pipelines
-{
+{   
     internal static class ReadWriteExtensions
     {
         /// <summary>
@@ -77,7 +77,6 @@ namespace System.IO.Pipelines
         public static T ReadBigEndian<T>(this ReadOnlySpan<byte> buffer) where T : struct
             => BitConverter.IsLittleEndian ? Reverse(ReadMachineEndian<T>(buffer)) : ReadMachineEndian<T>(buffer);
 
-
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static T ReadLittleEndian<T>(this ReadOnlySpan<byte> buffer) where T : struct
             => BitConverter.IsLittleEndian ? ReadMachineEndian<T>(buffer) : Reverse(ReadMachineEndian<T>(buffer));
@@ -98,5 +97,44 @@ namespace System.IO.Pipelines
                 value = Reverse(value);
             WriteMachineEndian(buffer, ref value);
         }
+
+        // BinaryPrimitives
+        public static void WriteMachineEndian<T>(this Span<byte> buffer, ref T value)
+        where T : struct
+        {
+            Unsafe.WriteUnaligned<T>(ref MemoryMarshal.GetReference(buffer), value);
+        }
+
+
+        public static bool TryWriteMachineEndian<T>(this Span<byte> buffer, ref T value)
+            where T : struct
+        {
+            if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
+            {
+                return false;
+            }
+            Unsafe.WriteUnaligned<T>(ref MemoryMarshal.GetReference(buffer), value);
+            return true;
+        }
+
+
+        public static T ReadMachineEndian<T>(this ReadOnlySpan<byte> buffer)
+            where T : struct
+        {
+            return Unsafe.ReadUnaligned<T>(ref MemoryMarshal.GetReference(buffer));
+        }
+
+
+        public static bool TryReadMachineEndian<T>(this ReadOnlySpan<byte> buffer, out T value)
+            where T : struct
+        {
+            if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
+            {
+                value = default;
+                return false;
+            }
+            value = Unsafe.ReadUnaligned<T>(ref MemoryMarshal.GetReference(buffer));
+            return true;
+        }
     }
 }

+ 3 - 2
src/MineCase.Protocol/Serialization/SpanReader.cs

@@ -3,13 +3,14 @@ using System.Collections.Generic;
 using System.IO;
 using System.IO.Pipelines;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 using System.Text;
 
 using MineCase.Nbt;
 
 namespace MineCase.Serialization
 {
-    public struct SpanReader
+    public ref struct SpanReader
     {
         private ReadOnlySpan<byte> _span;
 
@@ -53,7 +54,7 @@ namespace MineCase.Serialization
         {
             var len = ReadAsVarInt(out _);
             var bytes = ReadBytes((int)len);
-            return Encoding.UTF8.GetString((byte*)Unsafe.AsPointer(ref bytes.DangerousGetPinnableReference()), bytes.Length);
+            return Encoding.UTF8.GetString((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)), bytes.Length);
         }
 
         public ushort ReadAsUnsignedShort()

+ 0 - 68
src/MineCase.Protocol/Writer.cs

@@ -1,68 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Runtime;
-using System.Runtime.CompilerServices;
-
-#pragma warning disable
-
-namespace System.Buffers.Binary
-{
-    internal static partial class BinaryPrimitives
-    {
-        /// <summary>
-        /// Writes a structure of type T into a span of bytes.
-        /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static void WriteMachineEndian<T>(Span<byte> buffer, ref T value)
-            where T : struct
-        {
-            Unsafe.WriteUnaligned<T>(ref buffer.DangerousGetPinnableReference(), value);
-        }
-
-        /// <summary>
-        /// Writes a structure of type T into a span of bytes.
-        /// <returns>If the span is too small to contain the type T, return false.</returns>
-        /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static bool TryWriteMachineEndian<T>(Span<byte> buffer, ref T value)
-            where T : struct
-        {
-            if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
-            {
-                return false;
-            }
-            Unsafe.WriteUnaligned<T>(ref buffer.DangerousGetPinnableReference(), value);
-            return true;
-        }
-
-        /// <summary>
-        /// Reads a structure of type T out of a read-only span of bytes.
-        /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static T ReadMachineEndian<T>(ReadOnlySpan<byte> buffer)
-            where T : struct
-        {
-            return Unsafe.ReadUnaligned<T>(ref buffer.DangerousGetPinnableReference());
-        }
-
-        /// <summary>
-        /// Reads a structure of type T out of a span of bytes.
-        /// <returns>If the span is too small to contain the type T, return false.</returns>
-        /// </summary>
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static bool TryReadMachineEndian<T>(ReadOnlySpan<byte> buffer, out T value)
-            where T : struct
-        {
-            if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
-            {
-                value = default;
-                return false;
-            }
-            value = Unsafe.ReadUnaligned<T>(ref buffer.DangerousGetPinnableReference());
-            return true;
-        }
-    }
-}
-