using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using VideoConcat.Models; using System.Windows; using System.Windows.Forms; using MessageBox = System.Windows.MessageBox; using System.ComponentModel; using VideoConcat.Common.Tools; using System.IO; using static VideoConcat.Models.VideoModel; namespace VideoConcat.ViewModels { public class VideoViewModel { private VideoModel _videoModel; public VideoModel VideoModel { get { return _videoModel; } set { _videoModel = value; } } public VideoViewModel() { VideoModel = new VideoModel(); VideoModel.BtnOpenFolderCommand = new BtnOpenFolderCommand() { DoExcue = obj => { FolderBrowserDialog folderBrowserDialog = new(); if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { VideoModel.FolderPath = folderBrowserDialog.SelectedPath; LogUtils.Info($"获取视频文件夹,视频路径:{VideoModel.FolderPath}"); ListFolder(VideoModel.FolderPath); } } }; VideoModel.BtnStartVideoConcatCommand = new BtnStartVideoConcatCommand() { DoExcue = obj => { LogUtils.Info("开始合并视频"); } }; } private void ListFolder(string path) { DirectoryInfo dir = new(path); try { DirectoryInfo dirD = dir as DirectoryInfo; DirectoryInfo[] folders = dirD.GetDirectories(); VideoModel.FolderInfos.Clear(); //获取文件夹下所有视频文件 foreach (DirectoryInfo Folder in folders) { string[] files = Directory.GetFiles(Folder.FullName, "*.mp4"); LogUtils.Info($"{Folder.Name}下有{files.Length}个视频文件"); VideoModel.FolderInfos.Add(new FolderInfo { DirectoryInfo = Folder, Num = files.Length }); } VideoModel.UpdateSum(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } class BtnOpenFolderCommand : ICommand { public event EventHandler? CanExecuteChanged; public bool CanExecute(object? parameter) => true; public void Execute(object? parameter) { DoExcue?.Invoke(parameter); } public Action? DoExcue { get; set; } } class BtnStartVideoConcatCommand : ICommand { public event EventHandler? CanExecuteChanged; public bool CanExecute(object? parameter) => true; public void Execute(object? parameter) { DoExcue?.Invoke(parameter); } public Action? DoExcue { get; set; } } }