-/*******************************************************************************
- TPI - flexible but useless plug-in framework.
- Copyright (C) 2002-2009 Silky
-
- This library is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the Free
- Software Foundation; either version 2.1 of the License, or (at your option)
- any later version.
-
- This library is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- for more details.
-
- You should have received a copy of the GNU Lesser General Public License along
- with this library; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
- $Id$
-*******************************************************************************/
-
-#include "lychee.h"
-#include "dlg_process.h"
-
-ProcessDialog * g_procDlg = NULL;
-
-//******************************************************************************
-// ProcessDialog
-//******************************************************************************
-
-ProcessDialog::ProcessDialog(): wxDialog()
-{
- ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));
- ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));
-}
-
-ProcessDialog::~ProcessDialog()
-{
- g_procDlg = NULL;
-}
-
-//******************************************************************************
-// Event table.
-//******************************************************************************
-
-BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)
- EVT_INIT_DIALOG(ProcessDialog::OnInit)
- EVT_CLOSE( ProcessDialog::OnClose)
-END_EVENT_TABLE()
-
-//******************************************************************************
-// Event handler.
-//******************************************************************************
-
-void ProcessDialog::OnInit(wxInitDialogEvent &)
-{
- // XRC\82Æ\8c\8b\82Ñ\82Â\82¯\81B
- this->ebSource = XRCCTRL(* this, "ebSource", wxTextCtrl);
- this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
- this->gauge = XRCCTRL(* this, "gauge", wxGauge);
- this->fCancel = false;
- g_procDlg = this;
-
- ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
-}
-
-void ProcessDialog::OnClose(wxCloseEvent & e)
-{
- if (e.CanVeto() && ::AskDlg(wxT("Really do you want to cancel this operation?"), this) == wxYES)
- {
- this->fCancel = true;
- }
- e.Veto();
-}
-
-//******************************************************************************
-// \83_\83C\83A\83\8d\83O\83v\83\8d\83V\81[\83W\83\83
-//******************************************************************************
-
-int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
-{
- if (_uMsg != TPI_NOTIFY_COMMON)
- {
- return TPI_CALLBACK_UNSUPPORTED;
- }
-
- TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
- if (g_procDlg == NULL || piInfo == NULL || ! g_procDlg->IsShown())
- {
- return TPI_CALLBACK_CONTINUE;
- }
-
- switch (piInfo->uMessage)
- {
- case TPI_MESSAGE_STATUS:
- {
- static int s_nGaugeCounter = 0;
- switch (piInfo->uStatus)
- {
- case TPI_STATUS_OPENARCHIVE:
- g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
- break;
- case TPI_STATUS_BEGINPROCESS:
- g_procDlg->ebTarget->ChangeValue((piInfo->fnDestination.IsOk() ? piInfo->fnDestination : piInfo->fiInfo.fnFileName).GetFullPath());
- if (piInfo->fiInfo.llUnpackedSize > 10000)
- {
- g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());
- g_procDlg->gauge->SetValue(0);
- }
- ::wxSafeYield(g_procDlg, true);
- break;
- case TPI_STATUS_INPROCESS:
- if (s_nGaugeCounter++ > 100)
- {
- if (piInfo->fiInfo.llUnpackedSize > 10000)
- {
- g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());
- }
- ::wxSafeYield(g_procDlg, true);
- s_nGaugeCounter = 0;
- }
- break;
- case TPI_STATUS_ENDPROCESS:
-// g_procDlg->gauge->SetValue(piInfo->fiInfo.llUnpackedSize.ToULong());
- break;
- // \8f\91\8cÉ\83\8d\81[\83h\8e\9e\97p\82Ì\93Æ\8e©\8ed\97l\81B
- case 0x1000:
- g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
- g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());
- g_procDlg->gauge->SetValue(0);
- break;
- case 0x1001:
- // \8dX\90V\82µ\82·\82¬\82é\82Æ\92á\91¬\82È\82Ì\82Å100\83t\83@\83C\83\8b\96\88\82É\8dX\90V\82·\82é\81B
- if (piInfo->llProcessedSize > g_procDlg->gauge->GetValue() + 100)
- {
- g_procDlg->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
- g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());
- ::wxSafeYield(g_procDlg, true);
- }
- break;
- }
- break;
- }
- case TPI_MESSAGE_ASK:
- {
- switch (piInfo->uStatus)
- {
- case TPI_PARAM_PASSWORD:
- piInfo->szParam = ::wxGetPasswordFromUser(wxT("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, g_procDlg);
- if (piInfo->szParam.IsEmpty())
- {
- g_procDlg->fCancel = true;
- }
- break;
- case TPI_PARAM_NEXTVOLUME:
- {
- wxFileDialog fd(g_procDlg, wxT("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());
- fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);
- if (fd.ShowModal() == wxID_CANCEL)
- {
- g_procDlg->fCancel = true;
- }
- piInfo->szParam = fd.GetPath();
- break;
- }
- default:
- return TPI_CALLBACK_UNSUPPORTED;
- }
- break;
- }
- default:
- return TPI_CALLBACK_UNSUPPORTED;
- }
-
- return g_procDlg->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
-}
+/*******************************************************************************\r
+ TPI - flexible but useless plug-in framework.\r
+ Copyright (C) 2002-2009 Silky\r
+\r
+ This library is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU Lesser General Public License as published by the Free\r
+ Software Foundation; either version 2.1 of the License, or (at your option)\r
+ any later version.\r
+\r
+ This library is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License\r
+ for more details.\r
+\r
+ You should have received a copy of the GNU Lesser General Public License along\r
+ with this library; if not, write to the Free Software Foundation, Inc.,\r
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
+\r
+ $Id$\r
+*******************************************************************************/\r
+\r
+#include "lychee.h"\r
+#include "dlg_process.h"\r
+#include "dlg_make.h"\r
+#include "frm_main.h"\r
+#include "functions.h"\r
+\r
+ProcessDialog * g_procDlg = NULL;\r
+\r
+//******************************************************************************\r
+// ProcessDialog\r
+//******************************************************************************\r
+\r
+ProcessDialog::ProcessDialog(): wxDialog()\r
+{\r
+ ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
+ ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process")); \r
+}\r
+\r
+ProcessDialog::~ProcessDialog()\r
+{\r
+ g_procDlg = NULL;\r
+}\r
+\r
+//******************************************************************************\r
+// Event table.\r
+//******************************************************************************\r
+\r
+BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)\r
+ EVT_INIT_DIALOG(ProcessDialog::OnInit)\r
+ EVT_CLOSE(ProcessDialog::OnClose)\r
+END_EVENT_TABLE()\r
+\r
+//******************************************************************************\r
+// Event handler.\r
+//******************************************************************************\r
+\r
+void ProcessDialog::OnInit(wxInitDialogEvent &)\r
+{\r
+ // XRCと結びつけ。\r
+ this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);\r
+ this->ebSource = XRCCTRL(* this, "ebSource", wxTextCtrl);\r
+ this->gFile = XRCCTRL(* this, "gFile", wxGauge);\r
+ this->gArchive = XRCCTRL(* this, "gArchive", wxGauge);\r
+ this->fCancel = false;\r
+ this->nOverwriteMode = wxID_OK;\r
+ this->Update();\r
+ g_procDlg = this;\r
+\r
+ ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
+}\r
+\r
+void ProcessDialog::OnClose(wxCloseEvent & e)\r
+{\r
+ if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
+ {\r
+ this->fCancel = true;\r
+ }\r
+ e.Veto();\r
+}\r
+\r
+int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)\r
+{\r
+ if (_uMsg != TPI_NOTIFY_COMMON)\r
+ {\r
+ return TPI_CALLBACK_UNSUPPORTED;\r
+ }\r
+\r
+ TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
+ if (piInfo == NULL || ! this->IsShown())\r
+ {\r
+ return TPI_CALLBACK_CONTINUE;\r
+ }\r
+\r
+ switch (piInfo->eMessage)\r
+ {\r
+ case TPI_MESSAGE_STATUS:\r
+ {\r
+ static int s_nGaugeCounter = 0, s_nInterval = 0;\r
+ switch (piInfo->eStatus)\r
+ {\r
+ case TPI_STATUS_OPENARCHIVE:\r
+ this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+ break;\r
+ case TPI_STATUS_BEGINPROCESS:\r
+ // 小さなファイルなら表示しない。\r
+ if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+ {\r
+ this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+ this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
+ this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);\r
+ this->gFile->SetValue(0);\r
+ ::wxSafeYield(this, true);\r
+ }\r
+ break;\r
+ case TPI_STATUS_INPROCESS:\r
+ if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+ {\r
+ this->gFile->SetValue(piInfo->nProcessedSize);\r
+ ::wxSafeYield(this, true);\r
+ }\r
+ break;\r
+ case TPI_STATUS_ENDPROCESS:\r
+ if (s_nGaugeCounter++ > s_nInterval)\r
+ {\r
+ this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);\r
+ ::wxSafeYield(this, true);\r
+ s_nGaugeCounter = 0;\r
+ }\r
+ break;\r
+ // 書庫ロード時用の独自仕様。\r
+ case 0x1000:\r
+ this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+ this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
+ this->gArchive->SetValue(0);\r
+ this->Update();\r
+ s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;\r
+ break;\r
+ case 0x1001:\r
+ if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+ {\r
+ this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+ }\r
+ if (s_nGaugeCounter++ > s_nInterval)\r
+ {\r
+ this->gArchive->SetValue(piInfo->nProcessedSize);\r
+ ::wxSafeYield(this, true);\r
+ s_nGaugeCounter = 0;\r
+ }\r
+ break;\r
+ }\r
+ break;\r
+ }\r
+ case TPI_MESSAGE_ASK:\r
+ {\r
+ switch (piInfo->eStatus)\r
+ {\r
+ case TPI_PARAM_PASSWORD:\r
+ {\r
+ static wxFileName fnFormer;\r
+ static wxString szFormer;\r
+ if (piInfo->fiInfo.fnFileName == fnFormer)\r
+ {\r
+ piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
+ if (piInfo->szParam.IsEmpty())\r
+ {\r
+ this->fCancel = true;\r
+ }\r
+ szFormer = piInfo->szParam;\r
+ }\r
+ else\r
+ {\r
+ piInfo->szParam = szFormer;\r
+ fnFormer = piInfo->fiInfo.fnFileName;\r
+ }\r
+ break;\r
+ }\r
+ case TPI_PARAM_NEXTVOLUME:\r
+ {\r
+ wxFileDialog fd(this, _("Choose next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName(), piInfo->fiInfo.fnFileName.GetPath(), wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST);\r
+ if (fd.ShowModal() == wxID_CANCEL)\r
+ {\r
+ this->fCancel = true;\r
+ }\r
+ piInfo->szParam = fd.GetPath();\r
+ break;\r
+ }\r
+ case TPI_PARAM_DEST:\r
+ if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))\r
+ {\r
+ // 上書き確認を行う。\r
+ bool bPerm = false;\r
+ if (this->nOverwriteMode == wxID_OK)\r
+ {\r
+ OverwriteDialog odDlg;\r
+ odDlg.fnExist = & piInfo->fnDestination;\r
+ odDlg.tmWrite = & piInfo->fiInfo.tmModified;\r
+ odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;\r
+\r
+ this->nOverwriteMode = odDlg.ShowModal();\r
+ bPerm = odDlg.cbApplyAll->IsChecked();\r
+ }\r
+ else\r
+ {\r
+ bPerm = true;\r
+ }\r
+ switch (this->nOverwriteMode)\r
+ {\r
+ case wxID_CANCEL:\r
+ this->fCancel = true;\r
+ break;\r
+ case 0:\r
+ // 自動上書き。既存のファイルを削除しておく。\r
+ if (piInfo->fnDestination.FileExists())\r
+ {\r
+ ::wxRemoveFile(piInfo->fnDestination.GetFullPath());\r
+ }\r
+ else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))\r
+ {\r
+ // TODO: 再帰削除。\r
+ ::wxRmdir(piInfo->fnDestination.GetFullPath());\r
+ }\r
+ break;\r
+ case 1:\r
+ // 自動スキップ。\r
+ piInfo->fnDestination.Clear();\r
+ break;\r
+ case 2:\r
+ // 自動リネーム。\r
+ break;\r
+ }\r
+ if (! bPerm)\r
+ {\r
+ this->nOverwriteMode = wxID_OK;\r
+ }\r
+ }\r
+ break;\r
+ default:\r
+ return TPI_CALLBACK_UNSUPPORTED;\r
+ }\r
+ break;\r
+ }\r
+ default:\r
+ return TPI_CALLBACK_UNSUPPORTED;\r
+ }\r
+\r
+ return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
+}\r
+//******************************************************************************\r
+// OverwriteDialog\r
+//******************************************************************************\r
+\r
+OverwriteDialog::OverwriteDialog(): wxDialog()\r
+{\r
+ ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));\r
+ ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite")); \r
+}\r
+\r
+//******************************************************************************\r
+// Event table.\r
+//******************************************************************************\r
+\r
+BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)\r
+ EVT_INIT_DIALOG(OverwriteDialog::OnInit)\r
+ EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)\r
+ EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)\r
+ EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)\r
+ EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)\r
+ EVT_CLOSE(OverwriteDialog::OnClose)\r
+END_EVENT_TABLE()\r
+\r
+//******************************************************************************\r
+// Event handler.\r
+//******************************************************************************\r
+\r
+void OverwriteDialog::OnInit(wxInitDialogEvent &)\r
+{\r
+ // XRCと結びつけ。\r
+ this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);\r
+ this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);\r
+ ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));\r
+\r
+ // ファイル情報を設定。\r
+ this->ebTarget->SetValue(this->fnExist->GetFullPath());\r
+ XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));\r
+ XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());\r
+ XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));\r
+ XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));\r
+ XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));\r
+}\r
+\r
+void OverwriteDialog::OnClose(wxCloseEvent & e)\r
+{\r
+ if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
+ {\r
+ this->EndModal(wxID_CANCEL);\r
+ }\r
+ e.Veto();\r
+}\r
+\r
+void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)\r
+{\r
+ if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())\r
+ {\r
+ // 保存先を変えているので、次回もダイアログを表示。\r
+ this->cbApplyAll->SetValue(false);\r
+ * this->fnExist = wxFileName(this->ebTarget->GetValue());\r
+ }\r
+ this->EndModal(0);\r
+}\r
+\r
+void OverwriteDialog::OnBtnSkip(wxCommandEvent&)\r
+{\r
+ this->EndModal(1);\r
+}\r
+\r
+void OverwriteDialog::OnBtnAuto(wxCommandEvent&)\r
+{\r
+ this->EndModal(2);\r
+}\r
+\r
+void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)\r
+{\r
+ wxFileName fn(this->ebTarget->GetValue());\r
+ wxFileDialog fd(this, _("Choose a file"), fn.GetPath(), fn.GetFullName(), wxFileSelectorDefaultWildcardStr, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);\r
+ if (fd.ShowModal() == wxID_OK)\r
+ {\r
+ this->ebTarget->SetValue(fd.GetPath());\r
+ }\r
+}\r
+\r
+//******************************************************************************\r
+// ダイアログプロシージャ\r
+//******************************************************************************\r
+\r
+int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
+{\r
+ return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);\r
+}\r