/Settings Migrator Tester/MainWindow.xaml.cs

http://yet-another-music-application.googlecode.com/ · C# · 111 lines · 59 code · 15 blank · 37 comment · 6 complexity · 2aceb9d4583883e5cc5fb2d3a9b14122 MD5 · raw file

  1. /**
  2. * MainWindow.xaml.cs
  3. *
  4. * The main window of the migration tester.
  5. * It is used to test the Settings Migrator by providing
  6. * an interface for loading and migrating settings files.
  7. *
  8. * * * * * * * * *
  9. *
  10. * Copyright 2012 Simplare
  11. *
  12. * This code is part of the Stoffi Music Player Project.
  13. * Visit our website at: stoffiplayer.com
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 3 of the License, or (at your option) any later version.
  19. *
  20. * See stoffiplayer.com/license for more information.
  21. **/
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using System.Text;
  26. using System.IO;
  27. using System.Windows;
  28. using System.Windows.Controls;
  29. using System.Windows.Data;
  30. using System.Windows.Documents;
  31. using System.Windows.Input;
  32. using System.Windows.Media;
  33. using System.Windows.Media.Imaging;
  34. using System.Windows.Navigation;
  35. using Microsoft.Win32;
  36. namespace Stoffi
  37. {
  38. /// <summary>
  39. /// Interaction logic for MainWindow.xaml
  40. /// </summary>
  41. public partial class MainWindow : Window
  42. {
  43. #region Members
  44. private SettingsMigrator migrator = new SettingsMigrator();
  45. private string settingsFile = "";
  46. #endregion
  47. #region Constructor
  48. /// <summary>
  49. ///
  50. /// </summary>
  51. public MainWindow()
  52. {
  53. InitializeComponent();
  54. settingsFile = @"..\..\user.config";
  55. SettingsFileLabel.Content = settingsFile;
  56. }
  57. #endregion
  58. #region Methods
  59. #region Event handlers
  60. /// <summary>
  61. /// Invoked when the user clicks "Load"
  62. /// </summary>
  63. /// <param name="sender">The sender of the event</param>
  64. /// <param name="e">The event data</param>
  65. private void LoadSettings_Click(object sender, RoutedEventArgs e)
  66. {
  67. OpenFileDialog dlg = new OpenFileDialog();
  68. Nullable<bool> result = dlg.ShowDialog();
  69. if (result == true)
  70. {
  71. settingsFile = dlg.FileName;
  72. SettingsFileLabel.Content = dlg.FileName;
  73. }
  74. }
  75. /// <summary>
  76. /// Invoked when the user clicks "Migrate"
  77. /// </summary>
  78. /// <param name="sender">The sender of the event</param>
  79. /// <param name="e">The event data</param>
  80. private void Migrate_Click(object sender, RoutedEventArgs e)
  81. {
  82. if (settingsFile == "")
  83. MessageBox.Show("Select a settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
  84. else if (!File.Exists(settingsFile))
  85. MessageBox.Show("No such settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
  86. else
  87. {
  88. string newFile = Path.GetDirectoryName(settingsFile) + @"\" + Path.GetFileNameWithoutExtension(settingsFile) + "_2" + Path.GetExtension(settingsFile);
  89. migrator.Migrate(settingsFile, newFile);
  90. MessageBox.Show("Migrated to " + newFile, "Migration Complete", MessageBoxButton.OK, MessageBoxImage.Information);
  91. }
  92. }
  93. #endregion
  94. #endregion
  95. }
  96. }