OSDN Git Service

書庫を複製する機能を追加。
[tpi/lychee.git] / src / lychee / dlg_make.cpp
index 37d9674..f9c0449 100644 (file)
@@ -92,12 +92,6 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        // "Files"タブ\r
        this->lcFiles           = XRCCTRL(* this, "lcFiles",      myListCtrl2);\r
 \r
-       // 2回目以降は無視。\r
-       if (! this->cbDir->GetValue().IsEmpty())\r
-       {\r
-               return;\r
-       }\r
-\r
        // ListCtrlに列を追加。\r
        // wxGTKでは直接wxLC_VIRTUALを指定しないと反映されない。\r
        this->lcFiles->SetSingleStyle(wxLC_VIRTUAL);\r
@@ -105,6 +99,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        this->lcFiles->InsertColumn(1, _("Output"), wxLIST_FORMAT_LEFT,  290);\r
        this->lcFiles->asInput = & this->files;\r
        this->lcFiles->atDangerItem.SetTextColour(* wxRED);\r
+       this->lcFiles->atExistItem.SetTextColour(* wxBLUE);\r
 \r
        ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_make.xrc"));\r
 \r
@@ -112,28 +107,9 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        MainFrame * frm_main = (MainFrame *) this->GetParent();\r
        wxString szArcPath = frm_main->fnArchive.GetPath();\r
 \r
-       // パス履歴読み込み。\r
-       for (size_t i = 0; i < frm_main->conf.GetHistoryCount(CONF_HISTORY_PATH); i++)\r
-       {\r
-               wxString sz = frm_main->conf.ReadHistory(CONF_HISTORY_PATH, i);\r
-               if (sz.IsEmpty())\r
-               {\r
-                       continue;\r
-               }\r
-\r
-               this->cbDir->Append(sz);\r
-       }\r
-       // 書庫名履歴読み込み。\r
-       for (size_t i = 0; i < frm_main->conf.GetHistoryCount(CONF_HISTORY_NAME); i++)\r
-       {\r
-               wxString sz = frm_main->conf.ReadHistory(CONF_HISTORY_NAME, i);\r
-               if (sz.IsEmpty())\r
-               {\r
-                       continue;\r
-               }\r
-\r
-               this->cbFileName->Append(sz);\r
-       }\r
+       // 履歴読み込み。\r
+       this->myLoadHistory(CONF_HISTORY_PATH, this->cbDir);\r
+       this->myLoadHistory(CONF_HISTORY_NAME, this->cbFileName);\r
 \r
        // パスを設定。\r
        this->cbDir->SetValue(szArcPath);\r
@@ -145,6 +121,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                // 初期値を設定。\r
                this->SetTitle(_("Extract"));\r
                this->tcComment->SetValue(frm_main->aiArchive.szComment);\r
+               this->cbDir->SetFocus();\r
 \r
                // コントロールを無効化。\r
                this->scLevel->Disable();\r
@@ -195,6 +172,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
 \r
                // 書庫名を設定。初期化の都合上.を付加しておく。\r
                this->cbFileName->SetValue(frm_main->fnArchive.GetName() + wxT('.'));\r
+               this->cbFileName->SetFocus();\r
 \r
                // ライブラリを検索。\r
                TPIHandle tpi;\r
@@ -206,7 +184,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                        {\r
                                // ロード。\r
                                wxString szLibName = L_DIR_B_LIB + szTPIName;\r
-                               if (tpi.InitLibrary(szLibName, wxEmptyString, 0))\r
+                               if (tpi.InitLibrary(szLibName, wxEmptyString))\r
                                {\r
                                        // 対応する形式名を取得。\r
                                        TPI_FORMATINFO fiInfo;\r
@@ -221,7 +199,7 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
                                                                this->chType->Append(fiInfo.szTypeName);\r
                                                        }\r
                                                }\r
-                                               while (tpi.GetFormatInformation(& fiInfo, false));\r
+                                               while (tpi.GetFormatInformation(& fiInfo));\r
                                        }\r
                                        tpi.FreeLibrary();\r
                                }\r
@@ -245,12 +223,23 @@ void MakeDialog::OnInit(wxInitDialogEvent&)
        }\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
+       size_t n = this->lcFiles->asInput->GetCount();\r
+       this->lcFiles->asOutput.Alloc(n);\r
+       this->lcFiles->apItem.Alloc(n);\r
+       if (n < 3000 ||\r
+               ::AskDlg(\r
+                       this->uCommand == TPI_COMMAND_EXTRACT ?\r
+                               _("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?") :\r
+                               _("The files you want to store are too many, so it takes long to check Directory Traversal Vulnerability(DTV) problem. If you are sure the path of the files are no problem, you can skip this scanning process. Do you want to scan for DTV problem?"),\r
+                       this\r
+               ) == wxYES)\r
        {\r
                wxNotebookEvent e;\r
-               e.SetSelection(3);\r
+               e.SetSelection(4);\r
                this->OnTabChanged(e);\r
        }\r
+\r
+       this->Raise();\r
 }\r
 \r
 void MakeDialog::OnBtnDefault(wxCommandEvent&)\r
@@ -260,8 +249,7 @@ void MakeDialog::OnBtnDefault(wxCommandEvent&)
 \r
 void MakeDialog::OnBtnDesktop(wxCommandEvent&)\r
 {\r
-       wxFileName fn(wxFileName::GetHomeDir(), wxT("Desktop"));\r
-       this->cbDir->SetValue(fn.GetFullPath());\r
+       this->cbDir->SetValue(wxFileName(wxFileName::GetHomeDir(), wxT("Desktop")).GetFullPath());\r
 }\r
 \r
 void MakeDialog::OnBtnCurrent(wxCommandEvent&)\r
