private void BasicDataButton_Click(object sender, RoutedEventArgs e) { BasicInfoDialog dialog = new BasicInfoDialog(); dialog.UsernameText.Text = Properties.Settings.Default.UserName; dialog.AskCheckbox.IsChecked = !Properties.Settings.Default.UseDefaultSavePath; if (Properties.Settings.Default.DefaultSavePath != String.Empty) { dialog.DefaultSavePath = Properties.Settings.Default.DefaultSavePath; } dialog.ShowDialog(); if (dialog.Success) { Properties.Settings.Default.UserName = dialog.UsernameText.Text; Properties.Settings.Default.DefaultSavePath = dialog.DefaultSavePath; Properties.Settings.Default.UseDefaultSavePath = Directory.Exists(dialog.DefaultSavePath); Properties.Settings.Default.Save(); receiver.Name = Properties.Settings.Default.UserName; Func <string, string> choosePath; if (Properties.Settings.Default.UseDefaultSavePath) { choosePath = (x) => Properties.Settings.Default.DefaultSavePath; } else { choosePath = choosePathMethod; } receiver.Path = choosePath; refresh(); } }
public MainWindow() { InitializeComponent(); // Tray icon trayMenu = new System.Windows.Forms.ContextMenu(); trayMenu.MenuItems.Add("Exit", OnExit); trayIcon = new NotifyIcon(); trayIcon.Text = "Octo Sender"; trayIcon.Visible = true; trayIcon.ContextMenu = trayMenu; try { trayIcon.Icon = new Icon("Resources\\icon.ico"); } catch (Exception e) { Console.WriteLine(e.Message); } trayIcon.MouseClick += trayIcon_MouseClick; trayIcon.MouseMove += trayIcon_MouseMove; trayIcon.BalloonTipClicked += trayIcon_BalloonTipClicked; // Static properties StaticPenises.Initialize(); // Loading saved contacts dataLoader = new DataLoader(); if (!dataLoader.ReadData()) { dataLoader.SaveData(); } // Loading settings if (Properties.Settings.Default.FirstRun) { // First run setup Properties.Settings.Default.Reset(); // TODO Add welcome window // Basic info BasicInfoDialog dialog = new BasicInfoDialog(); dialog.ShowDialog(); if (!dialog.Success) { // Shutdown application if window was closed System.Windows.Application.Current.Shutdown(); Thread.Sleep(50); } else { // Save settings Properties.Settings.Default.UserName = dialog.UsernameText.Text; Properties.Settings.Default.DefaultSavePath = dialog.DefaultSavePath; Properties.Settings.Default.UseDefaultSavePath = Directory.Exists(dialog.DefaultSavePath); Properties.Settings.Default.FirstRun = false; Properties.Settings.Default.Save(); } } // Initialize sender sender = new Sender(usedPorts, sendingQueue.Items, Properties.Settings.Default.UserName); sender.FileSent += sender_FileSent; // Default path or ask everytime Func <string, string> choosePath; if (Properties.Settings.Default.UseDefaultSavePath) { choosePath = (x) => Properties.Settings.Default.DefaultSavePath; } else { choosePath = choosePathMethod; } // Initialize receiver receiver = new Receiver(usedPorts, receivingQueue.Items, contacts.Items, choosePath, Properties.Settings.Default.UserName); receiver.FileReceived += receiver_FileReceived; receiver.BannedIPs = Properties.Settings.Default.BannedIPs; receiver.Start(); // Starts listeners refresh(); // Adds contacts and tasks }