markus / SmartUpdate / MainWindow.xaml.cs @ 1c1abe3b
이력 | 보기 | 이력해설 | 다운로드 (5.11 KB)
1 | c4a4d59c | ljiyeon | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Diagnostics; |
||
5 | using System.IO; |
||
6 | using System.Net; |
||
7 | using System.Threading; |
||
8 | using System.Windows; |
||
9 | using System.Windows.Controls; |
||
10 | using System.Windows.Input; |
||
11 | using System.Xml; |
||
12 | using System.Drawing; |
||
13 | using System.Windows.Media; |
||
14 | using Image = System.Windows.Controls.Image; |
||
15 | using System.Windows.Media.Imaging; |
||
16 | using System.Text; |
||
17 | using System.Runtime.InteropServices; |
||
18 | using System.Security; |
||
19 | |||
20 | namespace SmartUpdate |
||
21 | { |
||
22 | /// <summary> |
||
23 | /// MainWindow.xaml에 대한 상호 작용 논리 |
||
24 | /// </summary> |
||
25 | public partial class MainWindow : Window |
||
26 | { |
||
27 | private int index = 0; //업데이트시 파일 하나씩 넘어가게 하기 위해서 |
||
28 | private bool check = false; //다운완료된것 체크 |
||
29 | private int lastIndex; |
||
30 | private Thread theProgBarThread; |
||
31 | private bool m_bLoop; |
||
32 | private string versionPath = null; //64, 86 버전에 따른 서버 파일 위치 |
||
33 | private string[] strArg; //KCOM 접속 파라미터 값 받기 위해 |
||
34 | private int c_index = 1; //마지막 파일 확인 후 종료하기 위해 |
||
35 | private string msgFileName = SmartUpdate.Properties.Settings.Default.msgFileName; //메시지창에 띄워줄 프로그램명 |
||
36 | private string FileName = SmartUpdate.Properties.Settings.Default.FileName; //실행파일명 |
||
37 | |||
38 | 97cde7e3 | ljiyeon | private string[] url; // msi 파일 url |
39 | string destfilepath = string.Empty; |
||
40 | public static string TempFolder |
||
41 | { |
||
42 | get |
||
43 | { |
||
44 | return Path.Combine(Path.GetTempPath(), "MARKUS"); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | c4a4d59c | ljiyeon | public MainWindow() |
49 | { |
||
50 | InitializeComponent(); |
||
51 | WindowStartupLocation = WindowStartupLocation.CenterOwner; //창 가운데로 |
||
52 | WindowStartupLocation = WindowStartupLocation.CenterScreen; //창 가운데로 |
||
53 | Topmost = true; //창 최상위로 |
||
54 | this.Loaded += new RoutedEventHandler(MainWindow_Loaded); |
||
55 | } |
||
56 | |||
57 | void MainWindow_Loaded(object sender, RoutedEventArgs e) |
||
58 | { |
||
59 | 54687182 | djkim | url = Environment.GetCommandLineArgs(); //file url |
60 | if(!Directory.Exists(TempFolder)) |
||
61 | Directory.CreateDirectory(TempFolder); |
||
62 | 97cde7e3 | ljiyeon | destfilepath = System.IO.Path.Combine(TempFolder, System.IO.Path.GetFileName(url[1])); |
63 | splashText.Text = "Update Download Start..."; |
||
64 | WebClient client = new WebClient(); |
||
65 | client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); |
||
66 | client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted); |
||
67 | client.DownloadFileAsync(new Uri(url[1]), destfilepath); |
||
68 | } |
||
69 | |||
70 | private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) |
||
71 | { |
||
72 | Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
73 | { |
||
74 | double bytesIn = double.Parse(e.BytesReceived.ToString()); |
||
75 | double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); |
||
76 | double percentage = bytesIn / totalBytes * 100; |
||
77 | splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %"; |
||
78 | progressBar.Value = int.Parse(Math.Truncate(percentage).ToString()); |
||
79 | })); |
||
80 | } |
||
81 | |||
82 | |||
83 | private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
||
84 | { |
||
85 | try |
||
86 | { |
||
87 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
88 | { |
||
89 | splashText.Text = "Download Completed"; |
||
90 | })); |
||
91 | |||
92 | if (File.Exists(destfilepath)) |
||
93 | { |
||
94 | ProcessStartInfo update_msi = new ProcessStartInfo(); |
||
95 | update_msi.FileName = destfilepath; |
||
96 | Process.Start(update_msi); |
||
97 | } |
||
98 | this.Close(); |
||
99 | } |
||
100 | catch (Exception) |
||
101 | { |
||
102 | throw; |
||
103 | } |
||
104 | |||
105 | c4a4d59c | ljiyeon | } |
106 | |||
107 | private void WinState(object sender, MouseButtonEventArgs e) |
||
108 | { |
||
109 | switch ((e.Source as Image).Name) |
||
110 | { |
||
111 | case ("Win_min"): |
||
112 | { |
||
113 | WindowState = WindowState.Minimized; |
||
114 | } |
||
115 | break; |
||
116 | case ("Win_max"): |
||
117 | { |
||
118 | if (WindowState == WindowState.Maximized) |
||
119 | { |
||
120 | WindowState = WindowState.Normal; |
||
121 | } |
||
122 | else |
||
123 | { |
||
124 | WindowState = WindowState.Maximized; |
||
125 | } |
||
126 | } |
||
127 | break; |
||
128 | case ("Win_Close"): |
||
129 | { |
||
130 | |||
131 | this.Close(); |
||
132 | } |
||
133 | break; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |