Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#pragma once
2
 
3
using namespace System;
4
using namespace System::ComponentModel;
5
using namespace System::Collections;
6
using namespace System::Windows::Forms;
7
using namespace System::Data;
8
using namespace System::Drawing;
9
 
10
 
11
namespace PluginManager {
12
 
13
	/// <summary>
14
	/// Summary for DownloadPackageList
15
	///
16
	/// WARNING: If you change the name of this class, you will need to change the
17
	///          'Resource File Name' property for the managed resource compiler tool
18
	///          associated with all .resx files this class depends on.  Otherwise,
19
	///          the designers will not be able to interact properly with localized
20
	///          resources associated with this form.
21
	/// </summary>
22
	public ref class DownloadPackageList : public System::Windows::Forms::Form
23
	{
24
	public:
25
		DownloadPackageList(CPackages *p, CyStringList *servers)
26
		{
27
			InitializeComponent();
28
 
29
			m_pPackages = p;
30
			m_pServers = servers;
31
			m_pCurrentServer = NULL;
32
			m_iServerPos = 0;
33
		}
34
 
35
		void NextServer()
36
		{
37
			if ( !m_pCurrentServer )
38
			{
39
				m_pCurrentServer = m_pServers->Head();
40
				m_iServerPos = 1;
41
			}
42
			else
43
			{
44
				m_pCurrentServer = m_pCurrentServer->next;
45
				++m_iServerPos;
46
			}
47
 
48
			// last server done
49
			if ( !m_pCurrentServer )
50
			{
51
				Finished();
52
				return;
53
			}
54
 
55
			this->label2->Text = Convert::ToString(m_iServerPos) + " / " + Convert::ToString(m_pServers->Count());
56
			this->label3->Text = SystemStringFromCyString(m_pCurrentServer->str);
57
 
58
			this->backgroundWorker1->RunWorkerAsync();
59
		}
60
 
61
		void Finished()
62
		{
63
			Close();
64
		}
65
 
66
		void ExtractWebData(String ^data)
67
		{
68
			cli::array<String ^> ^lines = data->Split('\n');
69
			if ( lines )
70
			{
71
				 for ( int i = 0; i < lines->Length; i++ )
72
					 m_pPackages->ParseAvailablePackage(CyStringFromSystemString(lines[i]).Remove(9).Remove('\r'), m_pCurrentServer->str);
73
			}
74
		}
75
 
76
	protected:
77
		/// <summary>
78
		/// Clean up any resources being used.
79
		/// </summary>
80
		~DownloadPackageList()
81
		{
82
			if (components)
83
			{
84
				delete components;
85
			}
86
		}
87
 
88
	private:
89
		int			  m_iServerPos;
90
		SStringList  *m_pCurrentServer;
91
		CPackages	 *m_pPackages;
92
		CyStringList *m_pServers;
93
	private: System::Windows::Forms::ProgressBar^  progressBar1;
94
	private: System::Windows::Forms::Label^  label1;
95
	private: System::Windows::Forms::Label^  label2;
96
	private: System::Windows::Forms::Panel^  panel1;
97
	private: System::Windows::Forms::Panel^  panel2;
98
	private: System::Windows::Forms::Label^  label3;
99
	private: System::Windows::Forms::Label^  label4;
100
private: System::ComponentModel::BackgroundWorker^  backgroundWorker1;
101
	private: System::Windows::Forms::Panel^  panel3;
102
	private: System::Windows::Forms::Label^  label5;
103
	private: System::Windows::Forms::Label^  label6;
104
 
105
		/// <summary>
106
		/// Required designer variable.
107
		/// </summary>
108
		System::ComponentModel::Container ^components;
109
 
110
#pragma region Windows Form Designer generated code
111
		/// <summary>
112
		/// Required method for Designer support - do not modify
113
		/// the contents of this method with the code editor.
114
		/// </summary>
115
		void InitializeComponent(void)
116
		{
117
			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
118
			this->label1 = (gcnew System::Windows::Forms::Label());
119
			this->label2 = (gcnew System::Windows::Forms::Label());
120
			this->panel1 = (gcnew System::Windows::Forms::Panel());
121
			this->panel2 = (gcnew System::Windows::Forms::Panel());
122
			this->label3 = (gcnew System::Windows::Forms::Label());
123
			this->label4 = (gcnew System::Windows::Forms::Label());
124
			this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
125
			this->panel3 = (gcnew System::Windows::Forms::Panel());
126
			this->label5 = (gcnew System::Windows::Forms::Label());
127
			this->label6 = (gcnew System::Windows::Forms::Label());
128
			this->panel1->SuspendLayout();
129
			this->panel2->SuspendLayout();
130
			this->panel3->SuspendLayout();
131
			this->SuspendLayout();
132
			// 
133
			// progressBar1
134
			// 
135
			this->progressBar1->Dock = System::Windows::Forms::DockStyle::Bottom;
136
			this->progressBar1->Location = System::Drawing::Point(5, 109);
137
			this->progressBar1->Name = L"progressBar1";
138
			this->progressBar1->Size = System::Drawing::Size(475, 23);
139
			this->progressBar1->Style = System::Windows::Forms::ProgressBarStyle::Marquee;
140
			this->progressBar1->TabIndex = 0;
141
			// 
142
			// label1
143
			// 
144
			this->label1->Dock = System::Windows::Forms::DockStyle::Left;
145
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
146
				static_cast<System::Byte>(0)));
147
			this->label1->Location = System::Drawing::Point(5, 5);
148
			this->label1->Name = L"label1";
149
			this->label1->Size = System::Drawing::Size(125, 20);
150
			this->label1->TabIndex = 1;
151
			this->label1->Text = L"Server:";
152
			this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
153
			// 
154
			// label2
155
			// 
156
			this->label2->Dock = System::Windows::Forms::DockStyle::Fill;
157
			this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
158
				static_cast<System::Byte>(0)));
