VideoConcat/Models/VideoModel.cs
2025-01-18 23:44:06 +08:00

219 lines
5.5 KiB
C#

using Standard;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace VideoConcat.Models
{
public class VideoModel : INotifyPropertyChanged
{
private int _num;
private int _maxNum;
private string _folderPath = "";
private string _auditImagePath = "";
private bool _canStart = false;
private bool _isStart = false;
private ObservableCollection<FolderInfo> _FolderInfos = [];
private ObservableCollection<ConcatVideo> _concatVideos = [];
private Dispatcher _dispatcher;
public static int Index= 0;
public bool IsStart
{
get => _isStart;
set
{
_isStart = value;
OnPropertyChanged();
SetCanStart();
}
}
public Dispatcher Dispatcher
{
get => _dispatcher;
set
{
_dispatcher = value;
}
}
public int Num
{
get => _num;
set
{
_num = value;
OnPropertyChanged();
UpdateSum();
}
}
public string AuditImagePath
{
get => _auditImagePath;
set
{
_auditImagePath = value;
OnPropertyChanged();
}
}
public int MaxNum
{
get => _maxNum;
set
{
_maxNum = value;
}
}
public struct FolderInfo
{
public DirectoryInfo DirectoryInfo { set; get; }
public int Num { set; get; }
public List<string> VideoPaths { set; get; }
}
public class ConcatVideo
{
public int Index { set; get; }
public string FileName { set; get; } = "";
public int Size { set; get; }
public double Seconds { set; get; }
public int Status { set; get; }
public int Progress { set; get; }
}
public ObservableCollection<FolderInfo> FolderInfos
{
get { return _FolderInfos; }
set
{
if (_FolderInfos != null)
{
_FolderInfos.CollectionChanged -= ItemList_CollectionChanged;
}
_FolderInfos = value;
if (_FolderInfos != null)
{
_FolderInfos.CollectionChanged += ItemList_CollectionChanged;
}
OnPropertyChanged();
UpdateSum();
}
}
public ObservableCollection<ConcatVideo> ConcatVideos
{
get { return _concatVideos; }
set
{
if (_concatVideos != null)
{
_concatVideos.CollectionChanged -= ItemList_CollectionChanged;
}
_concatVideos = value;
if (_concatVideos != null)
{
_concatVideos.CollectionChanged += ItemList_CollectionChanged;
}
OnPropertyChanged();
}
}
public string FolderPath
{
get { return _folderPath; }
set
{
_folderPath = value;
OnPropertyChanged(nameof(FolderPath));
}
}
public bool CanStart
{
get { return _canStart; }
set
{
_canStart = value;
OnPropertyChanged(nameof(CanStart));
}
}
public ICommand? BtnOpenFolderCommand { get; set; }
public ICommand? BtnStartVideoConcatCommand { get; set; }
public ICommand? BtnChooseAuditImageCommand { get; set; }
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void ItemList_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
UpdateSum();
}
public void UpdateSum()
{
int _temp = 1;
if (FolderInfos.Count > 0)
{
foreach (FolderInfo item in FolderInfos)
{
if (item.Num > 0)
{
_temp *= item.Num;
}
}
MaxNum = _temp;
SetCanStart();
}
else
{
MaxNum = 0;
SetCanStart();
}
}
public void SetCanStart()
{
if (Num > 0 && Num <= MaxNum && IsStart == false)
{
CanStart = true;
}
else
{
CanStart = false;
}
}
public VideoModel()
{
ConcatVideos = [];
_dispatcher = Dispatcher.CurrentDispatcher;
}
}
}