From 5a1e29680437c762255e08402dcfe6d4ed10e084 Mon Sep 17 00:00:00 2001
From: JoC0de <53140583+JoC0de@users.noreply.github.com>
Date: Sun, 22 Oct 2023 23:43:20 +0200
Subject: [PATCH] Fix compiler error on 2023.1 .net framework (#594)

* fix not compiling on 2023.1 with editor assembly compatibility level set to .net framework
* update to 4.0.1
---
 .../ConfigurationEncryptionHelper.cs          | 25 +++++++++++++------
 .../Editor/Ui/NugetPreferences.cs             |  2 +-
 src/NuGetForUnity/package.json                |  2 +-
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/NuGetForUnity/Editor/Configuration/ConfigurationEncryptionHelper.cs b/src/NuGetForUnity/Editor/Configuration/ConfigurationEncryptionHelper.cs
index a2cd6bee..ab1829ce 100644
--- a/src/NuGetForUnity/Editor/Configuration/ConfigurationEncryptionHelper.cs
+++ b/src/NuGetForUnity/Editor/Configuration/ConfigurationEncryptionHelper.cs
@@ -1,23 +1,34 @@
-#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
+#pragma warning disable SA1512,SA1124 // Single-line comments should not be followed by blank line
+#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
 using JetBrains.Annotations;
 #else
 using System.Security.Cryptography;
 #endif
+
+#region No ReShaper
+
+// ReSharper disable All
+// needed because 'JetBrains.Annotations.NotNull' and 'System.Diagnostics.CodeAnalysis.NotNull' collide if this file is compiled with a never version of Unity / C#
+using SuppressMessageAttribute = System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
+
+// ReSharper restore All
+
+#endregion
+
 using System;
-using System.Diagnostics.CodeAnalysis;
 using System.Text;
 using UnityEngine;
 
 namespace NugetForUnity.Configuration
 {
     /// <summary>
-    ///     Helper to encrypt sensitive data so they don't need to be stored in plaintext inside the configuration file.
+    ///     Helper to encrypt sensitive data so they don't need to be stored in plain-text inside the configuration file.
     /// </summary>
     internal static class ConfigurationEncryptionHelper
     {
         private static readonly byte[] EntropyBytes = Encoding.UTF8.GetBytes("NuGet");
 
-#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
+#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
 
         // on .net framework the type lives in 'System.Security' on .net standard it in 'System.Security.Cryptography.ProtectedData'
         [ItemCanBeNull]
@@ -44,7 +55,7 @@ public static string EncryptString(string value)
             {
                 var decryptedByteArray = Encoding.UTF8.GetBytes(value);
 
-#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI
+#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI
 #pragma warning disable CA1416 // Validate platform compatibility
                 var encryptedByteArray = ProtectedData.Protect(decryptedByteArray, EntropyBytes, DataProtectionScope.CurrentUser);
 #pragma warning restore CA1416 // Validate platform compatibility
@@ -86,7 +97,7 @@ public static string DecryptString(string encryptedString)
             {
                 var encryptedByteArray = Convert.FromBase64String(encryptedString);
 
-#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI
+#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI
 #pragma warning disable CA1416 // Validate platform compatibility
                 var decryptedByteArray = ProtectedData.Unprotect(encryptedByteArray, EntropyBytes, DataProtectionScope.CurrentUser);
 #pragma warning restore CA1416 // Validate platform compatibility
@@ -110,7 +121,7 @@ public static string DecryptString(string encryptedString)
             }
         }
 
-#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
+#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
         [CanBeNull]
         private static byte[] ProtectOrUnprotectUsingReflection(string methodName, byte[] data)
         {
diff --git a/src/NuGetForUnity/Editor/Ui/NugetPreferences.cs b/src/NuGetForUnity/Editor/Ui/NugetPreferences.cs
index 39935e11..3afcaea2 100644
--- a/src/NuGetForUnity/Editor/Ui/NugetPreferences.cs
+++ b/src/NuGetForUnity/Editor/Ui/NugetPreferences.cs
@@ -28,7 +28,7 @@ public class NugetPreferences : SettingsProvider
         /// <summary>
         ///     The current version of NuGet for Unity.
         /// </summary>
-        public const string NuGetForUnityVersion = "4.0.0";
+        public const string NuGetForUnityVersion = "4.0.1";
 
         /// <summary>
         ///     The current position of the scroll bar in the GUI.
diff --git a/src/NuGetForUnity/package.json b/src/NuGetForUnity/package.json
index bab45bae..45f82537 100644
--- a/src/NuGetForUnity/package.json
+++ b/src/NuGetForUnity/package.json
@@ -1,7 +1,7 @@
 {
     "name": "com.github-glitchenzo.nugetforunity",
     "displayName": "NuGetForUnity",
-    "version": "4.0.0",
+    "version": "4.0.1",
     "description": "A NuGet Package Manager for Unity",
     "unity": "2018.4",
     "keywords": [