159
			this->label2->Location = System::Drawing::Point(130, 5);
160
			this->label2->Name = L"label2";
161
			this->label2->Size = System::Drawing::Size(340, 20);
162
			this->label2->TabIndex = 2;
163
			this->label2->Text = L"1/1";
164
			this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
165
			// 
166
			// panel1
167
			// 
168
			this->panel1->Controls->Add(this->label2);
169
			this->panel1->Controls->Add(this->label1);
170
			this->panel1->Dock = System::Windows::Forms::DockStyle::Top;
171
			this->panel1->Location = System::Drawing::Point(5, 5);
172
			this->panel1->Name = L"panel1";
173
			this->panel1->Padding = System::Windows::Forms::Padding(5);
174
			this->panel1->Size = System::Drawing::Size(475, 30);
175
			this->panel1->TabIndex = 3;
176
			// 
177
			// panel2
178
			// 
179
			this->panel2->Controls->Add(this->label3);
180
			this->panel2->Controls->Add(this->label4);
181
			this->panel2->Dock = System::Windows::Forms::DockStyle::Top;
182
			this->panel2->Location = System::Drawing::Point(5, 35);
183
			this->panel2->Name = L"panel2";
184
			this->panel2->Padding = System::Windows::Forms::Padding(5);
185
			this->panel2->Size = System::Drawing::Size(475, 30);
186
			this->panel2->TabIndex = 4;
187
			// 
188
			// label3
189
			// 
190
			this->label3->Dock = System::Windows::Forms::DockStyle::Fill;
191
			this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
192
				static_cast<System::Byte>(0)));
193
			this->label3->Location = System::Drawing::Point(130, 5);
194
			this->label3->Name = L"label3";
195
			this->label3->Size = System::Drawing::Size(340, 20);
196
			this->label3->TabIndex = 2;
197
			this->label3->Text = L"http://";
198
			this->label3->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
199
			// 
200
			// label4
201
			// 
202
			this->label4->Dock = System::Windows::Forms::DockStyle::Left;
203
			this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
204
				static_cast<System::Byte>(0)));
205
			this->label4->Location = System::Drawing::Point(5, 5);
206
			this->label4->Name = L"label4";
207
			this->label4->Size = System::Drawing::Size(125, 20);
