/// <summary> /// Sets the external calendar. /// </summary> /// <param name="settings">The settings.</param> internal void SetExternalCalendar(SerializableSettings settings) { // Google calendar reminder method cbGoogleReminder.Items.Clear(); cbGoogleReminder.Items.AddRange(GoogleCalendarEvent.ReminderMethods.ToArray()); rbMSOutlook.Checked = settings.Calendar.Provider == CalendarProvider.Outlook && ExternalCalendar.OutlookInstalled; rbGoogle.Checked = !rbMSOutlook.Checked; rbDefaultCalendar.Checked = settings.Calendar.UseOutlookDefaultCalendar; rbCustomCalendar.Checked = !rbDefaultCalendar.Checked; tbOutlookCalendarPath.Text = settings.Calendar.OutlookCustomCalendarPath; tbGoogleCalendarName.Text = settings.Calendar.GoogleCalendarName; cbGoogleReminder.SelectedIndex = (int)settings.Calendar.GoogleEventReminder; cbSetReminder.Checked = settings.Calendar.UseReminding; tbReminder.Text = settings.Calendar.RemindingInterval.ToString(CultureConstants.DefaultCulture); cbUseAlterateReminder.Checked = settings.Calendar.UseAlternateReminding; dtpEarlyReminder.Value = settings.Calendar.EarlyReminding; dtpLateReminder.Value = settings.Calendar.LateReminding; cbLastQueuedSkillOnly.Checked = settings.Calendar.LastQueuedSkillOnly; UpdateControlsVisibility(); }
/// <summary> /// Constructor. /// </summary> public SettingsForm() { InitializeComponent(); m_settings = Settings.Export(); m_oldSettings = Settings.Export(); // Platform is Unix ? if (Environment.OSVersion.Platform == PlatformID.Unix) { runAtStartupComboBox.Enabled = false; treeView.Nodes["trayIconNode"].Remove(); } // Run with Mono ? if (Type.GetType("Mono.Runtime") != null) treeView.Nodes["generalNode"].Nodes["g15Node"].Remove(); // Fill the overview portraits sizes overviewPortraitSizeComboBox.Items.AddRange( Enum.GetValues(typeof(PortraitSizes)).Cast<PortraitSizes>().Select(x => { // Transforms x64 to 64 by 64 var size = x.ToString().Substring(1); return String.Format("{0} by {0}", size); }).ToArray()); // Expands the left panel and selects the first page and node. treeView.ExpandAll(); treeView.SelectedNode = treeView.Nodes[0]; multiPanel.SelectedPage = generalPage; }
/// <summary> /// Constructor. /// </summary> public SettingsForm() { InitializeComponent(); treeView.Font = FontFactory.GetFont("Tahoma", 9.75F); alwaysAskRadioButton.Font = FontFactory.GetFont("Tahoma", 8.25F, FontStyle.Bold); removeAllRadioButton.Font = FontFactory.GetFont("Tahoma", 8.25F, FontStyle.Bold); removeConfirmedRadioButton.Font = FontFactory.GetFont("Tahoma", 8.25F, FontStyle.Bold); settingsFileStorageControl.Font = FontFactory.GetFont("Tahoma", 8.25F); m_settings = Settings.Export(); m_oldSettings = Settings.Export(); }
/// <summary> /// Applies the external calendar settings. /// </summary> /// <param name="settings">The settings.</param> internal void ApplyExternalCalendarSettings(SerializableSettings settings) { settings.Calendar.Provider = rbMSOutlook.Checked ? CalendarProvider.Outlook : CalendarProvider.Google; settings.Calendar.UseOutlookDefaultCalendar = rbDefaultCalendar.Checked; settings.Calendar.OutlookCustomCalendarPath = tbOutlookCalendarPath.Text.Trim(); settings.Calendar.GoogleEventReminder = cbGoogleReminder.SelectedIndex != -1 ? (GoogleCalendarReminder)cbGoogleReminder.SelectedIndex : GoogleCalendarReminder.Email; settings.Calendar.GoogleCalendarName = tbGoogleCalendarName.Text; settings.Calendar.UseReminding = cbSetReminder.Checked; settings.Calendar.RemindingInterval = Int32.Parse(tbReminder.Text, CultureConstants.DefaultCulture); settings.Calendar.UseAlternateReminding = cbUseAlterateReminder.Checked; settings.Calendar.EarlyReminding = dtpEarlyReminder.Value; settings.Calendar.LateReminding = dtpLateReminder.Value; settings.Calendar.LastQueuedSkillOnly = cbLastQueuedSkillOnly.Checked; }
/// <summary> /// Deserializes a settings file from an old format. /// </summary> /// <param name="filename"></param> /// <returns></returns> private static SerializableSettings DeserializeOldFormat(string filename) { var oldSerial = Util.DeserializeXML<OldSettings>(filename, Util.LoadXSLT(Properties.Resources.SettingsAndPlanImport)); var serial = new SerializableSettings(); // Accounts serial.Accounts.AddRange(oldSerial.Accounts); // Characters foreach (var oldCharacter in oldSerial.Characters) { // Adds the char both to the characters list and the monitored characters list. var character = new SerializableCCPCharacter { ID = oldCharacter.ID, Name = oldCharacter.Name, Guid = Guid.NewGuid() }; serial.MonitoredCharacters.Add(new MonitoredCharacterSettings { CharacterGuid = character.Guid }); serial.Characters.Add(character); } // Plans foreach (var oldPlan in oldSerial.Plans) { // Look for the owner by his name var owner = serial.Characters.SingleOrDefault(x => x.Name == oldPlan.Owner); if (owner == null) continue; // Imports the plan var plan = new SerializablePlan { Owner = owner.Guid, Name = oldPlan.Name }; plan.Entries.AddRange(oldPlan.Entries); serial.Plans.Add(plan); } return serial; }
/// <summary> /// Creates a seriablizable version of the settings. /// </summary> /// <returns></returns> public static SerializableSettings Export() { SerializableSettings serial = new SerializableSettings(); serial.Revision = Settings.Revision; serial.Compatibility = Settings.Compatibility; // Export characters and such serial.Characters = EveClient.Characters.Export(); serial.Accounts = EveClient.Accounts.Export(); serial.Plans = EveClient.Characters.ExportPlans(); serial.MonitoredCharacters = EveClient.MonitoredCharacters.Export(); // API providers serial.APIProviders = EveClient.APIProviders.Export(); // Scheduler serial.Scheduler = Scheduler.Export(); // User settings serial.Calendar = Settings.Calendar.Clone(); serial.Notifications = Settings.Notifications.Clone(); serial.Exportation = Settings.Exportation.Clone(); serial.Updates = Settings.Updates.Clone(); serial.Proxy = Settings.Proxy.Clone(); serial.IGB = Settings.IGB.Clone(); serial.G15 = Settings.G15.Clone(); serial.UI = Settings.UI.Clone(); return serial; }
/// <summary> /// Compare the settings version with this version and, when different, update and prompt the user for a backup. /// </summary> /// <param name="settings"></param> private static void CheckSettingsVersion(SerializableSettings settings) { if (EveMonClient.IsDebugBuild) return; if (Revision == settings.Revision) return; DialogResult backupSettings = MessageBox.Show($"The current EVEMon settings file is from a previous version.{Environment.NewLine}" + @"Backup the current file before proceeding (recommended)?", @"EVEMon version changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (backupSettings != DialogResult.Yes) return; using (SaveFileDialog fileDialog = new SaveFileDialog()) { fileDialog.Title = @"Settings file backup"; fileDialog.Filter = @"Settings Backup Files (*.bak)|*.bak"; fileDialog.FileName = $"EVEMon_Settings_{settings.Revision}.xml.bak"; fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); if (fileDialog.ShowDialog() != DialogResult.OK) return; FileHelper.CopyOrWarnTheUser(EveMonClient.SettingsFileNameFullPath, fileDialog.FileName); } }
/// <summary> /// Asynchronously restores the settings from the specified file. /// </summary> /// <param name="filename">The fully qualified filename of the settings file to load</param> /// <returns>The Settings object loaded</returns> public static async Task RestoreAsync(string filename) { // Try deserialize s_settings = TryDeserializeFromBackupFile(filename, false); // Loading from file failed, we abort and keep our current settings if (s_settings == null) return; IsRestoring = true; Import(); await ImportDataAsync(); IsRestoring = false; }
/// <summary> /// Initialization for the EVEMon client settings. /// </summary> /// <remarks> /// Will attempt to fetch and initialize settings from a storage server, if user has specified so. /// Otherwise attempts to initialize from a locally stored file. /// </remarks> public static void Initialize() { // Deserialize the local settings file to determine // which cloud storage service provider should be used s_settings = TryDeserializeFromFile(); // Try to download the seetings file from the cloud CloudStorageServiceAPIFile settingsFile = s_settings?.CloudStorageServiceProvider?.Provider?.DownloadSettingsFile(); // If a settings file was downloaded try to deserialize it s_settings = settingsFile != null ? TryDeserializeFromFileContent(settingsFile.FileContent) : s_settings; // Loading settings // If there are none, we create them from scratch IsRestoring = true; Import(); IsRestoring = false; }
/// <summary> /// Imports the data. /// </summary> private static void ImportData() { EveMonClient.Trace("begin"); if (s_settings == null) s_settings = new SerializableSettings(); EveMonClient.ResetCollections(); EveMonClient.Characters.Import(s_settings.Characters); EveMonClient.APIKeys.Import(s_settings.APIKeys); EveMonClient.Characters.ImportPlans(s_settings.Plans); EveMonClient.MonitoredCharacters.Import(s_settings.MonitoredCharacters); OnImportCompleted(); EveMonClient.Trace("done"); // Notify the subscribers EveMonClient.OnSettingsChanged(); }
/// <summary> /// Imports the provided serialization object. /// </summary> private static void Import() { EveMonClient.Trace("begin"); // When null, we just reset if (s_settings == null) s_settings = new SerializableSettings(); try { // API providers EveMonClient.APIProviders.Import(s_settings.APIProviders); // User settings UI = s_settings.UI; G15 = s_settings.G15; IGB = s_settings.IGB; Proxy = s_settings.Proxy; Updates = s_settings.Updates; Calendar = s_settings.Calendar; Exportation = s_settings.Exportation; MarketPricer = s_settings.MarketPricer; Notifications = s_settings.Notifications; Compatibility = s_settings.Compatibility; LoadoutsProvider = s_settings.LoadoutsProvider; PortableEveInstallations = s_settings.PortableEveInstallations; CloudStorageServiceProvider = s_settings.CloudStorageServiceProvider; // Scheduler Scheduler.Import(s_settings.Scheduler); } finally { EveMonClient.Trace("done"); // Notify the subscribers EveMonClient.OnSettingsChanged(); } }
/// <summary> /// Asynchronously imports the settings. /// </summary> /// <param name="serial">The serial.</param> /// <param name="saveImmediate">if set to <c>true</c> [save immediate].</param> /// <returns></returns> public static async Task ImportAsync(SerializableSettings serial, bool saveImmediate = false) { s_settings = serial; Import(); IsRestoring = true; if (saveImmediate) await SaveImmediateAsync(); IsRestoring = false; }
/// <summary> /// Creates new empty Settings file, overwriting the existing file. /// </summary> public static async Task ResetAsync() { s_settings = new SerializableSettings(); IsRestoring = true; Import(); await ImportDataAsync(); IsRestoring = false; }
/// <summary> /// Occurs when the user click "Apply". /// We set up the new settings if they have changed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void applyButton_Click(object sender, EventArgs e) { ApplyToSettings(); if (!SettingsChanged) return; // Import the new settings await Settings.ImportAsync(m_settings, true); // Refresh the old settings m_oldSettings = Settings.Export(); }
/// <summary> /// Compare the settings version with this version and, when different, update and prompt the user for a backup. /// </summary> /// <param name="notifyUser"></param> private static void CheckSettingsVersion(SerializableSettings settings) { #if !DEBUG int revision = Assembly.GetExecutingAssembly().GetName().Version.Revision; if (revision != settings.Revision) { DialogResult backupSettings = MessageBox.Show("The current EVEMon settings file is from a previous version of EVEMon. Backup the current file before proceeding (recommended)?", "EVEMon version changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (backupSettings == DialogResult.Yes) { using (SaveFileDialog fileDialog = new SaveFileDialog()) { fileDialog.Title = "Settings file backup"; fileDialog.Filter = "Settings Backup Files (*.bak)|*.bak"; fileDialog.FileName = String.Format(CultureConstants.DefaultCulture, "EVEMon_Settings_{0}.xml.bak", revision.ToString()); fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); DialogResult saveFile = fileDialog.ShowDialog(); if (saveFile != DialogResult.OK) return; FileHelper.OverwriteOrWarnTheUser(EveClient.SettingsFileNameFullPath, fileDialog.FileName); } } } #endif }
/// <summary> /// Updates from the provided serialization object /// </summary> /// <param name="serial">The serializable version of the new settings. May be null (acts as a reset)</param> /// <param name="preferencesOnly">When true, only the user preferences will be reimported, not plans, characters, accounts and such.</param> public static void Import(SerializableSettings serial, bool preferencesOnly) { // When null, we just reset if (serial == null) { Reset(); return; } IsRestoringSettings = true; try { EveClient.Trace("Settings.Import() - begin"); // Import the characters, accounts and plans if (!preferencesOnly) { // The above check prevents the settings form to trigger a // characters updates since the last queried infos would be lost. EveClient.Characters.Import(serial.Characters); EveClient.Characters.ImportPlans(serial.Plans); EveClient.MonitoredCharacters.Import(serial.MonitoredCharacters); EveClient.Accounts.Import(serial.Accounts); } // Global settings Settings.Compatibility = serial.Compatibility; // API providers EveClient.APIProviders.Import(serial.APIProviders); // Scheduler Scheduler.Import(serial.Scheduler); // User settings Settings.UI = serial.UI.Clone(); Settings.G15 = serial.G15.Clone(); Settings.IGB = serial.IGB.Clone(); Settings.Proxy = serial.Proxy.Clone(); Settings.Updates = serial.Updates.Clone(); Settings.Notifications = serial.Notifications.Clone(); Settings.Exportation = serial.Exportation.Clone(); Settings.Calendar = serial.Calendar.Clone(); // Trim the data OnImportCompleted(); // Save SaveImmediate(); // Updates the data right now EveClient.UpdateOnOneSecondTick(); EveClient.OnSettingsChanged(); EveClient.Trace("Settings.Import() - done"); } finally { IsRestoringSettings = false; } }
/// <summary> /// Creates a serializable version of the settings. /// </summary> /// <returns></returns> public static SerializableSettings Export() { SerializableSettings serial = new SerializableSettings { Revision = Revision, Compatibility = Compatibility, APIProviders = EveMonClient.APIProviders.Export(), Scheduler = Scheduler.Export(), Calendar = Calendar, CloudStorageServiceProvider = CloudStorageServiceProvider, PortableEveInstallations = PortableEveInstallations, LoadoutsProvider = LoadoutsProvider, MarketPricer = MarketPricer, Notifications = Notifications, Exportation = Exportation, Updates = Updates, Proxy = Proxy, IGB = IGB, G15 = G15, UI = UI }; serial.Characters.AddRange(EveMonClient.Characters.Export()); serial.APIKeys.AddRange(EveMonClient.APIKeys.Export()); serial.Plans.AddRange(EveMonClient.Characters.ExportPlans()); serial.MonitoredCharacters.AddRange(EveMonClient.MonitoredCharacters.Export()); return serial; }