From aba8787f7648d87ab728fc6546a44849c03e31fe Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 20 Aug 2021 21:50:21 -0500 Subject: sort by full name --- src/slskd/Application/SharedFileCache.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 4e0d5cd0..2b9c4d79 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -99,7 +99,12 @@ namespace slskd directories.AddOrUpdate(group.Name, group, (_, _) => group); } - return directories.Values.OrderBy(f => f.Name[8..]); + Console.WriteLine(directories.Values.ToJson()); + + return directories.Values.OrderBy(f => { + Console.WriteLine($"Sorting by {f.Name}"); + return f.Name[8..]; + }); } /// @@ -206,7 +211,6 @@ namespace slskd Log.Warning("Failed to scan files in directory {Directory}: {Message}", directory, ex.Message); } - current++; State.SetValue(state => state with { FillProgress = current / (double)unmaskedDirectories.Count, Files = files.Count }); } -- cgit v1.2.3 From 928724e62943ad2f026098d66d1e700514237b0b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 20 Aug 2021 21:53:46 -0500 Subject: sort shares by full name --- src/slskd/Application/SharedFileCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 4e0d5cd0..a3d7da93 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -99,7 +99,7 @@ namespace slskd directories.AddOrUpdate(group.Name, group, (_, _) => group); } - return directories.Values.OrderBy(f => f.Name[8..]); + return directories.Values.OrderBy(f => f.Name); } /// -- cgit v1.2.3 From f5f534c23f39599bb83b69a022ba141b6168ff8c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 20 Aug 2021 22:23:45 -0500 Subject: use split instead of Uri() --- src/slskd/Application/SharedFileCache.cs | 2 +- src/slskd/Options.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 2b9c4d79..5ef9be64 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -365,7 +365,7 @@ namespace slskd } else { - Alias = new Uri(share).Segments.Last(); + Alias = share.Split(new[] { '/', '\\' }).Last(); LocalPath = share; } diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 62bc0a6c..ec1eab06 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -280,7 +280,7 @@ namespace slskd return (share, Compute.MaskHash(Directory.GetParent(matches[0].Groups[3].Value).FullName), matches[0].Groups[2].Value, matches[0].Groups[3].Value); } - return (share, Compute.MaskHash(Directory.GetParent(share).FullName), new Uri(share).Segments.Last(), share); + return (share, Compute.MaskHash(Directory.GetParent(share).FullName), share.Split(new[] { '/', '\\' }).Last(), share); } var digestedShared = Shared -- cgit v1.2.3 From 810f8660bcc435bfb6dd4e1be99b8194462b263a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 21 Aug 2021 07:25:30 -0500 Subject: stop replacing forward slashes in file paths --- src/slskd/Application/SharedFileCache.cs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 5ef9be64..06442797 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -99,12 +99,7 @@ namespace slskd directories.AddOrUpdate(group.Name, group, (_, _) => group); } - Console.WriteLine(directories.Values.ToJson()); - - return directories.Values.OrderBy(f => { - Console.WriteLine($"Sorting by {f.Name}"); - return f.Name[8..]; - }); + return directories.Values.OrderBy(f => f.Name[8..]); } /// @@ -191,7 +186,7 @@ namespace slskd try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => new File(1, f.Replace("/", @"\").ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f))) + .Select(f => new File(1, f.ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f))) .ToDictionary(f => f.Filename, f => f); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully @@ -373,15 +368,8 @@ namespace slskd var maskedPath = LocalPath.ReplaceFirst(System.IO.Directory.GetParent(LocalPath).FullName, Mask); - if (!string.IsNullOrEmpty(Alias)) - { - var aliasedSegment = LocalPath[(System.IO.Directory.GetParent(LocalPath).FullName.Length + 1)..]; - RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); - } - else - { - RemotePath = LocalPath.ReplaceFirst(System.IO.Directory.GetParent(LocalPath).FullName, Mask); - } + var aliasedSegment = LocalPath[(System.IO.Directory.GetParent(LocalPath).FullName.Length + 1)..]; + RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); } public string Alias { get; init; } -- cgit v1.2.3 From 726b692ed2e57db1940caa07da61e4419bc8564c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 21 Aug 2021 10:55:39 -0500 Subject: rename Files to MaskedFiles --- src/slskd/Application/SharedFileCache.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/slskd/Application/SharedFileCache.cs') diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 06442797..b4503cb7 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -52,14 +52,13 @@ namespace slskd /// public IStateMonitor State { get; } = new StateMonitor(); - private Dictionary Files { get; set; } private ILogger Log { get; } = Serilog.Log.ForContext(); private HashSet MaskedDirectories { get; set; } + private Dictionary MaskedFiles { get; set; } private IOptionsMonitor OptionsMonitor { get; set; } private List Shares { get; set; } private SqliteConnection SQLite { get; set; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); - private HashSet UnmaskedDirectories { get; set; } /// /// Returns the contents of the cache. @@ -79,7 +78,7 @@ namespace slskd directories.TryAdd(directory, new Directory(directory)); } - var groups = Files + var groups = MaskedFiles .GroupBy(f => Path.GetDirectoryName(f.Key)) .Select(g => new Directory(g.Key, g.Select(g => { @@ -221,11 +220,10 @@ namespace slskd Log.Debug("Inserted {Files} records in {Elapsed}ms", files.Count, sw.ElapsedMilliseconds - swSnapshot); - UnmaskedDirectories = unmaskedDirectories; MaskedDirectories = maskedDirectories; - Files = files; + MaskedFiles = files; - State.SetValue(state => state with { Filling = false, Faulted = false, FillProgress = 1, Directories = UnmaskedDirectories.Count, Files = Files.Count }); + State.SetValue(state => state with { Filling = false, Faulted = false, FillProgress = 1, Directories = MaskedDirectories.Count, Files = MaskedFiles.Count }); Log.Debug($"Shared file cache recreated in {sw.ElapsedMilliseconds}ms. Directories: {unmaskedDirectories.Count}, Files: {files.Count}"); } catch (Exception ex) @@ -297,7 +295,7 @@ namespace slskd results.Add(reader.GetString(0)); } - return results.Select(r => Files[r.Replace("''", "'")]); + return results.Select(r => MaskedFiles[r.Replace("''", "'")]); } catch (Exception ex) { @@ -330,9 +328,8 @@ namespace slskd private void ResetCache() { CreateTable(); - UnmaskedDirectories = new HashSet(); MaskedDirectories = new HashSet(); - Files = new Dictionary(); + MaskedFiles = new Dictionary(); State.SetValue(state => state with { Directories = 0, Files = 0 }); } -- cgit v1.2.3