프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / SmartUpdate / MainWindow.xaml.cs @ 90de6e1d

이력 | 보기 | 이력해설 | 다운로드 (5.02 KB)

1
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
        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
        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
            url = Environment.GetCommandLineArgs(); //file url                  
60
            destfilepath = System.IO.Path.Combine(TempFolder, System.IO.Path.GetFileName(url[1]));
61
            splashText.Text = "Update Download Start...";
62
            WebClient client = new WebClient();
63
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
64
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
65
            client.DownloadFileAsync(new Uri(url[1]), destfilepath);
66
        }
67

    
68
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
69
        {
70
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
71
            {
72
                double bytesIn = double.Parse(e.BytesReceived.ToString());
73
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
74
                double percentage = bytesIn / totalBytes * 100;
75
                splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
76
                progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
77
            }));
78
        }
79

    
80

    
81
        private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
82
        {
83
            try
84
            {
85
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
86
                {
87
                    splashText.Text = "Download Completed";
88
                }));
89

    
90
                if (File.Exists(destfilepath))
91
                {
92
                    ProcessStartInfo update_msi = new ProcessStartInfo();
93
                    update_msi.FileName = destfilepath;
94
                    Process.Start(update_msi);
95
                }
96
                this.Close();
97
            }
98
            catch (Exception)
99
            {
100
                throw;
101
            }
102

    
103
        }
104

    
105
        private void WinState(object sender, MouseButtonEventArgs e)
106
        {
107
            switch ((e.Source as Image).Name)
108
            {
109
                case ("Win_min"):
110
                    {
111
                        WindowState = WindowState.Minimized;
112
                    }
113
                    break;
114
                case ("Win_max"):
115
                    {
116
                        if (WindowState == WindowState.Maximized)
117
                        {
118
                            WindowState = WindowState.Normal;
119
                        }
120
                        else
121
                        {
122
                            WindowState = WindowState.Maximized;
123
                        }
124
                    }
125
                    break;
126
                case ("Win_Close"):
127
                    {                       
128
                        
129
                        this.Close();
130
                    }
131
                    break;
132
            }
133
        }
134
    }
135
}
클립보드 이미지 추가 (최대 크기: 500 MB)