OSDN Git Service

asInputをfilesへのポインタに変更。
[tpi/lychee.git] / src / lychee / dlg_make.cpp
index effa9e1..0fb4a6c 100644 (file)
@@ -76,18 +76,21 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        // "Config"タブ\r
        this->scLevel           = XRCCTRL(* this, "scLevel",      wxSpinCtrl);\r
        this->scRR              = XRCCTRL(* this, "scRR",         wxSpinCtrl);\r
-       this->tcPassword        = XRCCTRL(* this, "tcPassword",   wxTextCtrl);\r
-       this->tcKeyfile         = XRCCTRL(* this, "tcKeyfile",    wxTextCtrl);\r
-       this->cbSplitSize       = XRCCTRL(* this, "cbSplitSize",  wxComboBox);\r
-       this->cbUnmask          = XRCCTRL(* this, "cbUnmask",     wxCheckBox);\r
-       this->cbEncryptHeader   = XRCCTRL(* this, "cbEncryptHeader", wxCheckBox);\r
        this->cbSolid           = XRCCTRL(* this, "cbSolid",      wxCheckBox);\r
        this->cbMMOptimize      = XRCCTRL(* this, "cbMMOptimize", wxCheckBox);\r
+       this->cbCompressHeader  = XRCCTRL(* this, "cbCompressHeader", wxCheckBox);\r
        this->cbMakeSFX         = XRCCTRL(* this, "cbMakeSFX",    wxCheckBox);\r
        // "Comment"タブ\r
        this->tcComment         = XRCCTRL(* this, "tcComment",    wxTextCtrl);\r
+       // "Encryption"タブ\r
+       this->tcPassword        = XRCCTRL(* this, "tcPassword",   wxTextCtrl);\r
+       this->tcKeyfile         = XRCCTRL(* this, "tcKeyfile",    wxTextCtrl);\r
+       this->cbSplitSize       = XRCCTRL(* this, "cbSplitSize",  wxComboBox);\r
+       this->cbUnmask          = XRCCTRL(* this, "cbUnmask",     wxCheckBox);\r
+       this->cbEncryptHeader   = XRCCTRL(* this, "cbEncryptHeader", wxCheckBox);\r
+       this->chEncryptMethod   = XRCCTRL(* this, "chEncryptMethod", wxChoice);\r
        // "Files"タブ\r
-       this->lcFiles           = XRCCTRL(* this, "lcFiles",      wxListCtrl);\r
+       this->lcFiles           = XRCCTRL(* this, "lcFiles",      myListCtrl2);\r
 \r
        // 2回目以降は無視。\r
        if (! this->cbDir->GetValue().IsEmpty())\r
@@ -96,8 +99,12 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        }\r
 \r
        // ListCtrlに列を追加。\r
+       // wxGTKでは直接wxLC_VIRTUALを指定しないと反映されない。\r
+       this->lcFiles->SetSingleStyle(wxLC_VIRTUAL);\r
        this->lcFiles->InsertColumn(0, _("Input"),  wxLIST_FORMAT_LEFT,  150);\r
-       this->lcFiles->InsertColumn(1, _("Output"), wxLIST_FORMAT_LEFT,  300);\r
+       this->lcFiles->InsertColumn(1, _("Output"), wxLIST_FORMAT_LEFT,  290);\r
+       this->lcFiles->asInput = & this->files;\r
+       this->lcFiles->atDangerItem.SetTextColour(* wxRED);\r
 \r
        ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_make.xrc"));\r
 \r
@@ -139,27 +146,21 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                this->SetTitle(_("Extract"));\r
                this->tcComment->SetValue(frm_main->aiArchive.szComment);\r
 \r
-               // 展開先を予測。ただしDTVスキャンに時間がかかる場合はスキップ可能。\r
-               if (this->files.GetCount() < 3000 || ::AskDlg(_("This archive contains so many files that it takes long to check Directory Traversal Vulnerability(DTV) problem. If you are sure this archive is safe, you can skip this scanning process. Do you want to scan for DTV problem?"), this) == wxYES)\r
-               {\r
-                       wxNotebookEvent e;\r
-                       e.SetSelection(-3);\r
-                       this->OnTabChanged(e);\r
-               }\r
-\r
                // コントロールを無効化。\r
                this->scLevel->Disable();\r
                this->scRR->Disable();\r
-               this->cbEncryptHeader->Disable();\r
                this->cbSolid->Disable();\r
                this->cbMMOptimize->Disable();\r
                this->tcComment->SetEditable(false);\r
