Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#pragma onceusing namespace System;using namespace System::ComponentModel;using namespace System::Collections;using namespace System::Windows::Forms;using namespace System::Data;using namespace System::Drawing;namespace Creator {/// <summary>/// Summary for SaveDialog////// WARNING: If you change the name of this class, you will need to change the/// 'Resource File Name' property for the managed resource compiler tool/// associated with all .resx files this class depends on. Otherwise,/// the designers will not be able to interact properly with localized/// resources associated with this form./// </summary>public ref class SaveDialog : public System::Windows::Forms::Form{public:SaveDialog(CBaseFile *package, String ^saveFile){InitializeComponent();m_iStatus = 0;m_pMultiPackage = NULL;m_pPackage = package;m_sSaveFile = saveFile;m_pInfo = new CProgressInfoDone;}SaveDialog(CMultiSpkFile *package, String ^saveFile){InitializeComponent();m_iStatus = 0;m_pMultiPackage = package;m_pPackage = NULL;m_sSaveFile = saveFile;m_pInfo = new CProgressInfoDone;}protected:/// <summary>/// Clean up any resources being used./// </summary>~SaveDialog(){if (components){delete components;}delete m_pInfo;}int m_iStatus;CBaseFile *m_pPackage;CMultiSpkFile *m_pMultiPackage;CProgressInfoDone *m_pInfo;String ^m_sSaveFile;private: System::Windows::Forms::Timer^ timer1;protected:private: System::Windows::Forms::Label^ label1;private: System::Windows::Forms::Panel^ panel1;private: System::Windows::Forms::Label^ label2;private: System::Windows::Forms::Panel^ PanelCompress;private: System::Windows::Forms::Label^ LabelCompress;private: System::Windows::Forms::Label^ LabelStatus;private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;private: System::Windows::Forms::ProgressBar^ progressBar1;private: System::Windows::Forms::Panel^ panel2;private: System::ComponentModel::IContainer^ components;private:/// <summary>/// Required designer variable./// </summary>#pragma region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary>void InitializeComponent(void){this->components = (gcnew System::ComponentModel::Container());this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));this->label1 = (gcnew System::Windows::Forms::Label());this->panel1 = (gcnew System::Windows::Forms::Panel());this->label2 = (gcnew System::Windows::Forms::Label());this->PanelCompress = (gcnew System::Windows::Forms::Panel());this->LabelCompress = (gcnew System::Windows::Forms::Label());this->LabelStatus = (gcnew System::Windows::Forms::Label());this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());this->panel2 = (gcnew System::Windows::Forms::Panel());this->panel1->SuspendLayout();this->PanelCompress->SuspendLayout();this->panel2->SuspendLayout();this->SuspendLayout();//// timer1//this->timer1->Enabled = true;this->timer1->Interval = 1000;this->timer1->Tick += gcnew System::EventHandler(this, &SaveDialog::timer1_Tick);//// label1//this->label1->Dock = System::Windows::Forms::DockStyle::Left;this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));this->label1->Location = System::Drawing::Point(0, 0);this->label1->Name = L"label1";this->label1->Size = System::Drawing::Size(163, 28);this->label1->TabIndex = 0;this->label1->Text = L"Saving:";this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;this->label1->UseWaitCursor = true;//// panel1//this->panel1->Controls->Add(this->label2);this->panel1->Controls->Add(this->label1);this->panel1->Dock = System::Windows::Forms::DockStyle::Top;this->panel1->Location = System::Drawing::Point(0, 0);this->panel1->Name = L"panel1";this->panel1->Size = System::Drawing::Size(579, 28);this->panel1->TabIndex = 1;this->panel1->UseWaitCursor = true;//// label2//this->label2->Dock = System::Windows::Forms::DockStyle::Fill;this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));this->label2->Location = System::Drawing::Point(163, 0);this->label2->Name = L"label2";this->label2->Size = System::Drawing::Size(416, 28);this->label2->TabIndex = 1;this->label2->Text = L"filename";this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;this->label2->UseWaitCursor = true;//// PanelCompress//this->PanelCompress->Controls->Add(this->LabelCompress);this->PanelCompress->Controls->Add(this->LabelStatus);this->PanelCompress->Dock = System::Windows::Forms::DockStyle::Top;this->PanelCompress->Location = System::Drawing::Point(0, 28);this->PanelCompress->Name = L"PanelCompress";this->PanelCompress->Size = System::Drawing::Size(579, 28);this->PanelCompress->TabIndex = 2;this->PanelCompress->UseWaitCursor = true;//// LabelCompress//this->LabelCompress->Dock = System::Windows::Forms::DockStyle::Fill;this->LabelCompress->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));this->LabelCompress->Location = System::Drawing::Point(163, 0);this->LabelCompress->Name = L"LabelCompress";this->LabelCompress->Size = System::Drawing::Size(416, 28);this->LabelCompress->TabIndex = 1;this->LabelCompress->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;this->LabelCompress->UseWaitCursor = true;//// LabelStatus//this->LabelStatus->Dock = System::Windows::Forms::DockStyle::Left;this->LabelStatus->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,static_cast<System::Byte>(0)));this->LabelStatus->Location = System::Drawing::Point(0, 0);this->LabelStatus->Name = L"LabelStatus";this->LabelStatus->Size = System::Drawing::Size(163, 28);this->LabelStatus->TabIndex = 0;this->LabelStatus->Text = L"Compressing";this->LabelStatus->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;this->LabelStatus->UseWaitCursor = true;//// backgroundWorker1//this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &SaveDialog::backgroundWorker1_DoWork);this->backgroundWorker1->RunWorkerCompleted += gcnew System::ComponentModel::RunWorkerCompletedEventHandler(this, &SaveDialog::backgroundWorker1_RunWorkerCompleted);//// progressBar1//this->progressBar1->Dock = System::Windows::Forms::DockStyle::Fill;this->progressBar1->Location = System::Drawing::Point(10, 10);this->progressBar1->Maximum = 1000;this->progressBar1->Name = L"progressBar1";this->progressBar1->Size = System::Drawing::Size(559, 25);this->progressBar1->TabIndex = 5;this->progressBar1->UseWaitCursor = true;//// panel2//this->panel2->Controls->Add(this->progressBar1);this->panel2->Dock = System::Windows::Forms::DockStyle::Top;this->panel2->Location = System::Drawing::Point(0, 56);this->panel2->Name = L"panel2";this->panel2->Padding = System::Windows::Forms::Padding(10);this->panel2->Size = System::Drawing::Size(579, 45);this->panel2->TabIndex = 6;this->panel2->UseWaitCursor = true;//// SaveDialog//this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;this->ClientSize = System::Drawing::Size(579, 101);this->ControlBox = false;this->Controls->Add(this->panel2);this->Controls->Add(this->PanelCompress);this->Controls->Add(this->panel1);this->Name = L"SaveDialog";this->ShowInTaskbar = false;this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;this->Text = L"Saving Package";this->UseWaitCursor = true;this->Load += gcnew System::EventHandler(this, &SaveDialog::SaveDialog_Load);this->panel1->ResumeLayout(false);this->PanelCompress->ResumeLayout(false);this->panel2->ResumeLayout(false);this->ResumeLayout(false);}#pragma endregionprivate: System::Void SaveDialog_Load(System::Object^ sender, System::EventArgs^ e) {this->label2->Text = m_sSaveFile;m_pInfo->SetDone(0);this->backgroundWorker1->RunWorkerAsync();}private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {if ( m_iStatus == 0 ){if ( (m_pPackage && m_pInfo->GetFile()) || (m_pMultiPackage && m_pInfo->GetPackage()) ){if ( m_pPackage )LabelCompress->Text = SystemStringFromCyString(m_pInfo->GetFile()->GetNameDirectory(m_pPackage) + " (" + SPK::GetSizeString(m_pInfo->GetDone()) + "/" + SPK::GetSizeString(m_pInfo->GetMax()) + ")");else if ( m_pMultiPackage )LabelCompress->Text = SystemStringFromCyString(m_pInfo->GetPackage()->sName + " (" + SPK::GetSizeString(m_pInfo->GetDone()) + "/" + SPK::GetSizeString(m_pInfo->GetMax()) + ")");this->progressBar1->Maximum = m_pInfo->GetMax();if ( (int)m_pInfo->GetDone() >= this->progressBar1->Minimum ){if ( (int)m_pInfo->GetDone() > this->progressBar1->Maximum )this->progressBar1->Value = this->progressBar1->Maximum;elsethis->progressBar1->Value = m_pInfo->GetDone();}}elseLabelCompress->Text = "";}else if ( m_iStatus == 3 ){this->progressBar1->Style = Windows::Forms::ProgressBarStyle::Marquee;LabelStatus->Text = "Writing..";LabelCompress->Text = "";}}private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {m_iStatus = 0;if ( m_pPackage ){m_pPackage->UpdateSigned(true);m_pPackage->CompressAllFiles(SPKCOMPRESS_LZMA, m_pInfo);m_iStatus = 3;if ( !m_pPackage->WriteFile(CyStringFromSystemString(m_sSaveFile), m_pInfo) )m_iStatus = 1;elsem_iStatus = 2;}else if ( m_pMultiPackage ){m_pMultiPackage->ReadAllFilesToMemory(m_pInfo);m_iStatus = 3;if ( !m_pMultiPackage->WriteFile(CyStringFromSystemString(m_sSaveFile), m_pInfo) )m_iStatus = 1;elsem_iStatus = 2;}}private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {this->timer1->Stop();if ( m_iStatus == 1 ){MessageBox::Show(this, "Unable to save package\n" + m_sSaveFile, "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);this->DialogResult = Windows::Forms::DialogResult::Cancel;}elsethis->DialogResult = Windows::Forms::DialogResult::OK;this->Close();}};}