diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-03-20 21:06:15 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-03-20 21:06:15 -0500 |
| commit | ef73185e540d66a650164909993e84c6e3396aa5 (patch) | |
| tree | 1b732f21b64c03cf8adcab9df9f975117474e2f6 /src | |
| parent | 1deff8981e2f8dd8edb077501a6fbc106ff17988 (diff) | |
| download | slskd-ef73185e540d66a650164909993e84c6e3396aa5.tar.gz | |
move extension method to SoulseekFileFactory
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 10 | ||||
| -rw-r--r-- | src/slskd/Shares/SoulseekFileFactory.cs (renamed from src/slskd/Shares/Extensions.cs) | 13 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index f13eaad4..d68cbc3b 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -86,10 +86,13 @@ namespace slskd.Shares /// Initializes a new instance of the <see cref="SharedFileCache"/> class. /// </summary> /// <param name="optionsMonitor"></param> + /// <param name="soulseekFileFactory"></param> public SharedFileCache( - IOptionsMonitor<Options> optionsMonitor) + IOptionsMonitor<Options> optionsMonitor, + ISoulseekFileFactory soulseekFileFactory = null) { OptionsMonitor = optionsMonitor; + SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory(); } /// <summary> @@ -105,6 +108,7 @@ namespace slskd.Shares private List<Share> Shares { get; set; } private SqliteConnection SQLite { get; set; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); + private ISoulseekFileFactory SoulseekFileFactory { get; } /// <summary> /// Returns the contents of the cache. @@ -249,8 +253,8 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => f.ToSoulseekFile(share)) - .ToDictionary(f => f.Filename, f => f); + .Select(filename => SoulseekFileFactory.Create(filename, share.LocalPath, share.RemotePath)) + .ToDictionary(file => file.Filename, file => file); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully // qualified name the only time this *should* cause problems is if one of the shares is a subdirectory of another. diff --git a/src/slskd/Shares/Extensions.cs b/src/slskd/Shares/SoulseekFileFactory.cs index 01e7e000..b7223c56 100644 --- a/src/slskd/Shares/Extensions.cs +++ b/src/slskd/Shares/SoulseekFileFactory.cs @@ -1,4 +1,4 @@ -// <copyright file="Extensions.cs" company="slskd Team"> +// <copyright file="SoulseekFileFactory.cs" company="slskd Team"> // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -23,16 +23,21 @@ namespace slskd.Shares using System.Linq; using Soulseek; - public static class Extensions + public interface ISoulseekFileFactory + { + File Create(string filename, string localPath, string remotePath); + } + + public class SoulseekFileFactory : ISoulseekFileFactory { private static readonly string[] VideoExtensions = { "mkv", "ogv", "avi", "wmv", "asf", "mp4", "m4p", "m4v", "mpg", "mpe", "mpv", "mpg", "m2v" }; private static readonly string[] AudioExtensions = { "aa", "aax", "aac", "aiff", "ape", "dsf", "flac", "m4a", "m4b", "m4p", "mp3", "mpc", "mpp", "ogg", "oga", "wav", "wma", "wv", "webm" }; private static readonly HashSet<string> SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet(); - public static File ToSoulseekFile(this string filename, Share share) + public File Create(string filename, string localPath, string remotePath) { var code = 1; - var maskedFilename = filename.ReplaceFirst(share.LocalPath, share.RemotePath); + var maskedFilename = filename.ReplaceFirst(localPath, remotePath); var size = new FileInfo(filename).Length; var extension = Path.GetExtension(filename)[1..].ToLowerInvariant(); List<FileAttribute> attributeList = default; |
