public void cacheDriverNames(List<String> driverNames)
{
List<String> namesWithNoSoundFile = new List<string>();
List<String> namesWithSoundFile = new List<String>();
namesWithNoSoundFile.AddRange(driverNames);
try
{
availableDriverNames.Clear();
DirectoryInfo driverNamesSoundDirectory = new DirectoryInfo(driverNamesFolderPath);
if (!driverNamesSoundDirectory.Exists)
{
Console.WriteLine("Unable to find driver names directory " + driverNamesSoundDirectory.FullName);
return;
}
FileInfo[] driverNamesFiles = driverNamesSoundDirectory.GetFiles();
foreach (FileInfo driverNameFile in driverNamesFiles)
{
if (driverNameFile.Name.EndsWith(".wav"))
{
foreach (String driverName in driverNames)
{
if (driverNameFile.Name.ToLower().Equals(driverName.ToLower() + ".wav") ||
driverNameFile.Name.Equals(driverName + ".wav") ||
driverNameFile.Name.ToLowerInvariant().Equals(driverName.ToLower() + ".wav"))
{
namesWithNoSoundFile.Remove(driverName);
namesWithSoundFile.Add(driverName);
if (!clips.ContainsKey(driverName))
{
SoundPlayer clip = new SoundPlayer(driverNameFile.FullName);
clip.Load();
List<SoundPlayer> driverNameClips = new List<SoundPlayer>();
driverNameClips.Add(clip);
clips.Add(driverName, driverNameClips);
}
if (!availableDriverNames.Contains(driverName))
{
availableDriverNames.Add(driverName);
}
}
}
}
}
if (namesWithSoundFile.Count > 0)
{
Console.WriteLine("Cached sound files for driver names:");
Console.WriteLine(String.Join(", ", namesWithSoundFile));
}
if (namesWithNoSoundFile.Count > 0)
{
Console.WriteLine("These driver names have no sound file:");
Console.WriteLine(String.Join(", ", namesWithNoSoundFile));
}
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("Unable to find driver names directory - path: " + driverNamesFolderPath);
}
}