aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Installer/MainWindow.xaml.cs
blob: 5990becce93f853ec10e470f37aa80e7648b8338 (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
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using System.Web;
using System.Linq;
using MediaBrowser.Installer.Code;
using ServiceStack.Text;
using ServiceStack.Text.Json;

namespace MediaBrowser.Installer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        protected PackageVersionClass PackageClass;
        protected Version PackageVersion;
        protected string PackageName = "MBServer";

        public MainWindow()
        {
            GetArgs();
            InitializeComponent();
            StartInstall();
        }

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

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("Cancel Installation - Are you sure?", "Cancel", MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                e.Cancel = true;
            }
            base.OnClosing(e);
        }

        protected void GetArgs()
        {
            var args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;

            if (args == null || args.ActivationData == null || args.ActivationData.Length <= 0) return;
            var url = new Uri(args.ActivationData[0], UriKind.Absolute);

            var parameters = HttpUtility.ParseQueryString(url.Query);

            // fill in our arguments if there
            PackageName = parameters["package"] ?? "MBServer";
            PackageClass = (PackageVersionClass)Enum.Parse(typeof(PackageVersionClass), parameters["class"] ?? "Release");
            PackageVersion = new Version(parameters["version"].ValueOrDefault("0.0.0.1"));

        }

        protected async Task StartInstall()
        {
            lblStatus.Content = "Downloading Server Package...";
            dlAnimation.StartAnimation();
            prgProgress.Value = 0;
            prgProgress.Visibility = Visibility.Visible;

            var archive = await DownloadPackage();

        }

        protected async Task<string> DownloadPackage()
        {
            using (var client = new WebClient())
            {
                try
                {
                    // get the package information for the server
                    var json = await client.DownloadStringTaskAsync("http://www.mb3admin.com/admin/service/package/retrieveAll?name="+PackageName);
                    var packages = JsonSerializer.DeserializeFromString<List<PackageInfo>>(json);

                    var version = packages[0].versions.Where(v => v.classification == PackageClass).OrderByDescending(v => v.version).FirstOrDefault();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        return "";

        }
    }
}