From e42cfe016ee5c66ed07a28fb2aae0faeb172381c Mon Sep 17 00:00:00 2001 From: "VANGUARD\\michael.hauptvogel" Date: Sun, 27 Aug 2023 10:11:21 +0200 Subject: [PATCH] Enhancement: Support multiple files at once from context menu? #131 --- uploader/uploader/MainForm.cs | 48 +++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/uploader/uploader/MainForm.cs b/uploader/uploader/MainForm.cs index 1186d1f..29d3e3e 100644 --- a/uploader/uploader/MainForm.cs +++ b/uploader/uploader/MainForm.cs @@ -16,8 +16,9 @@ namespace uploader public partial class MainForm : DarkForm { private SettingsForm _settingsForm = new SettingsForm(); + int maxArgs = 10; - public MainForm() + public MainForm() { InitializeComponent(); } @@ -53,26 +54,41 @@ private void MainForm_DragDrop(object sender, DragEventArgs e) var settings = Settings.LoadSettings(); var files = (string[])e.Data.GetData(DataFormats.FileDrop); - foreach (var file in files) - { - var uploadForm = new UploadForm(this, settings, true, file); - uploadForm.Show(); - this.Hide(); - } - } + showMultipleUploadForms(files, settings); + } + + private void showMultipleUploadForms(string[] files, Settings settings) + { + foreach (var file in files) + { + var uploadForm = new UploadForm(this, settings, true, file); + uploadForm.Show(); + this.Hide(); + } + } private void MainForm_Shown(object sender, EventArgs e) { var settings = Settings.LoadSettings(); var args = Environment.GetCommandLineArgs(); - if (args.Length == 2) - { - var file = args[1]; // Second argument because .NET puts program filename to the first - var uploadForm = new UploadForm(this, settings, false, file); - uploadForm.Show(); - this.Hide(); - } - } + if (args.Length >= 2 && args.Length <= maxArgs) + { + var files = args.ToList() + .GetRange(1, args.Count()-1).ToArray(); + showMultipleUploadForms(files, settings); + } + else if (args.Length > maxArgs) + { + string message = "Number of files exceeds maximum"; + string title = $"The app can handle max {maxArgs} files at once."; + MessageBoxButtons buttons = MessageBoxButtons.OK; + DialogResult result = MessageBox.Show(message, title, buttons); + if (result == DialogResult.Yes) + { + this.Close(); + } + } + } } }