From cdef8238bd5925caf855023db4b00dc449307aa2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Sep 2021 15:11:09 -0500 Subject: clean up warnings --- src/slskd/Common/Extensions.cs | 30 ---------------------------- src/slskd/Common/IStateMonitor.cs | 40 -------------------------------------- src/slskd/Common/IStateMutator.cs | 14 ------------- src/slskd/Common/IStateSnapshot.cs | 7 ------- src/slskd/Common/ManagedState.cs | 5 +++-- src/slskd/Program.cs | 2 +- 6 files changed, 4 insertions(+), 94 deletions(-) delete mode 100644 src/slskd/Common/IStateMonitor.cs delete mode 100644 src/slskd/Common/IStateMutator.cs delete mode 100644 src/slskd/Common/IStateSnapshot.cs (limited to 'src') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 077f5b17..4f2cf29f 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -88,36 +88,6 @@ namespace slskd return str.Substring(0, pos) + replacement + str.Substring(pos + phrase.Length); } - /// - /// Computes a stable/consistent hash code for strings. - /// - /// - /// https://stackoverflow.com/questions/5154970/how-do-i-create-a-hashcode-in-net-c-for-a-string-that-is-safe-to-store-in-a - /// - /// The string for which the hash code is to be computed. - /// The hash code. - public static int GetStableHashCode(this string str) - { - unchecked - { - int hash1 = 5381; - int hash2 = hash1; - - for (int i = 0; i < str.Length && str[i] != '\0'; i += 2) - { - hash1 = ((hash1 << 5) + hash1) ^ str[i]; - if (i == str.Length - 1 || str[i + 1] == '\0') - { - break; - } - - hash2 = ((hash2 << 5) + hash2) ^ str[i + 1]; - } - - return hash1 + (hash2 * 1566083941); - } - } - /// /// Determines whether the string is a valid regular expression. /// diff --git a/src/slskd/Common/IStateMonitor.cs b/src/slskd/Common/IStateMonitor.cs deleted file mode 100644 index 9600e37a..00000000 --- a/src/slskd/Common/IStateMonitor.cs +++ /dev/null @@ -1,40 +0,0 @@ -//// -//// Copyright (c) slskd Team. All rights reserved. -//// -//// This program is free software: you can redistribute it and/or modify -//// it under the terms of the GNU Affero General Public License as published -//// by the Free Software Foundation, either version 3 of the License, or -//// (at your option) any later version. -//// -//// This program is distributed in the hope that it will be useful, -//// but WITHOUT ANY WARRANTY; without even the implied warranty of -//// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//// GNU Affero General Public License for more details. -//// -//// You should have received a copy of the GNU Affero General Public License -//// along with this program. If not, see https://www.gnu.org/licenses/. -//// - -//namespace slskd -//{ -// using System; - -// /// -// /// Provideds observable management of state objects. -// /// -// /// The type of the tracked state object. -// public interface IStateMonitor -// { -// /// -// /// Gets the current application state. -// /// -// T CurrentValue { get; } - -// /// -// /// Registers a listener to be called whenever the tracked state changes. -// /// -// /// Registers a listener to be called whenver state changes. -// /// An which should be disposed to stop listening for changes. -// IDisposable OnChange(Action<(T Previous, T Current)> listener); -// } -//} diff --git a/src/slskd/Common/IStateMutator.cs b/src/slskd/Common/IStateMutator.cs deleted file mode 100644 index b4f35e78..00000000 --- a/src/slskd/Common/IStateMutator.cs +++ /dev/null @@ -1,14 +0,0 @@ -//using System; - -//namespace slskd -//{ -// public interface IStateMutator -// { -// /// -// /// Replaces the current state with the value resolved by the . -// /// -// /// Given the current state, resolves a new state value. -// /// The updated state. -// T SetValue(Func setter); -// } -//} diff --git a/src/slskd/Common/IStateSnapshot.cs b/src/slskd/Common/IStateSnapshot.cs deleted file mode 100644 index 56113ca4..00000000 --- a/src/slskd/Common/IStateSnapshot.cs +++ /dev/null @@ -1,7 +0,0 @@ -//namespace slskd -//{ -// public interface IStateSnapshot -// { -// T Value { get; } -// } -//} diff --git a/src/slskd/Common/ManagedState.cs b/src/slskd/Common/ManagedState.cs index 0453aa06..bfde3c80 100644 --- a/src/slskd/Common/ManagedState.cs +++ b/src/slskd/Common/ManagedState.cs @@ -18,6 +18,7 @@ namespace slskd { using System; + using System.Text.Json; using Microsoft.Extensions.DependencyInjection; /// @@ -57,7 +58,7 @@ namespace slskd /// Provides point-in-time read access for state objects. /// /// The type of the tracked state object. - public interface IStateSnapshot + public interface IStateSnapshot { /// /// Gets the snapshotted state. @@ -133,7 +134,7 @@ namespace slskd /// The current value of the state. public StateSnapshot(T value) { - Value = value.ToJson().ToObject(); + Value = JsonSerializer.Deserialize(JsonSerializer.Serialize(value)); } /// diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index ec672f23..9590ed48 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -89,7 +89,7 @@ namespace slskd /// /// Inaccurate when running locally. /// - public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1,0,0,0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; + public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1, 0, 0, 0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; /// /// Gets the informational version of the application, including the git sha at the latest commit. -- cgit v1.2.3