mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:56:31 +00:00
fde9a9f418
also restrict detections to be no bigger than in classes.json
75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using Azaion.Common.Extensions;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Azaion.Common.DTO.Config;
|
|
|
|
public class AppConfig
|
|
{
|
|
public LoaderClientConfig LoaderClientConfig { get; set; } = null!;
|
|
|
|
public InferenceClientConfig InferenceClientConfig { get; set; } = null!;
|
|
|
|
public GpsDeniedClientConfig GpsDeniedClientConfig { get; set; } = null!;
|
|
|
|
public QueueConfig QueueConfig { get; set; } = null!;
|
|
|
|
public DirectoriesConfig DirectoriesConfig { get; set; } = null!;
|
|
|
|
public AnnotationConfig AnnotationConfig { get; set; } = null!;
|
|
|
|
public UIConfig UIConfig { get; set; } = null!;
|
|
|
|
public AIRecognitionConfig AIRecognitionConfig { get; set; } = null!;
|
|
|
|
public ThumbnailConfig ThumbnailConfig { get; set; } = null!;
|
|
|
|
public MapConfig MapConfig{ get; set; } = null!;
|
|
|
|
public GpsDeniedConfig GpsDeniedConfig { get; set; } = null!;
|
|
|
|
public CameraConfig CameraConfig { get; set; } = null!;
|
|
}
|
|
|
|
public interface IConfigUpdater
|
|
{
|
|
void CheckConfig();
|
|
void Save(AppConfig config);
|
|
}
|
|
|
|
public class ConfigUpdater : IConfigUpdater
|
|
{
|
|
private static readonly Guid SaveConfigTaskId = Guid.NewGuid();
|
|
|
|
public void CheckConfig()
|
|
{
|
|
var exePath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)!;
|
|
var configFilePath = Path.Combine(exePath, Constants.CONFIG_PATH);
|
|
|
|
if (File.Exists(configFilePath))
|
|
return;
|
|
|
|
Save(Constants.FailsafeAppConfig);
|
|
}
|
|
|
|
public void Save(AppConfig config)
|
|
{
|
|
ThrottleExt.Throttle(async () =>
|
|
{
|
|
var publicConfig = new
|
|
{
|
|
config.LoaderClientConfig,
|
|
config.InferenceClientConfig,
|
|
config.GpsDeniedClientConfig,
|
|
config.DirectoriesConfig,
|
|
config.UIConfig,
|
|
config.CameraConfig
|
|
};
|
|
|
|
await File.WriteAllTextAsync(Constants.CONFIG_PATH, JsonConvert.SerializeObject(publicConfig, Formatting.Indented), Encoding.UTF8);
|
|
}, SaveConfigTaskId, TimeSpan.FromSeconds(5));
|
|
|
|
}
|
|
}
|