43 lines
944 B
C#
43 lines
944 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace LLib.Notifications;
|
|
|
|
public static class WindowsSounds
|
|
{
|
|
public static string MediaDirectory => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Media");
|
|
|
|
public static IReadOnlyList<string> ListWavFileNames()
|
|
{
|
|
try
|
|
{
|
|
if (!Directory.Exists(MediaDirectory))
|
|
{
|
|
return Array.Empty<string>();
|
|
}
|
|
return Directory.EnumerateFiles(MediaDirectory, "*.wav").Select(Path.GetFileName).OfType<string>()
|
|
.OrderBy<string, string>((string x) => x, StringComparer.OrdinalIgnoreCase)
|
|
.ToArray();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return Array.Empty<string>();
|
|
}
|
|
}
|
|
|
|
public static string? ResolvePath(string? fileName)
|
|
{
|
|
if (string.IsNullOrEmpty(fileName))
|
|
{
|
|
return null;
|
|
}
|
|
string text = Path.Combine(MediaDirectory, fileName);
|
|
if (!File.Exists(text))
|
|
{
|
|
return null;
|
|
}
|
|
return text;
|
|
}
|
|
}
|