From ca97a7f48b1a1782a4fb38d9ee86c41a04fd58cc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 18 Mar 2022 15:49:10 -0500 Subject: gather metadata when processing shares --- src/slskd/Shares/SharedFileCache.cs | 48 +------------------------------------ 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'src/slskd/Shares/SharedFileCache.cs') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index ad2468da..f13eaad4 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -249,7 +249,7 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => new File(1, f.ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f))) + .Select(f => f.ToSoulseekFile(share)) .ToDictionary(f => f.Filename, f => f); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully @@ -462,51 +462,5 @@ namespace slskd.Shares MaskedFiles = new Dictionary(); State.SetValue(state => state with { Directories = 0, Files = 0 }); } - - private sealed class Share - { - 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; - } - - var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\'); - - Mask = Compute.MaskHash(parent); - - var maskedPath = LocalPath.ReplaceFirst(parent, Mask); - - var aliasedSegment = LocalPath[(parent.Length + 1)..]; - RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); - } - - public string Alias { get; init; } - public bool IsExcluded { get; init; } - public string LocalPath { get; init; } - public string Mask { get; init; } - public string Raw { get; init; } - public string RemotePath { get; init; } - } } } \ No newline at end of file -- cgit v1.2.3