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
70 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
73 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
75 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
77 this->fCancel = true;
\r
82 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
84 if (_uMsg != TPI_NOTIFY_COMMON)
\r
86 return TPI_CALLBACK_UNSUPPORTED;
\r
89 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
90 if (piInfo == NULL || ! this->IsShown())
\r
92 return TPI_CALLBACK_CONTINUE;
\r
95 switch (piInfo->eMessage)
\r
97 case TPI_MESSAGE_STATUS:
\r
99 static int s_nGaugeCounter = 0, s_nInterval = 0;
\r
100 switch (piInfo->eStatus)
\r
102 case TPI_STATUS_OPENARCHIVE:
\r
103 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
105 case TPI_STATUS_BEGINPROCESS:
\r
107 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
109 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
110 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());
\r
111 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
112 this->gFile->SetValue(0);
\r
113 ::wxSafeYield(this, true);
\r
116 case TPI_STATUS_INPROCESS:
\r
117 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
119 this->gFile->SetValue(piInfo->nProcessedSize);
\r
120 ::wxSafeYield(this, true);
\r
123 case TPI_STATUS_ENDPROCESS:
\r
124 if (s_nGaugeCounter++ > s_nInterval)
\r
126 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);
\r
127 ::wxSafeYield(this, true);
\r
128 s_nGaugeCounter = 0;
\r
133 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
134 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
135 this->gArchive->SetValue(0);
\r
137 s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;
\r
140 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
142 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
144 if (s_nGaugeCounter++ > s_nInterval)
\r
146 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
147 ::wxSafeYield(this, true);
\r
148 s_nGaugeCounter = 0;
\r
154 case TPI_MESSAGE_ASK:
\r
156 switch (piInfo->eStatus)
\r
158 case TPI_PARAM_PASSWORD:
\r
160 static wxFileName fnFormer;
\r
161 static wxString szFormer;
\r
162 if (piInfo->fiInfo.fnFileName == fnFormer)
\r
164 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);
\r
165 if (piInfo->szParam.IsEmpty())
\r
167 this->fCancel = true;
\r
169 szFormer = piInfo->szParam;
\r
173 piInfo->szParam = szFormer;
\r
174 fnFormer = piInfo->fiInfo.fnFileName;
\r
178 case TPI_PARAM_NEXTVOLUME:
\r
180 wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());
\r
181 fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);
\r
182 if (fd.ShowModal() == wxID_CANCEL)
\r
184 this->fCancel = true;
\r
186 piInfo->szParam = fd.GetPath();
\r
189 case TPI_PARAM_DEST:
\r
190 if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
193 bool bPerm = false;
\r
194 if (this->nOverwriteMode == wxID_OK)
\r
196 OverwriteDialog odDlg;
\r
197 odDlg.fnExist = & piInfo->fnDestination;
\r
198 odDlg.tmWrite = & piInfo->fiInfo.tmModified;
\r
199 odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;
\r
201 this->nOverwriteMode = odDlg.ShowModal();
\r
202 bPerm = odDlg.cbApplyAll->IsChecked();
\r
208 switch (this->nOverwriteMode)
\r
211 this->fCancel = true;
\r
214 // 自動上書き。既存のファイルを削除しておく。
\r
215 if (piInfo->fnDestination.FileExists())
\r
217 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());
\r
219 else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
222 ::wxRmdir(piInfo->fnDestination.GetFullPath());
\r
227 piInfo->fnDestination.Clear();
\r
235 this->nOverwriteMode = wxID_OK;
\r
240 return TPI_CALLBACK_UNSUPPORTED;
\r
245 return TPI_CALLBACK_UNSUPPORTED;
\r
248 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
250 //******************************************************************************
\r
252 //******************************************************************************
\r
254 OverwriteDialog::OverwriteDialog(): wxDialog()
\r
256 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
257 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));
\r
260 //******************************************************************************
\r
262 //******************************************************************************
\r
264 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)
\r
265 EVT_INIT_DIALOG(OverwriteDialog::OnInit)
\r
266 EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)
\r
267 EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)
\r
268 EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)
\r
269 EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)
\r
270 EVT_CLOSE(OverwriteDialog::OnClose)
\r
273 //******************************************************************************
\r
275 //******************************************************************************
\r
277 void OverwriteDialog::OnInit(wxInitDialogEvent &)
\r
280 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
281 this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);
\r
282 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
285 this->ebTarget->SetValue(this->fnExist->GetFullPath());
\r
286 XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
287 XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());
\r
288 XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
289 XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));
\r
290 XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));
\r
293 void OverwriteDialog::OnClose(wxCloseEvent & e)
\r
295 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
297 this->EndModal(wxID_CANCEL);
\r
302 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)
\r
304 if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())
\r
306 // 保存先を変えているので、次回もダイアログを表示。
\r
307 this->cbApplyAll->SetValue(false);
\r
308 * this->fnExist = wxFileName(this->ebTarget->GetValue());
\r
313 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)
\r
318 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)
\r
323 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)
\r
325 wxFileDialog fd(this);
\r
326 fd.SetWindowStyleFlag(wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
\r
327 fd.SetPath(this->ebTarget->GetValue());
\r
328 if (fd.ShowModal() == wxID_OK)
\r
330 this->ebTarget->SetValue(fd.GetPath());
\r
334 //******************************************************************************
\r
336 //******************************************************************************
\r
338 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
340 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r