OSDN Git Service

書庫閲覧時にツリービューからのDnDに対応。
[tpi/lychee.git] / src / frontend / frm_main.cpp
1 /*******************************************************************************
2   TPI - flexible but useless plug-in framework.
3   Copyright (C) 2002-2009 Silky
4
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)
8   any later version.
9
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
13   for more details.
14
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
18
19   $Id: frm_main.cpp,v 1.42 2009/09/05 03:24:58 sirakaba Exp $
20 *******************************************************************************/
21
22 #include "frontend.h"
23
24 #include "frm_main.h"
25 #include "cls_filedroptarget.h"
26 #include "dlg_make.h"
27 #include "dlg_process.h"
28 #include "functions.h"
29
30 #include <wx/fileconf.h>
31 #include <wx/arrimpl.cpp>
32
33 WX_DEFINE_OBJARRAY(ArrayTPI_FILEINFO);
34
35 #define SetMenuToolState(id, state) this->toolbar->EnableTool(XRCID(id), state); this->menubar->Enable(XRCID(id), state)
36
37 //******************************************************************************
38 //    \83O\83\8d\81[\83o\83\8b\95Ï\90\94
39 //******************************************************************************
40
41 wxImageList g_hIconT(16, 16), g_hIconLL(32, 32), g_hIconLS(16, 16);
42 int g_nSortColumn;
43 bool g_fSortAscend;
44
45 //******************************************************************************
46 // MainFrame
47 //******************************************************************************
48
49 MainFrame::MainFrame(): wxFrame()
50 {
51 }
52
53 MainFrame::~MainFrame()
54 {
55         wxCommandEvent e;
56         this->OnArcClose(e);
57
58         // \90Ý\92è\82ð\8bL\98^\81B
59         wxFileConfig fc(wxEmptyString, wxEmptyString, ::wxGetCwd() + wxT("/frontend.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
60         if (! this->IsIconized() && ! this->IsMaximized())
61         {
62                 int a, b;
63                 this->GetSize(& a, & b);
64                 fc.Write(wxT("Window-Width"), a);
65                 fc.Write(wxT("Window-Height"), b);
66                 this->GetPosition(& a, & b);
67                 fc.Write(wxT("Window-X"), a);
68                 fc.Write(wxT("Window-Y"), b);
69         }
70         fc.Write(wxT("Splitter-Pos"), this->window_splitter->GetSashPosition());
71         fc.Write(wxT("LastOpenPath"), this->fnLastOpenPath.GetFullPath());
72
73         // \83c\81[\83\8b\83o\81[/\83X\83e\81[\83^\83X\83o\81[\8aÖ\98A\81B
74         fc.Write(wxT("StatusBar-Show"), this->statusbar->IsShown());
75         fc.Write(wxT("ToolBar-Show"),   this->toolbar->IsShown());
76
77         // ListView\8aÖ\98A\81B
78         fc.Write(wxT("ListView-IconMode"), this->menubar->IsChecked(XRCID("Exe_View_Icons")) ? 1 : this->menubar->IsChecked(XRCID("Exe_View_List")) ? 2 : 0);
79         if (this->menubar->IsChecked(XRCID("Exe_View_Details")))
80         {
81                 fc.Write(wxT("ListView-C-Filename"), this->list_ctrl->GetColumnWidth(0));
82                 fc.Write(wxT("ListView-C-Unpacked"), this->list_ctrl->GetColumnWidth(1));
83                 fc.Write(wxT("ListView-C-Packed"), this->list_ctrl->GetColumnWidth(2));
84                 fc.Write(wxT("ListView-C-Ratio"), this->list_ctrl->GetColumnWidth(3));
85                 fc.Write(wxT("ListView-C-Method"), this->list_ctrl->GetColumnWidth(4));
86                 fc.Write(wxT("ListView-C-Attr"), this->list_ctrl->GetColumnWidth(5));
87                 fc.Write(wxT("ListView-C-Lastmodified"), this->list_ctrl->GetColumnWidth(6));
88                 fc.Write(wxT("ListView-C-Path"), this->list_ctrl->GetColumnWidth(7));
89                 fc.Write(wxT("ListView-C-Type"), this->list_ctrl->GetColumnWidth(8));
90                 fc.Write(wxT("ListView-C-No"), this->list_ctrl->GetColumnWidth(9));
91                 fc.Write(wxT("ListView-SortColumn"), g_nSortColumn);
92                 fc.Write(wxT("ListView-SortAscend"), g_fSortAscend);
93         }
94
95         this->Close(true);
96 }
97
98 //******************************************************************************
99 // Event Table.
100 //******************************************************************************
101
102 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
103         EVT_INIT_DIALOG(      MainFrame::OnInit)
104         // Menu
105         EVT_MENU(XRCID("Arc_Create"),  MainFrame::OnArcCreate)
106         EVT_MENU(XRCID("Arc_Open"),    MainFrame::OnArcOpen)
107         EVT_MENU(XRCID("Arc_Close"),   MainFrame::OnArcClose)
108         EVT_MENU(XRCID("Arc_Add"),     MainFrame::OnArcAdd)
109         EVT_MENU(XRCID("Arc_SFX"),     MainFrame::OnArcConvert)
110         EVT_MENU(XRCID("Arc_UnSFX"),   MainFrame::OnArcConvert)
111         EVT_MENU(XRCID("Exe_Exit"),    MainFrame::OnExit)
112         EVT_MENU(XRCID("Arc_Extract"), MainFrame::OnArcExtract)
113         EVT_MENU(XRCID("Arc_Delete"),  MainFrame::OnArcDelete)
114         EVT_MENU(XRCID("Arc_Test"),    MainFrame::OnArcTest)
115         EVT_MENU(XRCID("Arc_Repair"),  MainFrame::OnArcRepair)
116         EVT_MENU(XRCID("Exe_View_Icons"),  MainFrame::OnViewMode)
117         EVT_MENU(XRCID("Exe_View_Details"),MainFrame::OnViewMode)
118         EVT_MENU(XRCID("Exe_View_List"),   MainFrame::OnViewMode)
119         EVT_MENU(XRCID("Exe_View_ToolBar"),MainFrame::OnShowToolBar)
120         EVT_MENU(XRCID("Exe_View_StatusBar"),MainFrame::OnShowStatusBar)
121         EVT_MENU(XRCID("Exe_View_SelectAll"),MainFrame::OnSelectAll)
122         // TreeView
123         EVT_TREE_SEL_CHANGED(XRCID("TreeView"), MainFrame::OnTreeChanged)
124         EVT_TREE_BEGIN_DRAG( XRCID("TreeView"), MainFrame::OnTreeBeginDrag)
125         // ListView
126         EVT_LIST_ITEM_ACTIVATED(XRCID("ListView"), MainFrame::OnListItemDClick)
127         EVT_LIST_BEGIN_DRAG(    XRCID("ListView"), MainFrame::OnListBeginDrag)
128         // Filter
129         EVT_TEXT(XRCID("tcFilter"), MainFrame::OnFilter)
130 END_EVENT_TABLE()
131
132 //******************************************************************************
133 // Event handler.
134 //******************************************************************************
135
136 void MainFrame::OnInit(wxInitDialogEvent&)
137 {
138         // XRC\82Æ\8c\8b\82Ñ\82Â\82¯\81B
139         this->menubar    = this->GetMenuBar();
140         this->toolbar    = this->GetToolBar();
141         this->statusbar = XRCCTRL(* this, "statusbar", wxStatusBar);
142         this->tree_ctrl = XRCCTRL(* this, "TreeView", wxTreeCtrl);
143         this->list_ctrl = XRCCTRL(* this, "ListView", myListCtrl);
144         this->tcFilter  = XRCCTRL(* this, "tcFilter", wxTextCtrl);
145         this->window_splitter = XRCCTRL(* this, "window_splitter", wxSplitterWindow);
146
147         // \90Ý\92è\82ð\93Ç\82Ý\8d\9e\82Ý\81B
148         wxFileConfig fc(wxEmptyString, wxEmptyString, ::wxGetCwd() + wxT("/frontend.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
149         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));
150         this->fnLastOpenPath = wxFileName::DirName(fc.Read(wxT("LastOpenPath"), ::wxGetCwd()));
151         wxTheMimeTypesManager->Initialize(wxMAILCAP_ALL);
152
153         // \8f\89\8aú\92l\90Ý\92è\81B
154         {
155                 wxIcon icon;
156                 icon.CopyFromBitmap(wxBitmap(FE_DIR_S_ICO wxT("app.png"), wxBITMAP_TYPE_ANY));
157                 this->SetIcon(icon);
158         }
159         wxCommandEvent e;
160         this->OnArcClose(e);
161
162         // \83X\83v\83\8a\83b\83^\81[\90Ý\92è\81B
163         this->window_splitter->SetSashPosition(fc.Read(wxT("Splitter-Pos"), 200));
164
165         // \83\8a\83X\83g\83r\83\85\81[\90Ý\92è\81B
166         int nIconMode = fc.Read(wxT("ListView-IconMode"), 0l);
167         e.SetId(nIconMode == 1 ? XRCID("Exe_View_Icons") : (nIconMode == 2 ? XRCID("Exe_View_List") : XRCID("Exe_View_Details")));
168         this->OnViewMode(e);
169         // wxGTK\82Å\82Í\92¼\90ÚwxLC_VIRTUAL\82ð\8ew\92è\82µ\82È\82¢\82Æ\94½\89f\82³\82ê\82È\82¢\81B
170         this->list_ctrl->SetSingleStyle(wxLC_VIRTUAL);
171         this->list_ctrl->InsertColumn(0, wxT("Filename"),      wxLIST_FORMAT_LEFT,   fc.Read(wxT("ListView-C-Filename"), 140));
172         this->list_ctrl->InsertColumn(1, wxT("Unpacked"),      wxLIST_FORMAT_RIGHT,  fc.Read(wxT("ListView-C-Unpacked"), 80));
173         this->list_ctrl->InsertColumn(2, wxT("Packed"),        wxLIST_FORMAT_RIGHT,  fc.Read(wxT("ListView-C-Packed"), 80));
174         this->list_ctrl->InsertColumn(3, wxT("Ratio"),         wxLIST_FORMAT_RIGHT,  fc.Read(wxT("ListView-C-Ratio"), 50));
175         this->list_ctrl->InsertColumn(4, wxT("Method"),        wxLIST_FORMAT_LEFT,   fc.Read(wxT("ListView-C-Method"), 60));
176         this->list_ctrl->InsertColumn(5, wxT("Attr"),          wxLIST_FORMAT_LEFT,   fc.Read(wxT("ListView-C-Attr"), 50));
177         this->list_ctrl->InsertColumn(6, wxT("Last modified"), wxLIST_FORMAT_RIGHT,  fc.Read(wxT("ListView-C-Lastmodified"), 150));
178         this->list_ctrl->InsertColumn(7, wxT("Path"),          wxLIST_FORMAT_LEFT,   fc.Read(wxT("ListView-C-Path"), 100));
179         this->list_ctrl->InsertColumn(8, wxT("Type"),          wxLIST_FORMAT_LEFT,   fc.Read(wxT("ListView-C-Type"), 100));
180         this->list_ctrl->InsertColumn(9, wxT("No."),           wxLIST_FORMAT_RIGHT,  fc.Read(wxT("ListView-C-No"), 35));
181         g_nSortColumn = fc.Read(wxT("ListView-SortColumn"), 9);
182         g_fSortAscend = fc.Read(wxT("ListView-SortAscend"), 1) == 1;
183         this->list_ctrl->SetDropTarget(new myFileDropTarget(this));
184
185         // \83c\81[\83\8b\83o\81[/\83X\83e\81[\83^\83X\83o\81[\90Ý\92è\81B
186         int nStatusBarParts[] = {70, 70, 180, 50, -1};
187         this->statusbar->SetFieldsCount(5, nStatusBarParts);
188         this->SetStatusBarPane(-1);
189         bool fShow = fc.Read(wxT("StatusBar-Show"), 1) == 1;
190         this->menubar->Check(XRCID("Exe_View_StatusBar"), fShow);
191         this->statusbar->Show(fShow);
192         fShow = fc.Read(wxT("ToolBar-Show"), 1) == 1;
193         this->menubar->Check(XRCID("Exe_View_ToolBar"), fShow);
194         this->toolbar->Show(fShow);
195
196         // \83R\83}\83\93\83h\83\89\83C\83\93\93Ç\82Ý\8d\9e\82Ý\81B
197         this->cmdLine.SetSwitchChars(wxT("-"));
198         this->cmdLine.AddSwitch(wxT("x"), wxEmptyString, wxT("(command) Extract filenames in archive."));
199         this->cmdLine.AddSwitch(wxT("l"), wxEmptyString, wxT("(command) List archive(default)."));
200         this->cmdLine.AddParam(wxT("archive"),   wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
201         this->cmdLine.AddParam(wxT("filenames"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
202         if (this->cmdLine.Parse() == 0)
203         {
204                 if (this->cmdLine.GetParamCount() == 0)
205                 {
206                         return;
207                 }
208
209                 // \8f\91\8cÉ\82ð\8aJ\82­\81B
210                 wxFileName fnArchive(this->cmdLine.GetParam(0));
211                 fnArchive.Normalize(wxPATH_NORM_ALL, this->szCurrentPath);
212                 e.SetString(fnArchive.GetFullPath());
213                 this->OnArcOpen(e);
214                 if (this->cmdLine.Found(wxT("x")))
215                 {
216                         // \8f\91\8cÉ\82ð\93W\8aJ\81B
217                         this->OnArcExtract(e);
218                         this->Close(true);
219                 }
220         }
221 }
222
223 // MenuBar
224
225 void MainFrame::OnExit(wxCommandEvent&)
226 {
227         this->Close(true);
228 }
229
230 void MainFrame::OnArcCreate(wxCommandEvent& e)
231 {
232         TPI_SWITCHES swInfo;
233         swInfo.pCustomSwitches = NULL;
234
235         // \8dì\90¬\83_\83C\83A\83\8d\83O\82ð\90Ý\92è\81B
236         MakeDialog mkDlg;
237         ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_make.xrc"));
238         ::wxXmlResource::Get()->LoadDialog(& mkDlg, this, wxT("dlg_make"));
239
240         if (e.GetClientData() == NULL)
241         {
242                 // \8f\88\97\9d\91Î\8fÛ\82Ì\83t\83@\83C\83\8b\82ð\91I\91ð\81B
243                 wxFileDialog fd(this, wxT("Choose files to compress"), this->fnLastOpenPath.GetFullPath());
244                 fd.SetWindowStyleFlag(wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
245                 if (fd.ShowModal() == wxID_CANCEL)
246                 {
247                         return;
248                 }
249                 // \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
250                 // \82 \82Ü\82è\82æ\82¢\8ed\97l\82Å\82Í\82È\82¢\82ª\93®\82­\82Ì\82Å\82Æ\82è\82 \82¦\82¸\95ú\92u\81B
251                 this->fnLastOpenPath = wxFileName::FileName(fd.GetDirectory());
252                 swInfo.fnDestinationDirectory = wxFileName::DirName(this->fnLastOpenPath.GetFullPath());
253                 this->statusbar->SetStatusText(swInfo.fnDestinationDirectory.GetFullPath(), 4);
254
255                 fd.GetFilenames(mkDlg.files);
256         }
257         else
258         {
259                 mkDlg.files = * (wxArrayString *) e.GetClientData();
260                 swInfo.fnDestinationDirectory = wxFileName::DirName(wxFileName::FileName(mkDlg.files[0]).GetPath());
261                 // \91\8a\91Î\83p\83X\82É\95Ï\8a·\81B
262                 for (size_t n = 0; n < mkDlg.files.Count(); n++)
263                 {
264                         wxFileName fn(mkDlg.files[n]);
265                         bool fIsDir = fn.DirExists() && ! fn.FileExists();
266                         fn.MakeRelativeTo(swInfo.fnDestinationDirectory.GetPath());
267                         mkDlg.files[n] = fn.GetFullPath();
268                         if (fIsDir)
269                         {
270                                 mkDlg.files[n] += fn.GetPathSeparator();
271                         }
272                 }
273         }
274
275         mkDlg.InitDialog();
276         mkDlg.cbDir->SetValue(swInfo.fnDestinationDirectory.GetPath());
277         // \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
278         wxFileName fnFirstFile(mkDlg.files[0]);
279         mkDlg.cbFileName->SetValue(mkDlg.files.GetCount() == 1 ? (fnFirstFile.GetName().IsEmpty() ? fnFirstFile.GetDirs().Last() : fnFirstFile.GetName()) : swInfo.fnDestinationDirectory.GetDirs().Last());
280
281         // \83_\83C\83A\83\8d\83O\82ð\95\\8e¦\81B
282         if (mkDlg.ShowModal() == wxID_CANCEL)
283         {
284                 this->statusbar->SetStatusText(wxEmptyString, 4);
285                 return;
286         }
287         this->statusbar->SetStatusText(wxEmptyString, 4);
288
289         // \8ae\8eí\90Ý\92è\81B
290         swInfo.fStoreDirectoryPathes= ! mkDlg.cbIgnorePath->IsChecked();
291         swInfo.fMakeSFX                     = mkDlg.cbMakeSFX->IsChecked();
292         swInfo.fSolid               = mkDlg.cbSolid->IsChecked();
293         swInfo.fMMOptimize          = mkDlg.cbMMOptimize->IsChecked();
294         swInfo.fEncryptHeader       = mkDlg.cbEncryptHeader->IsChecked();
295         swInfo.sCompressLevel       = mkDlg.scLevel->GetValue();
296         swInfo.sRecoveryRecord      = mkDlg.scRR->GetValue();
297         swInfo.szPassword           = mkDlg.tcPassword->GetValue();
298         swInfo.szKeyFile            = mkDlg.tcKeyfile->GetValue();
299         swInfo.szComment            = mkDlg.tcComment->GetValue();
300         {
301                 wxULongLong_t ll;
302                 mkDlg.cbSplitSize->GetValue().ToULongLong(& ll);
303                 swInfo.llSplitSize      = ll;
304         }
305
306         // TPI\82ð\93Ç\82Ý\8d\9e\82Ý\81B
307         int nSelected = mkDlg.chType->GetSelection();
308         wxFileName fnArchive = wxFileName::DirName(mkDlg.cbDir->GetValue());
309         fnArchive.SetName(mkDlg.cbFileName->GetValue());
310         fnArchive.SetExt(swInfo.fMakeSFX ? EXE_EXT : mkDlg.afInfo[nSelected].szSuffix.BeforeFirst(wxT(';')));
311         if (! tpi.InitLibrary(mkDlg.afInfo[nSelected].szTPIName, fnArchive.GetFullPath(), mkDlg.afInfo[nSelected].llTypeId))
312         {
313                 ::ErrDlg(wxT("InitLibrary()!"), this);
314                 return;
315         }
316
317         // \83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\82ð\90Ý\92è\81B
318         if (tpi.SetCallbackProc(TPICallbackProc) != TPI_ERROR_SUCCESS)
319         {
320                 ::ErrDlg(wxT("SetCallbackProc()!"), this);
321         }
322
323         // \8f\88\97\9d\82ð\8ds\82¤\81B
324         ProcessDialog procDlg;
325         procDlg.InitDialog();
326         procDlg.Show(true);
327         int nErrorCode = this->ErrorCheck(tpi.Command(TPI_COMMAND_ADD, & swInfo, fnArchive.GetFullPath(), mkDlg.files));
328         procDlg.Show(false);
329         tpi.FreeLibrary();
330         if (nErrorCode != TPI_ERROR_SUCCESS)
331         {
332                 return;
333         }
334
335         if (mkDlg.cbOpenAfter->IsChecked())
336         {
337                 // \8dì\90¬\90æ\82ð\8aJ\82­\81B
338 #ifdef __WINDOWS__
339                 ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());
340 #endif
341         }
342
343         if (mkDlg.cbExitAfter->IsChecked())
344         {
345                 // \8fI\97¹\81B
346                 this->Close(true);
347         }
348
349         // \8fI\97¹\82µ\82È\82¢\8fê\8d\87\82Í\8f\91\8cÉ\82ð\8aJ\82­\81B
350         e.SetString(fnArchive.GetFullPath());
351         this->OnArcOpen(e);
352 }
353
354 void MainFrame::OnArcOpen(wxCommandEvent& e)
355 {
356         // \8f\91\8cÉ\82ð\91I\91ð\81B
357         wxString szFileName = e.GetString();
358         if (szFileName.IsEmpty())
359         {
360                 wxFileDialog fd(this);
361                 fd.SetDirectory(this->fnLastOpenPath.GetFullPath());
362                 fd.SetWindowStyleFlag(wxFD_OPEN | wxFD_FILE_MUST_EXIST);
363                 if (fd.ShowModal() == wxID_CANCEL)
364                 {
365                         return;
366                 }
367                 this->fnLastOpenPath = wxFileName::DirName(fd.GetDirectory());
368                 szFileName = fd.GetPath();
369         }
370         this->OnArcClose(e);
371
372         // \90i\92»\83_\83C\83A\83\8d\83O\95\\8e¦\81B
373         ProcessDialog procDlg;
374         procDlg.InitDialog();
375         procDlg.Show(true);
376
377         // TPI\82ð\93Ç\82Ý\8d\9e\82Ý\81A\8dÅ\8f\89\82Ì\83R\81[\83\8b\83o\83b\83N\82ð\91\97\90M\81B
378         TPI_PROCESSINFO piInfo;
379         piInfo.uMessage = TPI_MESSAGE_STATUS;
380         piInfo.uStatus = 0x1000;
381         piInfo.llProcessedSize = 0;
382         piInfo.fiInfo.fnFileName = wxFileName::FileName(szFileName);
383         piInfo.fiInfo.llUnpackedSize = this->LoadTPI(szFileName);
384         if ((signed) piInfo.fiInfo.llUnpackedSize.ToULong() == -1)
385         {
386                 procDlg.Show(false);
387                 tpi.FreeLibrary();
388                 ::ErrDlg(wxT("No plug-in supporting this archive was found!"), this);
389                 return;
390         }
391         TPICallbackProc(TPI_NOTIFY_COMMON, & piInfo);
392
393         // \94z\97ñ\82Ì\83T\83C\83Y\82ð\8am\95Û\81B
394         this->fileinfo.Alloc(piInfo.fiInfo.llUnpackedSize.ToULong());
395
396         // \8f\91\8cÉ\82ð\8aJ\82­\81B
397         if (tpi.OpenArchive(szFileName) != TPI_ERROR_SUCCESS)
398         {
399                 procDlg.Show(false);
400                 tpi.FreeLibrary();
401                 ::ErrDlg(wxT("OpenArchive()!"), this);
402                 return;
403         }
404
405         // \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
406         g_hIconT.Add(wxBitmap(FE_DIR_S_ICO wxT("folder_closed.png"), wxBITMAP_TYPE_ANY));
407         g_hIconT.Add(wxBitmap(FE_DIR_S_ICO wxT("folder_open.png"), wxBITMAP_TYPE_ANY));
408         this->tree_ctrl->SetImageList(& g_hIconT);
409         wxTreeItemId
410                 idRoot = this->tree_ctrl->AddRoot(wxEmptyString),
411 #ifdef __WINDOWS__
412                 idArchive = this->tree_ctrl->AppendItem(idRoot, piInfo.fiInfo.fnFileName.GetFullName(), g_hIconT.Add(GetFileTypeIcon(piInfo.fiInfo.fnFileName))),
413 #else
414                 idArchive = this->tree_ctrl->AppendItem(idRoot, piInfo.fiInfo.fnFileName.GetFullName(), g_hIconT.Add(GetFileTypeIcon(piInfo.fiInfo.fnFileName).ConvertToImage().Rescale(16, 16))),
415 #endif
416                 idArcRoot = this->tree_ctrl->AppendItem(idRoot, wxT("-----"), 0, 1);
417
418         // \83t\83@\83C\83\8b\8fî\95ñ\82ð\83\8d\81[\83h\81B
419         if (tpi.GetFileInformation(& piInfo.fiInfo, true) == TPI_ERROR_SUCCESS)
420         {
421                 piInfo.uStatus = 0x1001;
422                 do
423                 {
424                         piInfo.llProcessedSize++;
425                         if (this->ErrorCheck(TPICallbackProc(TPI_NOTIFY_COMMON, & piInfo)) == TPI_CALLBACK_CANCEL)
426                         {
427                                 procDlg.Show(false);
428                                 tpi.CloseArchive();
429                                 wxCommandEvent e;
430                                 this->OnArcClose(e);
431                                 return;
432                         }
433
434                         // \83c\83\8a\81[\83r\83\85\81[\82É\94½\89f\81B
435                         TreeView_CheckNewerItem(this->tree_ctrl, idArcRoot, piInfo.fiInfo.fnFileName.GetPath(wxPATH_GET_VOLUME), true);
436
437                         // \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
438                         if (piInfo.fiInfo.dwAttribute & TPI_ATTRIBUTE_DIRECTORY)
439                         {
440                                 continue;
441                         }
442
443                         // \83Z\83L\83\85\83\8a\83e\83B\83`\83F\83b\83N\81B
444                         // DTV\8c\9f\8d¸\81B
445                         if (piInfo.fiInfo.fnFileName.GetPathWithSep().Find(wxT("..")) != wxNOT_FOUND)
446                         {
447                                 piInfo.fiInfo.uDanger = TRUE;
448                                 ::WrnDlg(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, this);
449                         }
450                         // \8bó\94\92\82Ì\98A\91±\82É\82æ\82é\8ag\92£\8eq\8bU\91\95\82ð\8c\9f\8d¸\81B
451                         if (piInfo.fiInfo.fnFileName.GetFullName().Find(wxT("        ")) != wxNOT_FOUND)
452                         {
453                                 piInfo.fiInfo.uDanger = TRUE;
454                                 ::WrnDlg(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, this);
455                         }
456                         // Unicode\90§\8cä\95\8e\9a\82ð\8c\9f\8d¸\81B
457                         for (wxChar c = 0x200c; c <= 0x206f; c++)
458                         {
459                                 if (piInfo.fiInfo.fnFileName.GetFullName().Find(c) != wxNOT_FOUND)
460                                 {
461                                         piInfo.fiInfo.uDanger = TRUE;
462                                         ::WrnDlg(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, this);
463                                 }
464                                 switch (c)
465                                 {
466                                 case 0x200f: c = 0x2027; break;
467                                 case 0x202e: c = 0x2060; break;
468                                 }
469                         }
470
471                         // \8fî\95ñ\82ð\95Û\91\82µ\82Ä\83J\83E\83\93\83g\83A\83b\83v\81B
472                         this->fileinfo.Add(piInfo.fiInfo);
473                 }
474                 while (tpi.GetFileInformation(& piInfo.fiInfo, false) == TPI_ERROR_SUCCESS);
475         }
476
477         // \8f\91\8cÉ\82Ì\8fî\95ñ\82ð\8eæ\93¾\81B
478         TPI_ARCHIVEINFO aiInfo;
479         if (tpi.GetArchiveInformation(& aiInfo) != TPI_ERROR_SUCCESS)
480         {
481                 procDlg.Show(false);
482                 tpi.FreeLibrary();
483                 ::ErrDlg(wxT("GetArchiveInformation()!"), this);
484                 return;
485         }
486
487         // \8f\91\8cÉ\82ð\95Â\82\82é\81B
488         if (tpi.CloseArchive() != TPI_ERROR_SUCCESS)
489         {
490                 ::ErrDlg(wxT("CloseArchive()!"), this);
491         }
492
493         // \83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\82ð\90Ý\92è\81B
494         if (tpi.SetCallbackProc(TPICallbackProc) != TPI_ERROR_SUCCESS)
495         {
496                 ::ErrDlg(wxT("SetCallbackProc()!"), this);
497         }
498
499         // \88È\89º\81AUI\8f\88\97\9d\81B
500         this->fileinfo.Shrink();
501         this->tree_ctrl->ExpandAll();
502         this->tree_ctrl->ScrollTo(idArchive);
503         this->tree_ctrl->SelectItem(idArchive);
504         this->list_ctrl->atDangerItem.SetTextColour(* wxRED);
505
506         // \83X\83e\81[\83^\83X\83o\81[\90Ý\92è\81B
507         this->statusbar->SetStatusText(aiInfo.fiInfo.szTypeName, 0);
508         this->statusbar->SetStatusText(wxString::Format(wxT("%d file(s)"), this->fileinfo.Count()), 1);
509         this->statusbar->SetStatusText(aiInfo.llUnpackedSize.ToString() + wxT(" B -> ") + aiInfo.llPackedSize.ToString()   + wxT(" B"), 2);
510         this->statusbar->SetStatusText(wxString::Format(wxT("%3.1f%%"), aiInfo.wCompressRatio / 10.0), 3);
511         this->statusbar->SetStatusText(szFileName, 4);
512
513         // \83c\81[\83\8b\83o\81[\81E\83\81\83j\83\85\81[\83o\81[\90Ý\92è\81B
514         SetMenuToolState("Arc_Close",   true);
515         SetMenuToolState("Arc_Add",     (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_ADD)    == TPI_COMMAND_ADD);
516         SetMenuToolState("Arc_SFX",     (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_SFX)    == TPI_COMMAND_SFX   && aiInfo.nSFXType == 0);
517         SetMenuToolState("Arc_UnSFX",   (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_UNSFX)  == TPI_COMMAND_UNSFX && aiInfo.nSFXType != 0);
518         SetMenuToolState("Arc_Extract", (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_EXTRACT)== TPI_COMMAND_EXTRACT);
519         SetMenuToolState("Arc_Delete",  (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_DELETE) == TPI_COMMAND_DELETE);
520         SetMenuToolState("Arc_Test",    (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_TEST)   == TPI_COMMAND_TEST);
521         SetMenuToolState("Arc_Repair",  (aiInfo.fiInfo.llSupportedCommand & TPI_COMMAND_REPAIR) == TPI_COMMAND_REPAIR);
522
523         procDlg.Show(false);
524 }
525
526 void MainFrame::OnArcClose(wxCommandEvent&)
527 {
528         // \83c\83\8a\81[\83r\83\85\81[\81E\83\8a\83X\83g\83r\83\85\81[\90Ý\92è\81B
529         this->tree_ctrl->DeleteAllItems();
530         this->list_ctrl->DeleteAllItems();
531         this->list_ctrl->showFileInfo.Clear();
532
533         // \83c\81[\83\8b\83o\81[\81E\83\81\83j\83\85\81[\83o\81[\90Ý\92è\81B
534         SetMenuToolState("Arc_Close",   false);
535         SetMenuToolState("Arc_Add",     false);
536         SetMenuToolState("Arc_SFX",     false);
537         SetMenuToolState("Arc_UnSFX",   false);
538         SetMenuToolState("Arc_Extract", false);
539         SetMenuToolState("Arc_Delete",  false);
540         SetMenuToolState("Arc_Test",    false);
541         SetMenuToolState("Arc_Repair",  false);
542
543         for (int i = 0; i < this->statusbar->GetFieldsCount(); i++)
544         {
545                 this->statusbar->SetStatusText(wxEmptyString, i);
546         }
547         this->fileinfo.Clear();
548
549         g_hIconT.RemoveAll();
550         g_hIconLL.RemoveAll();
551         g_hIconLS.RemoveAll();
552         this->tpi.FreeLibrary();
553 }
554
555 void MainFrame::OnArcAdd(wxCommandEvent& e)
556 {
557         // \8f\88\97\9d\91Î\8fÛ\82Ì\83t\83@\83C\83\8b\82ð\91I\91ð\81B
558         wxArrayString files;
559         wxFileDialog fd(this, wxT("Choose files to add"), this->fnLastOpenPath.GetFullPath());
560         fd.SetWindowStyleFlag(wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
561         if (fd.ShowModal() == wxID_CANCEL)
562         {
563                 return;
564         }
565         fd.GetFilenames(files);
566
567         // \8ae\8eí\90Ý\92è\81B
568         TPI_SWITCHES swInfo;
569         swInfo.fnDestinationDirectory = wxFileName::DirName(fd.GetDirectory());
570         swInfo.fMakeSFX = false;
571         swInfo.pCustomSwitches = NULL;
572         wxString szArcName = this->statusbar->GetStatusText(4);
573
574         ProcessDialog procDlg;
575         procDlg.InitDialog();
576         procDlg.Show(true);
577         this->ErrorCheck(this->tpi.Command(TPI_COMMAND_ADD, & swInfo, szArcName, files));
578         procDlg.Show(false);
579
580         // \8f\91\8cÉ\82ð\8dÄ\93Ç\82Ý\8d\9e\82Ý\81B
581         e.SetString(szArcName);
582         this->OnArcOpen(e);
583 }
584
585 void MainFrame::OnArcConvert(wxCommandEvent& e)
586 {
587         TPI_SWITCHES swInfo;
588         swInfo.fMakeSFX = e.GetId() == XRCID("Arc_SFX");
589
590         // \95Û\91\90æ\82ð\90q\82Ë\82é\81B
591         wxFileName fnArchive(this->statusbar->GetStatusText(4));
592         wxFileDialog fd(this, swInfo.fMakeSFX ? wxT("Save as SFX") : wxT("Save as normal archive"), fnArchive.GetPath(wxPATH_GET_VOLUME), fnArchive.GetName() + (swInfo.fMakeSFX ? EXE_EXT : (wxString) wxEmptyString));
593         fd.SetWindowStyleFlag(wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
594         if (fd.ShowModal() == wxID_CANCEL)
595         {
596                 return;
597         }
598         swInfo.fnDestinationDirectory = wxFileName::DirName(fd.GetDirectory());
599         this->fnLastOpenPath = swInfo.fnDestinationDirectory;
600
601         wxArrayString files;
602         files.Add(fd.GetPath());
603
604         ProcessDialog procDlg;
605         procDlg.InitDialog();
606         procDlg.Show(true);
607         this->ErrorCheck(this->tpi.Command(swInfo.fMakeSFX ? TPI_COMMAND_SFX : TPI_COMMAND_UNSFX, & swInfo, fnArchive.GetFullPath(), files));
608         procDlg.Show(false);
609 }
610
611 void MainFrame::OnArcExtract(wxCommandEvent& e)
612 {
613         TPI_SWITCHES swInfo;
614         swInfo.pCustomSwitches = NULL;
615
616         // \83\82\81[\83h\8eæ\93¾\81B\92Ê\8fí\82Í0, \8eÀ\8ds\82È\82ç1, \83t\83@\83C\83\8bDnD\82È\82ç2\81A\83f\83B\83\8c\83N\83g\83\8aDnD\82È\82ç3\81B
617         int nMode = e.GetInt();
618         // \8eÀ\8ds\8e\9e\82Ì\82Ý\8eg\97p\81B
619         wxFileType * ftFile = NULL;
620
621         // \93W\8aJ\83_\83C\83A\83\8d\83O\82ð\8dì\90¬\81BDnD\82Ü\82½\82Í\8eÀ\8ds\8e\9e\82Í\95\\8e¦\82µ\82È\82¢\81B
622         MakeDialog mkDlg;
623         ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_make.xrc"));
624         ::wxXmlResource::Get()->LoadDialog(& mkDlg, this, wxT("dlg_make"));
625         mkDlg.bIsMake = false;
626         mkDlg.files   = MakeTargetFileList(this, nMode == 1);
627
628         if (nMode != 0)
629         {
630                 if (nMode == 1)
631                 {
632                         // \83R\83}\83\93\83h\82ð\8eæ\93¾\81B
633                         ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(wxFileName::FileName(mkDlg.files[0]).GetExt());
634                         if (! ftFile)
635                         {
636                                 ::ErrDlg(wxT("Unable to get the file type!"), this);
637                                 return;
638                         }
639                 }
640
641                 // \8dì\8bÆ\83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81B
642                 swInfo.fStoreDirectoryPathes = false;
643                 wxString szDestDirBase = nMode == 3 ? this->tree_ctrl->GetItemText(this->tree_ctrl->GetSelection()) : wxT("tpi_tmp");
644                 if (szDestDirBase == wxT("-----"))
645                 {
646                         // \8f\91\8cÉ\83\8b\81[\83g\82Ì\82Æ\82«\82Í\8f\91\8cÉ\96¼\82É\82µ\82Ä\82¨\82­\81B
647                         szDestDirBase = wxFileName::FileName(this->statusbar->GetStatusText(4)).GetName();
648                 }
649                 swInfo.fnDestinationDirectory = MakeDirPath(wxFileName::DirName(::wxGetCwd()), szDestDirBase, true);
650                 if (! swInfo.fnDestinationDirectory.IsOk())
651                 {
652                         ::ErrDlg(wxT("Unable to make the temporary directory!"), this);
653                         return;
654                 }
655         }
656         else
657         {
658                 mkDlg.InitDialog();
659                 if (mkDlg.ShowModal() == wxID_CANCEL)
660                 {
661                         return;
662                 }
663
664                 // \8ae\8eí\90Ý\92è\81B
665                 swInfo.fStoreDirectoryPathes = ! mkDlg.cbIgnorePath->IsChecked();
666                 swInfo.fnDestinationDirectory = wxFileName::DirName(mkDlg.cbDir->GetValue());
667                 swInfo.szPassword = mkDlg.tcPassword->GetValue();
668                 swInfo.szKeyFile  = mkDlg.tcKeyfile->GetValue();
669
670                 // \95K\97v\82È\82ç\8f\91\8cÉ\96¼\82Å\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\82·\82é\81B
671                 if (WillMakeDirByArcName(this, & mkDlg))
672                 {
673                         swInfo.fnDestinationDirectory = MakeDirPath(swInfo.fnDestinationDirectory, wxFileName::FileName(this->statusbar->GetStatusText(4)).GetName(), true);
674                         if (! swInfo.fnDestinationDirectory.IsOk())
675                         {
676                                 ::ErrDlg(wxT("Unable to make the destination directory!"), this);
677                                 return;
678                         }
679                 }
680         }
681
682         ProcessDialog procDlg;
683         procDlg.InitDialog();
684         procDlg.Show(true);
685         int nErrorCode = this->ErrorCheck(this->tpi.Command(TPI_COMMAND_EXTRACT, & swInfo, this->statusbar->GetStatusText(4), mkDlg.files));
686         procDlg.Show(false);
687
688         if (nMode == 0)
689         {
690                 if (mkDlg.cbOpenAfter->IsChecked())
691                 {
692                         // \93W\8aJ\90æ\82ð\8aJ\82­\81B
693 #ifdef __WINDOWS__
694                         ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());
695 #endif
696                 }
697
698                 if (mkDlg.cbExitAfter->IsChecked())
699                 {
700                         // \8fI\97¹\81B
701                         this->Close(true);
702                 }
703         }
704         else
705         {
706                 wxArrayString asFiles;
707                 if (nMode == 1)
708                 {
709                         // \83R\83}\83\93\83h\82ð\8eÀ\8ds\81B
710                         asFiles.Add(swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName::FileName(mkDlg.files[0]).GetFullName());
711                         if (nErrorCode == TPI_ERROR_SUCCESS)
712                         {
713                                 ::wxExecute(ftFile->GetOpenCommand(asFiles[0]), wxEXEC_SYNC);
714                         }
715                 }
716                 else
717                 {
718                         // \93W\8aJ\91Î\8fÛ\82ð\8c\88\92è\81B
719                         wxFileDataObject objFile;
720                         for (size_t i = 0; i < mkDlg.files.Count(); i++)
721                         {
722                                 wxString szFileName = swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName::FileName(mkDlg.files[i]).GetFullName();
723                                 if (nMode == 2)
724                                 {
725                                         // \83\8a\83X\83g\82É\92Ç\89Á\81B
726                                         objFile.AddFile(szFileName);
727                                 }
728                                 asFiles.Add(szFileName);
729                         }
730                         if (nMode == 3)
731                         {
732                                 objFile.AddFile(swInfo.fnDestinationDirectory.GetPath());
733                         }
734
735                         // DnD\8aJ\8en\81B
736                         wxDropSource dropSource(objFile, this);
737                         if (dropSource.DoDragDrop() != wxDragMove)
738                         {
739 #ifdef __LINUX__
740                                 // 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
741                                 sleep(3);
742 #endif
743                         }
744                 }
745
746                 // \83t\83@\83C\83\8b\82Æ\88ê\8e\9e\83f\83B\83\8c\83N\83g\83\8a\82ð\8dí\8f\9c\81B
747                 for (size_t i = 0; i < asFiles.GetCount(); i++)
748                 {
749                         ::wxRemoveFile(asFiles[i]);
750                 }
751                 ::wxRmdir(swInfo.fnDestinationDirectory.GetFullPath());
752         }
753 }
754
755 void MainFrame::OnArcDelete(wxCommandEvent& e)
756 {
757         // \91S\83t\83@\83C\83\8b\8dí\8f\9c\82Í\8aë\8c¯\82Å\82Í\82È\82¢\82©\82Æ\81B
758         if (this->list_ctrl->GetSelectedItemCount() == 0)
759         {
760                 return;
761         }
762
763         if (::AskDlg(wxT("Are you sure to delete selected files?"), this) == wxNO)
764         {
765                 return;
766         }
767
768         // \8ae\8eí\90Ý\92è\81B
769         TPI_SWITCHES swInfo;
770         wxString szArcName = this->statusbar->GetStatusText(4);
771         wxArrayString files = MakeTargetFileList(this, false);
772
773         ProcessDialog procDlg;
774         procDlg.InitDialog();
775         procDlg.Show(true);
776         this->ErrorCheck(this->tpi.Command(TPI_COMMAND_DELETE, & swInfo, szArcName, files));
777         procDlg.Show(false);    
778
779         // \8f\91\8cÉ\82ð\8dÄ\93Ç\82Ý\8d\9e\82Ý\82·\82é\81B
780         e.SetString(szArcName);
781         this->OnArcOpen(e);
782 }
783
784 void MainFrame::OnArcTest(wxCommandEvent&)
785 {
786         // \8ae\8eí\90Ý\92è\81B
787         wxArrayString files = MakeTargetFileList(this, false);
788         TPI_SWITCHES swInfo;
789
790         ProcessDialog procDlg;
791         procDlg.InitDialog();
792         procDlg.Show(true);
793         if (this->ErrorCheck(this->tpi.Command(TPI_COMMAND_TEST, & swInfo, this->statusbar->GetStatusText(4), files)) == TPI_ERROR_SUCCESS)
794         {
795                 ::MsgDlg(wxT("This is a correct archive."), & procDlg, wxICON_INFORMATION);
796         }
797         procDlg.Show(false);
798 }
799
800 void MainFrame::OnArcRepair(wxCommandEvent&)
801 {
802         // \8ae\8eí\90Ý\92è\81B
803         wxArrayString files = MakeTargetFileList(this, false);
804         TPI_SWITCHES swInfo;
805
806         ProcessDialog procDlg;
807         procDlg.InitDialog();
808         procDlg.Show(true);
809         this->ErrorCheck(this->tpi.Command(TPI_COMMAND_REPAIR, & swInfo, this->statusbar->GetStatusText(4), files));
810         procDlg.Show(false);    
811 }
812
813 void MainFrame::OnViewMode(wxCommandEvent & e)
814 {
815         int n = e.GetId();
816         this->menubar->Check(n, true);
817         this->list_ctrl->SetSingleStyle(wxLC_REPORT, n == XRCID("Exe_View_Details"));
818         this->list_ctrl->SetSingleStyle(wxLC_ICON,   n == XRCID("Exe_View_Icons"));
819         this->list_ctrl->SetSingleStyle(wxLC_LIST,   n == XRCID("Exe_View_List"));
820 }
821
822 void MainFrame::OnShowToolBar(wxCommandEvent & e)
823 {
824         this->toolbar->Show(e.IsChecked());
825 }
826
827 void MainFrame::OnShowStatusBar(wxCommandEvent & e)
828 {
829         this->statusbar->Show(e.IsChecked());
830 }
831
832 void MainFrame::OnSelectAll(wxCommandEvent &)
833 {
834         for (int i = 0; i < this->list_ctrl->GetItemCount(); i++)
835         {
836                 this->list_ctrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
837         }
838 }
839
840 // TreeView
841
842 void MainFrame::OnTreeChanged(wxTreeEvent& e)
843 {
844         // \83c\83\8a\81[\83r\83\85\81[\82©\82ç\83p\83X\82ð\8eæ\93¾\81B
845         wxString szNodePath = TreeView_GetItemPath(this->tree_ctrl, e.GetItem());
846         // \83\8a\83X\83g\83r\83\85\81[\82ð\8f\89\8aú\89»\81B
847         this->list_ctrl->showFileInfo.Clear();
848         g_hIconLL.RemoveAll();
849         g_hIconLS.RemoveAll();
850
851         // \83A\83C\83R\83\93\90Ý\92è\81B
852         this->list_ctrl->SetImageList(& g_hIconLL, wxIMAGE_LIST_NORMAL);
853         this->list_ctrl->SetImageList(& g_hIconLS, wxIMAGE_LIST_SMALL);
854
855         // \94z\97ñ\82Æ\94ä\8ar\82µ\81A\83p\83X\82ª\88ê\92v\82µ\82È\82¯\82ê\82Î\8fÁ\82·\81B
856         for (size_t i = 0; i < this->fileinfo.GetCount(); i++)
857         {
858                 // \83p\83X\82ð\94ä\8ar\81B
859                 if (szNodePath == wxT("*") || szNodePath == this->fileinfo[i].fnFileName.GetPath())
860                 {
861                         // \8d\80\96Ú\82ª\83t\83H\83\8b\83_\82Å\82 \82é\82È\82ç\96³\8e\8b\81B
862                         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))
863                         {
864                                 continue;
865                         }
866
867                         // \83t\83B\83\8b\83^\82É\82©\82©\82ç\82È\82¯\82ê\82Î\96³\8e\8b\81B
868                         if (this->fileinfo[i].fnFileName.GetFullName().MakeLower().Find(this->tcFilter->GetValue().MakeLower()) == wxNOT_FOUND)
869                         {
870                                 continue;
871                         }
872
873                         this->list_ctrl->showFileInfo.Add(this->fileinfo[i]);
874                 }
875         }
876         // \83\\81[\83g\82µ\82Ä\95\\8e¦\81B
877         this->list_ctrl->showFileInfo.Sort(& ListCtrlCompareProc);
878         this->list_ctrl->SetItemCount(this->list_ctrl->showFileInfo.Count());
879 }
880
881 void MainFrame::OnTreeBeginDrag(wxTreeEvent& e)
882 {
883         // TODO : \83A\83C\83e\83\80\82ª\8eq\8aK\91w\82ð\8e\9d\82Á\82Ä\82¢\82Ä\82à\93W\8aJ\82Å\82«\82È\82¢\81B
884         this->tree_ctrl->SelectItem(e.GetItem());
885         for (int i = 0; i < this->list_ctrl->GetItemCount(); i++)\r
886         {\r
887                 this->list_ctrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);\r
888         }\r
889
890         wxCommandEvent e1;
891         e1.SetInt(3);
892         this->OnArcExtract(e1);
893 }
894
895 // ListView
896
897 void MainFrame::OnListItemDClick(wxListEvent&)
898 {
899         wxCommandEvent e;
900         e.SetInt(1);
901         this->OnArcExtract(e);
902 }
903
904 void MainFrame::OnListBeginDrag(wxListEvent&)
905 {
906         if (this->list_ctrl->GetSelectedItemCount() == 0)
907         {
908                 // \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
909                 return;
910         }
911
912         wxCommandEvent e;
913         e.SetInt(2);
914         this->OnArcExtract(e);
915 }
916
917 // Filter
918
919 void MainFrame::OnFilter(wxCommandEvent&)
920 {
921         wxTreeEvent e;
922         e.SetItem(this->tree_ctrl->GetSelection());
923         this->OnTreeChanged(e);
924 }
925
926 // \83C\83x\83\93\83g\83n\83\93\83h\83\89\88È\8aO\81B
927
928 int MainFrame::LoadTPI(wxString & szFileName)
929 {
930         // TPI\82ð\93Ç\82Ý\8d\9e\82Ý\81B
931         wxFileSystem fs;
932         fs.ChangePathTo(FE_DIR_B_LIB, true);
933         wxString szTPIName = fs.FindFirst(wxT("*" TPI_EXT), wxFILE);
934         int nFileCount = -1;
935         while (! szTPIName.IsEmpty())
936         {
937                 // \91Î\89\9e\8am\94F\81B
938                 if (! tpi.InitLibrary(szTPIName, szFileName, 0) || ! tpi.CheckArchive(szFileName, & nFileCount) || nFileCount < 0)
939                 {
940                         tpi.FreeLibrary();
941                         szTPIName = fs.FindNext();
942                         continue;
943                 }
944                 break;
945         }
946         return nFileCount;
947 }
948
949 int MainFrame::ErrorCheck(int nErrorCode)
950 {
951         switch (nErrorCode)
952         {
953         // \82Ç\82¿\82ç\82à\92l\82ªTRUE\82È\82Ì\82Å\8eb\92è\93I\82É\83R\83\81\83\93\83g\83A\83E\83g\81B
954         case TPI_ERROR_SUCCESS:
955 //      case TPI_CALLBACK_CONTINUE:
956                 break;
957         case TPI_ERROR_D_UNSUPPORTED:
958                 ::ErrDlg(wxT("Sorry, this function is not supported yet."), this);
959                 break;
960         case TPI_ERROR_D_SKIPPED:
961         case TPI_CALLBACK_CANCEL:
962                 ::ErrDlg(wxT("This operation is canceled by the user."), this);
963                 break;
964         default:
965                 ::ErrDlg(wxT("Error code is ") + wxString::Format(wxT("%d."), nErrorCode), this);
966         }
967         return nErrorCode;
968 }