private static void ReadProfiles()
{
CheckProfiles();
InstallDefaults();
lock (Profiles)
{
Profiles.Clear();
// Create the directory structure
var profilePaths = Directory.GetFiles(ProfileFolder, "*.json", SearchOption.AllDirectories);
// Parse the JSON files into objects and add them if they are valid
foreach (var path in profilePaths)
{
try
{
var prof = LoadProfileIfValid(path);
if (prof == null)
continue;
// Only add unique profiles
if (Profiles.Any(p => p.GameName == prof.GameName && p.Name == prof.Name &&
p.KeyboardSlug == prof.KeyboardSlug))
{
Logger.Error("Didn't load duplicate profile: {0}", path);
}
else
{
Profiles.Add(prof);
}
}
catch (Exception e)
{
Logger.Error("Failed to load profile: {0} - {1}", path, e.InnerException.Message);
}
}
}
}