프로젝트

일반

사용자정보

통계
| 개정판:

root / HAgent / Horizon(TCP, HTTP) / Horizon / Updater.xaml.cs

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

1 40 HKM
using Newtonsoft.Json.Linq;
2
using System;
3
using System.Collections.Generic;
4
using System.IO;
5
using System.Linq;
6
using System.Net;
7
using System.Text;
8
using System.Threading;
9
using System.Threading.Tasks;
10
using System.Windows;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Shapes;
18
using System.Windows.Threading;
19
20
namespace Horizon
21
{
22
    public partial class Updater : Window
23
    {
24
        private delegate void CSafeSetText(string text);
25
        private delegate void CSafeSetMaximum(Int32 value);
26
        private delegate void CSafeSetValue(Int32 value);
27
28
        private CSafeSetText csst;
29
        private CSafeSetMaximum cssm;
30
        private CSafeSetValue cssv;
31
        private WebClient wc;
32
        private Boolean setBaseSize;
33
        private Boolean nowDownloading;
34
35
        Thread thread;
36
        Communicator com = new Communicator();
37
38
        int FileNum;
39
        public Updater()
40
        {
41
            // 대리자를 초기화한다.
42
            //csst = new CSafeSetText(CrossSafeSetTextMethod);
43
            //cssm = new CSafeSetMaximum(CrossSafeSetMaximumMethod);
44
            //cssv = new CSafeSetValue(CrossSafeSetValueMethod);
45
46
            // 웹 클라이언트 개체를 초기화하고,
47
48
            //com.TCPConnect();
49
            wc = new WebClient();
50
            //thread = new Thread(new ThreadStart(com.TCPConnect)); // http 로 바꾸기
51
            //thread.Start();
52
            //com.HttpConnect();
53
            //thread = new Thread(new ThreadStart(com.HttpConnect)); // http 로 바꾸기
54
            //thread.Start();
55
56
            InitializeComponent();
57
            Communicator.state = "update";
58
59
            // MessageBox.Show("업데이트 내역");
60
61
        }
62
63
        public void DownLoad()
64
        {
65
66
            try
67
            {
68
                string file = com.filelist;
69
                JObject filelist = JObject.Parse(file);
70
                int value = filelist["files"].Count();
71
                Console.WriteLine(value);
72
                foreach (var fileinfo in filelist["files"])
73
                {
74
                    // 파일이 저장될 위치를 저장한다.
75
                    var downloadFileName = fileinfo.Value<string>("path");
76
                    Console.WriteLine(downloadFileName);
77
78
79
                    string foldername = downloadFileName.Substring(0, downloadFileName.LastIndexOf("/"));
80
                    DirectoryInfo folder = new DirectoryInfo(foldername);
81
                    if (!folder.Exists)
82
                    {
83
                        Directory.CreateDirectory("Program/"+folder.ToString());
84
                    }
85
86
87
                    String fileName = String.Format("Program", System.IO.Path.GetFileName("http://192.168.0.32:3000/Uploads/"));
88
89
                    // 폴더가 존재하지 않는다면 폴더를 생성한다.
90
                    if (!System.IO.Directory.Exists("Program"))
91
                        System.IO.Directory.CreateDirectory("Program");
92
93
                    wc.DownloadFile(new Uri("http://192.168.0.32:3000/Uploads/" + downloadFileName), "Program/"+ downloadFileName ); // 프로젝트네임 추가
94
95
                    Console.WriteLine(FileNum++);
96
                    //Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
97
                    //{
98
                    //    this.entire.Value = 100 * (FileNum / value);
99
                    //}));
100
101
                }
102
                // C 드라이브 밑의 downloadFiles 폴더에 파일 이름대로 저장한다.
103
104
                // 다운로드 중이라는걸 알리기 위한 값을 설정하고,
105
                // 프로그레스바의 크기를 0으로 만든다.
106
                //entire.Value = 0;
107
                setBaseSize = false;
108
                nowDownloading = true;
109
                //btnStart.Enabled = false;
110
                //txtAddress.Enabled = false;
111
112
            }
113
            catch (Exception ex)
114
            {
115
                MessageBox.Show(ex.Message);
116
            }
117
        }
118
119
120
        //void CrossSafeSetValueMethod(Int32 value)
121
        //{
122
        //    if (entire.InvokeRequired)
123
        //        entire.Invoke(cssm, value);
124
        //    else
125
        //        entire.Value = value;
126
        //}
127
        //void CrossSafeSetMaximumMethod(Int32 value)
128
        //{
129
        //    if (prgDownload.InvokeRequired)
130
        //        prgDownload.Invoke(cssm, value);
131
        //    else
132
        //        prgDownload.Maximum = value;
133
        //}
134
        //void CrossSafeSetTextMethod(String text)
135
        //{
136
        //    if (this.InvokeRequired)
137
        //        this.Invoke(csst, text);
138
        //    else
139
        //        this.Text = text;
140
        //}
141
142
        private void ExitButton(object sender, MouseButtonEventArgs e)
143
        {
144
            Close();
145
        }
146
147
        private void Minimization(object sender, MouseButtonEventArgs e)
148
        {
149
            this.WindowState = WindowState.Minimized;
150
        }
151
152
        private void Window_Loaded(object sender, RoutedEventArgs e)
153
        {
154
            //  updater.StartUpdate(callbackFunc);
155
        }
156
        private void callbackFunc(int entireProgress, int partProgress)
157
        {
158
            entire.Value = entireProgress;
159
            part.Value = partProgress;
160
            if (entireProgress == 100 && partProgress == 100) //업데이트가 끝나면
161
            {
162
                Close();
163
            }
164
        }
165
166
        private void Button_Click(object sender, RoutedEventArgs e)
167
        {
168
            Thread Down = new Thread(new ThreadStart(DownLoad));
169
            Down.Start();
170
            //DownLoad();
171
        }
172
173
        // UpdateClient updater;
174
175
        //public Updater()
176
        //{
177
        //    InitializeComponent();
178
        //    MessageBox.Show("업데이트 내역");
179
        //    //updater = new UpdateClient();
180
        //    //updater.GetUpdateList("http://" + url, project);
181
        //}
182
183
        //private void ExitButton(object sender, MouseButtonEventArgs e)
184
        //{
185
        //    Close();
186
        //}
187
188
        //private void Minimization(object sender, MouseButtonEventArgs e)
189
        //{
190
        //    this.WindowState = WindowState.Minimized;
191
        //}
192
193
        //private void Window_Loaded(object sender, RoutedEventArgs e)
194
        //{
195
        //  //  updater.StartUpdate(callbackFunc);
196
        //}
197
        //private void callbackFunc(int entireProgress, int partProgress)
198
        //{
199
        //    entire.Value = entireProgress;
200
        //    part.Value = partProgress;
201
        //    if (entireProgress == 100 && partProgress == 100) //업데이트가 끝나면
202
        //    {
203
        //        Close();
204
        //    }
205
        //}
206
    }
207
}