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