Skip to content

Commit

Permalink
Enhancement: Support multiple files at once from context menu? Samuel…
Browse files Browse the repository at this point in the history
  • Loading branch information
micha3056 committed Aug 27, 2023
1 parent dcb8edb commit e42cfe0
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions uploader/uploader/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ namespace uploader
public partial class MainForm : DarkForm
{
private SettingsForm _settingsForm = new SettingsForm();
int maxArgs = 10;

public MainForm()
public MainForm()
{
InitializeComponent();
}
Expand Down Expand Up @@ -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();
}
}
}
}
}

0 comments on commit e42cfe0

Please sign in to comment.