Add an Upload page where the user picks an MP3 or WAV file. The new SongImportService copies it into %LOCALAPPDATA%\Radiosender\Music under a unique name, reads the duration with NAudio and title/artist from tags with TagLibSharp (falling back to the file name), and saves the song with Source = Upload. Wrong extensions, unreadable files, garbage data and files without audio are rejected; the copied file is deleted again so nothing is left behind. The page shows the result in a Snackbar. The music folder is injected so the service is testable without UI. Tests cover a generated WAV, duplicate names, wrong extension, garbage files, empty audio and missing files. Refs #4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Windows;
|
|
using Microsoft.Win32;
|
|
using Radiosender.Controllers;
|
|
using Radiosender.Services;
|
|
using Wpf.Ui.Controls;
|
|
|
|
namespace Radiosender.Views.Pages;
|
|
|
|
public partial class UploadPage
|
|
{
|
|
private readonly UploadController _controller =
|
|
new(new SongImportService(App.Songs, SongImportService.DefaultMusicDirectory));
|
|
|
|
public UploadPage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ChooseFileButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var dialog = new OpenFileDialog { Filter = UploadController.FileDialogFilter };
|
|
if (dialog.ShowDialog() != true)
|
|
return;
|
|
|
|
var result = _controller.Upload(dialog.FileName);
|
|
new Snackbar(SnackbarPresenter)
|
|
{
|
|
Title = result.Success ? "Song uploaded" : "Upload failed",
|
|
Content = result.Message,
|
|
Appearance = result.Success ? ControlAppearance.Success : ControlAppearance.Danger,
|
|
Icon = new SymbolIcon(result.Success ? SymbolRegular.CheckmarkCircle24 : SymbolRegular.ErrorCircle24),
|
|
Timeout = TimeSpan.FromSeconds(5),
|
|
}.Show();
|
|
}
|
|
}
|