2021-01-13 23:27:46 +01:00
|
|
|
|
using Flowframes.Data;
|
|
|
|
|
|
using Flowframes.IO;
|
2021-05-09 18:15:37 +02:00
|
|
|
|
using Flowframes.OS;
|
2020-11-23 16:51:05 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.UI
|
|
|
|
|
|
{
|
|
|
|
|
|
class UIUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void InitCombox(ComboBox box, int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (box.Items.Count >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
box.SelectedIndex = index;
|
|
|
|
|
|
box.Text = box.Items[index].ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool AssignComboxIndexFromText (ComboBox box, string text) // Set index to corresponding text
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = box.Items.IndexOf(text);
|
|
|
|
|
|
|
|
|
|
|
|
if (index == -1) // custom value, index not found
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
box.SelectedIndex = index;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
2021-05-17 11:46:49 +02:00
|
|
|
|
public static ComboBox LoadAiModelsIntoGui (ComboBox combox, AI ai)
|
2021-01-13 23:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
|
combox.Items.Clear();
|
|
|
|
|
|
|
2021-02-09 16:25:46 +01:00
|
|
|
|
try
|
2021-01-13 23:27:46 +01:00
|
|
|
|
{
|
2021-03-11 12:58:18 +01:00
|
|
|
|
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.pkgDir);
|
2021-05-17 11:46:49 +02:00
|
|
|
|
string modelsFile = Path.Combine(pkgPath, "models.json");
|
|
|
|
|
|
ModelCollection modelCollection = new ModelCollection(ai, modelsFile);
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
2021-05-17 11:46:49 +02:00
|
|
|
|
for (int i = 0; i < modelCollection.models.Count; i++)
|
2021-02-09 16:25:46 +01:00
|
|
|
|
{
|
2021-05-17 11:46:49 +02:00
|
|
|
|
ModelCollection.ModelInfo modelInfo = modelCollection.models[i];
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
2021-05-17 11:46:49 +02:00
|
|
|
|
if (string.IsNullOrWhiteSpace(modelInfo.name))
|
2021-02-09 16:25:46 +01:00
|
|
|
|
continue;
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
2021-05-17 11:46:49 +02:00
|
|
|
|
combox.Items.Add(modelInfo.GetUiString());
|
2021-02-09 16:25:46 +01:00
|
|
|
|
|
2021-05-17 11:46:49 +02:00
|
|
|
|
if (modelInfo.isDefault)
|
2021-02-09 16:25:46 +01:00
|
|
|
|
combox.SelectedIndex = i;
|
|
|
|
|
|
}
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
2021-02-09 16:25:46 +01:00
|
|
|
|
if (combox.SelectedIndex < 0)
|
|
|
|
|
|
combox.SelectedIndex = 0;
|
2021-05-09 18:15:37 +02:00
|
|
|
|
|
|
|
|
|
|
SelectNcnnIfNoCudaAvail(combox);
|
2021-02-09 16:25:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log($"Failed to load available AI models for {ai.aiName}! {e.Message}");
|
2021-05-17 11:46:49 +02:00
|
|
|
|
Logger.Log($"Stack Trace: {e.StackTrace}", true);
|
2021-02-09 16:25:46 +01:00
|
|
|
|
}
|
2021-01-13 23:27:46 +01:00
|
|
|
|
|
|
|
|
|
|
return combox;
|
|
|
|
|
|
}
|
2021-05-09 18:15:37 +02:00
|
|
|
|
|
|
|
|
|
|
static void SelectNcnnIfNoCudaAvail (ComboBox combox)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(NvApi.gpuList.Count < 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < combox.Items.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (((string)combox.Items[i]).ToUpper().Contains("NCNN"))
|
|
|
|
|
|
combox.SelectedIndex = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-11-23 16:51:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|