+               this->cbEncryptHeader->Disable();\r
+               this->chEncryptMethod->Disable();\r
        case TPI_COMMAND_ADD:\r
                // コントロールを無効化(展開時も)。\r
                this->cbFileName->Disable();\r
                this->chType->Disable();\r
                this->chDirMake->Enable();\r
                this->cbSplitSize->Disable();\r
+               this->cbCompressHeader->Disable();\r
                this->cbMakeSFX->Disable();\r
 \r
                // 書庫名を設定。\r
@@ -168,8 +169,6 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                // 書庫形式欄を設定。\r
                this->afInfo.Add(frm_main->aiArchive.fiInfo);\r
                this->chType->Append(frm_main->aiArchive.fiInfo.szTypeName);\r
-\r
-               // とりあえず最初の形式にしておく。\r
                this->chType->SetSelection(0);\r
                {\r
                        wxCommandEvent e;\r
@@ -186,6 +185,10 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                // コントロールを無効化(追加時のみ)。\r
                this->cbDir->Disable();\r
                this->chDirMake->Disable();\r
+               XRCCTRL(* this, "btnDefault", wxButton)->Disable();\r
+               XRCCTRL(* this, "btnDesktop", wxButton)->Disable();\r
+               XRCCTRL(* this, "btnCurrent", wxButton)->Disable();\r
+               XRCCTRL(* this, "btnBrowse",  wxButton)->Disable();\r
                break;\r
        case TPI_COMMAND_CREATE:\r
                this->SetTitle(_("Create"));\r
@@ -195,43 +198,59 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
 \r
                // ライブラリを検索。\r
                TPIHandle tpi;\r
-               wxFileSystem fs;\r
-               fs.ChangePathTo(L_DIR_B_LIB, true);\r
-               wxString szTPIName = fs.FindFirst(wxT("*" TPI_EXT), wxFILE);\r
-               while (! szTPIName.IsEmpty())\r
+               wxDir fs(L_DIR_B_LIB);\r
+               wxString szTPIName;\r
+               if (fs.GetFirst(& szTPIName,wxT("*" TPI_EXT)))\r
                {\r
-                       // ロード。\r
-                       if (tpi.InitLibrary(szTPIName, wxEmptyString, 0))\r
+                       do\r
                        {\r
-                               // 対応する形式名を取得\r
-                               TPI_FORMATINFO fiInfo;\r
-                               if (tpi.GetFormatInformation(& fiInfo, true))\r
+                               // ロード\r
+                               wxString szLibName = L_DIR_B_LIB + szTPIName;\r
+                               if (tpi.InitLibrary(szLibName, wxEmptyString, 0))\r
                                {\r
-                                       do\r
+                                       // 対応する形式名を取得。\r
+                                       TPI_FORMATINFO fiInfo;\r
+                                       if (tpi.GetFormatInformation(& fiInfo, true))\r
                                        {\r
-                                               if (fiInfo.llSupportedCommand & TPI_COMMAND_CREATE && (this->files.GetCount() == 1 || fiInfo.fArchive))\r
+                                               do\r
                                                {\r
-                                                       fiInfo.szTPIName = szTPIName;\r
-                                                       this->afInfo.Add(fiInfo);\r
-                                                       this->chType->Append(fiInfo.szTypeName);\r
+                                                       if (fiInfo.eSupportedCommand & TPI_COMMAND_CREATE && (this->lcFiles->asInput->GetCount() == 1 || fiInfo.fArchive))\r
+                                                       {\r
+                                                               fiInfo.szTPIName = szLibName;\r
+                                                               this->afInfo.Add(fiInfo);\r
+                                                               this->chType->Append(fiInfo.szTypeName);\r
+                                                       }\r
                                                }\r
+                                               while (tpi.GetFormatInformation(& fiInfo, false));\r
                                        }\r
-                                       while (tpi.GetFormatInformation(& fiInfo, false));\r
+                                       tpi.FreeLibrary();\r
                                }\r
-                               tpi.FreeLibrary();\r
                        }\r
-                       szTPIName = fs.FindNext();\r
+                       while (fs.GetNext(& szTPIName));\r
                }\r
 \r
-               // とりあえず最初の形式にしておく。\r
-               this->chType->SetSelection(0);\r
+               if (this->chType->GetCount() == 0)\r
                {\r
-                       wxCommandEvent e;\r
-                       e.SetInt(0);\r
-                       this->OnChoice(e);\r
+                       // 形式の候補が一つもない場合。\r
+                       XRCCTRL(* this, "btnOK", wxButton)->Disable();\r
+                       break;\r
                }\r
+\r
+               // とりあえず最初の形式にしておく。\r
+               this->chType->SetSelection(0);\r
+               wxCommandEvent e;\r
+               e.SetInt(0);\r
+               this->OnChoice(e);\r
                break;\r
        }\r
