Files
annotations/Azaion.Annotator/DTO/FormState.cs
T
Alex Bezdieniezhnykh 9436e96d81 gallery manager WIP
2024-08-30 18:15:02 +03:00

44 lines
1.4 KiB
C#

using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
namespace Azaion.Annotator.DTO;
public class FormState
{
public SelectionState SelectionState { get; set; } = SelectionState.None;
public MediaFileInfo? CurrentMedia { get; set; }
public string VideoName => string.IsNullOrEmpty(CurrentMedia?.Name)
? ""
: Path.GetFileNameWithoutExtension(CurrentMedia.Name).Replace(" ", "");
public string CurrentMrl { get; set; }
public Size CurrentVideoSize { get; set; }
public TimeSpan CurrentVideoLength { get; set; }
public int CurrentVolume { get; set; } = 100;
public ObservableCollection<AnnotationResult> AnnotationResults { get; set; } = [];
public string GetTimeName(TimeSpan ts) => $"{VideoName}_{ts:hmmssf}";
public TimeSpan? GetTime(string name)
{
var timeStr = name.Split("_").LastOrDefault();
if (string.IsNullOrEmpty(timeStr))
return null;
try
{
//For some reason, TimeSpan.ParseExact doesn't work on every platform.
return new TimeSpan(
days: 0,
hours: int.Parse(timeStr[0..1]),
minutes: int.Parse(timeStr[1..3]),
seconds: int.Parse(timeStr[3..5]),
milliseconds: int.Parse(timeStr[5..6]) * 100);
}
catch (Exception e) { return null; }
}
}