markus / MarkusAutoUpdate / src / NetSparkle.UI.WPF / ViewModels / DownloadProgressWindowViewModel.cs @ ddc223b4
이력 | 보기 | 이력해설 | 다운로드 (4.06 KB)
1 | d8f5045e | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Text; |
||
4 | using WPFTemplate.Helpers; |
||
5 | |||
6 | namespace NetSparkleUpdater.UI.WPF.ViewModels |
||
7 | { |
||
8 | public class DownloadProgressWindowViewModel : ChangeNotifier |
||
9 | { |
||
10 | private AppCastItem _itemToDownload; |
||
11 | |||
12 | private bool _isDownloading; |
||
13 | private bool _didDownloadAnything; |
||
14 | |||
15 | private string _errorMessageText; |
||
16 | private bool _isErrorMessageVisible; |
||
17 | |||
18 | private string _downloadingTitle; |
||
19 | private double _downloadProgressValue; |
||
20 | private string _userReadableDownloadProgress; |
||
21 | |||
22 | private string _actionButtonTitle; |
||
23 | private bool _isActionButtonVisible; |
||
24 | |||
25 | public DownloadProgressWindowViewModel() |
||
26 | { |
||
27 | IsDownloading = true; |
||
28 | DidDownloadAnything = false; |
||
29 | ErrorMessageText = ""; |
||
30 | IsErrorMessageVisible = false; |
||
31 | _downloadingTitle = ""; |
||
32 | _downloadProgressValue = 0.0; |
||
33 | IsActionButtonVisible = false; |
||
34 | } |
||
35 | |||
36 | public AppCastItem ItemToDownload |
||
37 | { |
||
38 | get => _itemToDownload; |
||
39 | set |
||
40 | { |
||
41 | _itemToDownload = value; |
||
42 | NotifyPropertyChanged(); |
||
43 | |||
44 | if (value != null) |
||
45 | { |
||
46 | DownloadingTitle = string.Format("Downloading {0}", _itemToDownload.AppName + " " + _itemToDownload.Version); |
||
47 | } |
||
48 | else |
||
49 | { |
||
50 | DownloadingTitle = "Downloading..."; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | public bool IsDownloading |
||
56 | { |
||
57 | get => _isDownloading; |
||
58 | set { _isDownloading = value; NotifyPropertyChanged(); } |
||
59 | } |
||
60 | |||
61 | public bool DidDownloadAnything |
||
62 | { |
||
63 | get => _didDownloadAnything; |
||
64 | set { _didDownloadAnything = value; NotifyPropertyChanged(); } |
||
65 | } |
||
66 | |||
67 | public string ErrorMessageText |
||
68 | { |
||
69 | get => _errorMessageText; |
||
70 | set { _errorMessageText = value; NotifyPropertyChanged(); } |
||
71 | } |
||
72 | |||
73 | public bool IsErrorMessageVisible |
||
74 | { |
||
75 | get => _isErrorMessageVisible; |
||
76 | set { _isErrorMessageVisible = value; NotifyPropertyChanged(); } |
||
77 | } |
||
78 | |||
79 | public string DownloadingTitle |
||
80 | { |
||
81 | get => _downloadingTitle; |
||
82 | set { _downloadingTitle = value; NotifyPropertyChanged(); } |
||
83 | } |
||
84 | |||
85 | public double DownloadProgress |
||
86 | { |
||
87 | get => _downloadProgressValue; |
||
88 | set { _downloadProgressValue = value; NotifyPropertyChanged(); } |
||
89 | } |
||
90 | |||
91 | public string UserReadableDownloadProgress |
||
92 | { |
||
93 | get => _userReadableDownloadProgress; |
||
94 | set { _userReadableDownloadProgress = value; NotifyPropertyChanged(); } |
||
95 | } |
||
96 | |||
97 | public string ActionButtonTitle |
||
98 | { |
||
99 | get => _actionButtonTitle; |
||
100 | set { _actionButtonTitle = value; NotifyPropertyChanged(); } |
||
101 | } |
||
102 | |||
103 | public bool IsActionButtonVisible |
||
104 | { |
||
105 | get => _isActionButtonVisible; |
||
106 | set { _isActionButtonVisible = value; NotifyPropertyChanged(); } |
||
107 | } |
||
108 | |||
109 | public void SetFinishedDownloading(bool isInstallFileValid) |
||
110 | { |
||
111 | IsDownloading = false; |
||
112 | |||
113 | DownloadProgress = 100; |
||
114 | if (!_didDownloadAnything) |
||
115 | { |
||
116 | UserReadableDownloadProgress = string.Format(""); |
||
117 | } |
||
118 | if (isInstallFileValid) |
||
119 | { |
||
120 | IsActionButtonVisible = true; |
||
121 | ActionButtonTitle = "Install and Relaunch"; |
||
122 | } |
||
123 | else |
||
124 | { |
||
125 | IsActionButtonVisible = false; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public void UpdateProgress(long bytesReceived, long totalBytesToReceive, int percentage) |
||
130 | { |
||
131 | DidDownloadAnything = true; |
||
132 | DownloadProgress = percentage; |
||
133 | UserReadableDownloadProgress = string.Format("({0} / {1})", |
||
134 | Utilities.ConvertNumBytesToUserReadableString(bytesReceived), |
||
135 | Utilities.ConvertNumBytesToUserReadableString(totalBytesToReceive)); |
||
136 | } |
||
137 | |||
138 | } |
||
139 | } |