mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 19:56:31 +00:00
I like it move it move it
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System.Drawing;
|
||||
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 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 List<AnnotationClass> AnnotationClasses { get; set; } = [];
|
||||
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()
|
||||
{
|
||||
if (!File.Exists(CONFIG_PATH))
|
||||
{
|
||||
var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user