Error handling for FillAiModelsCombox()

This commit is contained in:
N00MKRAD
2021-02-09 16:25:46 +01:00
parent e8f440ee52
commit 925902889d

View File

@@ -36,27 +36,35 @@ namespace Flowframes.UI
public static ComboBox FillAiModelsCombox (ComboBox combox, AI ai)
{
string pkgPath = PkgUtils.GetPkgFolder(ai.pkg);
string modelsFile = Path.Combine(pkgPath, "models.txt");
string[] modelsWithDec = IOUtils.ReadLines(modelsFile);
combox.Items.Clear();
for (int i = 0; i < modelsWithDec.Length; i++)
try
{
string model = modelsWithDec[i];
string pkgPath = PkgUtils.GetPkgFolder(ai.pkg);
string modelsFile = Path.Combine(pkgPath, "models.txt");
string[] modelsWithDec = IOUtils.ReadLines(modelsFile);
if (string.IsNullOrWhiteSpace(model))
continue;
for (int i = 0; i < modelsWithDec.Length; i++)
{
string model = modelsWithDec[i];
combox.Items.Add(model);
if (string.IsNullOrWhiteSpace(model))
continue;
if (model.Contains("Recommended") || model.Contains("Default"))
combox.SelectedIndex = i;
combox.Items.Add(model);
if (model.Contains("Recommended") || model.Contains("Default"))
combox.SelectedIndex = i;
}
if (combox.SelectedIndex < 0)
combox.SelectedIndex = 0;
}
catch (Exception e)
{
Logger.Log($"Failed to load available AI models for {ai.aiName}! {e.Message}");
}
if(combox.SelectedIndex < 0)
combox.SelectedIndex = 0;
return combox;
}
}