+\r
+       // 展開/格納先を予測。ただしDTVスキャンに時間がかかる場合はスキップ可能。\r
+       if (this->lcFiles->asInput->GetCount() < 3000 || ::AskDlg(_("This archive contains so many files that it takes long to check Directory Traversal Vulnerability(DTV) problem. If you are sure this archive is safe, you can skip this scanning process. Do you want to scan for DTV problem?"), this) == wxYES)\r
+       {\r
+               wxNotebookEvent e;\r
+               e.SetSelection(3);\r
+               this->OnTabChanged(e);\r
+       }\r
 }\r
 \r
 void MakeDialog::OnBtnDefault(wxCommandEvent&)\r
@@ -295,21 +314,24 @@ void MakeDialog::OnChoice(wxCommandEvent& e)
        // 形式が各種設定に対応しているか。\r
        // 作成時/追加時/展開時設定。\r
        this->tcPassword->Enable(fiInfo->fEncryptPassword);\r
-       this->cbUnmask->Enable(fiInfo->fEncryptPassword);\r
        this->tcKeyfile->Enable(fiInfo->fEncryptKeyFile);\r
+       this->cbUnmask->Enable(fiInfo->fEncryptPassword);\r
+       this->chEncryptMethod->Enable(fiInfo->fEncryptPassword || fiInfo->fEncryptKeyFile);\r
+       XRCCTRL(* this, "btnBrowseKF", wxButton)->Enable(fiInfo->fEncryptKeyFile);\r
        if (this->uCommand == TPI_COMMAND_EXTRACT)\r
        {\r
                return;\r
        }\r
 \r
        // 作成時/追加時設定。\r
-       this->scLevel->SetRange(fiInfo->sCompressLevelMin, fiInfo->sCompressLevelMax);\r
-       this->scLevel->SetValue(fiInfo->sCompressLevelMax);\r
-       this->scLevel->Enable(fiInfo->sCompressLevelMin != fiInfo->sCompressLevelMax);\r
-       this->scRR->SetRange(fiInfo->sRecoveryRecordMin, fiInfo->sRecoveryRecordMax);\r
-       this->scRR->SetValue(fiInfo->sRecoveryRecordMin);\r
-       this->scRR->Enable(fiInfo->sRecoveryRecordMin != fiInfo->sRecoveryRecordMax);\r
+       this->scLevel->SetRange(fiInfo->nCompressLevelMin, fiInfo->nCompressLevelMax);\r
+       this->scLevel->SetValue(fiInfo->nCompressLevelMax);\r
+       this->scLevel->Enable(fiInfo->nCompressLevelMin != fiInfo->nCompressLevelMax);\r
+       this->scRR->SetRange(fiInfo->nRecoveryRecordMin, fiInfo->nRecoveryRecordMax);\r
+       this->scRR->SetValue(fiInfo->nRecoveryRecordMin);\r
+       this->scRR->Enable(fiInfo->nRecoveryRecordMin != fiInfo->nRecoveryRecordMax);\r
        this->cbEncryptHeader->Enable(fiInfo->fEncryptHeader);\r
+       this->cbCompressHeader->Enable(fiInfo->fCompressHeader);\r
        this->cbSolid->Enable(fiInfo->fSolid);\r
        this->cbMMOptimize->Enable(fiInfo->fMMOptimize);\r
        this->tcComment->Enable(fiInfo->fComment);\r
