public void RemoveFolder(object sender, RoutedEventArgs e) { Button b = sender as Button; b.Opacity = 0.1; MessageBoxImage mbi = new MessageBoxImage(); string desc = $"Do you wish to {_deleteButtonText.Text}"; // should be custom messagebox... but meh MessageBoxResult result = MessageBox.Show(desc, "Remove from the list", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { Tiles.Remove(b.CommandParameter.ToString()); Counters.Remove(b.CommandParameter.ToString()); chConfig.list.Remove(b.CommandParameter.ToString()); config.ChConfig = chConfig; UpdateFolderGrid(true); RefreshDropboxList(); myTray.UpdateTrayFolders(); string json = JsonConvert.SerializeObject(config, Formatting.Indented); byte[] fileContent = Encoding.UTF8.GetBytes(json); Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup"); } }
public void CloseApp(object sender, RoutedEventArgs e) { /* * MessageBoxImage mbi = new MessageBoxImage(); * string desc = "Are you sure you want to exit?\nAll the ongoing downloading will pause. (check for downloading, then warn?)"; * * // should be custom messagebox... because. * MessageBoxResult result = MessageBox.Show(desc, "Close app", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes); * * if (result == MessageBoxResult.No) * { * return; * } */ config.LastWidth = (int)this.ActualWidth; config.LastHeight = (int)this.ActualHeight; string json = JsonConvert.SerializeObject(config, Formatting.Indented); byte[] fileContent = Encoding.UTF8.GetBytes(json); Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup"); Application.Current.Shutdown(); }
// Dropdown Lists private void OnAccountSelected(object sender, RoutedEventArgs e) { if (!(_accountComboBox.SelectedItem is ViewGuild vg)) { return; } config.Token = ((ViewGuild)_accountComboBox.SelectedItem).Id; string json = JsonConvert.SerializeObject(config, Formatting.Indented); byte[] fileContent = Encoding.UTF8.GetBytes(json); Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup"); _pfp.Source = vg.Image; _preUsername.Text = "Logged in as:"; _username.Text = vg.Name; }
public void AddFolder(object sender, RoutedEventArgs e) { //ListBoxItem channelItem = _channelList.SelectedItem as ListBoxItem; //string channelID = channelItem.GetValue(idProperty).ToString(); ViewGuild serverItem = _guildComboBox.SelectedItem as ViewGuild; ComboBoxItem channelItem = _channelComboBox.SelectedItem as ComboBoxItem; string path = ((Button)sender).CommandParameter.ToString(); string channelID = channelItem.GetValue(idProperty).ToString(); string channelName = channelItem.Content.ToString(); //chConfig = JsonConvert.DeserializeObject<ChannelConfig>(File.ReadAllText("channels.json")); Random r = new Random(); Color c = Color.FromRgb((Byte)r.Next(0, 256), (Byte)r.Next(0, 256), (Byte)r.Next(0, 256)); string color = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2"); if (!chConfig.list.ContainsKey(channelID)) { chConfig.list.Add(channelID, new ChannelConfig.Values() { IconUrl = serverItem.ImageUrl, GuildName = serverItem.Name, ChannelName = channelName, GuildId = serverItem.Id, ChannelId = channelID, LastMsgChecked = null, SavePath = path, ImagesSaved = 0, Color = color }); } else { MessageBoxImage mbi = new MessageBoxImage(); string desc = $"This action will overwrite channel's save path, however the program will still download new images from where it left off.\nDo you wish to continue?"; // should be custom messagebox... but meh MessageBoxResult result = MessageBox.Show(desc, "This channel already has a folder set-up", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes); if (result == MessageBoxResult.No) { return; } config.ChConfig = chConfig; chConfig.list[channelID] = new ChannelConfig.Values() { IconUrl = serverItem.ImageUrl, GuildName = serverItem.Name, ChannelName = channelName, GuildId = serverItem.Id, ChannelId = channelID, LastMsgChecked = chConfig.list[channelID].LastMsgChecked, SavePath = path, ImagesSaved = chConfig.list[channelID].ImagesSaved, Color = color }; } config.ChConfig = chConfig; UpdateFolderGrid(true); RefreshDropboxList(); myTray.UpdateTrayFolders(); string json = JsonConvert.SerializeObject(config, Formatting.Indented); byte[] fileContent = Encoding.UTF8.GetBytes(json); Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup"); }