WdDownload.xaml.cs 2.76 KB
Newer Older
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
using GalaSoft.MvvmLight.Command;
using Install.Core;
using Install.Core.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Install.View
{
    /// <summary>
    /// PgDownload.xaml 的交互逻辑
    /// </summary>
    public partial class WdDownload : Window
    {
        WdDownloadVm viewModel;

        public WdDownload()
        {
            InitializeComponent();

            viewModel = new WdDownloadVm();
        }

        public void Init() 
        {
            viewModel.Init();
            this.DataContext = viewModel;

            viewModel.DownloadNewestInstallZip();

        }
    }
    public class WdDownloadVm : INotifyPropertyChanged 
    {
        InstallWizard installWizard;
        
        public event PropertyChangedEventHandler PropertyChanged;

        public bool IsReady { get; private set; } = false;
        public string Msg { get; private set; }
        public InstallWizard InstallWizard => installWizard;

        public RelayCommand ExecCmd { get; set; }
        public RelayCommand CancelCmd { get; set; }

        public WdDownloadVm() 
        {
            ExecCmd = new RelayCommand(Exec);
            CancelCmd = new RelayCommand(Cancel);
        }



        public void Init()
        {
潘栩锋's avatar
潘栩锋 committed
67
            installWizard = App.Resolve<InstallWizard>(); 
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 93 94 95 96 97 98 99 100 101 102 103 104 105
            Msg = $"下载 {installWizard.NewestInstallZipVersionInfo.InstallZipUrl}";
            
        }
        public async void DownloadNewestInstallZip()
        {
            var ret = await installWizard.DownloadNewestInstallZip();
            Msg = installWizard.DownloadInfo_ErrMsg;
            if (ret == true)
            {

                //解压
                //获取当前 exe 目录

                Msg = "开始解压......";
                await Task.Factory.StartNew(() =>
                {
                    SeverZipExt.Uncompress(installWizard.NewestInstallZipPath + ".7z", installWizard.NewestInstallZipPath);
                });
                Msg = "解压完成!!!";
                IsReady = true;
            }
        }
        private void Cancel()
        {
            //关闭当前

            Application.Current.Shutdown();
        }

        private void Exec()
        {
            //关闭当前,进入新的安装包,运行
            string exePath = System.IO.Path.Combine(installWizard.NewestInstallZipPath, "install.exe");
            CMD.RunExe(exePath);
            Application.Current.Shutdown();
        }
    }
}