From 296b0df4a8eca6321317103d829fc6c2b5495302 Mon Sep 17 00:00:00 2001 From: butaixianran Date: Thu, 4 Jan 2024 02:06:37 +0800 Subject: [PATCH] update file drag for merging video --- VideoRangeCopier/Model/MergeOption.cs | 8 ++++- VideoRangeCopier/Util/Global.cs | 2 +- VideoRangeCopier/Views/MergeView.axaml | 11 ++++--- VideoRangeCopier/Views/MergeView.axaml.cs | 37 +++++++++++++++++------ 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/VideoRangeCopier/Model/MergeOption.cs b/VideoRangeCopier/Model/MergeOption.cs index fd13bba..704e31f 100644 --- a/VideoRangeCopier/Model/MergeOption.cs +++ b/VideoRangeCopier/Model/MergeOption.cs @@ -27,7 +27,13 @@ public void GetVideoInfoByUri(string file_name, Uri file_path) string name_no_ext = video_name.Replace(ext, ""); - string new_name = name_no_ext + "_merged" + ext; + string new_ext = ext; + if (new_ext != ".mp4" && new_ext != ".mkv") + { + new_ext = ".mp4"; + } + + string new_name = name_no_ext + "_merged" + new_ext; output_path = video_path.Replace(video_name, new_name); diff --git a/VideoRangeCopier/Util/Global.cs b/VideoRangeCopier/Util/Global.cs index ed0132f..d210efd 100644 --- a/VideoRangeCopier/Util/Global.cs +++ b/VideoRangeCopier/Util/Global.cs @@ -10,7 +10,7 @@ namespace VideoRangeCopier.Util public static class Global { public static string AppName = "VideoRangeCopier"; - public static string AppVersion = ""; + public static string AppVersion = "0.3.0"; public static string Error = ""; diff --git a/VideoRangeCopier/Views/MergeView.axaml b/VideoRangeCopier/Views/MergeView.axaml index 2752bd7..9817cd8 100644 --- a/VideoRangeCopier/Views/MergeView.axaml +++ b/VideoRangeCopier/Views/MergeView.axaml @@ -20,13 +20,14 @@ - - Drop File - + Video File: + + Drop Video File + @@ -34,7 +35,9 @@ Audio File: - + + Drop Audio File + diff --git a/VideoRangeCopier/Views/MergeView.axaml.cs b/VideoRangeCopier/Views/MergeView.axaml.cs index 32696cc..2b93274 100644 --- a/VideoRangeCopier/Views/MergeView.axaml.cs +++ b/VideoRangeCopier/Views/MergeView.axaml.cs @@ -16,7 +16,8 @@ public partial class MergeView : UserControl public MergeView() { InitializeComponent(); - AddHandler(DragDrop.DropEvent, File_Drop); + DropVideoBorder.AddHandler(DragDrop.DropEvent, DropVideo); + DropAudioBorder.AddHandler(DragDrop.DropEvent, DropAudio); } private async void SelectVideoFile_Clicked(object sender, RoutedEventArgs args) @@ -75,7 +76,7 @@ private async void SelectAudioFile_Clicked(object sender, RoutedEventArgs args) } - private void File_Drop(object? sender, DragEventArgs e) + private void DropVideo(object? sender, DragEventArgs e) { if (!e.Data.Contains(DataFormats.Files)) { return; } @@ -98,21 +99,37 @@ private void File_Drop(object? sender, DragEventArgs e) Helper.Log($"Dragged Item name:{item.Name}"); Helper.Log($"Dragged Item path:{item.Path}"); - string ext = Path.GetExtension(item.Name); + Global.MergeOpt.GetVideoInfoByUri(item.Name, item.Path); + VideoPathTextBlock.Text = Global.MergeOpt.video_path; + + } - string[] audio_exts = [".m4a", ".wav", ".mp3"]; + private void DropAudio(object? sender, DragEventArgs e) + { + if (!e.Data.Contains(DataFormats.Files)) { return; } - if (audio_exts.Contains(ext)) + var files = e.Data.GetFiles() ?? Array.Empty(); + + if (files.Count() < 1) { - Global.MergeOpt.GetAudioInfoByUri(item.Path); - AudioPathTextBlock.Text = Global.MergeOpt.audio_path; + return; } - else + + var item = files.First(); + + if (item is null) { return; } + + if (!(item is IStorageFile)) { - Global.MergeOpt.GetVideoInfoByUri(item.Name, item.Path); - VideoPathTextBlock.Text = Global.MergeOpt.video_path; + return; } + Helper.Log($"Dragged Item name:{item.Name}"); + Helper.Log($"Dragged Item path:{item.Path}"); + + Global.MergeOpt.GetAudioInfoByUri(item.Path); + AudioPathTextBlock.Text = Global.MergeOpt.audio_path; + } private async void Start_Click(object sender, RoutedEventArgs args)