53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using System;
|
|
|
|
namespace NixWslWrapper.Core.Domain
|
|
{
|
|
public class WslTarget
|
|
{
|
|
public string Distribution { get; }
|
|
public string User { get; }
|
|
public string NixProfilePath { get; }
|
|
|
|
public WslTarget(string distribution, string user, string nixProfilePath = "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh")
|
|
{
|
|
if (string.IsNullOrWhiteSpace(distribution))
|
|
throw new ArgumentException("WSL Distribution name cannot be null or empty.", nameof(distribution));
|
|
if (string.IsNullOrWhiteSpace(user))
|
|
throw new ArgumentException("WSL User cannot be null or empty.", nameof(user));
|
|
if (string.IsNullOrWhiteSpace(nixProfilePath))
|
|
throw new ArgumentException("Nix Profile Path cannot be null or empty.", nameof(nixProfilePath));
|
|
|
|
Distribution = distribution.Trim();
|
|
User = user.Trim();
|
|
NixProfilePath = nixProfilePath.Trim();
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj is not WslTarget other) return false;
|
|
return string.Equals(Distribution, other.Distribution, StringComparison.OrdinalIgnoreCase) &&
|
|
string.Equals(User, other.User, StringComparison.OrdinalIgnoreCase) &&
|
|
string.Equals(NixProfilePath, other.NixProfilePath, StringComparison.Ordinal);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(
|
|
Distribution.ToLowerOrdinal(),
|
|
User.ToLowerOrdinal(),
|
|
NixProfilePath
|
|
);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"WSL Distro: {Distribution}, User: {User}, Profile: {NixProfilePath}";
|
|
}
|
|
}
|
|
|
|
internal static class StringExtensions
|
|
{
|
|
public static string ToLowerOrdinal(this string str) => str.ToLowerInvariant();
|
|
}
|
|
}
|