Skip to content

Commit

Permalink
Move to file-scoped namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Mar 8, 2024
1 parent 09e3af5 commit 8a2f2a4
Show file tree
Hide file tree
Showing 38 changed files with 4,157 additions and 4,195 deletions.
33 changes: 16 additions & 17 deletions Launchpad.Common/Enums/EManifestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

namespace Launchpad.Common.Enums
namespace Launchpad.Common.Enums;

/// <summary>
/// Enum defining the type of manifest.
/// </summary>
public enum EManifestType
{
/// <summary>
/// Enum defining the type of manifest.
/// An unknown manifest.
/// </summary>
public enum EManifestType
{
/// <summary>
/// An unknown manifest.
/// </summary>
Unknown = 0,
Unknown = 0,

/// <summary>
/// A launcher manifest.
/// </summary>
Launchpad = 1,
/// <summary>
/// A launcher manifest.
/// </summary>
Launchpad = 1,

/// <summary>
/// A game manifest.
/// </summary>
Game = 2
}
/// <summary>
/// A game manifest.
/// </summary>
Game = 2
}
17 changes: 8 additions & 9 deletions Launchpad.Common/Enums/ESystemTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@

#pragma warning disable CS1591, SA1600, SA1602 // Elements should be documented, enumeration items should be documented

namespace Launchpad.Common.Enums
namespace Launchpad.Common.Enums;

public enum ESystemTarget
{
public enum ESystemTarget
{
Linux,
Mac,
Win64,
Win32,
Unknown
}
Linux,
Mac,
Win64,
Win32,
Unknown
}
67 changes: 33 additions & 34 deletions Launchpad.Common/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,47 @@
using System;
using System.Collections.Generic;

namespace Launchpad.Common
namespace Launchpad.Common;

/// <summary>
/// Various extension methods.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Various extension methods.
/// Sanitizes the input string, removing any \n, \r, or \0 characters.
/// </summary>
public static class ExtensionMethods
/// <param name="input">Input string.</param>
/// <returns>The string, without the illegal characters.</returns>
public static string RemoveLineSeparatorsAndNulls(this string input)
{
/// <summary>
/// Sanitizes the input string, removing any \n, \r, or \0 characters.
/// </summary>
/// <param name="input">Input string.</param>
/// <returns>The string, without the illegal characters.</returns>
public static string RemoveLineSeparatorsAndNulls(this string input)
return input.Replace("\n", string.Empty).Replace("\0", string.Empty).Replace("\r", string.Empty);
}

/// <summary>
/// Adds a new value to an existing IDictionary, or if the dictionary already contains a value for the given key,
/// updates the existing key with the new value.
/// </summary>
/// <param name="dictionary">The dictionary to update.</param>
/// <param name="key">The key of the provided value.</param>
/// <param name="value">The value to add or update.</param>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
where TKey : notnull
{
if (dictionary == null)
{
return input.Replace("\n", string.Empty).Replace("\0", string.Empty).Replace("\r", string.Empty);
throw new ArgumentNullException(nameof(dictionary));
}

/// <summary>
/// Adds a new value to an existing IDictionary, or if the dictionary already contains a value for the given key,
/// updates the existing key with the new value.
/// </summary>
/// <param name="dictionary">The dictionary to update.</param>
/// <param name="key">The key of the provided value.</param>
/// <param name="value">The value to add or update.</param>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
where TKey : notnull
if (dictionary.ContainsKey(key))
{
if (dictionary == null)
{
throw new ArgumentNullException(nameof(dictionary));
}

if (dictionary.ContainsKey(key))
{
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
}
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
}
}
}
29 changes: 14 additions & 15 deletions Launchpad.Common/Handlers/MD5Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@
using System.IO;
using System.Security.Cryptography;

namespace Launchpad.Common.Handlers
namespace Launchpad.Common.Handlers;

/// <summary>
/// MD5 hashing handler. Used to ensure file integrity.
/// </summary>
public static class MD5Handler
{
/// <summary>
/// MD5 hashing handler. Used to ensure file integrity.
/// Gets the file hash from a data stream.
/// </summary>
public static class MD5Handler
/// <returns>The hash.</returns>
/// <param name="dataStream">File stream.</param>
public static string GetStreamHash(Stream dataStream)
{
/// <summary>
/// Gets the file hash from a data stream.
/// </summary>
/// <returns>The hash.</returns>
/// <param name="dataStream">File stream.</param>
public static string GetStreamHash(Stream dataStream)
{
using var md5 = MD5.Create();
using var md5 = MD5.Create();

// Calculate the hash of the stream.
var resultString = BitConverter.ToString(md5.ComputeHash(dataStream)).Replace("-", string.Empty);
// Calculate the hash of the stream.
var resultString = BitConverter.ToString(md5.ComputeHash(dataStream)).Replace("-", string.Empty);

return resultString;
}
return resultString;
}
}
Loading

0 comments on commit 8a2f2a4

Please sign in to comment.