Skip to content

Commit

Permalink
Added the possibility to import settings (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Jun 15, 2021
1 parent d3d6927 commit 0182133
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
31 changes: 31 additions & 0 deletions ColorPicker/Classes/Settings.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -146,5 +147,35 @@ public static void Export(string path)
MessageBox.Show(ex.Message, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Error); // Show error message
}
}

/// <summary>
/// Imports settings.
/// </summary>
/// <param name="path">The path to the settings file.</param>
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
}
}
}
}
9 changes: 9 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ColorPicker/Properties/Resources.fr-FR.resx
Expand Up @@ -241,7 +241,7 @@
<value>ColorPicker est à jour.</value>
</data>
<data name="InstallConfirmMsg" xml:space="preserve">
<value>Pour installer les mises à jour, Gerayis doit redémarrer. Voulez-vous continuer ?</value>
<value>Pour installer les mises à jour, ColorPicker doit redémarrer. Voulez-vous continuer ?</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version</value>
Expand Down

0 comments on commit 0182133

Please sign in to comment.