diff --git a/DownKyi/ViewModels/Toolbox/ViewBiliHelperViewModel.cs b/DownKyi/ViewModels/Toolbox/ViewBiliHelperViewModel.cs index 769892a..f874027 100644 --- a/DownKyi/ViewModels/Toolbox/ViewBiliHelperViewModel.cs +++ b/DownKyi/ViewModels/Toolbox/ViewBiliHelperViewModel.cs @@ -15,36 +15,36 @@ public class ViewBiliHelperViewModel : ViewModelBase #region 页面属性申明 - private string avid; + private string _avid; public string Avid { - get => avid; - set => SetProperty(ref avid, value); + get => _avid; + set => SetProperty(ref _avid, value); } - private string bvid; + private string _bvid; public string Bvid { - get => bvid; - set => SetProperty(ref bvid, value); + get => _bvid; + set => SetProperty(ref _bvid, value); } - private string danmakuUserID; + private string _danmakuUserId; - public string DanmakuUserID + public string DanmakuUserId { - get => danmakuUserID; - set => SetProperty(ref danmakuUserID, value); + get => _danmakuUserId; + set => SetProperty(ref _danmakuUserId, value); } - private string userMid; + private string _userMid; public string UserMid { - get => userMid; - set => SetProperty(ref userMid, value); + get => _userMid; + set => SetProperty(ref _userMid, value); } #endregion @@ -59,10 +59,9 @@ public class ViewBiliHelperViewModel : ViewModelBase #region 命令申明 // 输入avid事件 - private DelegateCommand avidCommand; + private DelegateCommand? _avidCommand; - public DelegateCommand AvidCommand => - avidCommand ?? (avidCommand = new DelegateCommand(ExecuteAvidCommand)); + public DelegateCommand AvidCommand => _avidCommand ??= new DelegateCommand(ExecuteAvidCommand); /// /// 输入avid事件 @@ -79,7 +78,7 @@ public class ViewBiliHelperViewModel : ViewModelBase return; } - long avid = ParseEntrance.GetAvId(parameter); + var avid = ParseEntrance.GetAvId(parameter); if (avid == -1) { return; @@ -89,10 +88,9 @@ public class ViewBiliHelperViewModel : ViewModelBase } // 输入bvid事件 - private DelegateCommand bvidCommand; + private DelegateCommand? _bvidCommand; - public DelegateCommand BvidCommand => - bvidCommand ?? (bvidCommand = new DelegateCommand(ExecuteBvidCommand)); + public DelegateCommand BvidCommand => _bvidCommand ??= new DelegateCommand(ExecuteBvidCommand); /// /// 输入bvid事件 @@ -112,16 +110,15 @@ public class ViewBiliHelperViewModel : ViewModelBase await Task.Run(() => { - ulong avid = BvId.Bv2Av(parameter); + var avid = BvId.Bv2Av(parameter); Avid = $"av{avid}"; }); } // 访问网页事件 - private DelegateCommand gotoWebCommand; + private DelegateCommand? _gotoWebCommand; - public DelegateCommand GotoWebCommand => - gotoWebCommand ?? (gotoWebCommand = new DelegateCommand(ExecuteGotoWebCommand)); + public DelegateCommand GotoWebCommand => _gotoWebCommand ??= new DelegateCommand(ExecuteGotoWebCommand); /// /// 访问网页事件 @@ -133,11 +130,9 @@ public class ViewBiliHelperViewModel : ViewModelBase } // 查询弹幕发送者事件 - private DelegateCommand findDanmakuSenderCommand; + private DelegateCommand? _findDanmakuSenderCommand; - public DelegateCommand FindDanmakuSenderCommand => findDanmakuSenderCommand ?? - (findDanmakuSenderCommand = - new DelegateCommand(ExecuteFindDanmakuSenderCommand)); + public DelegateCommand FindDanmakuSenderCommand => _findDanmakuSenderCommand ??= new DelegateCommand(ExecuteFindDanmakuSenderCommand); /// /// 查询弹幕发送者事件 @@ -148,7 +143,7 @@ public class ViewBiliHelperViewModel : ViewModelBase { try { - UserMid = DanmakuSender.FindDanmakuSender(DanmakuUserID); + UserMid = DanmakuSender.FindDanmakuSender(DanmakuUserId); } catch (Exception e) { @@ -161,11 +156,9 @@ public class ViewBiliHelperViewModel : ViewModelBase } // 访问用户空间事件 - private DelegateCommand visitUserSpaceCommand; + private DelegateCommand? _visitUserSpaceCommand; - public DelegateCommand VisitUserSpaceCommand => visitUserSpaceCommand ?? - (visitUserSpaceCommand = - new DelegateCommand(ExecuteVisitUserSpaceCommand)); + public DelegateCommand VisitUserSpaceCommand => _visitUserSpaceCommand ??= new DelegateCommand(ExecuteVisitUserSpaceCommand); /// /// 访问用户空间事件 diff --git a/DownKyi/ViewModels/Toolbox/ViewDelogoViewModel.cs b/DownKyi/ViewModels/Toolbox/ViewDelogoViewModel.cs index 1e693f2..11c5bcb 100644 --- a/DownKyi/ViewModels/Toolbox/ViewDelogoViewModel.cs +++ b/DownKyi/ViewModels/Toolbox/ViewDelogoViewModel.cs @@ -1,5 +1,7 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using Avalonia.Controls; +using Avalonia.VisualTree; using DownKyi.Core.FFMpeg; using DownKyi.Events; using DownKyi.Utils; @@ -13,56 +15,56 @@ public class ViewDelogoViewModel : ViewModelBase public const string Tag = "PageToolboxDelogo"; // 是否正在执行去水印任务 - private bool isDelogo = false; + private bool _isDelogo = false; #region 页面属性申明 - private string videoPath; + private string _videoPath; public string VideoPath { - get { return videoPath; } - set { SetProperty(ref videoPath, value); } + get => _videoPath; + set => SetProperty(ref _videoPath, value); } - private int logoWidth; + private int _logoWidth; public int LogoWidth { - get { return logoWidth; } - set { SetProperty(ref logoWidth, value); } + get => _logoWidth; + set => SetProperty(ref _logoWidth, value); } - private int logoHeight; + private int _logoHeight; public int LogoHeight { - get { return logoHeight; } - set { SetProperty(ref logoHeight, value); } + get => _logoHeight; + set => SetProperty(ref _logoHeight, value); } - private int logoX; + private int _logoX; public int LogoX { - get { return logoX; } - set { SetProperty(ref logoX, value); } + get => _logoX; + set => SetProperty(ref _logoX, value); } - private int logoY; + private int _logoY; public int LogoY { - get { return logoY; } - set { SetProperty(ref logoY, value); } + get => _logoY; + set => SetProperty(ref _logoY, value); } - private string status; + private string _status; public string Status { - get { return status; } - set { SetProperty(ref status, value); } + get => _status; + set => SetProperty(ref _status, value); } #endregion @@ -84,17 +86,16 @@ public class ViewDelogoViewModel : ViewModelBase #region 命令申明 // 选择视频事件 - private DelegateCommand selectVideoCommand; + private DelegateCommand? _selectVideoCommand; - public DelegateCommand SelectVideoCommand => - selectVideoCommand ?? (selectVideoCommand = new DelegateCommand(ExecuteSelectVideoCommand)); + public DelegateCommand SelectVideoCommand => _selectVideoCommand ??= new DelegateCommand(ExecuteSelectVideoCommand); /// /// 选择视频事件 /// private async void ExecuteSelectVideoCommand() { - if (isDelogo) + if (_isDelogo) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; @@ -104,17 +105,16 @@ public class ViewDelogoViewModel : ViewModelBase } // 去水印事件 - private DelegateCommand delogoCommand; + private DelegateCommand? _delogoCommand; - public DelegateCommand DelogoCommand => - delogoCommand ?? (delogoCommand = new DelegateCommand(ExecuteDelogoCommand)); + public DelegateCommand DelogoCommand => _delogoCommand ??= new DelegateCommand(ExecuteDelogoCommand); /// /// 去水印事件 /// private async void ExecuteDelogoCommand() { - if (isDelogo) + if (_isDelogo) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; @@ -151,26 +151,25 @@ public class ViewDelogoViewModel : ViewModelBase } // 新文件名 - string newFileName = VideoPath.Insert(VideoPath.Length - 4, "_delogo"); + var newFileName = VideoPath.Insert(VideoPath.Length - 4, "_delogo"); Status = string.Empty; await Task.Run(() => { // 执行去水印程序 - isDelogo = true; + _isDelogo = true; FFMpeg.Instance.Delogo(VideoPath, newFileName, LogoX, LogoY, LogoWidth, LogoHeight, output => { Status += output + "\n"; }); - isDelogo = false; + _isDelogo = false; }); } // Status改变事件 - private DelegateCommand statusCommand; + private DelegateCommand? _statusCommand; - public DelegateCommand StatusCommand => - statusCommand ?? (statusCommand = new DelegateCommand(ExecuteStatusCommand)); + public DelegateCommand StatusCommand => _statusCommand ??= new DelegateCommand(ExecuteStatusCommand); /// /// Status改变事件 @@ -178,13 +177,13 @@ public class ViewDelogoViewModel : ViewModelBase /// private void ExecuteStatusCommand(object parameter) { - if (!(parameter is TextBox output)) + if (parameter is not TextChangedEventArgs output) { return; } // TextBox滚动到底部 - // output.ScrollToEnd(); + ((TextBox?)output.Source)?.GetVisualDescendants().OfType().FirstOrDefault()?.ScrollToEnd(); } #endregion diff --git a/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs b/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs index e5bc80e..00780a1 100644 --- a/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs +++ b/DownKyi/ViewModels/Toolbox/ViewExtractMediaViewModel.cs @@ -1,6 +1,8 @@ using System; +using System.Linq; using System.Threading.Tasks; using Avalonia.Controls; +using Avalonia.VisualTree; using DownKyi.Core.FFMpeg; using DownKyi.Events; using DownKyi.Utils; @@ -14,36 +16,36 @@ public class ViewExtractMediaViewModel : ViewModelBase public const string Tag = "PageToolboxExtractMedia"; // 是否正在执行任务 - private bool isExtracting = false; + private bool _isExtracting; #region 页面属性申明 - private string videoPathsStr; + private string _videoPathsStr; public string VideoPathsStr { - get => videoPathsStr; - set { SetProperty(ref videoPathsStr, value); } + get => _videoPathsStr; + set => SetProperty(ref _videoPathsStr, value); } - private string[] videoPaths; + private string[] _videoPaths; public string[] VideoPaths { - get => videoPaths; + get => _videoPaths; set { - videoPaths = value; + _videoPaths = value; VideoPathsStr = string.Join(Environment.NewLine, value); } } - private string status; + private string _status; public string Status { - get => status; - set => SetProperty(ref status, value); + get => _status; + set => SetProperty(ref _status, value); } #endregion @@ -52,7 +54,7 @@ public class ViewExtractMediaViewModel : ViewModelBase { #region 属性初始化 - VideoPaths = new string[0]; + VideoPaths = Array.Empty(); #endregion } @@ -60,17 +62,16 @@ public class ViewExtractMediaViewModel : ViewModelBase #region 命令申明 // 选择视频事件 - private DelegateCommand selectVideoCommand; + private DelegateCommand? _selectVideoCommand; - public DelegateCommand SelectVideoCommand => - selectVideoCommand ?? (selectVideoCommand = new DelegateCommand(ExecuteSelectVideoCommand)); + public DelegateCommand SelectVideoCommand => _selectVideoCommand ??= new DelegateCommand(ExecuteSelectVideoCommand); /// /// 选择视频事件 /// private async void ExecuteSelectVideoCommand() { - if (isExtracting) + if (_isExtracting) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; @@ -80,24 +81,22 @@ public class ViewExtractMediaViewModel : ViewModelBase } // 提取音频事件 - private DelegateCommand extractAudioCommand; + private DelegateCommand? _extractAudioCommand; - public DelegateCommand ExtractAudioCommand => extractAudioCommand ?? - (extractAudioCommand = - new DelegateCommand(ExecuteExtractAudioCommand)); + public DelegateCommand ExtractAudioCommand => _extractAudioCommand ??= new DelegateCommand(ExecuteExtractAudioCommand); /// /// 提取音频事件 /// private async void ExecuteExtractAudioCommand() { - if (isExtracting) + if (_isExtracting) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; } - if (VideoPaths.Length <= 0) + if (VideoPaths?.Length <= 0) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipNoSeletedVideo")); return; @@ -107,35 +106,30 @@ public class ViewExtractMediaViewModel : ViewModelBase await Task.Run(() => { - isExtracting = true; + _isExtracting = true; foreach (var item in VideoPaths) { // 音频文件名 - string audioFileName = item.Remove(item.Length - 4, 4) + ".aac"; + var audioFileName = item.Remove(item.Length - 4, 4) + ".aac"; // 执行提取音频程序 - FFMpeg.Instance.ExtractAudio(item, audioFileName, output => - { - Status += output + "\n"; - }); + FFMpeg.Instance.ExtractAudio(item, audioFileName, output => { Status += output + "\n"; }); } - isExtracting = false; + _isExtracting = false; }); } // 提取视频事件 - private DelegateCommand extractVideoCommand; + private DelegateCommand? _extractVideoCommand; - public DelegateCommand ExtractVideoCommand => extractVideoCommand ?? - (extractVideoCommand = - new DelegateCommand(ExecuteExtractVideoCommand)); + public DelegateCommand ExtractVideoCommand => _extractVideoCommand ??= new DelegateCommand(ExecuteExtractVideoCommand); /// /// 提取视频事件 /// private async void ExecuteExtractVideoCommand() { - if (isExtracting) + if (_isExtracting) { EventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipWaitTaskFinished")); return; @@ -151,27 +145,23 @@ public class ViewExtractMediaViewModel : ViewModelBase await Task.Run(() => { - isExtracting = true; + _isExtracting = true; foreach (var item in VideoPaths) { // 视频文件名 - string videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4"; + var videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4"; // 执行提取视频程序 - FFMpeg.Instance.ExtractVideo(item, videoFileName, new Action((output) => - { - Status += output + "\n"; - })); + FFMpeg.Instance.ExtractVideo(item, videoFileName, new Action((output) => { Status += output + "\n"; })); } - isExtracting = false; + _isExtracting = false; }); } // Status改变事件 - private DelegateCommand statusCommand; + private DelegateCommand? _statusCommand; - public DelegateCommand StatusCommand => - statusCommand ?? (statusCommand = new DelegateCommand(ExecuteStatusCommand)); + public DelegateCommand StatusCommand => _statusCommand ??= new DelegateCommand(ExecuteStatusCommand); /// /// Status改变事件 @@ -179,13 +169,13 @@ public class ViewExtractMediaViewModel : ViewModelBase /// private void ExecuteStatusCommand(object parameter) { - if (!(parameter is TextBox output)) + if (parameter is not TextChangedEventArgs output) { return; } // TextBox滚动到底部 - // output.ScrollToEnd(); + ((TextBox?)output.Source)?.GetVisualDescendants().OfType().FirstOrDefault()?.ScrollToEnd(); } #endregion diff --git a/DownKyi/Views/Toolbox/ViewBiliHelper.axaml b/DownKyi/Views/Toolbox/ViewBiliHelper.axaml index dfd8ad0..8c2daf9 100644 --- a/DownKyi/Views/Toolbox/ViewBiliHelper.axaml +++ b/DownKyi/Views/Toolbox/ViewBiliHelper.axaml @@ -98,7 +98,7 @@ Height="25" Margin="10" VerticalContentAlignment="Center" - Text="{Binding DanmakuUserID, Mode=TwoWay}" /> + Text="{Binding DanmakuUserId, Mode=TwoWay}" />