|
1 | | -namespace HomeSpeaker.Server |
| 1 | +namespace HomeSpeaker.Server2; |
| 2 | + |
| 3 | +public interface IFileSource |
2 | 4 | { |
3 | | - public interface IFileSource |
4 | | - { |
5 | | - IEnumerable<string> GetAllMp3s(); |
6 | | - void SoftDelete(string path); |
| 5 | + IEnumerable<string> GetAllMp3s(); |
| 6 | + void SoftDelete(string path); |
7 | 7 |
|
8 | | - string RootFolder { get; } |
9 | | - } |
| 8 | + string RootFolder { get; } |
| 9 | +} |
10 | 10 |
|
11 | | - public class DefaultFileSource : IFileSource |
| 11 | +public class DefaultFileSource : IFileSource |
| 12 | +{ |
| 13 | + private readonly string _rootFolder; |
| 14 | + private readonly string _userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
| 15 | + |
| 16 | + public DefaultFileSource(string rootFolder) |
12 | 17 | { |
13 | | - private readonly string rootFolder; |
14 | | - string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
| 18 | + _rootFolder = rootFolder; |
| 19 | + } |
15 | 20 |
|
16 | | - public DefaultFileSource(string rootFolder) |
17 | | - { |
18 | | - this.rootFolder = rootFolder; |
19 | | - } |
| 21 | + public string RootFolder => _rootFolder; |
20 | 22 |
|
21 | | - public string RootFolder => rootFolder; |
| 23 | + public IEnumerable<string> GetAllMp3s() |
| 24 | + { |
| 25 | + var musicFolder = _rootFolder.Replace("~", _userProfile); |
22 | 26 |
|
23 | | - public IEnumerable<string> GetAllMp3s() |
| 27 | + if (!Directory.Exists(musicFolder)) |
24 | 28 | { |
25 | | - var musicFolder = rootFolder.Replace("~", userProfile); |
26 | | - |
27 | | - if (!Directory.Exists(musicFolder)) |
28 | | - { |
29 | | - Directory.CreateDirectory(musicFolder); |
30 | | - } |
31 | | - |
32 | | - return Directory.GetFiles(musicFolder, "*.mp3", SearchOption.AllDirectories); |
| 29 | + Directory.CreateDirectory(musicFolder); |
33 | 30 | } |
34 | 31 |
|
35 | | - public void SoftDelete(string path) |
| 32 | + return Directory.GetFiles(musicFolder, "*.mp3", SearchOption.AllDirectories); |
| 33 | + } |
| 34 | + |
| 35 | + public void SoftDelete(string path) |
| 36 | + { |
| 37 | + var destFolder = Path.Combine(_userProfile, "DeletedMusic"); |
| 38 | + if (!Directory.Exists(destFolder)) |
36 | 39 | { |
37 | | - var destFolder = Path.Combine(userProfile, "DeletedMusic"); |
38 | | - if (!Directory.Exists(destFolder)) |
39 | | - { |
40 | | - Directory.CreateDirectory(destFolder); |
41 | | - } |
42 | | - File.Move(path, Path.Combine(destFolder, Path.GetFileName(path))); |
| 40 | + Directory.CreateDirectory(destFolder); |
43 | 41 | } |
| 42 | + File.Move(path, Path.Combine(destFolder, Path.GetFileName(path))); |
44 | 43 | } |
45 | 44 | } |
0 commit comments