Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Support multiple files at once from context menu? #131 #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}
}