Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12c4f56a22 | |||
| 6d650b7962 | |||
| 73bb417bde |
@@ -92,29 +92,6 @@ public class DirectoryManager : BaseManager
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteEmptyDirectories()
|
||||
{
|
||||
try
|
||||
{
|
||||
var albumDirectory = AlbumDirectory();
|
||||
var artistDirectory = ArtistDirectory();
|
||||
if (IsDirectoryEmpty(albumDirectory))
|
||||
{
|
||||
Directory.Delete(albumDirectory);
|
||||
Console.WriteLine($"directory {albumDirectory} deleted");
|
||||
}
|
||||
if (IsDirectoryEmpty(artistDirectory))
|
||||
{
|
||||
Directory.Delete(artistDirectory);
|
||||
Console.WriteLine($"directory {artistDirectory} deleted");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var exMsg = ex.Message;
|
||||
Console.WriteLine($"An error occurred {exMsg}");
|
||||
}
|
||||
}
|
||||
|
||||
public int DeleteEmptyDirectories(string? directory, int level)
|
||||
{
|
||||
@@ -157,12 +134,12 @@ public class DirectoryManager : BaseManager
|
||||
var albumDirectory = AlbumDirectory(song);
|
||||
var artistDirectory = ArtistDirectory(song);
|
||||
|
||||
if (IsDirectoryEmpty(albumDirectory))
|
||||
if (Directory.Exists(albumDirectory) && IsDirectoryEmpty(albumDirectory))
|
||||
{
|
||||
Directory.Delete(albumDirectory);
|
||||
_logger.Info("Album directory deleted");
|
||||
}
|
||||
if (IsDirectoryEmpty(artistDirectory))
|
||||
if (Directory.Exists(artistDirectory) && IsDirectoryEmpty(artistDirectory))
|
||||
{
|
||||
Directory.Delete(artistDirectory);
|
||||
_logger.Info("Artist directory deleted");
|
||||
@@ -175,66 +152,7 @@ public class DirectoryManager : BaseManager
|
||||
}
|
||||
}
|
||||
|
||||
public string RetrieveAlbumPath(Song song)
|
||||
{
|
||||
_logger.Info("Retrieving album song path");
|
||||
|
||||
var albumPath = string.Empty;
|
||||
albumPath = AlbumDirectory(song);
|
||||
|
||||
return albumPath;
|
||||
}
|
||||
public string RetrieveArtistPath(Song song)
|
||||
{
|
||||
_logger.Info("Retrieving artist path");
|
||||
|
||||
var artistPath = string.Empty;
|
||||
artistPath = ArtistDirectory(song);
|
||||
|
||||
return artistPath;
|
||||
}
|
||||
|
||||
public string GenerateSongPath(Song song)
|
||||
{
|
||||
_logger.Info("Generating song path");
|
||||
|
||||
var artistPath = ArtistDirectory(song);
|
||||
var albumPath = AlbumDirectory(song);
|
||||
|
||||
GenerateDirectories(new List<DirEnt>{
|
||||
new DirEnt
|
||||
{
|
||||
Pre = "Artist path does not exist",
|
||||
Path = artistPath,
|
||||
Post = "Creating artist path"
|
||||
},
|
||||
new DirEnt
|
||||
{
|
||||
Pre = "Album path does not exist",
|
||||
Path = albumPath,
|
||||
Post = "Created album path"
|
||||
}
|
||||
});
|
||||
|
||||
return albumPath;
|
||||
}
|
||||
|
||||
private class DirEnt
|
||||
{
|
||||
public string? Pre { get; set; }
|
||||
public string? Path { get; set; }
|
||||
public string? Post { get; set; }
|
||||
}
|
||||
|
||||
private void GenerateDirectories(List<DirEnt> dirs)
|
||||
{
|
||||
foreach (var di in dirs)
|
||||
{
|
||||
_logger.Info(di.Pre);
|
||||
Directory.CreateDirectory(di.Path!);
|
||||
_logger.Info(di.Post);
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
||||
{
|
||||
@@ -249,10 +167,8 @@ public class DirectoryManager : BaseManager
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsDirectoryEmpty(string path)
|
||||
{
|
||||
return !Directory.EnumerateFileSystemEntries(path).Any();
|
||||
}
|
||||
private bool IsDirectoryEmpty(string path) =>
|
||||
!(Directory.EnumerateFileSystemEntries(path).Any());
|
||||
|
||||
private string AlbumDirectory()
|
||||
{
|
||||
@@ -267,10 +183,6 @@ public class DirectoryManager : BaseManager
|
||||
|
||||
return directory;
|
||||
}
|
||||
private string ArtistDirectory()
|
||||
{
|
||||
return ArtistDirectory(_song!);
|
||||
}
|
||||
private string ArtistDirectory(Song song)
|
||||
{
|
||||
var directory = _rootSongDirectory;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<Version>0.1.22</Version>
|
||||
<Version>0.1.30</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user