@@ -343,21 +365,13 @@ void MakeDialog::OnCbMakeSFX(wxCommandEvent&)
 void MakeDialog::OnTabChanged(wxNotebookEvent& e)\r
 {\r
        // "Files"タブのときは処理。\r
-       bool bReallyShow = e.GetSelection() == 3;\r
-       if (abs(e.GetSelection()) != 3)\r
+       if (e.GetSelection() != 3)\r
        {\r
                return;\r
        }\r
-\r
-       // "Files"タブを表示する初回かどうか。\r
-       if (bReallyShow && this->lcFiles->GetItemCount() == 0)\r
-       {\r
-               // ファイルリストを追加。\r
-               for (size_t i = 0; i < this->files.GetCount(); i++)\r
-               {\r
-                       this->lcFiles->InsertItem(i, this->files[i]);\r
-               }\r
-       }\r
+       this->lcFiles->DeleteAllItems();\r
+       this->lcFiles->asOutput.Clear();\r
+       this->lcFiles->apItem.Clear();\r
 \r
        switch (this->uCommand)\r
        {\r
@@ -368,50 +382,70 @@ void MakeDialog::OnTabChanged(wxNotebookEvent& e)
 \r
                // 各ファイルにパスを付加。\r
                bool fDTVWarning = false;\r
-               for (size_t i = 0; i < this->files.GetCount(); i++)\r
+               for (size_t i = 0; i < this->lcFiles->asInput->GetCount(); i++)\r
                {\r
                        wxString szOutputFile = szOutputRootDir + wxFileName::GetPathSeparator();\r
-                       wxFileName fnStored(this->files[i]);\r
+                       wxFileName fnStored(this->lcFiles->asInput->Item(i));\r
                        if (! this->cbIgnorePath->IsChecked())\r
                        {\r
                                szOutputFile += fnStored.GetPathWithSep();\r
                        }\r
-                       szOutputFile += fnStored.GetFullName();\r
-                       wxFileName fnOutput(szOutputFile);\r
-                       if (! fnOutput.Normalize() || ! fnOutput.GetFullPath().StartsWith(szOutputRootDir))\r
+                       wxFileName fnOutput(szOutputFile + fnStored.GetFullName());\r
+                       if (! fnOutput.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE | wxPATH_NORM_LONG) || ! fnOutput.GetFullPath().StartsWith(szOutputRootDir))\r
                        {\r
                                fDTVWarning = true;\r
-                               if (bReallyShow)\r
-                               {\r
-                                       this->lcFiles->SetItemTextColour(i, * wxRED);\r
-                               }\r
+                               this->lcFiles->apItem.Add(& this->lcFiles->atDangerItem);\r
                        }\r
-                       if (bReallyShow)\r
+                       else\r
                        {\r
-                               this->lcFiles->SetItem(i, 1, fnOutput.GetFullPath());\r
+                               this->lcFiles->apItem.Add(NULL);\r
                        }\r
+                       this->lcFiles->asOutput.Add(fnOutput.GetFullPath());\r
                }\r
 \r
                if (fDTVWarning && ::AskDlg(_("This archive may have Directory Traversal Vulnerability(DTV) problem, and some danger files may be extracted to the unexpected system directory! It is strongly recommended to ignore file path. Would you like to do so?"), this) == wxYES)\r
                {\r
                        this->cbIgnorePath->SetValue(true);\r
-                       if (bReallyShow)\r
-                       {\r
-                               this->OnTabChanged(e);\r
-                       }\r
+                       this->OnTabChanged(e);\r
                }\r
                break;\r
        }\r
        case TPI_COMMAND_ADD:\r
        case TPI_COMMAND_CREATE:\r
-               // 格納パスを推測。\r
-               for (size_t i = 0; i < this->files.GetCount(); i++)\r
-               {\r
-                       if (bReallyShow)\r
-                       {\r
-                               this->lcFiles->SetItem(i, 1, this->files[i]);\r
-                       }\r
-               }\r
+               // TODO : 格納パスを推測。\r
+               this->lcFiles->asOutput = * this->lcFiles->asInput;\r
+               this->lcFiles->apItem.SetCount(this->lcFiles->asInput->GetCount(), NULL);\r
                break;\r
        }\r
+\r
+       // リストビューに表示。\r
+       this->lcFiles->SetItemCount(this->lcFiles->asInput->GetCount());\r
+}\r
+\r
+//******************************************************************************\r
+// myListCtrl2\r
+//******************************************************************************\r
+\r
+IMPLEMENT_DYNAMIC_CLASS(myListCtrl2, wxListView)\r
+\r
+//******************************************************************************\r
+// Event handler.\r
+//******************************************************************************\r
+wxString myListCtrl2::OnGetItemText(long i, long column) const\r
+{\r
+       // リストビューに項目を追加。\r
+       switch (column)\r
+       {\r
+       case 0:\r
+               return this->asInput->Item(i);\r
+       case 1:\r
+               return this->asOutput[i];\r
+       default:\r
+               return wxEmptyString;\r
+       }\r
+}\r
+\r
+wxListItemAttr * myListCtrl2::OnGetItemAttr(long i) const\r
+{\r
+       return (wxListItemAttr *) this->apItem[i];\r
 }\r