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(): wxDialog()
\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
40 ProcessDialog::~ProcessDialog()
\r
45 //******************************************************************************
\r
47 //******************************************************************************
\r
49 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)
\r
50 EVT_INIT_DIALOG(ProcessDialog::OnInit)
\r
51 EVT_CLOSE(ProcessDialog::OnClose)
\r
54 //******************************************************************************
\r
56 //******************************************************************************
\r
58 void ProcessDialog::OnInit(wxInitDialogEvent &)
\r
61 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
62 this->ebSource = XRCCTRL(* this, "ebSource", wxTextCtrl);
\r
63 this->gFile = XRCCTRL(* this, "gFile", wxGauge);
\r
64 this->gArchive = XRCCTRL(* this, "gArchive", wxGauge);
\r
65 this->fCancel = false;
\r
66 this->nOverwriteMode = wxID_OK;
\r
69 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
72 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
74 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
76 this->fCancel = true;
\r
81 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
83 if (_uMsg != TPI_NOTIFY_COMMON)
\r
85 return TPI_CALLBACK_UNSUPPORTED;
\r
88 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
89 if (piInfo == NULL || ! this->IsShown())
\r
91 return TPI_CALLBACK_CONTINUE;
\r
94 switch (piInfo->eMessage)
\r
96 case TPI_MESSAGE_STATUS:
\r
98 static int s_nGaugeCounter = 0, s_nInterval = 0;
\r
99 switch (piInfo->eStatus)
\r
101 case TPI_STATUS_OPENARCHIVE:
\r
102 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
104 case TPI_STATUS_BEGINPROCESS:
\r
106 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
108 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
109 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());
\r
110 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
111 this->gFile->SetValue(0);
\r
112 ::wxSafeYield(this, true);
\r
115 case TPI_STATUS_INPROCESS:
\r
116 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
118 this->gFile->SetValue(piInfo->nProcessedSize);
\r
119 ::wxSafeYield(this, true);
\r
122 case TPI_STATUS_ENDPROCESS:
\r
123 if (s_nGaugeCounter++ > s_nInterval)
\r
125 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);
\r
126 ::wxSafeYield(this, true);
\r
127 s_nGaugeCounter = 0;
\r
132 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
133 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
134 this->gArchive->SetValue(0);
\r
135 s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;
\r
138 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
140 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
142 if (s_nGaugeCounter++ > s_nInterval)
\r
144 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
145 ::wxSafeYield(this, true);
\r
146 s_nGaugeCounter = 0;
\r
152 case TPI_MESSAGE_ASK:
\r
154 switch (piInfo->eStatus)
\r
156 case TPI_PARAM_PASSWORD:
\r
158 static wxFileName fnFormer;
\r
159 static wxString szFormer;
\r
160 if (piInfo->fiInfo.fnFileName == fnFormer)
\r
162 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);
\r
163 if (piInfo->szParam.IsEmpty())
\r
165 this->fCancel = true;
\r
167 szFormer = piInfo->szParam;
\r
171 piInfo->szParam = szFormer;
\r
172 fnFormer = piInfo->fiInfo.fnFileName;
\r
176 case TPI_PARAM_NEXTVOLUME:
\r
178 wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());
\r
179 fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);
\r
180 if (fd.ShowModal() == wxID_CANCEL)
\r
182 this->fCancel = true;
\r
184 piInfo->szParam = fd.GetPath();
\r
187 case TPI_PARAM_DEST:
\r
188 if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
191 bool bPerm = false;
\r
192 if (this->nOverwriteMode == wxID_OK)
\r
194 OverwriteDialog odDlg;
\r
195 odDlg.fnExist = & piInfo->fnDestination;
\r
196 odDlg.tmWrite = & piInfo->fiInfo.tmModified;
\r
197 odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;
\r
199 this->nOverwriteMode = odDlg.ShowModal();
\r
200 bPerm = odDlg.cbApplyAll->IsChecked();
\r
206 switch (this->nOverwriteMode)
\r
209 this->fCancel = true;
\r
212 // 自動上書き。既存のファイルを削除しておく。
\r
213 if (piInfo->fnDestination.FileExists())
\r
215 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());
\r
217 else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
220 ::wxRmdir(piInfo->fnDestination.GetFullPath());
\r
225 piInfo->fnDestination.Clear();
\r
233 this->nOverwriteMode = wxID_OK;
\r
238 return TPI_CALLBACK_UNSUPPORTED;
\r
243 return TPI_CALLBACK_UNSUPPORTED;
\r
246 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
248 //******************************************************************************
\r
250 //******************************************************************************
\r
252 OverwriteDialog::OverwriteDialog(): wxDialog()
\r
254 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
255 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));
\r
258 //******************************************************************************
\r
260 //******************************************************************************
\r
262 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)
\r
263 EVT_INIT_DIALOG(OverwriteDialog::OnInit)
\r
264 EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)
\r
265 EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)
\r
266 EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)
\r
267 EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)
\r
268 EVT_CLOSE(OverwriteDialog::OnClose)
\r
271 //******************************************************************************
\r
273 //******************************************************************************
\r
275 void OverwriteDialog::OnInit(wxInitDialogEvent &)
\r
278 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
279 this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);
\r
280 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
283 this->ebTarget->SetValue(this->fnExist->GetFullPath());
\r
284 XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
285 XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());
\r
286 XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
287 XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));
\r
288 XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));
\r
291 void OverwriteDialog::OnClose(wxCloseEvent & e)
\r
293 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
295 this->EndModal(wxID_CANCEL);
\r
300 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)
\r
302 if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())
\r
304 // 保存先を変えているので、次回もダイアログを表示。
\r
305 this->cbApplyAll->SetValue(false);
\r
306 * this->fnExist = wxFileName(this->ebTarget->GetValue());
\r
311 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)
\r
316 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)
\r
321 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)
\r
323 wxFileDialog fd(this);
\r
324 fd.SetWindowStyleFlag(wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
\r
325 fd.SetPath(this->ebTarget->GetValue());
\r
326 if (fd.ShowModal() == wxID_OK)
\r
328 this->ebTarget->SetValue(fd.GetPath());
\r
332 //******************************************************************************
\r
334 //******************************************************************************
\r
336 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
338 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r