mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:46:30 +00:00
105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using Azaion.CommonSecurity;
|
|
using Azaion.CommonSecurity.DTO;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Azaion.Common.DTO.Config;
|
|
|
|
public class AppConfig
|
|
{
|
|
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 interface IConfigUpdater
|
|
{
|
|
void CheckConfig();
|
|
void Save(AppConfig config);
|
|
}
|
|
|
|
public class ConfigUpdater : IConfigUpdater
|
|
{
|
|
public void CheckConfig()
|
|
{
|
|
var exePath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)!;
|
|
var configFilePath = Path.Combine(exePath, SecurityConstants.CONFIG_PATH);
|
|
|
|
if (File.Exists(configFilePath))
|
|
return;
|
|
|
|
var appConfig = new AppConfig
|
|
{
|
|
AnnotationConfig = new AnnotationConfig
|
|
{
|
|
DetectionClasses = Constants.DefaultAnnotationClasses,
|
|
VideoFormats = Constants.DefaultVideoFormats,
|
|
ImageFormats = Constants.DefaultImageFormats,
|
|
|
|
AnnotationsDbFile = Constants.DEFAULT_ANNOTATIONS_DB_FILE
|
|
},
|
|
|
|
UIConfig = new UIConfig
|
|
{
|
|
LeftPanelWidth = Constants.DEFAULT_LEFT_PANEL_WIDTH,
|
|
RightPanelWidth = Constants.DEFAULT_RIGHT_PANEL_WIDTH,
|
|
GenerateAnnotatedImage = false
|
|
},
|
|
|
|
DirectoriesConfig = new DirectoriesConfig
|
|
{
|
|
VideosDirectory = Constants.DEFAULT_VIDEO_DIR,
|
|
ImagesDirectory = Constants.DEFAULT_IMAGES_DIR,
|
|
LabelsDirectory = Constants.DEFAULT_LABELS_DIR,
|
|
ResultsDirectory = Constants.DEFAULT_RESULTS_DIR,
|
|
ThumbnailsDirectory = Constants.DEFAULT_THUMBNAILS_DIR
|
|
},
|
|
|
|
ThumbnailConfig = new ThumbnailConfig
|
|
{
|
|
Size = Constants.DefaultThumbnailSize,
|
|
Border = Constants.DEFAULT_THUMBNAIL_BORDER
|
|
},
|
|
|
|
AIRecognitionConfig = new AIRecognitionConfig
|
|
{
|
|
FrameRecognitionSeconds = Constants.DEFAULT_FRAME_RECOGNITION_SECONDS,
|
|
TrackingDistanceConfidence = Constants.TRACKING_DISTANCE_CONFIDENCE,
|
|
TrackingProbabilityIncrease = Constants.TRACKING_PROBABILITY_INCREASE,
|
|
TrackingIntersectionThreshold = Constants.TRACKING_INTERSECTION_THRESHOLD,
|
|
FramePeriodRecognition = Constants.DEFAULT_FRAME_PERIOD_RECOGNITION
|
|
}
|
|
};
|
|
Save(appConfig);
|
|
}
|
|
|
|
public void Save(AppConfig config)
|
|
{
|
|
//Save only user's config
|
|
var publicConfig = new
|
|
{
|
|
config.InferenceClientConfig,
|
|
config.GpsDeniedClientConfig,
|
|
config.DirectoriesConfig,
|
|
config.UIConfig
|
|
};
|
|
|
|
File.WriteAllText(SecurityConstants.CONFIG_PATH, JsonConvert.SerializeObject(publicConfig, Formatting.Indented), Encoding.UTF8);
|
|
}
|
|
}
|