diff --git a/ColorPicker/Classes/Settings.cs b/ColorPicker/Classes/Settings.cs index b237c3f..94046f1 100644 --- a/ColorPicker/Classes/Settings.cs +++ b/ColorPicker/Classes/Settings.cs @@ -24,6 +24,7 @@ MIT License using LeoCorpLibrary; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -146,5 +147,35 @@ public static void Export(string path) MessageBox.Show(ex.Message, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Error); // Show error message } } + + /// + /// Imports settings. + /// + /// The path to the settings file. + public static void Import(string path) + { + try + { + if (File.Exists(path)) // If the file exist + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(Settings)); // XML Serializer + StreamReader streamReader = new StreamReader(path); // Where the file is going to be read + + Global.Settings = (Settings)xmlSerializer.Deserialize(streamReader); // Read + + streamReader.Dispose(); + Save(); // Save + MessageBox.Show(Properties.Resources.SettingsImportedMsg, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Information); // Show error message + + // Restart app + Process.Start(Directory.GetCurrentDirectory() + @"\ColorPicker.exe"); // Start app + Environment.Exit(0); // Quit + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Error); // Show error message + } + } } } diff --git a/ColorPicker/Pages/SettingsPage.xaml.cs b/ColorPicker/Pages/SettingsPage.xaml.cs index 68c6c67..211953e 100644 --- a/ColorPicker/Pages/SettingsPage.xaml.cs +++ b/ColorPicker/Pages/SettingsPage.xaml.cs @@ -308,7 +308,16 @@ private void HEXUseUpperCaseChk_Checked(object sender, RoutedEventArgs e) private void ImportBtn_Click(object sender, RoutedEventArgs e) { + OpenFileDialog openFileDialog = new() + { + Filter = "XML|*.xml", + Title = Properties.Resources.Import + }; // Create file dialog + if (openFileDialog.ShowDialog() ?? true) + { + SettingsManager.Import(openFileDialog.FileName); // Import games + } } private void ExportBtn_Click(object sender, RoutedEventArgs e) diff --git a/ColorPicker/Properties/Resources.fr-FR.resx b/ColorPicker/Properties/Resources.fr-FR.resx index d8cbf6d..e4a2532 100644 --- a/ColorPicker/Properties/Resources.fr-FR.resx +++ b/ColorPicker/Properties/Resources.fr-FR.resx @@ -241,7 +241,7 @@ ColorPicker est à jour. - Pour installer les mises à jour, Gerayis doit redémarrer. Voulez-vous continuer ? + Pour installer les mises à jour, ColorPicker doit redémarrer. Voulez-vous continuer ? Version