Files
annotations/Azaion.Annotator/DTO/Config.cs
T
Oleksandr Bezdieniezhnykh 83e3532de2 add results pane
differentiate videos which already has annotations
2024-07-20 13:50:10 +03:00

70 lines
2.4 KiB
C#

using System.IO;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
using Size = System.Windows.Size;
using Point = System.Windows.Point;
namespace Azaion.Annotator.DTO;
public class Config
{
private const string CONFIG_PATH = "config.json";
private const string DEFAULT_VIDEO_DIR = "video";
private const string DEFAULT_LABELS_DIR = "labels";
private const string DEFAULT_IMAGES_DIR = "images";
private const string DEFAULT_RESULTS_DIR = "results";
private static readonly Size DefaultWindowSize = new(1280, 720);
private static readonly Point DefaultWindowLocation = new(100, 100);
public string VideosDirectory { get; set; } = DEFAULT_VIDEO_DIR;
public string LabelsDirectory { get; set; } = DEFAULT_LABELS_DIR;
public string ImagesDirectory { get; set; } = DEFAULT_IMAGES_DIR;
public string ResultsDirectory { get; set; } = DEFAULT_RESULTS_DIR;
public List<AnnotationClass> AnnotationClasses { get; set; } = [];
private Dictionary<int, AnnotationClass>? _annotationClassesDict;
public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
public Size WindowSize { get; set; }
public Point WindowLocation { get; set; }
public bool ShowHelpOnStart { get; set; }
public void Save()
{
File.WriteAllText(CONFIG_PATH, JsonConvert.SerializeObject(this, Formatting.Indented), Encoding.UTF8);
}
public static Config Read()
{
string configFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_PATH);
if (!File.Exists(configFilePath))
{
var exePath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)!;
return new Config
{
VideosDirectory = Path.Combine(exePath, DEFAULT_VIDEO_DIR),
LabelsDirectory = Path.Combine(exePath, DEFAULT_LABELS_DIR),
ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR),
WindowLocation = DefaultWindowLocation,
WindowSize = DefaultWindowSize,
ShowHelpOnStart = true
};
}
try
{
var str = File.ReadAllText(CONFIG_PATH);
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
}
catch (Exception)
{
return new Config();
}
}
}