1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\r
5 This library is free software; you can redistribute it and/or modify it under
\r
6 the terms of the GNU Lesser General Public License as published by the Free
\r
7 Software Foundation; either version 2.1 of the License, or (at your option)
\r
10 This library is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
\r
15 You should have received a copy of the GNU Lesser General Public License along
\r
16 with this library; if not, write to the Free Software Foundation, Inc.,
\r
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
\r
20 *******************************************************************************/
\r
23 #include "dlg_process.h"
\r
24 #include "dlg_make.h"
\r
25 #include "frm_main.h"
\r
26 #include "functions.h"
\r
28 ProcessDialog * g_procDlg = NULL;
\r
30 //******************************************************************************
\r
32 //******************************************************************************
\r
34 ProcessDialog::ProcessDialog(wxWindow * parent, wxULongLong_t n, wxString szPassword): wxDialog(), nFileCount(n), szPassword(szPassword), fOpen(false)
\r
36 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
37 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));
\r
39 this->hParent = parent;
\r
43 ProcessDialog::~ProcessDialog()
\r
46 MainFrame * frm_main = (MainFrame *) this->hParent;
\r
47 frm_main->tree_ctrl->Thaw();
\r
48 frm_main->list_ctrl->Thaw();
\r
49 frm_main->menubar->EnableTop(0, true);
\r
50 frm_main->menubar->EnableTop(1, true);
\r
51 frm_main->menubar->EnableTop(2, true);
\r
52 frm_main->toolbar->Enable();
\r
54 // 書庫を開く途中に中断した場合、書庫を閉じる処理を行う。
\r
55 if (this->fOpen && this->fCancel)
\r
58 frm_main->OnArcClose(e);
\r
62 if (this->tlTaskbar != NULL)
\r
64 this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_NOPROGRESS);
\r
65 this->tlTaskbar->Release();
\r
68 ((MainFrame *) this->hParent)->gFrame->Show(false);
\r
72 //******************************************************************************
\r
74 //******************************************************************************
\r
76 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)
\r
77 EVT_INIT_DIALOG(ProcessDialog::OnInit)
\r
78 EVT_CLOSE(ProcessDialog::OnClose)
\r
81 //******************************************************************************
\r
83 //******************************************************************************
\r
85 void ProcessDialog::OnInit(wxInitDialogEvent &)
\r
87 if (this->nOverwriteMode == wxID_OK)
\r
94 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
95 this->ebSource = XRCCTRL(* this, "ebSource", wxTextCtrl);
\r
96 this->gFile = XRCCTRL(* this, "gFile", wxGauge);
\r
97 this->gArchive = XRCCTRL(* this, "gArchive", wxGauge);
\r
98 this->fCancel = false;
\r
99 this->nOverwriteMode = wxID_OK;
\r
100 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
103 TPI_PROCESSINFO piInfo;
\r
104 piInfo.eMessage = TPI_MESSAGE_STATUS;
\r
105 piInfo.eStatus = 0x1000;
\r
106 piInfo.fiInfo.fnFileName = ((MainFrame *) this->hParent)->fnArchive;
\r
107 piInfo.fiInfo.nUnpackedSize = this->nFileCount;
\r
108 this->CallbackProc(TPI_NOTIFY_COMMON, & piInfo);
\r
110 if (((MainFrame *) this->hParent)->conf.ReadId(CONF_PROCESS_DLG, false))
\r
113 // ここでOnInitが呼ばれるので、OnInitの最初で無効化している。
\r
118 MainFrame * frm_main = (MainFrame *) this->hParent;
\r
119 frm_main->tree_ctrl->Freeze();
\r
120 frm_main->list_ctrl->Freeze();
\r
121 frm_main->menubar->EnableTop(0, false);
\r
122 frm_main->menubar->EnableTop(1, false);
\r
123 frm_main->menubar->EnableTop(2, false);
\r
124 frm_main->toolbar->Enable(false);
\r
127 this->hTBWnd = this->hParent->GetHandle();
\r
129 ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **) & this->tlTaskbar);
\r
130 if (this->tlTaskbar != NULL)
\r
132 this->tlTaskbar->HrInit();
\r
137 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
139 if (e.CanVeto() && AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
141 this->fCancel = true;
\r
146 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
148 if (_uMsg != TPI_NOTIFY_COMMON)
\r
150 return TPI_CALLBACK_UNSUPPORTED;
\r
153 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
154 if (piInfo == NULL)
\r
156 return TPI_CALLBACK_CONTINUE;
\r
159 switch (piInfo->eMessage)
\r
161 case TPI_MESSAGE_STATUS:
\r
163 static int s_nProcess;
\r
165 static int s_nFileCount;
\r
167 static wxStopWatch sw;
\r
168 switch (piInfo->eStatus)
\r
170 case TPI_STATUS_OPENARCHIVE:
\r
171 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
174 case TPI_STATUS_BEGINPROCESS:
\r
175 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
177 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
179 case TPI_STATUS_INPROCESS:
\r
180 if (sw.Time() > 500)
\r
182 if (this->IsShownOnScreen())
\r
185 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
186 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());
\r
187 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
189 this->gFile->SetValue(piInfo->nProcessedSize);
\r
191 this->gArchive->SetValue(s_nProcess);
\r
193 ::wxSafeYield(this, true);
\r
197 ::wxSafeYield(this->hParent, true);
\r
199 ((MainFrame *) this->hParent)->gFrame->SetValue(s_nProcess);
\r
202 if (this->tlTaskbar != NULL)
\r
204 this->tlTaskbar->SetProgressValue(this->hTBWnd, s_nProcess, s_nFileCount);
\r
208 case TPI_STATUS_ENDPROCESS:
\r
212 case 0x1000: // 初期設定。
\r
213 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
215 ((MainFrame *) this->hParent)->gFrame->Show();
\r
216 ::wxSafeYield(this->hParent, true);
\r
217 case 0x1001: // 閲覧時は最初にファイル数が分からないので、ここで設定。
\r
218 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
219 ((MainFrame *) this->hParent)->gFrame->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
222 s_nFileCount = piInfo->fiInfo.nUnpackedSize;
\r
225 if (piInfo->eStatus == 0x1001)
\r
227 this->fOpen = true;
\r
230 case 0x1002: // 各ファイルの処理を開始。
\r
231 // if (sw.Time() > 500)
\r
233 if (this->IsShownOnScreen())
\r
236 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
237 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
239 // ::wxSafeYield(this, true);
\r
241 // ::wxSafeYield(this->hParent, true);
\r
243 ((MainFrame *) this->hParent)->gFrame->SetValue(piInfo->nProcessedSize);
\r
245 if (this->tlTaskbar != NULL)
\r
247 this->tlTaskbar->SetProgressValue(this->hTBWnd, piInfo->nProcessedSize, s_nFileCount);
\r
254 case TPI_MESSAGE_ASK:
\r
257 if (this->tlTaskbar != NULL)
\r
259 this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_PAUSED);
\r
262 switch (piInfo->eStatus)
\r
264 case TPI_PARAM_PASSWORD:
\r
266 if (piInfo->fiInfo.fnFileName == fnFormer || this->szPassword.IsEmpty())
\r
268 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);
\r
269 if (piInfo->szParam.IsEmpty())
\r
271 this->fCancel = true;
\r
273 this->szPassword = piInfo->szParam;
\r
277 piInfo->szParam = this->szPassword;
\r
278 fnFormer = piInfo->fiInfo.fnFileName;
\r
282 case TPI_PARAM_NEXTVOLUME:
\r
284 wxFileDialog fd(this, _("Choose next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName(), piInfo->fiInfo.fnFileName.GetPath(), wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
\r
285 if (fd.ShowModal() == wxID_CANCEL)
\r
287 this->fCancel = true;
\r
289 piInfo->szParam = fd.GetPath();
\r
292 case TPI_PARAM_DEST:
\r
293 if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
296 bool bPerm = false;
\r
297 if (this->nOverwriteMode == wxID_OK)
\r
299 OverwriteDialog odDlg;
\r
300 odDlg.fnExist = & piInfo->fnDestination;
\r
301 odDlg.tmWrite = & piInfo->fiInfo.tmModify;
\r
302 odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;
\r
304 this->nOverwriteMode = odDlg.ShowModal();
\r
305 bPerm = odDlg.cbApplyAll->IsChecked();
\r
311 switch (this->nOverwriteMode)
\r
314 this->fCancel = true;
\r
317 // 自動上書き。既存のファイルを削除しておく。
\r
318 if (piInfo->fnDestination.FileExists())
\r
320 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());
\r
322 else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
325 ::wxRmdir(piInfo->fnDestination.GetFullPath());
\r
330 piInfo->fnDestination.Clear();
\r
338 this->nOverwriteMode = wxID_OK;
\r
343 return TPI_CALLBACK_UNSUPPORTED;
\r
346 if (this->tlTaskbar != NULL)
\r
348 this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_NORMAL);
\r
354 return TPI_CALLBACK_UNSUPPORTED;
\r
357 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
359 //******************************************************************************
\r
361 //******************************************************************************
\r
363 OverwriteDialog::OverwriteDialog(): wxDialog()
\r
365 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
366 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));
\r
369 //******************************************************************************
\r
371 //******************************************************************************
\r
373 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)
\r
374 EVT_INIT_DIALOG(OverwriteDialog::OnInit)
\r
375 EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)
\r
376 EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)
\r
377 EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)
\r
378 EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)
\r
379 EVT_CLOSE(OverwriteDialog::OnClose)
\r
382 //******************************************************************************
\r
384 //******************************************************************************
\r
386 void OverwriteDialog::OnInit(wxInitDialogEvent &)
\r
389 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
390 this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);
\r
391 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
394 this->ebTarget->SetValue(this->fnExist->GetFullPath());
\r
395 XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
396 XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());
\r
397 XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
398 XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));
\r
399 XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));
\r
402 void OverwriteDialog::OnClose(wxCloseEvent & e)
\r
404 if (e.CanVeto() && AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
406 this->EndModal(wxID_CANCEL);
\r
411 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)
\r
413 if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())
\r
415 // 保存先を変えているので、次回もダイアログを表示。
\r
416 this->cbApplyAll->SetValue(false);
\r
417 * this->fnExist = wxFileName(this->ebTarget->GetValue());
\r
422 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)
\r
427 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)
\r
432 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)
\r
434 wxFileName fn(this->ebTarget->GetValue());
\r
435 wxFileDialog fd(this, _("Choose a file"), fn.GetPath(), fn.GetFullName(), wxFileSelectorDefaultWildcardStr, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
\r
436 if (fd.ShowModal() == wxID_OK)
\r
438 this->ebTarget->SetValue(fd.GetPath());
\r
442 //******************************************************************************
\r
444 //******************************************************************************
\r
446 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
448 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r