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)
\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
88 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
89 this->ebSource = XRCCTRL(* this, "ebSource", wxTextCtrl);
\r
90 this->gFile = XRCCTRL(* this, "gFile", wxGauge);
\r
91 this->gArchive = XRCCTRL(* this, "gArchive", wxGauge);
\r
92 this->fCancel = false;
\r
93 this->nOverwriteMode = wxID_OK;
\r
94 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
97 TPI_PROCESSINFO piInfo;
\r
98 piInfo.eMessage = TPI_MESSAGE_STATUS;
\r
99 piInfo.eStatus = 0x1000;
\r
100 piInfo.fiInfo.fnFileName = ((MainFrame *) this->hParent)->fnArchive;
\r
101 piInfo.fiInfo.nUnpackedSize = this->nFileCount;
\r
102 this->CallbackProc(TPI_NOTIFY_COMMON, & piInfo);
\r
105 MainFrame * frm_main = (MainFrame *) this->hParent;
\r
106 frm_main->tree_ctrl->Freeze();
\r
107 frm_main->list_ctrl->Freeze();
\r
108 frm_main->menubar->EnableTop(0, false);
\r
109 frm_main->menubar->EnableTop(1, false);
\r
110 frm_main->menubar->EnableTop(2, false);
\r
111 frm_main->toolbar->Enable(false);
\r
114 this->hTBWnd = this->hParent->GetHandle();
\r
116 ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **) & this->tlTaskbar);
\r
117 if (this->tlTaskbar != NULL)
\r
119 this->tlTaskbar->HrInit();
\r
124 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
126 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
128 this->fCancel = true;
\r
133 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
135 if (_uMsg != TPI_NOTIFY_COMMON)
\r
137 return TPI_CALLBACK_UNSUPPORTED;
\r
140 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
141 if (piInfo == NULL)
\r
143 return TPI_CALLBACK_CONTINUE;
\r
146 switch (piInfo->eMessage)
\r
148 case TPI_MESSAGE_STATUS:
\r
150 static int s_nProcess;
\r
152 static int s_nFileCount;
\r
154 static wxStopWatch sw;
\r
155 switch (piInfo->eStatus)
\r
157 case TPI_STATUS_OPENARCHIVE:
\r
158 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
161 case TPI_STATUS_BEGINPROCESS:
\r
162 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
164 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
166 case TPI_STATUS_INPROCESS:
\r
167 if (sw.Time() > 500)
\r
169 if (this->IsShownOnScreen())
\r
172 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
173 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());
\r
174 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
176 this->gFile->SetValue(piInfo->nProcessedSize);
\r
178 this->gArchive->SetValue(s_nProcess);
\r
180 ::wxSafeYield(this, true);
\r
184 ::wxSafeYield(this->hParent, true);
\r
186 ((MainFrame *) this->hParent)->gFrame->SetValue(s_nProcess);
\r
189 if (this->tlTaskbar != NULL)
\r
191 this->tlTaskbar->SetProgressValue(this->hTBWnd, s_nProcess, s_nFileCount);
\r
195 case TPI_STATUS_ENDPROCESS:
\r
199 case 0x1000: // 初期設定。
\r
200 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
202 ((MainFrame *) this->hParent)->gFrame->Show();
\r
203 case 0x1001: // 閲覧時は最初にファイル数が分からないので、ここで設定。
\r
204 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
205 ((MainFrame *) this->hParent)->gFrame->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
208 s_nFileCount = piInfo->fiInfo.nUnpackedSize;
\r
211 if (piInfo->eStatus == 0x1001)
\r
213 this->fOpen = true;
\r
216 case 0x1002: // 各ファイルの処理を開始。
\r
217 if (sw.Time() > 500)
\r
219 if (this->IsShownOnScreen())
\r
222 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
223 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
225 ::wxSafeYield(this, true);
\r
227 ::wxSafeYield(this->hParent, true);
\r
229 ((MainFrame *) this->hParent)->gFrame->SetValue(piInfo->nProcessedSize);
\r
231 if (this->tlTaskbar != NULL)
\r
233 this->tlTaskbar->SetProgressValue(this->hTBWnd, piInfo->nProcessedSize, s_nFileCount);
\r
240 case TPI_MESSAGE_ASK:
\r
243 if (this->tlTaskbar != NULL)
\r
245 this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_PAUSED);
\r
248 switch (piInfo->eStatus)
\r
250 case TPI_PARAM_PASSWORD:
\r
252 if (piInfo->fiInfo.fnFileName == fnFormer || this->szPassword.IsEmpty())
\r
254 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);
\r
255 if (piInfo->szParam.IsEmpty())
\r
257 this->fCancel = true;
\r
259 this->szPassword = piInfo->szParam;
\r
263 piInfo->szParam = this->szPassword;
\r
264 fnFormer = piInfo->fiInfo.fnFileName;
\r
268 case TPI_PARAM_NEXTVOLUME:
\r
270 wxFileDialog fd(this, _("Choose next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName(), piInfo->fiInfo.fnFileName.GetPath(), wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
\r
271 if (fd.ShowModal() == wxID_CANCEL)
\r
273 this->fCancel = true;
\r
275 piInfo->szParam = fd.GetPath();
\r
278 case TPI_PARAM_DEST:
\r
279 if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
282 bool bPerm = false;
\r
283 if (this->nOverwriteMode == wxID_OK)
\r
285 OverwriteDialog odDlg;
\r
286 odDlg.fnExist = & piInfo->fnDestination;
\r
287 odDlg.tmWrite = & piInfo->fiInfo.tmModify;
\r
288 odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;
\r
290 this->nOverwriteMode = odDlg.ShowModal();
\r
291 bPerm = odDlg.cbApplyAll->IsChecked();
\r
297 switch (this->nOverwriteMode)
\r
300 this->fCancel = true;
\r
303 // 自動上書き。既存のファイルを削除しておく。
\r
304 if (piInfo->fnDestination.FileExists())
\r
306 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());
\r
308 else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
311 ::wxRmdir(piInfo->fnDestination.GetFullPath());
\r
316 piInfo->fnDestination.Clear();
\r
324 this->nOverwriteMode = wxID_OK;
\r
329 return TPI_CALLBACK_UNSUPPORTED;
\r
332 if (this->tlTaskbar != NULL)
\r
334 this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_NORMAL);
\r
340 return TPI_CALLBACK_UNSUPPORTED;
\r
343 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
345 //******************************************************************************
\r
347 //******************************************************************************
\r
349 OverwriteDialog::OverwriteDialog(): wxDialog()
\r
351 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
352 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));
\r
355 //******************************************************************************
\r
357 //******************************************************************************
\r
359 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)
\r
360 EVT_INIT_DIALOG(OverwriteDialog::OnInit)
\r
361 EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)
\r
362 EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)
\r
363 EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)
\r
364 EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)
\r
365 EVT_CLOSE(OverwriteDialog::OnClose)
\r
368 //******************************************************************************
\r
370 //******************************************************************************
\r
372 void OverwriteDialog::OnInit(wxInitDialogEvent &)
\r
375 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
376 this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);
\r
377 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
380 this->ebTarget->SetValue(this->fnExist->GetFullPath());
\r
381 XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
382 XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());
\r
383 XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
384 XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));
\r
385 XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));
\r
388 void OverwriteDialog::OnClose(wxCloseEvent & e)
\r
390 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
392 this->EndModal(wxID_CANCEL);
\r
397 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)
\r
399 if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())
\r
401 // 保存先を変えているので、次回もダイアログを表示。
\r
402 this->cbApplyAll->SetValue(false);
\r
403 * this->fnExist = wxFileName(this->ebTarget->GetValue());
\r
408 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)
\r
413 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)
\r
418 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)
\r
420 wxFileName fn(this->ebTarget->GetValue());
\r
421 wxFileDialog fd(this, _("Choose a file"), fn.GetPath(), fn.GetFullName(), wxFileSelectorDefaultWildcardStr, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
\r
422 if (fd.ShowModal() == wxID_OK)
\r
424 this->ebTarget->SetValue(fd.GetPath());
\r
428 //******************************************************************************
\r
430 //******************************************************************************
\r
432 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
434 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r