aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Shares/Types
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-06-26 15:37:34 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-06-26 15:37:34 -0500
commit851dcdfa4824d6b06287959d89484db16f3a4d91 (patch)
tree34b81882a6fff569bcbad21f5a3715f9887f0595 /src/slskd/Shares/Types
parent093d75736d19c9e353368bc890d7f74cfd7e5bf0 (diff)
downloadslskd-851dcdfa4824d6b06287959d89484db16f3a4d91.tar.gz
move stuff again
Diffstat (limited to 'src/slskd/Shares/Types')
-rw-r--r--src/slskd/Shares/Types/Share.cs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/slskd/Shares/Types/Share.cs b/src/slskd/Shares/Types/Share.cs
new file mode 100644
index 00000000..6a6d1f66
--- /dev/null
+++ b/src/slskd/Shares/Types/Share.cs
@@ -0,0 +1,91 @@
+// <copyright file="Share.cs" company="slskd Team">
+// 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/.
+// </copyright>
+
+namespace slskd.Shares
+{
+ using System.Linq;
+ using System.Text.Json.Serialization;
+ using System.Text.RegularExpressions;
+
+ /// <summary>
+ /// A file share.
+ /// </summary>
+ public sealed class Share
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Share"/> class.
+ /// </summary>
+ /// <param name="id"></param>
+ /// <param name="alias"></param>
+ /// <param name="isExcluded"></param>
+ /// <param name="localPath"></param>
+ /// <param name="raw"></param>
+ /// <param name="remotePath"></param>
+ [JsonConstructor]
+ public Share (string id, string alias, bool isExcluded, string localPath, string raw, string remotePath)
+ {
+ Id = id;
+ Alias = alias;
+ IsExcluded = isExcluded;
+ LocalPath = localPath;
+ Raw = raw;
+ RemotePath = remotePath;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Share"/> class.
+ /// </summary>
+ /// <param name="share"></param>
+ public Share(string share)
+ {
+ Raw = share;
+ IsExcluded = share.StartsWith('-') || share.StartsWith('!');
+
+ if (IsExcluded)
+ {
+ share = share[1..];
+ }
+
+ // test to see whether an alias has been specified
+ var matches = Regex.Matches(share, @"^\[(.*)\](.*)$");
+
+ if (matches.Any())
+ {
+ // split the alias from the path, and validate the alias
+ var groups = matches[0].Groups;
+ Alias = groups[1].Value;
+ LocalPath = groups[2].Value;
+ }
+ else
+ {
+ Alias = share.Split(new[] { '/', '\\' }).Last();
+ LocalPath = share;
+ }
+
+ RemotePath = Alias;
+
+ Id = Compute.Sha1Hash(RemotePath);
+ }
+
+ public string Id { get; init; }
+ public string Alias { get; init; }
+ public bool IsExcluded { get; init; }
+ public string LocalPath { get; init; }
+ public string Raw { get; init; }
+ public string RemotePath { get; init; }
+ }
+}