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
68 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
71 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
73 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
75 this->fCancel = true;
\r
80 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
82 if (_uMsg != TPI_NOTIFY_COMMON)
\r
84 return TPI_CALLBACK_UNSUPPORTED;
\r
87 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
88 if (piInfo == NULL || ! this->IsShown())
\r
90 return TPI_CALLBACK_CONTINUE;
\r
93 switch (piInfo->eMessage)
\r
95 case TPI_MESSAGE_STATUS:
\r
97 static int s_nGaugeCounter = 0, s_nInterval = 0;
\r
98 switch (piInfo->eStatus)
\r
100 case TPI_STATUS_OPENARCHIVE:
\r
101 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
103 case TPI_STATUS_BEGINPROCESS:
\r
105 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
107 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
108 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());
\r
109 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
110 this->gFile->SetValue(0);
\r
111 ::wxSafeYield(this, true);
\r
114 case TPI_STATUS_INPROCESS:
\r
115 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
117 this->gFile->SetValue(piInfo->nProcessedSize);
\r
118 ::wxSafeYield(this, true);
\r
121 case TPI_STATUS_ENDPROCESS:
\r
122 if (s_nGaugeCounter++ > s_nInterval)
\r
124 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);
\r
125 ::wxSafeYield(this, true);
\r
126 s_nGaugeCounter = 0;
\r
131 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
132 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
133 this->gArchive->SetValue(0);
\r
134 s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;
\r
137 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
139 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
141 if (s_nGaugeCounter++ > s_nInterval)
\r
143 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
144 ::wxSafeYield(this, true);
\r
145 s_nGaugeCounter = 0;
\r
151 case TPI_MESSAGE_ASK:
\r
153 switch (piInfo->eStatus)
\r
155 case TPI_PARAM_PASSWORD:
\r
157 static wxFileName fnFormer;
\r
158 static wxString szFormer;
\r
159 if (piInfo->fiInfo.fnFileName == fnFormer)
\r
161 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);
\r
162 if (piInfo->szParam.IsEmpty())
\r
164 this->fCancel = true;
\r
166 szFormer = piInfo->szParam;
\r
170 piInfo->szParam = szFormer;
\r
171 fnFormer = piInfo->fiInfo.fnFileName;
\r
175 case TPI_PARAM_NEXTVOLUME:
\r
177 wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());
\r
178 fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);
\r
179 if (fd.ShowModal() == wxID_CANCEL)
\r
181 this->fCancel = true;
\r
183 piInfo->szParam = fd.GetPath();
\r
186 case TPI_PARAM_DEST:
\r
187 if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
190 static int nMode = wxID_OK;
\r
191 bool bPerm = false;
\r
192 if (nMode == 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 nMode = odDlg.ShowModal();
\r
200 bPerm = odDlg.cbApplyAll->IsChecked();
\r
205 this->fCancel = true;
\r
208 // 自動上書き。既存のファイルを削除しておく。
\r
209 if (piInfo->fnDestination.FileExists())
\r
211 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());
\r
213 else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))
\r
216 ::wxRmdir(piInfo->fnDestination.GetFullPath());
\r
221 piInfo->fnDestination.Clear();
\r
234 return TPI_CALLBACK_UNSUPPORTED;
\r
239 return TPI_CALLBACK_UNSUPPORTED;
\r
242 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
244 //******************************************************************************
\r
246 //******************************************************************************
\r
248 OverwriteDialog::OverwriteDialog(): wxDialog()
\r
250 ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
251 ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));
\r
254 //******************************************************************************
\r
256 //******************************************************************************
\r
258 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)
\r
259 EVT_INIT_DIALOG(OverwriteDialog::OnInit)
\r
260 EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)
\r
261 EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)
\r
262 EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)
\r
263 EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)
\r
264 EVT_CLOSE(OverwriteDialog::OnClose)
\r
267 //******************************************************************************
\r
269 //******************************************************************************
\r
271 void OverwriteDialog::OnInit(wxInitDialogEvent &)
\r
274 this->ebTarget = XRCCTRL(* this, "ebTarget", wxTextCtrl);
\r
275 this->cbApplyAll = XRCCTRL(* this, "cbApplyAll", wxCheckBox);
\r
276 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));
\r
279 this->ebTarget->SetValue(this->fnExist->GetFullPath());
\r
280 XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
281 XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());
\r
282 XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));
\r
283 XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));
\r
284 XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));
\r
287 void OverwriteDialog::OnClose(wxCloseEvent & e)
\r
289 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
291 this->EndModal(wxID_CANCEL);
\r
296 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)
\r
298 if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())
\r
300 // 保存先を変えているので、次回もダイアログを表示。
\r
301 this->cbApplyAll->SetValue(false);
\r
302 * this->fnExist = wxFileName(this->ebTarget->GetValue());
\r
307 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)
\r
312 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)
\r
317 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)
\r
319 wxFileDialog fd(this);
\r
320 fd.SetWindowStyleFlag(wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
\r
321 fd.SetPath(this->ebTarget->GetValue());
\r
322 if (fd.ShowModal() == wxID_OK)
\r
324 this->ebTarget->SetValue(fd.GetPath());
\r
328 //******************************************************************************
\r
330 //******************************************************************************
\r
332 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
334 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r