diff --git a/DaramRenamer.Shared/Strings/Strings.default.json b/DaramRenamer.Shared/Strings/Strings.default.json index f85b42b..b51dfe9 100644 --- a/DaramRenamer.Shared/Strings/Strings.default.json +++ b/DaramRenamer.Shared/Strings/Strings.default.json @@ -267,6 +267,10 @@ "DragAndDrop_DirectoryQuestionDescription": "Add to Directory mode or iterate files? Directory mode can edit directory name.", "DragAndDrop_ButtonAddDirectory": "Add folder", "DragAndDrop_ButtonIterateFiles": "Add files from folder", + "DragAndDrop_DrbQuestion": "It looks like you're probably adding a DaramRenamer batch file.", + "DragAndDrop_DrbQuestionDescription": "Do you want to execute batch file(s)? When execute, DRB files will not be added to the list.", + "DragAndDrop_ButtonExecuteDRB": "Execute Batch files", + "DragAndDrop_ButtonJustAddDRB": "Just Add Batch files", "BatchWindow_Title": "Batch Commands Processor", "BatchWindow_Remove": "_Remove", diff --git a/DaramRenamer.Shared/Strings/Strings.ko_kr.json b/DaramRenamer.Shared/Strings/Strings.ko_kr.json index 50852be..ec3b61f 100644 --- a/DaramRenamer.Shared/Strings/Strings.ko_kr.json +++ b/DaramRenamer.Shared/Strings/Strings.ko_kr.json @@ -267,6 +267,10 @@ "DragAndDrop_DirectoryQuestionDescription": "해당 폴더를 디렉토리 모드로 추가하시겠습니까? 또는 폴더 내 파일을 추가하시겠습니까?\n디렉토리 모드로 추가된 폴더는 폴더명을 편집할 수 있습니다.", "DragAndDrop_ButtonAddDirectory": "폴더 추가", "DragAndDrop_ButtonIterateFiles": "폴더 내 파일 추가", + "DragAndDrop_DrbQuestion": "아마도 다람리네이머 배치 파일을 추가하는 것 같습니다.", + "DragAndDrop_DrbQuestionDescription": "배치 파일을 실행 하시겠습니까? 실행하면 DRB 파일은 목록에 추가되지 않습니다.", + "DragAndDrop_ButtonExecuteDRB": "배치 파일 실행", + "DragAndDrop_ButtonJustAddDRB": "그냥 목록에 추가", "BatchWindow_Title": "명령 일괄처리기", "BatchWindow_Remove": "제거(_R)", diff --git a/DaramRenamer.Windows/MainWindow.xaml.cs b/DaramRenamer.Windows/MainWindow.xaml.cs index 54d9573..8484864 100644 --- a/DaramRenamer.Windows/MainWindow.xaml.cs +++ b/DaramRenamer.Windows/MainWindow.xaml.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Principal; +using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -231,10 +232,15 @@ private void ListViewFiles_Drop(object sender, DragEventArgs e) if (!(e.Data.GetData(DataFormats.FileDrop) is string[] temp)) return; + var hasDrb = false; var hasDirectory = false; foreach (var filename in temp) + { if (File.GetAttributes(filename).HasFlag(FileAttributes.Directory) && filename.Length > 3) hasDirectory = true; + if (!File.GetAttributes(filename).HasFlag(FileAttributes.Directory) && filename.EndsWith(".drb")) + hasDrb = true; + } var directoryMode = false; if (hasDirectory) @@ -249,11 +255,50 @@ private void ListViewFiles_Drop(object sender, DragEventArgs e) directoryMode = result.Button == 101; } + var executeDrb = false; + if (hasDrb) + { + var result = MessageBox(Strings.Instance["DragAndDrop_DrbQuestion"], + Strings.Instance["DragAndDrop_DrbQuestionDescription"], + TaskDialogIcon.Warning, TaskDialogCommonButtonFlags.Cancel, + Strings.Instance["DragAndDrop_ButtonExecuteDRB"], + Strings.Instance["DragAndDrop_ButtonJustAddDRB"]); + if (result.Button == TaskDialogResult.Cancel) + return; + executeDrb = result.Button == 101; + } + _undoManager.SaveToUndoStack(FileInfo.Files); + var drbList = new List(); foreach (var s in from b in temp orderby b select b) + { + if (!File.GetAttributes(s).HasFlag(FileAttributes.Directory) && + s.EndsWith(s) && hasDrb && executeDrb) + { + try + { + using Stream stream = new FileStream(s, FileMode.Open); + using TextReader reader = new StreamReader(stream, Encoding.UTF8, false, -1, true); + + var rootNode = new RootBatchNode(); + rootNode.Deserializer(reader); + + drbList.Add(rootNode); + continue; + } + catch + { + // Ignore and add to list DRB. + } + } + AddItem(s, s.Length > 3 && File.GetAttributes(s).HasFlag(FileAttributes.Directory) && directoryMode); + } + + foreach (var rootNode in drbList) + Parallel.ForEach(FileInfo.Files, fileInfo => rootNode.Execute(fileInfo)); } private void ListViewFiles_KeyUp(object sender, KeyEventArgs e)