Skip to content

Commit

Permalink
파일 목록에 DRB 파일 드래그&드롭 시 배치파일을 실행하는 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
daramkun committed Jul 1, 2024
1 parent 66f6386 commit c56cf5a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DaramRenamer.Shared/Strings/Strings.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions DaramRenamer.Shared/Strings/Strings.ko_kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
45 changes: 45 additions & 0 deletions DaramRenamer.Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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<BatchNode>();
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)
Expand Down

0 comments on commit c56cf5a

Please sign in to comment.