208
			this->label4->TabIndex = 1;
209
			this->label4->Text = L"Address:";
210
			this->label4->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
211
			// 
212
			// backgroundWorker1
213
			// 
214
			this->backgroundWorker1->WorkerReportsProgress = true;
215
			this->backgroundWorker1->WorkerSupportsCancellation = true;
216
			this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &DownloadPackageList::backgroundWorker1_DoWork);
217
			this->backgroundWorker1->RunWorkerCompleted += gcnew System::ComponentModel::RunWorkerCompletedEventHandler(this, &DownloadPackageList::backgroundWorker1_RunWorkerCompleted);
218
			// 
219
			// panel3
220
			// 
221
			this->panel3->Controls->Add(this->label5);
222
			this->panel3->Controls->Add(this->label6);
223
			this->panel3->Dock = System::Windows::Forms::DockStyle::Top;
224
			this->panel3->Location = System::Drawing::Point(5, 65);
225
			this->panel3->Name = L"panel3";
226
			this->panel3->Padding = System::Windows::Forms::Padding(5);
227
			this->panel3->Size = System::Drawing::Size(475, 30);
228
			this->panel3->TabIndex = 5;
229
			// 
230
			// label5
231
			// 
232
			this->label5->Dock = System::Windows::Forms::DockStyle::Fill;
233
			this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
234
				static_cast<System::Byte>(0)));
235
			this->label5->Location = System::Drawing::Point(130, 5);
236
			this->label5->Name = L"label5";
237
			this->label5->Size = System::Drawing::Size(340, 20);
238
			this->label5->TabIndex = 2;
239
			this->label5->Text = L"0";
240
			this->label5->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
241
			// 
242
			// label6
243
			// 
244
			this->label6->Dock = System::Windows::Forms::DockStyle::Left;
245
			this->label6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
246
				static_cast<System::Byte>(0)));
247
			this->label6->Location = System::Drawing::Point(5, 5);
248
			this->label6->Name = L"label6";
249
			this->label6->Size = System::Drawing::Size(125, 20);
250
			this->label6->TabIndex = 1;
251
			this->label6->Text = L"Packages:";
252
			this->label6->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
253
			// 
254
			// DownloadPackageList
255
			// 
256
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
257
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
258
			this->ClientSize = System::Drawing::Size(485, 137);
259
			this->Controls->Add(this->panel3);
260
			this->Controls->Add(this->panel2);
261
			this->Controls->Add(this->panel1);
262
			this->Controls->Add(this->progressBar1);
263
			this->MaximizeBox = false;
264
			this->MinimizeBox = false;
265
			this->Name = L"DownloadPackageList";
266
			this->Padding = System::Windows::Forms::Padding(5);
267
			this->ShowIcon = false;
268
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
269
			this->Text = L"Download Package List";
270
			this->Load += gcnew System::EventHandler(this, &DownloadPackageList::DownloadPackageList_Load);
271
			this->panel1->ResumeLayout(false);
272
			this->panel2->ResumeLayout(false);
273
			this->panel3->ResumeLayout(false);
274
			this->ResumeLayout(false);
275
 
276
		}
277
#pragma endregion
278
	private: System::Void DownloadPackageList_Load(System::Object^  sender, System::EventArgs^  e) {
279
				 this->NextServer();
280
			 }
281
private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
282
			 String ^url = SystemStringFromCyString(m_pCurrentServer->str) + "\\xpackagedata.dat";
283
			 int error = CheckWebFileExists(url);
284
 
285
			 if ( backgroundWorker1->CancellationPending )
286
				 return;
287
 
288
			 if ( error == CONNECTERROR_NONE )
289
			 {
290
				 String ^data = ReadDataFromWeb(url);
291
				 if ( data )
292
					 this->ExtractWebData(data);
293
			 }
294
		 }
295
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^  sender, System::ComponentModel::RunWorkerCompletedEventArgs^  e) {
296
			 // update the package list
297
			 this->label5->Text = Convert::ToString(m_pPackages->GetAvailablePackageList()->size());
298
 
299
			 // do next server
300
			 this->NextServer();
301
		 }
302
};
303
}