コード例 #1
0
        public Downloader(UpdateEngine updater)
        {
            InitializeComponent();

            Updater = updater;
            HideAll();

            switch (updater.Type)
            {
            case UpdateEngine.InstanceType.Install:
                Welcome.Visibility = Visibility.Visible;
                State = WelcomeState.State;

                Updater.DownloadDirectory   =
                    DirectoryTextBlock.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                if (Updater.GetUpdateVersions().Count > 0)
                {
                    VersionLabel.Content  = Updater.GetUpdateVersions().OrderBy(v => v.Version).Last().Version.ToString();
                    WelcomeNext.IsEnabled = true;
                }

                break;

            case UpdateEngine.InstanceType.Update:
                Updates.Visibility = Visibility.Visible;
                State = States.Updates.State;

                if (Updater.GetUpdateVersions().Count > 0)
                {
                    foreach (DetailVersion updateVersion in Updater.GetUpdateVersions())
                    {
                        UpdateComboBox.Items.Add(updateVersion.Version.ToString());
                    }

                    UpdateComboBox.SelectionChanged += OnUpdateSelectionChanged;
                    UpdateComboBox.Text              = Updater.GetUpdateVersions().OrderBy(v => v.Version).Last().Version.ToString();
                    UpdateDetails.Text = Updater.GetUpdateVersions().OrderBy(v => v.Version).Last().Details;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            DirectoryTextBlock.Text = Updater.DownloadDirectory;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: wrmcodeblocks/Updater
        private static void Main(string[] args)
        {
            if (args.Length < 3)// Fresh install.
            {
                _updater = new HttpEngine
                {
                    Type = UpdateEngine.InstanceType.Install
                };
                Downloader download = new Downloader(_updater);
                download.ShowDialog();
                return;
            }

            _currentVersion    = new Version(args[0]);
            _downloadDirectory = args[1];
            _url = args[2];

            _updater = new HttpEngine(_downloadDirectory, _url);

            if (args.Length >= 4)
            {
                _upToDate = args[3];
            }

            var versions = new List <DetailVersion>(_updater.GetUpdateVersions().OrderBy(v => v.Version));

            if (versions.Count > 0)
            {
                if (versions.Last().Version > new Version(args[0]))
                {
                    try
                    {
                        _updater.Type = UpdateEngine.InstanceType.Update;
                        _updater.DownloadDirectory = _downloadDirectory;
                        Downloader updater = new Downloader(_updater);
                        updater.ShowDialog();
                    }
                    catch (Exception e) // Other wise if the server is wrong or something we get a terrible error message
                    {
                        if (_upToDate != "false")
                        {
                            MessageBox.Show(e.ToString());
                        }
                    }
                }
                else
                {
                    if (_upToDate != "false")
                    {
                        MessageBox.Show("Up to date!");
                    }
                }
            }
            else
            {
                if (_upToDate != "false")
                {
                    MessageBox.Show("Cannot communicate with server!");
                }
            }
        }