MainWindow.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. namespace MediaBrowser.Uninstaller
  16. {
  17. /// <summary>
  18. /// Interaction logic for MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. protected string Product = "Server";
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. var args = Environment.GetCommandLineArgs();
  27. var product = args.Length > 1 ? args[1] : "server";
  28. switch (product)
  29. {
  30. case "server":
  31. Product = "Server";
  32. break;
  33. case "mbt":
  34. Product = "Theater";
  35. break;
  36. default:
  37. Console.WriteLine("Please specify which application to un-install (server or mbt)");
  38. Close();
  39. break;
  40. }
  41. lblHeading.Content = this.Title = "Uninstall Media Browser " + Product;
  42. }
  43. private void btnCancel_Click(object sender, RoutedEventArgs e)
  44. {
  45. Close();
  46. }
  47. private void cbxRemoveAll_Checked(object sender, RoutedEventArgs e)
  48. {
  49. if (cbxRemoveAll.IsChecked == true)
  50. {
  51. cbxRemoveCache.IsChecked = cbxRemoveConfig.IsChecked = cbxRemovePlugins.IsChecked = true;
  52. }
  53. cbxRemoveCache.IsEnabled = cbxRemoveConfig.IsEnabled = cbxRemovePlugins.IsEnabled = !cbxRemoveAll.IsChecked.Value;
  54. }
  55. private void btnUninstall_Click(object sender, RoutedEventArgs e)
  56. {
  57. // First remove our shortcuts
  58. var startMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser");
  59. var linkName = "Media Browser " + Product + ".lnk";
  60. try
  61. {
  62. File.Delete(Path.Combine(startMenu,linkName));
  63. }
  64. catch {} // oh well
  65. linkName = "Uninstall " + linkName;
  66. try
  67. {
  68. File.Delete(Path.Combine(startMenu,linkName));
  69. }
  70. catch {} // oh well
  71. }
  72. }
  73. }