mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-22 03:09:28 +01:00
Case-sensitive rename operation (2/2)
This commit is contained in:
71
Code/Main/AiModels.cs
Normal file
71
Code/Main/AiModels.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flowframes.Main
|
||||
{
|
||||
class AiModels
|
||||
{
|
||||
public static ModelCollection GetModels (AI ai)
|
||||
{
|
||||
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.pkgDir);
|
||||
string modelsFile = Path.Combine(pkgPath, "models.json");
|
||||
ModelCollection modelCollection = new ModelCollection(ai, modelsFile);
|
||||
|
||||
foreach (string customModel in GetCustomModels(ai))
|
||||
{
|
||||
string name = customModel.Remove("_alpha").Remove("_custom");
|
||||
bool alpha = customModel.Contains("_alpha");
|
||||
modelCollection.models.Add(new ModelCollection.ModelInfo(ai, name, "Custom Model", customModel, alpha, false));
|
||||
}
|
||||
|
||||
return modelCollection;
|
||||
}
|
||||
|
||||
public static List<string> GetCustomModels(AI ai)
|
||||
{
|
||||
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.pkgDir);
|
||||
List<string> custModels = new List<string>();
|
||||
|
||||
foreach (DirectoryInfo dir in new DirectoryInfo(pkgPath).GetDirectories())
|
||||
{
|
||||
if (dir.Name.EndsWith("_custom") && Regex.IsMatch(dir.Name, @"^[a-zA-Z0-9_]+$"))
|
||||
custModels.Add(dir.Name);
|
||||
}
|
||||
|
||||
return custModels;
|
||||
}
|
||||
|
||||
public static ModelCollection.ModelInfo GetModelByName(AI ai, string modelName)
|
||||
{
|
||||
ModelCollection modelCollection = GetModels(ai);
|
||||
|
||||
foreach(ModelCollection.ModelInfo model in modelCollection.models)
|
||||
{
|
||||
if (model.name == modelName)
|
||||
return model;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ModelCollection.ModelInfo GetModelByDir(AI ai, string dirName)
|
||||
{
|
||||
ModelCollection modelCollection = GetModels(ai);
|
||||
|
||||
foreach (ModelCollection.ModelInfo model in modelCollection.models)
|
||||
{
|
||||
if (model.dir == dirName)
|
||||
return model;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user