-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinUpdateDialog.xaml.cs
131 lines (124 loc) · 4.38 KB
/
WinUpdateDialog.xaml.cs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http.Handlers;
using System.Windows;
using System.Windows.Input;
using Office.Work.Platform.AppCodes;
using Office.Work.Platform.AppDataService;
namespace Office.Work.Platform
{
/// <summary>
/// WinUpdateDialog.xaml 的交互逻辑
/// </summary>
public partial class WinUpdateDialog : Window
{
private readonly CurWinViewModel _CurWinViewModel;
public WinUpdateDialog(List<string> PDownFiles)
{
InitializeComponent();
this.Owner = AppSet.AppMainWindow;
_CurWinViewModel = new CurWinViewModel(PDownFiles);
this.DataContext = _CurWinViewModel;
}
/// <summary>
/// 下载新程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Window_LoadedAsync(object sender, RoutedEventArgs e)
{
//创建下载文件存放目录
//合成目录
string tempFileDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpdateApp");
DirectoryInfo directoryInfo = new DirectoryInfo(tempFileDir);
if (directoryInfo.Exists)
{
directoryInfo.Delete(true);
}
directoryInfo.Create();
_CurWinViewModel.DownCount = _CurWinViewModel.NeedDownFiles.Count;
for (int i = 0; i < _CurWinViewModel.NeedDownFiles.Count; i++)
{
_CurWinViewModel.DownFileName = $"{_CurWinViewModel.NeedDownFiles[i]}正在下载...。";
ProgressMessageHandler DownProgress = new ProgressMessageHandler();
DownProgress.HttpReceiveProgress += (object sender, HttpProgressEventArgs e) =>
{
_CurWinViewModel.DownIntProgress = e.ProgressPercentage;
};
string downFileName = await DataFileUpdateAppRepository.DownLoadNewVerFile(_CurWinViewModel.NeedDownFiles[i], tempFileDir, DownProgress);
if (!string.IsNullOrWhiteSpace(downFileName))
{
_CurWinViewModel.DownIndex++;
_CurWinViewModel.DownFileName = $"{_CurWinViewModel.NeedDownFiles[i]}下载完成。";
}
else
{
_CurWinViewModel.DownFileName = $"{_CurWinViewModel.NeedDownFiles[i]}下载失败。";
}
}
this.Btn_Update.IsEnabled = true;
}
private void Border_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
{
Dispatcher.BeginInvoke(new Action(() => this.DragMove()));
}
}
/// <summary>
/// 该窗口对象的ViewModel类
/// </summary>
public class CurWinViewModel : NotificationObject
{
private int _DownIndex;
private int _DownCount;
private string _DownFileName;
private int _DownIntProgress;
public CurWinViewModel(List<string> PDownFiles)
{
NeedDownFiles = PDownFiles;
}
public int DownIntProgress
{
get { return _DownIntProgress; }
set
{
_DownIntProgress = value; RaisePropertyChanged();
}
}
public int DownIndex
{
get { return _DownIndex; }
set
{
_DownIndex = value; RaisePropertyChanged();
}
}
public int DownCount
{
get { return _DownCount; }
set
{
_DownCount = value; RaisePropertyChanged();
}
}
public string DownFileName
{
get
{
return _DownFileName;
}
set
{
_DownFileName = value; RaisePropertyChanged();
}
}
public List<string> NeedDownFiles { get; set; }
}
private void Btn_UpdateOk_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}