mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
126 lines
4.4 KiB
C#
126 lines
4.4 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using Size = System.Windows.Size;
|
|
using Point = System.Windows.Point;
|
|
|
|
namespace Azaion.Annotator.DTO;
|
|
|
|
public class Config
|
|
{
|
|
public const string ThumbnailPrefix = "_thumb";
|
|
public const string ThumbnailsCacheFile = "thumbnails.cache";
|
|
|
|
public string VideosDirectory { get; set; }
|
|
public string LabelsDirectory { get; set; }
|
|
public string ImagesDirectory { get; set; }
|
|
public string ResultsDirectory { get; set; }
|
|
public string ThumbnailsDirectory { get; set; }
|
|
public string UnknownImages { get; set; }
|
|
|
|
public List<AnnotationClass> AnnotationClasses { get; set; } = [];
|
|
|
|
private Dictionary<int, AnnotationClass>? _annotationClassesDict;
|
|
public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
|
|
|
|
public WindowConfig MainWindowConfig { get; set; }
|
|
public WindowConfig DatasetExplorerConfig { get; set; }
|
|
|
|
public double LeftPanelWidth { get; set; }
|
|
public double RightPanelWidth { get; set; }
|
|
|
|
public bool ShowHelpOnStart { get; set; }
|
|
|
|
public List<string> VideoFormats { get; set; }
|
|
public List<string> ImageFormats { get; set; }
|
|
|
|
public ThumbnailConfig ThumbnailConfig { get; set; }
|
|
public int? LastSelectedExplorerClass { get; set; }
|
|
}
|
|
|
|
public class WindowConfig
|
|
{
|
|
public Size WindowSize { get; set; }
|
|
public Point WindowLocation { get; set; }
|
|
public bool FullScreen { get; set; }
|
|
}
|
|
|
|
public class ThumbnailConfig
|
|
{
|
|
public Size Size { get; set; }
|
|
public int Border { get; set; }
|
|
}
|
|
|
|
public interface IConfigRepository
|
|
{
|
|
public Config Get();
|
|
public void Save(Config config);
|
|
}
|
|
|
|
public class FileConfigRepository(ILogger<FileConfigRepository> logger) : IConfigRepository
|
|
{
|
|
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 const string DEFAULT_THUMBNAILS_DIR = "thumbnails";
|
|
private const string DEFAULT_UNKNOWN_IMG_DIR = "unknown";
|
|
|
|
private static readonly Size DefaultWindowSize = new(1280, 720);
|
|
private static readonly Point DefaultWindowLocation = new(100, 100);
|
|
private static readonly Size DefaultThumbnailSize = new(240, 135);
|
|
|
|
private static readonly List<string> DefaultVideoFormats = ["mp4", "mov", "avi"];
|
|
private static readonly List<string> DefaultImageFormats = ["jpg", "jpeg", "png", "bmp"];
|
|
|
|
public Config Get()
|
|
{
|
|
var exePath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)!;
|
|
var configFilePath = Path.Combine(exePath, CONFIG_PATH);
|
|
|
|
if (!File.Exists(configFilePath))
|
|
{
|
|
return new Config
|
|
{
|
|
VideosDirectory = Path.Combine(exePath, DEFAULT_VIDEO_DIR),
|
|
LabelsDirectory = Path.Combine(exePath, DEFAULT_LABELS_DIR),
|
|
ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR),
|
|
ResultsDirectory = Path.Combine(exePath, DEFAULT_RESULTS_DIR),
|
|
ThumbnailsDirectory = Path.Combine(exePath, DEFAULT_THUMBNAILS_DIR),
|
|
UnknownImages = Path.Combine(exePath, DEFAULT_UNKNOWN_IMG_DIR),
|
|
|
|
MainWindowConfig = new WindowConfig
|
|
{
|
|
WindowSize = DefaultWindowSize,
|
|
WindowLocation = DefaultWindowLocation
|
|
},
|
|
DatasetExplorerConfig = new WindowConfig
|
|
{
|
|
WindowSize = DefaultWindowSize,
|
|
WindowLocation = DefaultWindowLocation
|
|
},
|
|
ShowHelpOnStart = true,
|
|
|
|
VideoFormats = DefaultVideoFormats,
|
|
ImageFormats = DefaultImageFormats,
|
|
ThumbnailConfig = new ThumbnailConfig
|
|
{
|
|
Size = DefaultThumbnailSize,
|
|
Border = 10
|
|
}
|
|
};
|
|
}
|
|
var str = File.ReadAllText(CONFIG_PATH);
|
|
return JsonConvert.DeserializeObject<Config>(str) ?? new Config();
|
|
}
|
|
|
|
public void Save(Config config)
|
|
{
|
|
File.WriteAllText(CONFIG_PATH, JsonConvert.SerializeObject(config, Formatting.Indented), Encoding.UTF8);
|
|
}
|
|
}
|