PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 23using System;
 24using System.Collections.Generic;
 25using System.Linq;
 26using System.Text;
 27using System.IO;
 28using System.Windows;
 29using System.Windows.Controls;
 30using System.Windows.Data;
 31using System.Windows.Documents;
 32using System.Windows.Input;
 33using System.Windows.Media;
 34using System.Windows.Media.Imaging;
 35using System.Windows.Navigation;
 36using Microsoft.Win32;
 37
 38namespace Stoffi
 39{
 40	/// <summary>
 41	/// Interaction logic for MainWindow.xaml
 42	/// </summary>
 43	public partial class MainWindow : Window
 44    {
 45        #region Members
 46
 47		private SettingsMigrator migrator = new SettingsMigrator();
 48		private string settingsFile = "";
 49
 50        #endregion
 51
 52        #region Constructor
 53
 54        /// <summary>
 55        /// 
 56        /// </summary>
 57		public MainWindow()
 58		{
 59			InitializeComponent();
 60			settingsFile = @"..\..\user.config";
 61			SettingsFileLabel.Content = settingsFile;
 62		}
 63
 64        #endregion
 65
 66        #region Methods
 67
 68        #region Event handlers
 69
 70        /// <summary>
 71        /// Invoked when the user clicks "Load"
 72        /// </summary>
 73        /// <param name="sender">The sender of the event</param>
 74        /// <param name="e">The event data</param>
 75		private void LoadSettings_Click(object sender, RoutedEventArgs e)
 76		{
 77			OpenFileDialog dlg = new OpenFileDialog();
 78			Nullable<bool> result = dlg.ShowDialog();
 79			if (result == true)
 80			{
 81				settingsFile = dlg.FileName;
 82				SettingsFileLabel.Content = dlg.FileName;
 83			}
 84		}
 85
 86        /// <summary>
 87        /// Invoked when the user clicks "Migrate"
 88		/// </summary>
 89		/// <param name="sender">The sender of the event</param>
 90		/// <param name="e">The event data</param>
 91		private void Migrate_Click(object sender, RoutedEventArgs e)
 92		{
 93			if (settingsFile == "")
 94				MessageBox.Show("Select a settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
 95
 96			else if (!File.Exists(settingsFile))
 97				MessageBox.Show("No such settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
 98
 99			else
100			{
101				string newFile = Path.GetDirectoryName(settingsFile) + @"\" + Path.GetFileNameWithoutExtension(settingsFile) + "_2" + Path.GetExtension(settingsFile);
102				migrator.Migrate(settingsFile, newFile);
103				MessageBox.Show("Migrated to " + newFile, "Migration Complete", MessageBoxButton.OK, MessageBoxImage.Information);
104			}
105        }
106
107        #endregion
108
109        #endregion
110    }
111}