public void HandleArguments(string[] args) { if (args.Length == 0) { Form.Invoke(new Action(Form.Show)); } else { foreach (string s in args) { if (File.Exists(s)) { FileUploadHandler.UploadFile(s); } else if (Directory.Exists(s)) { FileUploadHandler.UploadDirectory(s); } } } }
public IconHandler(string[] args) { notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);; notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); notifyIcon.ContextMenuStrip.Items.Add("Show", null, Show); notifyIcon.ContextMenuStrip.Items.Add("Configuration", null, ShowConfig); notifyIcon.ContextMenuStrip.Items.Add("Exit", null, Exit); notifyIcon.MouseClick += new MouseEventHandler(LeftClick); //Dont show icon untill everything is set ups notifyIcon.Visible = false; CertificateHandler.Load(); Client = new ClientManager(); try { Task.Run(() => Client.Connect()).Wait(); } catch (AggregateException ex) { MessageBox.Show("Agg Couldn´t connect:\n" + ex.InnerException.Message); string text = $"AggregateException with {ex.InnerExceptions.Count} InnerExceptions:\n" + ex.ToString() + "\nInnerExceptions:"; foreach (Exception exception in ex.InnerExceptions) { text += "\n" + exception.ToString(); } File.WriteAllText("crashLog " + DateTime.Now.ToString("dd-MM-yy HH_mm") + ".txt", text); Thread.Sleep(1000); Exit(); return; } catch (Exception e) { MessageBox.Show("Couldn´t connect:\n" + e.Message); File.WriteAllText("crashLog " + DateTime.Now.ToString("dd-MM-yy HH_mm") + ".txt", e.ToString()); Exit(); return; } mainForm = new MainForm(Client); //if client is not logged in -> show a login prompt if (Client.LoggedIn == false) { mainForm.Show(); } FileUploadHandler.Init(mainForm, Client); mainForm.CreateControl(); //Everything is ready -> show icon notifyIcon.Visible = true; var argumentsHandler = new ArgumentsHandler(mainForm); if (args.Length != 0) { argumentsHandler.HandleArguments(args); } PipeHandler.Start(argumentsHandler); }