Compare commits
2 Commits
0083539bac
...
6a92451776
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a92451776 | |||
| 17b8bafccd |
BIN
Assets/vinyl.png
Normal file
BIN
Assets/vinyl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -13,7 +13,7 @@ public partial class _00000000000000_StoredProcedure : Migration
|
||||
AS $$
|
||||
BEGIN
|
||||
DELETE FROM "Songs"
|
||||
WHERE "State" = 0;
|
||||
WHERE "State" = 1;
|
||||
|
||||
COMMIT;
|
||||
END;
|
||||
|
||||
@@ -44,9 +44,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Mapping\" />
|
||||
<Folder Include="DTOs\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
49
Tools/Cli.cs
49
Tools/Cli.cs
@@ -154,7 +154,8 @@ public class Cli
|
||||
{
|
||||
Name = username!,
|
||||
NormalizedName = username!.ToLower(),
|
||||
Password = password
|
||||
Password = password,
|
||||
Role = isUserAdmin ? 0 : 1 // 0 = admin
|
||||
};
|
||||
|
||||
db.Users.Add(newUser);
|
||||
@@ -218,9 +219,9 @@ public class Cli
|
||||
|
||||
Console.WriteLine($"[Shadow] Remove user");
|
||||
if (args.Length == 2)
|
||||
Console.WriteLine($" You will be promped to enter the password.");
|
||||
Console.WriteLine($" You will be prompted to enter the password.");
|
||||
else
|
||||
Console.WriteLine($" You will be promped to enter the username and password.");
|
||||
Console.WriteLine($" You will be prompted to enter the username and password.");
|
||||
|
||||
string? username = null;
|
||||
if (args.Length != 2)
|
||||
@@ -339,6 +340,29 @@ public class Cli
|
||||
System.IO.Directory.CreateDirectory(newMusicLibraryPath);
|
||||
System.IO.Directory.CreateDirectory(newMusicThumbnailPath);
|
||||
|
||||
// Try to find the Assets directory automatically
|
||||
string currentPath = AppContext.BaseDirectory;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (Directory.GetFiles(currentPath, "Shadow.slnx")
|
||||
.FirstOrDefault() != null)
|
||||
{
|
||||
File.Copy(
|
||||
Path.Combine(currentPath, "Assets", "vinyl.png"),
|
||||
Path.Combine(newMusicThumbnailPath, "default.png"),
|
||||
true
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
currentPath = Path.Combine(currentPath, "..");
|
||||
|
||||
if (i == 5) Console.WriteLine("\n" +
|
||||
"[Error] Could not determine content root path. \n" +
|
||||
"Please place Assets/vinyl.png in your thumbnail path directory manually\n" +
|
||||
"and rename it to default.png.");
|
||||
}
|
||||
|
||||
// UpdateRange can both Add and Update rows.
|
||||
db.Globals.UpdateRange(musicLibraryPath, musicThumbnailPath);
|
||||
db.SaveChanges();
|
||||
@@ -362,7 +386,10 @@ public class Cli
|
||||
int rowsAffected = 0;
|
||||
|
||||
// Retrieve orphaned songs
|
||||
List<Song> orphanedSongs = db.Songs.Where(s => s.State == 1).ToList();
|
||||
List<Song> orphanedSongs = db.Songs
|
||||
.Where(s => s.State == 1)
|
||||
.Include(s => s.Album)
|
||||
.ToList();
|
||||
|
||||
// Ask if it's alright to remove them
|
||||
// and related listening data permanently
|
||||
@@ -390,11 +417,13 @@ public class Cli
|
||||
|
||||
// TODO: Remove song images if not used by any other resource
|
||||
// ...
|
||||
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
// Perform cleanup with stored procedure
|
||||
rowsAffected += db.Database.ExecuteSqlRaw("CALL song_cleanup()");
|
||||
// rowsAffected += songs.Count;
|
||||
db.Database.ExecuteSqlRaw("CALL song_cleanup()");
|
||||
rowsAffected += orphanedSongs.Count;
|
||||
}
|
||||
}
|
||||
else Console.WriteLine("No orphaned songs found.");
|
||||
@@ -411,13 +440,17 @@ public class Cli
|
||||
{
|
||||
db.Albums.RemoveRange(orphanedAlbums);
|
||||
rowsAffected += orphanedAlbums.Count;
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
else Console.WriteLine("No orphaned albums found.");
|
||||
|
||||
// Retrieve orphaned artists (artists with no songs AND albums)
|
||||
List<Artist> orphanedArtists = db.Artists.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0).ToList();
|
||||
Artist? unknownArtist = db.Artists.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
|
||||
List<Artist> orphanedArtists = db.Artists
|
||||
.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0)
|
||||
.ToList();
|
||||
Artist? unknownArtist = db.Artists
|
||||
.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
|
||||
|
||||
// Account for the [Unknown Artist],
|
||||
// which is a meta-artist and shall
|
||||
|
||||
Reference in New Issue
Block a user