1 /*******************************************************************************
2 TPI - flexible but useless plug-in framework.
3 Copyright (C) 2002-2009 Silky
5 This library is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License as published by the Free
7 Software Foundation; either version 2.1 of the License, or (at your option)
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 You should have received a copy of the GNU Lesser General Public License along
16 with this library; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 $Id: frm_main.cpp,v 1.42 2009/09/05 03:24:58 sirakaba Exp $
20 *******************************************************************************/
25 #include "cls_filedroptarget.h"
27 #include "dlg_process.h"
28 #include "functions.h"
30 #include <wx/fileconf.h>
31 #include <wx/arrimpl.cpp>
33 WX_DEFINE_OBJARRAY(ArrayTPI_FILEINFO);
35 #define SetMenuToolState(id, state) this->toolbar->EnableTool(XRCID(id), state); this->menubar->Enable(XRCID(id), state)
37 //******************************************************************************
38 //
\83O
\83\8d\81[
\83o
\83\8b\95Ï
\90\94
39 //******************************************************************************
41 wxImageList g_hIconT(16, 16), g_hIconLL(32, 32), g_hIconLS(16, 16);
44 //******************************************************************************
46 //******************************************************************************
48 MainFrame::MainFrame(): wxFrame()
52 MainFrame::~MainFrame()
57 //
\90Ý
\92è
\82ð
\8bL
\98^
\81B
58 wxFileConfig fc(wxEmptyString, wxEmptyString, ::wxGetCwd() + wxT("/frontend.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
59 if (! this->IsIconized() && ! this->IsMaximized())
62 this->GetSize(& a, & b);
63 fc.Write(wxT("Window-Width"), a);
64 fc.Write(wxT("Window-Height"), b);
65 this->GetPosition(& a, & b);
66 fc.Write(wxT("Window-X"), a);
67 fc.Write(wxT("Window-Y"), b);
69 fc.Write(wxT("Splitter-Pos"), this->window_splitter->GetSashPosition());
70 fc.Write(wxT("ListView-IconMode"), this->menubar->IsChecked(XRCID("Exe_View_Icons")));
71 fc.Write(wxT("ListView-SortingColumn"), g_nSortingColumn);
72 fc.Write(wxT("LastOpenPath"), this->fnLastOpenPath.GetFullPath());
77 //******************************************************************************
79 //******************************************************************************
81 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
82 EVT_INIT_DIALOG( MainFrame::OnInit)
84 EVT_MENU(XRCID("Arc_Create"), MainFrame::OnArcCreate)
85 EVT_MENU(XRCID("Arc_Open"), MainFrame::OnArcOpen)
86 EVT_MENU(XRCID("Arc_Close"), MainFrame::OnArcClose)
87 EVT_MENU(XRCID("Arc_Add"), MainFrame::OnArcAdd)
88 EVT_MENU(XRCID("Arc_SFX"), MainFrame::OnArcSFX)
89 EVT_MENU(XRCID("Arc_UnSFX"), MainFrame::OnArcUnSFX)
90 EVT_MENU(XRCID("Exe_Exit"), MainFrame::OnExit)
91 EVT_MENU(XRCID("Arc_Extract"), MainFrame::OnArcExtract)
92 EVT_MENU(XRCID("Arc_Delete"), MainFrame::OnArcDelete)
93 EVT_MENU(XRCID("Arc_Test"), MainFrame::OnArcTest)
94 EVT_MENU(XRCID("Arc_Repair"), MainFrame::OnArcRepair)
95 EVT_MENU(XRCID("Exe_View_Icons"), MainFrame::OnViewMode)
96 EVT_MENU(XRCID("Exe_View_Details"),MainFrame::OnViewMode)
97 EVT_MENU(XRCID("Exe_View_SelectAll"),MainFrame::OnSelectAll)
99 EVT_TREE_SEL_CHANGED(XRCID("TreeView"), MainFrame::OnTreeChanged)
101 EVT_LIST_ITEM_ACTIVATED(XRCID("ListView"), MainFrame::OnListItemDClick)
102 EVT_LIST_BEGIN_DRAG(XRCID("ListView"), MainFrame::OnListBeginDrag)
105 //******************************************************************************
107 //******************************************************************************
109 void MainFrame::OnInit(wxInitDialogEvent&)
111 // XRC
\82Æ
\8c\8b\82Ñ
\82Â
\82¯
\81B
112 this->menubar = this->GetMenuBar();
113 this->toolbar = this->GetToolBar();
114 this->statusbar = XRCCTRL(* this, "statusbar", wxStatusBar);
115 this->tree_ctrl = XRCCTRL(* this, "TreeView", wxTreeCtrl);
116 this->list_ctrl = XRCCTRL(* this, "ListView", myListCtrl);
117 this->window_splitter = XRCCTRL(* this, "window_splitter", wxSplitterWindow);
119 //
\90Ý
\92è
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\81B
120 wxFileConfig fc(wxEmptyString, wxEmptyString, ::wxGetCwd() + wxT("/frontend.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
121 this->SetSize(fc.Read(wxT("Window-X"), 0l), fc.Read(wxT("Window-Y"), 0l), fc.Read(wxT("Window-Width"), 800), fc.Read(wxT("Window-Height"), 400));
122 this->fnLastOpenPath = wxFileName::DirName(fc.Read(wxT("LastOpenPath"), ::wxGetCwd()));
123 wxTheMimeTypesManager->Initialize(wxMAILCAP_ALL);
125 //
\8f\89\8aú
\92l
\90Ý
\92è
\81B
128 icon.CopyFromBitmap(wxBitmap(FE_DIR_S_ICO wxT("app.png"), wxBITMAP_TYPE_ANY));
133 e.SetId(fc.Read(wxT("ListView-IconMode"), 0l) ? XRCID("Exe_View_Icons") : XRCID("Exe_View_Details"));
136 this->window_splitter->SetSashPosition(fc.Read(wxT("Splitter-Pos"), 200));
137 // wxGTK
\82Å
\82Í
\92¼
\90ÚwxLC_VIRTUAL
\82ð
\8ew
\92è
\82µ
\82È
\82¢
\82Æ
\94½
\89f
\82³
\82ê
\82È
\82¢
\81B
138 this->list_ctrl->SetSingleStyle(wxLC_VIRTUAL);
139 this->list_ctrl->InsertColumn(0, wxT("Filename"), wxLIST_FORMAT_LEFT, 140);
140 this->list_ctrl->InsertColumn(1, wxT("Unpacked"), wxLIST_FORMAT_RIGHT, 80);
141 this->list_ctrl->InsertColumn(2, wxT("Packed"), wxLIST_FORMAT_RIGHT, 80);
142 this->list_ctrl->InsertColumn(3, wxT("Ratio"), wxLIST_FORMAT_RIGHT, 50);
143 this->list_ctrl->InsertColumn(4, wxT("Method"), wxLIST_FORMAT_LEFT, 60);
144 this->list_ctrl->InsertColumn(5, wxT("Attr"), wxLIST_FORMAT_LEFT, 50);
145 this->list_ctrl->InsertColumn(6, wxT("Last modified"), wxLIST_FORMAT_RIGHT, 150);
146 this->list_ctrl->InsertColumn(7, wxT("Path"), wxLIST_FORMAT_LEFT, 100);
147 this->list_ctrl->InsertColumn(8, wxT("Type"), wxLIST_FORMAT_LEFT, 100);
148 this->list_ctrl->InsertColumn(9, wxT("No."), wxLIST_FORMAT_LEFT, 35);
149 g_nSortingColumn = fc.Read(wxT("ListView-SortingColumn"), 9);
151 this->list_ctrl->SetDropTarget(new myFileDropTarget(this));
153 int nStatusBarParts[] = {40, 60, 120, 120, 90, 1000};
154 this->statusbar->SetFieldsCount(6, nStatusBarParts);
156 //
\83R
\83}
\83\93\83h
\83\89\83C
\83\93\93Ç
\82Ý
\8d\9e\82Ý
\81B
157 this->cmdLine.SetSwitchChars(wxT("-"));
158 this->cmdLine.AddSwitch(wxT("x"), wxEmptyString, wxT("(command) Extract filenames in archive."));
159 this->cmdLine.AddSwitch(wxT("l"), wxEmptyString, wxT("(command) List archive(default)."));
160 this->cmdLine.AddParam(wxT("archive"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
161 this->cmdLine.AddParam(wxT("filenames"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
162 if (this->cmdLine.Parse() == 0)
164 if (this->cmdLine.GetParamCount() == 0)
169 if (this->cmdLine.Found(wxT("x")))
171 //
\8f\91\8cÉ
\82ð
\93W
\8aJ
\81B
172 wxFileName fnArchive(this->cmdLine.GetParam(0));
173 fnArchive.Normalize(wxPATH_NORM_ALL, this->szCurrentPath);
174 this->LoadArc(fnArchive.GetFullPath());
175 this->OnArcExtract(e);
180 //
\8f\91\8cÉ
\82ð
\8aJ
\82
\81B
181 wxFileName fnArchive(this->cmdLine.GetParam(0));
182 fnArchive.Normalize(wxPATH_NORM_ALL, this->szCurrentPath);
183 this->LoadArc(fnArchive.GetFullPath());
190 void MainFrame::OnExit(wxCommandEvent&)
195 void MainFrame::OnArcCreate(wxCommandEvent& e)
197 //
\8f\88\97\9d\91Î
\8fÛ
\82Ì
\83t
\83@
\83C
\83\8b\82ð
\91I
\91ð
\81B
198 wxFileDialog fdDlg(this, wxT("Choose files to compress"), this->fnLastOpenPath.GetFullPath(), wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
199 if (fdDlg.ShowModal() == wxID_CANCEL)
203 //
\82±
\82±
\82ÅwxFileName::FileName
\82ð
\97p
\82¢
\82Ä
\82¢
\82é
\82Ì
\82Í
\81A
\8cã
\82Å
\83f
\83B
\83\8c\83N
\83g
\83\8a\96¼
\82ð
\95K
\97v
\82Æ
\82·
\82é
\8fê
\8d\87\82ª
\82 \82é
\82½
\82ß
\81B
204 //
\82 \82Ü
\82è
\82æ
\82¢
\8ed
\97l
\82Å
\82Í
\82È
\82¢
\82ª
\93®
\82
\82Ì
\82Å
\82Æ
\82è
\82 \82¦
\82¸
\95ú
\92u
\81B
205 this->fnLastOpenPath = wxFileName::FileName(fdDlg.GetDirectory());
207 //
\8ae
\8eí
\90Ý
\92è
\81B
209 swInfo.fnDestinationDirectory = wxFileName::DirName(this->fnLastOpenPath.GetFullPath());
210 swInfo.pCustomSwitches = NULL;
211 this->statusbar->SetStatusText(swInfo.fnDestinationDirectory.GetFullPath(), 5);
213 //
\8dì
\90¬
\83_
\83C
\83A
\83\8d\83O
\82ð
\90Ý
\92è
\81B
215 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_make.xrc"));
216 ::wxXmlResource::Get()->LoadDialog(& mkDlg, this, wxT("dlg_make"));
217 fdDlg.GetFilenames(mkDlg.files);
219 mkDlg.cbDir->SetValue(swInfo.fnDestinationDirectory.GetFullPath());
220 //
\8f\91\8cÉ
\96¼
\82Í
\83t
\83@
\83C
\83\8b\96¼
\82Ì
\8ag
\92£
\8eq
\82æ
\82è
\91O
\81A
\82à
\82µ
\82
\82Í
\83f
\83B
\83\8c\83N
\83g
\83\8a\96¼
\81B
221 mkDlg.cbFileName->SetValue(mkDlg.files.GetCount() == 1 ? wxFileName::FileName(mkDlg.files[0]).GetName() : this->fnLastOpenPath.GetFullName());
223 //
\83_
\83C
\83A
\83\8d\83O
\82ð
\95\
\8e¦
\81B
224 if (mkDlg.ShowModal() == wxID_CANCEL)
226 this->statusbar->SetStatusText(wxEmptyString, 5);
229 this->statusbar->SetStatusText(wxEmptyString, 5);
231 //
\8ae
\8eí
\90Ý
\92è
\81B
232 swInfo.fStoreDirectoryPathes= ! mkDlg.cbIgnorePath->IsChecked();
233 swInfo.fMakeSFX = mkDlg.cbMakeSFX->IsChecked();
234 swInfo.fSolid = mkDlg.cbSolid->IsChecked();
235 swInfo.fMMOptimize = mkDlg.cbMMOptimize->IsChecked();
236 swInfo.fEncryptHeader = mkDlg.cbEncryptHeader->IsChecked();
237 swInfo.sCompressLevel = mkDlg.scLevel->GetValue();
238 swInfo.sRecoveryRecord = mkDlg.scRR->GetValue();
239 swInfo.szPassword = mkDlg.tcPassword->GetValue();
240 swInfo.szKeyFile = mkDlg.tcKeyfile->GetValue();
241 swInfo.szComment = mkDlg.tcComment->GetValue();
244 mkDlg.cbSplitSize->GetValue().ToULongLong(& ll);
245 swInfo.llSplitSize = ll;
248 // TPI
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\81B
249 int nSelected = mkDlg.chType->GetSelection();
250 wxFileName fnArchive = wxFileName::DirName(mkDlg.cbDir->GetValue());
251 fnArchive.SetName(mkDlg.cbFileName->GetValue());
252 fnArchive.SetExt(swInfo.fMakeSFX ? (wxString) EXE_EXT : mkDlg.defext[nSelected]);
253 if (! tpi.InitLibrary(mkDlg.libname[nSelected], fnArchive.GetFullPath(), mkDlg.nLibNum[nSelected]))
255 ::wxMessageBox(wxT("Fault: InitLibrary()!"));
259 //
\8f\88\97\9d\82ð
\8ds
\82¤
\81B
260 ProcessDialog procDlg;
261 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
262 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
263 procDlg.InitDialog();
265 int nErrorCode = this->ErrorCheck(tpi.Command(TPI_COMMAND_ADD, & swInfo, fnArchive.GetFullPath(), mkDlg.files));
268 if (nErrorCode != TPI_ERROR_SUCCESS)
273 if (mkDlg.cbOpenAfter->IsChecked())
275 //
\8dì
\90¬
\90æ
\82ð
\8aJ
\82
\81B
277 ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());
281 if (mkDlg.cbExitAfter->IsChecked())
287 //
\8fI
\97¹
\82µ
\82È
\82¢
\8fê
\8d\87\82Í
\8f\91\8cÉ
\82ð
\8aJ
\82
\81B
289 this->LoadArc(fnArchive.GetFullPath());
292 void MainFrame::OnArcOpen(wxCommandEvent& e)
294 //
\8f\91\8cÉ
\82ð
\91I
\91ð
\81B
297 wxFileDialog fdDlg(this);
298 fdDlg.SetDirectory(this->fnLastOpenPath.GetFullPath());
299 if (fdDlg.ShowModal() == wxID_CANCEL)
303 this->fnLastOpenPath = wxFileName::DirName(fdDlg.GetDirectory());
304 szFileName = fdDlg.GetPath();
307 //
\8f\91\8cÉ
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\81B
309 this->LoadArc(szFileName);
312 void MainFrame::OnArcClose(wxCommandEvent&)
314 //
\83c
\83\8a\81[
\83r
\83\85\81[
\81E
\83\8a\83X
\83g
\83r
\83\85\81[
\90Ý
\92è
\81B
315 this->tree_ctrl->DeleteAllItems();
316 this->list_ctrl->DeleteAllItems();
317 this->list_ctrl->showFileInfo.Clear();
319 //
\83c
\81[
\83\8b\83o
\81[
\81E
\83\81\83j
\83\85\81[
\83o
\81[
\90Ý
\92è
\81B
320 SetMenuToolState("Arc_Close", false);
321 SetMenuToolState("Arc_Add", false);
322 SetMenuToolState("Arc_SFX", false);
323 SetMenuToolState("Arc_UnSFX", false);
324 SetMenuToolState("Arc_Extract", false);
325 SetMenuToolState("Arc_Delete", false);
326 SetMenuToolState("Arc_Test", false);
327 SetMenuToolState("Arc_Repair", false);
329 for (int i = 0; i < this->statusbar->GetFieldsCount(); i++)
331 this->statusbar->SetStatusText(wxEmptyString, i);
333 this->fileinfo.Clear();
335 g_hIconT.RemoveAll();
336 g_hIconLL.RemoveAll();
337 g_hIconLS.RemoveAll();
338 this->tpi.FreeLibrary();
341 void MainFrame::OnArcAdd(wxCommandEvent& e)
343 //
\8f\88\97\9d\91Î
\8fÛ
\82Ì
\83t
\83@
\83C
\83\8b\82ð
\91I
\91ð
\81B
345 wxFileDialog fdDlg(this, wxT("Choose files to add"), wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
346 if (fdDlg.ShowModal() == wxID_CANCEL)
350 fdDlg.GetFilenames(files);
352 //
\8ae
\8eí
\90Ý
\92è
\81B
354 swInfo.fnDestinationDirectory = wxFileName::DirName(fdDlg.GetDirectory());
355 swInfo.fMakeSFX = false;
356 swInfo.pCustomSwitches = NULL;
357 wxString szArcName = this->statusbar->GetStatusText(5);
359 ProcessDialog procDlg;
360 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
361 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
362 procDlg.InitDialog();
364 this->ErrorCheck(this->tpi.Command(TPI_COMMAND_ADD, & swInfo, szArcName, files));
367 //
\8f\91\8cÉ
\82ð
\8dÄ
\93Ç
\82Ý
\8d\9e\82Ý
\81B
369 this->LoadArc(szArcName);
372 void MainFrame::OnArcSFX(wxCommandEvent&)
374 this->ConvertArc(true);
377 void MainFrame::OnArcUnSFX(wxCommandEvent&)
379 this->ConvertArc(false);
382 void MainFrame::OnArcExtract(wxCommandEvent&)
384 //
\93W
\8aJ
\83_
\83C
\83A
\83\8d\83O
\82ð
\8dì
\90¬
\81B
386 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_make.xrc"));
387 ::wxXmlResource::Get()->LoadDialog(& mkDlg, this, wxT("dlg_make"));
388 mkDlg.bIsMake = false;
389 mkDlg.files = MakeTargetFileList(this, false);
391 if (mkDlg.ShowModal() == wxID_CANCEL)
396 //
\8ae
\8eí
\90Ý
\92è
\81B
398 swInfo.fStoreDirectoryPathes = ! mkDlg.cbIgnorePath->IsChecked();
399 swInfo.fnDestinationDirectory = wxFileName::DirName(mkDlg.cbDir->GetValue());
400 swInfo.szPassword = mkDlg.tcPassword->GetValue();
401 swInfo.szKeyFile = mkDlg.tcKeyfile->GetValue();
402 swInfo.pCustomSwitches = NULL;
404 //
\95K
\97v
\82È
\82ç
\8f\91\8cÉ
\96¼
\82Å
\83f
\83B
\83\8c\83N
\83g
\83\8a\82ð
\8dì
\90¬
\82·
\82é
\81B
405 if (WillMakeDirByArcName(this, & mkDlg))
407 swInfo.fnDestinationDirectory = MakeDirPath(swInfo.fnDestinationDirectory, wxFileName::FileName(this->statusbar->GetStatusText(5)).GetName(), true);
408 if (! swInfo.fnDestinationDirectory.IsOk())
410 ::wxMessageBox(wxT("Fault: Unable to make the destination directory!"));
415 ProcessDialog procDlg;
416 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
417 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
418 procDlg.InitDialog();
420 this->ErrorCheck(this->tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->statusbar->GetStatusText(5), mkDlg.files));
423 if (mkDlg.cbOpenAfter->IsChecked())
425 //
\93W
\8aJ
\90æ
\82ð
\8aJ
\82
\81B
427 ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());
431 if (mkDlg.cbExitAfter->IsChecked())
438 void MainFrame::OnArcDelete(wxCommandEvent& e)
440 //
\91S
\83t
\83@
\83C
\83\8b\8dí
\8f\9c\82Í
\8aë
\8c¯
\82Å
\82Í
\82È
\82¢
\82©
\82Æ
\81B
441 if (this->list_ctrl->GetSelectedItemCount() == 0)
446 if (::wxMessageBox(wxT("Are you sure to delete selected files?"), wxMessageBoxCaptionStr, wxYES_NO | wxICON_EXCLAMATION, this) == wxNO)
451 //
\8ae
\8eí
\90Ý
\92è
\81B
453 wxString szArcName = this->statusbar->GetStatusText(5);
454 wxArrayString files = MakeTargetFileList(this, false);
456 ProcessDialog procDlg;
457 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
458 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
459 procDlg.InitDialog();
461 this->ErrorCheck(this->tpi.Command(TPI_COMMAND_DELETE, & swInfo, szArcName, files));
464 //
\8f\91\8cÉ
\82ð
\8dÄ
\93Ç
\82Ý
\8d\9e\82Ý
\82·
\82é
\81B
466 this->LoadArc(szArcName);
469 void MainFrame::OnArcTest(wxCommandEvent&)
471 //
\8ae
\8eí
\90Ý
\92è
\81B
472 wxArrayString files = MakeTargetFileList(this, false);
475 ProcessDialog procDlg;
476 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
477 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
478 procDlg.InitDialog();
480 if (this->ErrorCheck(this->tpi.Command(TPI_COMMAND_TEST, & swInfo, this->statusbar->GetStatusText(5), files)) == TPI_ERROR_SUCCESS)
482 ::wxMessageBox(wxT("This is a correct archive."), wxT("Frontend"), wxOK | wxCENTRE | wxICON_INFORMATION, this);
487 void MainFrame::OnArcRepair(wxCommandEvent&)
489 //
\8ae
\8eí
\90Ý
\92è
\81B
490 wxArrayString files = MakeTargetFileList(this, false);
493 ProcessDialog procDlg;
494 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
495 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
496 procDlg.InitDialog();
498 this->ErrorCheck(this->tpi.Command(TPI_COMMAND_REPAIR, & swInfo, this->statusbar->GetStatusText(5), files));
502 void MainFrame::OnViewMode(wxCommandEvent & e)
505 this->menubar->Check(n, true);
506 this->list_ctrl->SetSingleStyle(wxLC_REPORT, n == XRCID("Exe_View_Details"));
507 this->list_ctrl->SetSingleStyle(wxLC_ICON, n == XRCID("Exe_View_Icons"));
510 void MainFrame::OnSelectAll(wxCommandEvent &)
512 for (int i = 0; i < this->list_ctrl->GetItemCount(); i++)
514 this->list_ctrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
520 void MainFrame::OnTreeChanged(wxTreeEvent& e)
522 //
\83c
\83\8a\81[
\83r
\83\85\81[
\82©
\82ç
\83p
\83X
\82ð
\8eæ
\93¾
\81B
523 wxString szNodePath = TreeView_GetItemPath(this->tree_ctrl, e.GetItem());
524 //
\83\8a\83X
\83g
\83r
\83\85\81[
\82ð
\8f\89\8aú
\89»
\81B
525 this->list_ctrl->showFileInfo.Clear();
526 g_hIconLL.RemoveAll();
527 g_hIconLS.RemoveAll();
529 //
\83A
\83C
\83R
\83\93\90Ý
\92è
\81B
530 this->list_ctrl->SetImageList(& g_hIconLL, wxIMAGE_LIST_NORMAL);
531 this->list_ctrl->SetImageList(& g_hIconLS, wxIMAGE_LIST_SMALL);
533 //
\94z
\97ñ
\82Æ
\94ä
\8ar
\82µ
\81A
\83p
\83X
\82ª
\88ê
\92v
\82µ
\82È
\82¯
\82ê
\82Î
\8fÁ
\82·
\81B
534 for (size_t i = 0; i < this->fileinfo.GetCount(); i++)
536 //
\83p
\83X
\82ð
\94ä
\8ar
\81B
537 if (szNodePath == wxT("*") || szNodePath == this->fileinfo[i].fnFileName.GetPath())
539 //
\8d\80\96Ú
\82ª
\83t
\83H
\83\8b\83_
\82Å
\82 \82é
\82È
\82ç
\96³
\8e\8b\81B
540 if (this->fileinfo[i].fnFileName.IsDir() || ! TreeView_CheckNewerItem(this->tree_ctrl, this->tree_ctrl->GetLastChild(this->tree_ctrl->GetRootItem()), this->fileinfo[i].fnFileName.GetFullPath(), false))
545 this->list_ctrl->showFileInfo.Add(this->fileinfo[i]);
548 //
\83\
\81[
\83g
\82µ
\82Ä
\95\
\8e¦
\81B
549 this->list_ctrl->showFileInfo.Sort(& ListCtrlCompareProc);
550 this->list_ctrl->SetItemCount(this->list_ctrl->showFileInfo.Count());
555 void MainFrame::OnListItemDClick(wxListEvent&)
557 //
\93W
\8aJ
\91Î
\8fÛ
\82ð
\8c\88\92è
\81B
558 wxArrayString files = MakeTargetFileList(this, true);
560 //
\83R
\83}
\83\93\83h
\82ð
\8eæ
\93¾
\81B
561 wxFileType * ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(wxFileName::FileName(files[0]).GetExt());
564 ::wxMessageBox(wxT("Fault: Unable to get the file type!"));
568 //
\8ae
\8eí
\90Ý
\92è
\81B
570 swInfo.fStoreDirectoryPathes = false;
571 swInfo.pCustomSwitches = NULL;
572 swInfo.fnDestinationDirectory = MakeDirPath(wxFileName::DirName(::wxGetCwd()), wxT("tpi_tmp"), true);
573 if (! swInfo.fnDestinationDirectory.IsOk())
575 ::wxMessageBox(wxT("Fault: Unable to make the temporary directory!"));
579 ProcessDialog procDlg;
580 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
581 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
582 procDlg.InitDialog();
584 int nErrorCode = this->ErrorCheck(this->tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->statusbar->GetStatusText(5), files));
587 //
\83R
\83}
\83\93\83h
\82ð
\8eÀ
\8ds
\81B
588 wxString s = swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName::FileName(files[0]).GetFullName();
589 if (nErrorCode == TPI_ERROR_SUCCESS)
591 ::wxExecute(ftFile->GetOpenCommand(s), wxEXEC_SYNC);
594 //
\88ê
\8e\9e\83f
\83B
\83\8c\83N
\83g
\83\8a\82ð
\8dí
\8f\9c\81B
596 ::wxRmdir(swInfo.fnDestinationDirectory.GetFullPath());
599 void MainFrame::OnListBeginDrag(wxListEvent&)
601 if (this->list_ctrl->GetSelectedItemCount() == 0)
603 //
\83A
\83C
\83e
\83\80\82ð
\91I
\91ð
\82¹
\82¸
\83h
\83\89\83b
\83O
\82µ
\82æ
\82¤
\82Æ
\82µ
\82½
\8fê
\8d\87\81B
607 //
\8ae
\8eí
\90Ý
\92è
\81B
609 swInfo.fStoreDirectoryPathes = false;
610 swInfo.pCustomSwitches = NULL;
611 swInfo.fnDestinationDirectory = MakeDirPath(wxFileName::DirName(::wxGetCwd()), wxT("tpi_tmp"), true);
612 if (! swInfo.fnDestinationDirectory.IsOk())
614 ::wxMessageBox(wxT("Fault: Unable to make the temporary directory!"));
618 //
\93W
\8aJ
\91Î
\8fÛ
\82ð
\8c\88\92è
\81B
619 wxFileDataObject objFile;
620 wxArrayString files = MakeTargetFileList(this, false);
621 for (size_t i = 0; i < files.Count(); i++)
623 //
\83\8a\83X
\83g
\82É
\92Ç
\89Á
\81B
624 objFile.AddFile(swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName::FileName(files[i]).GetFullName());
627 this->ErrorCheck(tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->statusbar->GetStatusText(5), files));
629 wxDropSource dropSource(objFile, this);
630 if (dropSource.DoDragDrop() != wxDragMove)
633 // Linux
\82Å
\82Í
\82Ü
\82¾
\8f\88\97\9d\82ª
\8fI
\82í
\82Á
\82Ä
\82¢
\82È
\82¢(
\83R
\83\93\83e
\83L
\83X
\83g
\83\81\83j
\83\85\81[
\82ª
\95\
\8e¦
\82³
\82ê
\82Ä
\82¢
\82é)
\82Ì
\82Å
\81A
\82Æ
\82è
\82 \82¦
\82¸3
\95b
\82¾
\82¯
\91Ò
\82Â
\81B
636 //
\88ê
\8e\9e\83f
\83B
\83\8c\83N
\83g
\83\8a\82ð
\8dí
\8f\9c\81B
637 wxArrayString szFileNames = objFile.GetFilenames();
638 for (size_t i = 0; i < szFileNames.GetCount(); i++)
640 ::wxRemoveFile(szFileNames[i]);
642 ::wxRmdir(swInfo.fnDestinationDirectory.GetFullPath());
646 //
\83C
\83x
\83\93\83g
\83n
\83\93\83h
\83\89\88È
\8aO
\81B
648 void MainFrame::LoadArc(wxString szFileName)
650 if (szFileName.IsEmpty())
655 //
\90i
\92»
\83_
\83C
\83A
\83\8d\83O
\95\
\8e¦
\81B
656 ProcessDialog procDlg;
657 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
658 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
659 procDlg.InitDialog();
662 // TPI
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\81B
664 fs.ChangePathTo(FE_DIR_B_LIB, true);
665 wxString szTPIName = fs.FindFirst(wxT("*" TPI_EXT), wxFILE);
667 while (! szTPIName.IsEmpty())
669 //
\91Î
\89\9e\8am
\94F
\81B
670 if (! tpi.InitLibrary(szTPIName, szFileName, 0) || ! tpi.CheckArchive(szFileName, & nFileCount) || nFileCount < 0)
673 szTPIName = fs.FindNext();
678 if (nFileCount == -1)
682 ::wxMessageBox(wxT("Fault : No plug-in supporting this archive was found!"));
686 //
\8dÅ
\8f\89\82Ì
\83R
\81[
\83\8b\83o
\83b
\83N
\82ð
\91\97\90M
\81B
687 TPI_PROCESSINFO piInfo;
688 piInfo.uMessage = TPI_MESSAGE_STATUS;
689 piInfo.uStatus = 0x1000;
690 piInfo.llProcessedSize = 0;
691 piInfo.fiInfo.fnFileName = wxFileName::FileName(szFileName);
692 piInfo.fiInfo.llUnpackedSize = nFileCount;
693 TPICallbackProc(TPI_NOTIFY_COMMON, & piInfo);
695 //
\8f\91\8cÉ
\82ð
\8aJ
\82
\81B
697 if (tpi.OpenArchive(szFileName, & hArc) != TPI_ERROR_SUCCESS)
701 ::wxMessageBox(wxT("Fault : OpenArchive()!"));
705 //
\89æ
\91\9c\83\8a\83X
\83g
\82ð
\8dì
\90¬
\81B
706 this->tree_ctrl->SetImageList(& g_hIconT);
707 this->tree_ctrl->AddRoot(wxEmptyString);
709 //
\8f\91\8cÉ
\82Ì
\83A
\83C
\83R
\83\93\82ð
\8eæ
\93¾
\82µ
\81A
\8f\91\8cÉ
\83\8b\81[
\83g
\82ð
\8dì
\90¬
\81B
710 wxFileName fn(szFileName);
711 wxTreeItemId idRoot = this->tree_ctrl->GetRootItem();
713 wxTreeItemId idArchive = this->tree_ctrl->InsertItem(idRoot, idRoot, fn.GetFullName(), g_hIconT.Add(GetFileTypeIcon(fn)), -1);
715 wxTreeItemId idArchive = this->tree_ctrl->InsertItem(idRoot, idRoot, fn.GetFullName(), g_hIconT.Add(GetFileTypeIcon(fn).ConvertToImage().Rescale(16, 16)), -1);
718 //
\83\8b\81[
\83g
\83f
\83B
\83\8c\83N
\83g
\83\8a\82ð
\8dì
\90¬
\81B
719 g_hIconT.Add(wxBitmap(FE_DIR_S_ICO wxT("folder_closed.png"), wxBITMAP_TYPE_ANY));
720 g_hIconT.Add(wxBitmap(FE_DIR_S_ICO wxT("folder_open.png"), wxBITMAP_TYPE_ANY));
721 wxTreeItemId idArcRoot = this->tree_ctrl->InsertItem(idRoot, idArchive, wxT("-----"), 1, 2);
723 //
\94z
\97ñ
\82Ì
\83T
\83C
\83Y
\82ð
\8am
\95Û
\81B
724 this->fileinfo.Alloc(nFileCount);
726 //
\83t
\83@
\83C
\83\8b\8fî
\95ñ
\82ð
\83\8d\81[
\83h
\81B
727 if (tpi.GetFileInformation(hArc, & piInfo.fiInfo, true) == TPI_ERROR_SUCCESS)
731 piInfo.uStatus = 0x1001;
732 piInfo.llProcessedSize++;
733 if (TPICallbackProc(TPI_NOTIFY_COMMON, & piInfo) == TPI_CALLBACK_CANCEL)
736 tpi.CloseArchive(hArc);
739 ::wxMessageBox(wxT("Fault : Canceled by user!"));
743 //
\83c
\83\8a\81[
\83r
\83\85\81[
\82É
\94½
\89f
\81B
744 TreeView_CheckNewerItem(this->tree_ctrl, idArcRoot, piInfo.fiInfo.fnFileName.GetPath(wxPATH_GET_VOLUME), true);
746 //
\83f
\83B
\83\8c\83N
\83g
\83\8a\91®
\90«
\82ð
\8aÜ
\82Þ
\82à
\82Ì
\82É
\82Â
\82¢
\82Ä
\82Í
\8f\9c\8b\8e\81B
747 if (piInfo.fiInfo.dwAttribute & TPI_ATTRIBUTE_DIRECTORY)
752 //
\83Z
\83L
\83\85\83\8a\83e
\83B
\83`
\83F
\83b
\83N
\81B
754 if (piInfo.fiInfo.fnFileName.GetPathWithSep().Find(wxT("..")) != wxNOT_FOUND)
756 piInfo.fiInfo.uDanger = TRUE;
757 ::wxMessageBox(wxT("This archive may have Directory Traversal Vulnerability(DTV) problem, and some danger files may be extracted to the unexpected system directory! You should use the \"Ignore file pathes\" option when extracting this archive.\nDanger file is:\n" + piInfo.fiInfo.szStoredName), wxMessageBoxCaptionStr, wxICON_EXCLAMATION);
759 //
\8bó
\94\92\82Ì
\98A
\91±
\82É
\82æ
\82é
\8ag
\92£
\8eq
\8bU
\91\95\82ð
\8c\9f\8d¸
\81B
760 if (piInfo.fiInfo.fnFileName.GetFullName().Find(wxT(" ")) != wxNOT_FOUND)
762 piInfo.fiInfo.uDanger = TRUE;
763 ::wxMessageBox(wxT("This archive may contain extension-disguised files whose real extension is hidden by using many blank charactor and you may mistake that it is a \"safe\" file. Don\'t execute these files carelessly.\nDanger file is:\n" + piInfo.fiInfo.szStoredName), wxMessageBoxCaptionStr, wxICON_EXCLAMATION);
765 // Unicode
\90§
\8cä
\95¶
\8e\9a\82ð
\8c\9f\8d¸
\81B
766 for (wxChar c = 0x200c; c <= 0x206f; c++)
768 if (piInfo.fiInfo.fnFileName.GetFullName().Find(c) != wxNOT_FOUND)
770 piInfo.fiInfo.uDanger = TRUE;
771 ::wxMessageBox(wxT("This archive may contain extension-disguised files whose real extension is hidden by using Unicode control character and you may mistake that it is a \"safe\" file. Don\'t execute these files carelessly.\nDanger file is:\n" + piInfo.fiInfo.szStoredName), wxMessageBoxCaptionStr, wxICON_EXCLAMATION);
775 case 0x200f: c = 0x2027; break;
776 case 0x202e: c = 0x2060; break;
780 //
\8fî
\95ñ
\82ð
\95Û
\91¶
\82µ
\82Ä
\83J
\83E
\83\93\83g
\83A
\83b
\83v
\81B
781 this->fileinfo.Add(piInfo.fiInfo);
783 while (tpi.GetFileInformation(hArc, & piInfo.fiInfo, false) == TPI_ERROR_SUCCESS);
786 //
\8eG
\91½
\8f\88\97\9d\81B
787 this->fileinfo.Shrink();
788 this->tree_ctrl->ExpandAllChildren(idArcRoot);
789 this->tree_ctrl->ScrollTo(idArchive);
790 this->tree_ctrl->SelectItem(idArchive);
791 this->list_ctrl->atDangerItem.SetTextColour(* wxRED);
793 //
\8f\91\8cÉ
\82Ì
\8fî
\95ñ
\82ð
\8eæ
\93¾
\81B
794 TPI_ARCHIVEINFO aiInfo;
795 if (tpi.GetArchiveInformation(hArc, & aiInfo) != TPI_ERROR_SUCCESS)
799 ::wxMessageBox(wxT("Fault : GetArchiveInformation()!"));
803 wxString szStatusText;
804 this->statusbar->SetStatusText(wxEmptyString, 0);
805 this->statusbar->SetStatusText(wxString::Format(wxT("%d file(s)"), this->fileinfo.Count()), 1);
806 this->statusbar->SetStatusText(wxT("Unpacked: ") + aiInfo.llUnpackedSize.ToString() + wxT(" B"), 2);
807 this->statusbar->SetStatusText(wxT("Packed: ") + aiInfo.llPackedSize.ToString() + wxT(" B"), 3);
808 this->statusbar->SetStatusText(wxString::Format(wxT("Ratio: %3.1f%%"), aiInfo.wCompressRatio / 10.0), 4);
809 this->statusbar->SetStatusText(szFileName, 5);
811 //
\8f\91\8cÉ
\82ð
\95Â
\82¶
\82é
\81B
812 if (tpi.CloseArchive(hArc) != TPI_ERROR_SUCCESS)
814 ::wxMessageBox(wxT("Fault : CloseArchive()!"));
817 //
\83R
\81[
\83\8b\83o
\83b
\83N
\8aÖ
\90\94\82ð
\90Ý
\92è
\81B
818 if (tpi.SetCallbackProc(TPICallbackProc) != TPI_ERROR_SUCCESS)
820 ::wxMessageBox(wxT("Fault : SetCallbackProc()!"));
823 // UI
\8ae
\8eí
\90Ý
\92è
\81B
825 //
\83c
\81[
\83\8b\83o
\81[
\81E
\83\81\83j
\83\85\81[
\83o
\81[
\90Ý
\92è
\81B
826 SetMenuToolState("Arc_Close", true);
827 SetMenuToolState("Arc_Add", true);
828 SetMenuToolState("Arc_SFX", aiInfo.nSFXType == 0);
829 SetMenuToolState("Arc_UnSFX", aiInfo.nSFXType != 0);
830 SetMenuToolState("Arc_Extract", true);
831 SetMenuToolState("Arc_Delete", true);
832 SetMenuToolState("Arc_Test", true);
833 SetMenuToolState("Arc_Repair", true);
839 void MainFrame::ConvertArc(bool fToSFX)
841 //
\95Û
\91¶
\90æ
\82ð
\90q
\82Ë
\82é
\81B
842 wxFileName fnArchive(this->statusbar->GetStatusText(5));
845 fnArchive.SetExt(EXE_EXT);
847 wxFileDialog fdDlg(this, fToSFX ? wxT("Save as SFX") : wxT("Save as normal archive"), fnArchive.GetPath(wxPATH_GET_VOLUME), fToSFX ? fnArchive.GetFullName() : fnArchive.GetName(), wxFileSelectorDefaultWildcardStr, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
848 if (fdDlg.ShowModal() == wxID_CANCEL)
852 this->fnLastOpenPath = wxFileName::DirName(fdDlg.GetDirectory());
855 files.Add(fdDlg.GetPath());
858 swInfo.fMakeSFX = fToSFX;
859 swInfo.fnDestinationDirectory = wxFileName::DirName(fdDlg.GetDirectory());
861 ProcessDialog procDlg;
862 ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
863 ::wxXmlResource::Get()->LoadDialog(& procDlg, this, wxT("dlg_process"));
864 procDlg.InitDialog();
866 this->ErrorCheck(this->tpi.Command(fToSFX ? TPI_COMMAND_SFX : TPI_COMMAND_UNSFX, & swInfo, fnArchive.GetFullPath(), files));
870 int MainFrame::ErrorCheck(int nErrorCode)
875 case TPI_ERROR_SUCCESS:
876 return TPI_ERROR_SUCCESS;
877 case TPI_ERROR_D_UNSUPPORTED:
878 s = wxT("Sorry, this function is not supported yet.");
880 case TPI_ERROR_D_SKIPPED:
881 s = wxT("This operation is canceled by the user.");
884 s.Printf(wxT("ErrorCode:%d"), nErrorCode);
886 ::wxMessageBox(s, wxT("Frontend"), wxOK | wxCENTRE | wxICON_ERROR, this);