VideoConcat/Models/VideoModel.cs
2025-01-11 21:43:03 +08:00

113 lines
2.9 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.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace VideoConcat.Models
{
public class VideoModel : INotifyPropertyChanged
{
private int _num;
private string _folderPath = "";
private bool _canStart = false;
private ObservableCollection<FolderInfo> _FolderInfos = [];
public int Num
{
get { return _num; }
set
{
_num = value;
OnPropertyChanged();
}
}
public struct FolderInfo
{
public DirectoryInfo DirectoryInfo{set;get;}
public int Num { 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 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 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;
foreach (var item in FolderInfos)
{
if (item.Num > 0)
{
_temp *= item.Num;
}
}
Num = _temp;
if(Num > 0){
CanStart = true;
}
}
}
}