aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs
blob: bdf34b956b7e1e77f91d9765229ad3ac50bd73c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Threading;
using System.Windows;

namespace MediaBrowser.Uninstaller.Execute
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        protected string Product = "Server";

        public MainWindow()
        {
            Thread.Sleep(800); // be sure our caller is shut down

            var args = Environment.GetCommandLineArgs();
            var product = args.Length > 1 ? args[1] : "server";
            InitializeComponent();


            switch (product)
            {
                case "server":
                    Product = "Server";
                    break;

                case "mbt":
                    Product = "Theater";
                    break;

                default:
                    MessageBox.Show("Please specify which application to un-install (server or mbt)");
                    Close();
                    break;

            }

            lblHeading.Content = this.Title = "Uninstall Media Browser " + Product;

        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void cbxRemoveAll_Checked(object sender, RoutedEventArgs e)
        {
            if (cbxRemoveAll.IsChecked == true)
            {
                cbxRemoveCache.IsChecked = cbxRemoveConfig.IsChecked = cbxRemovePlugins.IsChecked = true;
            }

            cbxRemoveCache.IsEnabled = cbxRemoveConfig.IsEnabled = cbxRemovePlugins.IsEnabled = !cbxRemoveAll.IsChecked.Value;
        }

        private void btnUninstall_Click(object sender, RoutedEventArgs e)
        {
            // First remove our shortcuts
            var startMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser");
            var linkName = "Media Browser " + Product + ".lnk";
            try 
            {
                File.Delete(Path.Combine(startMenu,linkName));
            }
            catch {} // oh well

            linkName = "Uninstall " + linkName;
            try 
            {
                File.Delete(Path.Combine(startMenu,linkName));
            }
            catch {} // oh well

        }
    }
}