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 Creator {
|
|
|
12 |
|
|
|
13 |
/// <summary>
|
|
|
14 |
/// Summary for SaveDialog
|
|
|
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 SaveDialog : public System::Windows::Forms::Form
|
|
|
23 |
{
|
|
|
24 |
public:
|
|
|
25 |
SaveDialog(CBaseFile *package, String ^saveFile)
|
|
|
26 |
{
|
|
|
27 |
InitializeComponent();
|
|
|
28 |
|
|
|
29 |
m_iStatus = 0;
|
|
|
30 |
m_pMultiPackage = NULL;
|
|
|
31 |
m_pPackage = package;
|
|
|
32 |
m_sSaveFile = saveFile;
|
|
|
33 |
m_pInfo = new CProgressInfoDone;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
SaveDialog(CMultiSpkFile *package, String ^saveFile)
|
|
|
37 |
{
|
|
|
38 |
InitializeComponent();
|
|
|
39 |
|
|
|
40 |
m_iStatus = 0;
|
|
|
41 |
m_pMultiPackage = package;
|
|
|
42 |
m_pPackage = NULL;
|
|
|
43 |
m_sSaveFile = saveFile;
|
|
|
44 |
m_pInfo = new CProgressInfoDone;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
protected:
|
|
|
48 |
/// <summary>
|
|
|
49 |
/// Clean up any resources being used.
|
|
|
50 |
/// </summary>
|
|
|
51 |
~SaveDialog()
|
|
|
52 |
{
|
|
|
53 |
if (components)
|
|
|
54 |
{
|
|
|
55 |
delete components;
|
|
|
56 |
}
|
|
|
57 |
delete m_pInfo;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
int m_iStatus;
|
|
|
61 |
CBaseFile *m_pPackage;
|
|
|
62 |
CMultiSpkFile *m_pMultiPackage;
|
|
|
63 |
CProgressInfoDone *m_pInfo;
|
|
|
64 |
String ^m_sSaveFile;
|
|
|
65 |
private: System::Windows::Forms::Timer^ timer1;
|
|
|
66 |
protected:
|
|
|
67 |
private: System::Windows::Forms::Label^ label1;
|
|
|
68 |
private: System::Windows::Forms::Panel^ panel1;
|
|
|
69 |
private: System::Windows::Forms::Label^ label2;
|
|
|
70 |
private: System::Windows::Forms::Panel^ PanelCompress;
|
|
|
71 |
private: System::Windows::Forms::Label^ LabelCompress;
|
|
|
72 |
private: System::Windows::Forms::Label^ LabelStatus;
|
|
|
73 |
private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
|
|
|
74 |
private: System::Windows::Forms::ProgressBar^ progressBar1;
|
|
|
75 |
private: System::Windows::Forms::Panel^ panel2;
|
|
|
76 |
private: System::ComponentModel::IContainer^ components;
|
|
|
77 |
|
|
|
78 |
private:
|
|
|
79 |
/// <summary>
|
|
|
80 |
/// Required designer variable.
|
|
|
81 |
/// </summary>
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
#pragma region Windows Form Designer generated code
|
|
|
85 |
/// <summary>
|
|
|
86 |
/// Required method for Designer support - do not modify
|
|
|
87 |
/// the contents of this method with the code editor.
|
|
|
88 |
/// </summary>
|
|
|
89 |
void InitializeComponent(void)
|
|
|
90 |
{
|
|
|
91 |
this->components = (gcnew System::ComponentModel::Container());
|
|
|
92 |
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
|
|
|
93 |
this->label1 = (gcnew System::Windows::Forms::Label());
|
|
|
94 |
this->panel1 = (gcnew System::Windows::Forms::Panel());
|
|
|
95 |
this->label2 = (gcnew System::Windows::Forms::Label());
|
|
|
96 |
this->PanelCompress = (gcnew System::Windows::Forms::Panel());
|
|
|
97 |
this->LabelCompress = (gcnew System::Windows::Forms::Label());
|
|
|
98 |
this->LabelStatus = (gcnew System::Windows::Forms::Label());
|
|
|
99 |
this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
|
|
|
100 |
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
|
|
|
101 |
this->panel2 = (gcnew System::Windows::Forms::Panel());
|
|
|
102 |
this->panel1->SuspendLayout();
|
|
|
103 |
this->PanelCompress->SuspendLayout();
|
|
|
104 |
this->panel2->SuspendLayout();
|
|
|
105 |
this->SuspendLayout();
|
|
|
106 |
//
|
|
|
107 |
// timer1
|
|
|
108 |
//
|
|
|
109 |
this->timer1->Enabled = true;
|
|
|
110 |
this->timer1->Interval = 1000;
|
|
|
111 |
this->timer1->Tick += gcnew System::EventHandler(this, &SaveDialog::timer1_Tick);
|
|
|
112 |
//
|
|
|
113 |
// label1
|
|
|
114 |
//
|
|
|
115 |
this->label1->Dock = System::Windows::Forms::DockStyle::Left;
|
|
|
116 |
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
|
|
|
117 |
static_cast<System::Byte>(0)));
|
|
|
118 |
this->label1->Location = System::Drawing::Point(0, 0);
|
|
|
119 |
this->label1->Name = L"label1";
|
|
|
120 |
this->label1->Size = System::Drawing::Size(163, 28);
|
|
|
121 |
this->label1->TabIndex = 0;
|
|
|
122 |
this->label1->Text = L"Saving:";
|
|
|
123 |
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
|
|
|
124 |
this->label1->UseWaitCursor = true;
|
|
|
125 |
//
|
|
|
126 |
// panel1
|
|
|
127 |
//
|
|
|
128 |
this->panel1->Controls->Add(this->label2);
|
|
|
129 |
this->panel1->Controls->Add(this->label1);
|
|
|
130 |
this->panel1->Dock = System::Windows::Forms::DockStyle::Top;
|
|
|
131 |
this->panel1->Location = System::Drawing::Point(0, 0);
|
|
|
132 |
this->panel1->Name = L"panel1";
|
|
|
133 |
this->panel1->Size = System::Drawing::Size(579, 28);
|
|
|
134 |
this->panel1->TabIndex = 1;
|
|
|
135 |
this->panel1->UseWaitCursor = true;
|
|
|
136 |
//
|
|
|
137 |
// label2
|
|
|
138 |
//
|
|
|
139 |
this->label2->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
140 |
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,
|
|
|
141 |
static_cast<System::Byte>(0)));
|
|
|
142 |
this->label2->Location = System::Drawing::Point(163, 0);
|
|
|
143 |
this->label2->Name = L"label2";
|
|
|
144 |
this->label2->Size = System::Drawing::Size(416, 28);
|
|
|
145 |
this->label2->TabIndex = 1;
|
|
|
146 |
this->label2->Text = L"filename";
|
|
|
147 |
this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
|
|
|
148 |
this->label2->UseWaitCursor = true;
|
|
|
149 |
//
|
|
|
150 |
// PanelCompress
|
|
|
151 |
//
|
|
|
152 |
this->PanelCompress->Controls->Add(this->LabelCompress);
|
|
|
153 |
this->PanelCompress->Controls->Add(this->LabelStatus);
|
|
|
154 |
this->PanelCompress->Dock = System::Windows::Forms::DockStyle::Top;
|
|
|
155 |
this->PanelCompress->Location = System::Drawing::Point(0, 28);
|
|
|
156 |
this->PanelCompress->Name = L"PanelCompress";
|
|
|
157 |
this->PanelCompress->Size = System::Drawing::Size(579, 28);
|
|
|
158 |
this->PanelCompress->TabIndex = 2;
|
|
|
159 |
this->PanelCompress->UseWaitCursor = true;
|
|
|
160 |
//
|
|
|
161 |
// LabelCompress
|
|
|
162 |
//
|
|
|
163 |
this->LabelCompress->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
164 |
this->LabelCompress->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,
|
|
|
165 |
static_cast<System::Byte>(0)));
|
|
|
166 |
this->LabelCompress->Location = System::Drawing::Point(163, 0);
|
|
|
167 |
this->LabelCompress->Name = L"LabelCompress";
|
|
|
168 |
this->LabelCompress->Size = System::Drawing::Size(416, 28);
|
|
|
169 |
this->LabelCompress->TabIndex = 1;
|
|
|
170 |
this->LabelCompress->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
|
|
|
171 |
this->LabelCompress->UseWaitCursor = true;
|
|
|
172 |
//
|
|
|
173 |
// LabelStatus
|
|
|
174 |
//
|
|
|
175 |
this->LabelStatus->Dock = System::Windows::Forms::DockStyle::Left;
|
|
|
176 |
this->LabelStatus->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
|
|
|
177 |
static_cast<System::Byte>(0)));
|
|
|
178 |
this->LabelStatus->Location = System::Drawing::Point(0, 0);
|
|
|
179 |
this->LabelStatus->Name = L"LabelStatus";
|
|
|
180 |
this->LabelStatus->Size = System::Drawing::Size(163, 28);
|
|
|
181 |
this->LabelStatus->TabIndex = 0;
|
|
|
182 |
this->LabelStatus->Text = L"Compressing";
|
|
|
183 |
this->LabelStatus->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
|
|
|
184 |
this->LabelStatus->UseWaitCursor = true;
|
|
|
185 |
//
|
|
|
186 |
// backgroundWorker1
|
|
|
187 |
//
|
|
|
188 |
this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &SaveDialog::backgroundWorker1_DoWork);
|
|
|
189 |
this->backgroundWorker1->RunWorkerCompleted += gcnew System::ComponentModel::RunWorkerCompletedEventHandler(this, &SaveDialog::backgroundWorker1_RunWorkerCompleted);
|
|
|
190 |
//
|
|
|
191 |
// progressBar1
|
|
|
192 |
//
|
|
|
193 |
this->progressBar1->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
194 |
this->progressBar1->Location = System::Drawing::Point(10, 10);
|
|
|
195 |
this->progressBar1->Maximum = 1000;
|
|
|
196 |
this->progressBar1->Name = L"progressBar1";
|
|
|
197 |
this->progressBar1->Size = System::Drawing::Size(559, 25);
|
|
|
198 |
this->progressBar1->TabIndex = 5;
|
|
|
199 |
this->progressBar1->UseWaitCursor = true;
|
|
|
200 |
//
|
|
|
201 |
// panel2
|
|
|
202 |
//
|
|
|
203 |
this->panel2->Controls->Add(this->progressBar1);
|
|
|
204 |
this->panel2->Dock = System::Windows::Forms::DockStyle::Top;
|
|
|
205 |
this->panel2->Location = System::Drawing::Point(0, 56);
|
|
|
206 |
this->panel2->Name = L"panel2";
|
|
|
207 |
this->panel2->Padding = System::Windows::Forms::Padding(10);
|
|
|
208 |
this->panel2->Size = System::Drawing::Size(579, 45);
|
|
|
209 |
this->panel2->TabIndex = 6;
|
|
|
210 |
this->panel2->UseWaitCursor = true;
|
|
|
211 |
//
|
|
|
212 |
// SaveDialog
|
|
|
213 |
//
|
|
|
214 |
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
|
|
|
215 |
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
|
|
|
216 |
this->ClientSize = System::Drawing::Size(579, 101);
|
|
|
217 |
this->ControlBox = false;
|
|
|
218 |
this->Controls->Add(this->panel2);
|
|
|
219 |
this->Controls->Add(this->PanelCompress);
|
|
|
220 |
this->Controls->Add(this->panel1);
|
|
|
221 |
this->Name = L"SaveDialog";
|
|
|
222 |
this->ShowInTaskbar = false;
|
|
|
223 |
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
|
|
|
224 |
this->Text = L"Saving Package";
|
|
|
225 |
this->UseWaitCursor = true;
|
|
|
226 |
this->Load += gcnew System::EventHandler(this, &SaveDialog::SaveDialog_Load);
|
|
|
227 |
this->panel1->ResumeLayout(false);
|
|
|
228 |
this->PanelCompress->ResumeLayout(false);
|
|
|
229 |
this->panel2->ResumeLayout(false);
|
|
|
230 |
this->ResumeLayout(false);
|
|
|
231 |
|
|
|
232 |
}
|
|
|
233 |
#pragma endregion
|
|
|
234 |
private: System::Void SaveDialog_Load(System::Object^ sender, System::EventArgs^ e) {
|
|
|
235 |
this->label2->Text = m_sSaveFile;
|
|
|
236 |
m_pInfo->SetDone(0);
|
|
|
237 |
this->backgroundWorker1->RunWorkerAsync();
|
|
|
238 |
}
|
|
|
239 |
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
|
|
|
240 |
if ( m_iStatus == 0 )
|
|
|
241 |
{
|
|
|
242 |
if ( (m_pPackage && m_pInfo->GetFile()) || (m_pMultiPackage && m_pInfo->GetPackage()) )
|
|
|
243 |
{
|
|
|
244 |
if ( m_pPackage )
|
|
|
245 |
LabelCompress->Text = SystemStringFromCyString(m_pInfo->GetFile()->GetNameDirectory(m_pPackage) + " (" + SPK::GetSizeString(m_pInfo->GetDone()) + "/" + SPK::GetSizeString(m_pInfo->GetMax()) + ")");
|
|
|
246 |
else if ( m_pMultiPackage )
|
|
|
247 |
LabelCompress->Text = SystemStringFromCyString(m_pInfo->GetPackage()->sName + " (" + SPK::GetSizeString(m_pInfo->GetDone()) + "/" + SPK::GetSizeString(m_pInfo->GetMax()) + ")");
|
|
|
248 |
this->progressBar1->Maximum = m_pInfo->GetMax();
|
|
|
249 |
if ( (int)m_pInfo->GetDone() >= this->progressBar1->Minimum )
|
|
|
250 |
{
|
|
|
251 |
if ( (int)m_pInfo->GetDone() > this->progressBar1->Maximum )
|
|
|
252 |
this->progressBar1->Value = this->progressBar1->Maximum;
|
|
|
253 |
else
|
|
|
254 |
this->progressBar1->Value = m_pInfo->GetDone();
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
else
|
|
|
258 |
LabelCompress->Text = "";
|
|
|
259 |
}
|
|
|
260 |
else if ( m_iStatus == 3 )
|
|
|
261 |
{
|
|
|
262 |
this->progressBar1->Style = Windows::Forms::ProgressBarStyle::Marquee;
|
|
|
263 |
LabelStatus->Text = "Writing..";
|
|
|
264 |
LabelCompress->Text = "";
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
|
|
|
268 |
m_iStatus = 0;
|
|
|
269 |
if ( m_pPackage )
|
|
|
270 |
{
|
|
|
271 |
m_pPackage->UpdateSigned(true);
|
|
|
272 |
m_pPackage->CompressAllFiles(SPKCOMPRESS_LZMA, m_pInfo);
|
|
|
273 |
m_iStatus = 3;
|
|
|
274 |
|
|
|
275 |
if ( !m_pPackage->WriteFile(CyStringFromSystemString(m_sSaveFile), m_pInfo) )
|
|
|
276 |
m_iStatus = 1;
|
|
|
277 |
else
|
|
|
278 |
m_iStatus = 2;
|
|
|
279 |
}
|
|
|
280 |
else if ( m_pMultiPackage )
|
|
|
281 |
{
|
|
|
282 |
m_pMultiPackage->ReadAllFilesToMemory(m_pInfo);
|
|
|
283 |
m_iStatus = 3;
|
|
|
284 |
|
|
|
285 |
if ( !m_pMultiPackage->WriteFile(CyStringFromSystemString(m_sSaveFile), m_pInfo) )
|
|
|
286 |
m_iStatus = 1;
|
|
|
287 |
else
|
|
|
288 |
m_iStatus = 2;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {
|
|
|
292 |
this->timer1->Stop();
|
|
|
293 |
if ( m_iStatus == 1 )
|
|
|
294 |
{
|
|
|
295 |
MessageBox::Show(this, "Unable to save package\n" + m_sSaveFile, "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
|
|
|
296 |
this->DialogResult = Windows::Forms::DialogResult::Cancel;
|
|
|
297 |
}
|
|
|
298 |
else
|
|
|
299 |
this->DialogResult = Windows::Forms::DialogResult::OK;
|
|
|
300 |
this->Close();
|
|
|
301 |
}
|
|
|
302 |
};
|
|
|
303 |
}
|