@@ -281,8 +269,7 @@ void MakeDialog::OnBtnBrowse(wxCommandEvent&)
 \r
 void MakeDialog::OnBtnBrowseKF(wxCommandEvent&)\r
 {\r
-       wxFileDialog fd(this);\r
-       fd.SetWindowStyleFlag(wxFD_OPEN | wxFD_FILE_MUST_EXIST);\r
+       wxFileDialog fd(this, _("Choose a key file"), wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST);\r
        if (fd.ShowModal() == wxID_OK)\r
        {\r
                this->tcKeyfile->SetValue(fd.GetPath());\r
@@ -370,9 +357,10 @@ void MakeDialog::OnTabChanged(wxNotebookEvent& e)
                return;\r
        }\r
        this->lcFiles->DeleteAllItems();\r
-       this->lcFiles->asOutput.Clear();\r
-       this->lcFiles->apItem.Clear();\r
+       this->lcFiles->asOutput.Empty();\r
+       this->lcFiles->apItem.Empty();\r
 \r
+       bool fDTVWarning = false;\r
        switch (this->uCommand)\r
        {\r
        case TPI_COMMAND_EXTRACT:\r
@@ -381,7 +369,6 @@ void MakeDialog::OnTabChanged(wxNotebookEvent& e)
                wxString szOutputRootDir = WillMakeDirByArcName((MainFrame *) this->GetParent(), this) ? MakeDirPath(wxFileName::DirName(this->cbDir->GetValue()), wxFileName(this->cbFileName->GetValue()).GetName(), false).GetPath() : this->cbDir->GetValue();\r
 \r
                // 各ファイルにパスを付加。\r
-               bool fDTVWarning = false;\r
                for (size_t i = 0; i < this->lcFiles->asInput->GetCount(); i++)\r
                {\r
                        wxString szOutputFile = szOutputRootDir + wxFileName::GetPathSeparator();\r
@@ -398,30 +385,68 @@ void MakeDialog::OnTabChanged(wxNotebookEvent& e)
                        }\r
                        else\r
                        {\r
-                               this->lcFiles->apItem.Add(NULL);\r
+                               this->lcFiles->apItem.Add(fnOutput.FileExists() || ::wxDirExists(fnOutput.GetFullPath()) ? & this->lcFiles->atExistItem : 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
-                       this->OnTabChanged(e);\r
-               }\r
                break;\r
        }\r
        case TPI_COMMAND_ADD:\r
        case TPI_COMMAND_CREATE:\r
-               // TODO : 格納パスを推測。\r
-               this->lcFiles->asOutput = * this->lcFiles->asInput;\r
-               this->lcFiles->apItem.SetCount(this->lcFiles->asInput->GetCount(), NULL);\r
+               // 格納パスを推測。\r
+               for (size_t i = 0; i < this->lcFiles->asInput->GetCount(); i++)\r
+               {\r
+                       wxFileName fnStored(this->lcFiles->asInput->Item(i));\r
+                       this->lcFiles->asOutput.Add(this->cbIgnorePath->IsChecked() ? fnStored.GetFullName() : fnStored.GetFullPath());\r
+                       fnStored = wxFileName(this->lcFiles->asOutput.Item(i));\r
+                       if (fnStored.GetPathWithSep(wxPATH_UNIX).Find(wxT("../")) != wxNOT_FOUND)\r
+                       {\r
+                               fDTVWarning = true;\r
+                               this->lcFiles->apItem.Add(& this->lcFiles->atDangerItem);\r
+                       }\r
+                       else\r
+                       {\r
+                               this->lcFiles->apItem.Add(NULL);\r
+                       }\r
+               }\r
                break;\r
        }\r
 \r
+       // DTV検査で異常があれば警告。\r
+       if (fDTVWarning)\r
+       {\r
+               wxString sz;\r
+               sz.Printf(\r
+                       _("This archive may have Directory Traversal Vulnerability(DTV) problem, %s It is strongly recommended to ignore file path. Would you like to do so?"),\r
+                       (this->uCommand == TPI_COMMAND_EXTRACT ?\r
+                               _("and some danger files may be extracted to the unexpected system directory!") :\r
+                               _("and some danger files may be stored!")\r
+                       )\r
+               );\r
+               if (::AskDlg(sz, this) == wxYES)\r
+               {\r
+                       this->cbIgnorePath->SetValue(true);\r
+                       this->OnTabChanged(e);\r
+               }\r
+       }\r
+\r
        // リストビューに表示。\r
        this->lcFiles->SetItemCount(this->lcFiles->asInput->GetCount());\r
 }\r
 \r
+void MakeDialog::myLoadHistory(myConfigId confId, wxComboBox * cb)\r
+{\r
+       MainFrame * frm_main = (MainFrame *) this->GetParent();\r
+       for (size_t i = 0; i < frm_main->conf.GetHistoryCount(confId); i++)\r
+       {\r
+               wxString sz = frm_main->conf.ReadHistory(confId, i);\r
+               if (! sz.IsEmpty())\r
+               {\r
+                       cb->Append(sz);\r
+               }\r
+       }\r
+}\r
+\r
 //******************************************************************************\r
 // myListCtrl2\r
 //******************************************************************************\r