OSDN Git Service

改行文字やタブ文字を名前に含むファイルを含む書庫を開こうとした場合に警告する機能を追加。
[tpi/lychee.git] / src / lychee / frm_main.cpp
index 4f680b8..3a02ef6 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************\r
+/*******************************************************************************\r
   TPI - flexible but useless plug-in framework.\r
   Copyright (C) 2002-2009 Silky\r
 \r
@@ -316,8 +316,11 @@ void MainFrame::OnArcCreate(wxCommandEvent& e)
 \r
 void MainFrame::OnArcOpen(wxCommandEvent& e)\r
 {\r
+       // モード取得。通常は0, それ以外で開く場合は1, ファイルDnDなら2。\r
+       int nMode = e.GetInt() == 2 ? 2 : e.GetId() == XRCID("Arc_Open") ? 0 : 1;\r
+\r
        // 書庫を選択。\r
-       if (e.GetId() == XRCID("Arc_Open"))\r
+       if (nMode == 0)\r
        {\r
                wxFileDialog fd(this, _("Choose an archive"), this->conf.ReadHistory(CONF_HISTORY_PATH, 0), wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_OPEN | wxFD_FILE_MUST_EXIST);\r
                if (fd.ShowModal() == wxID_CANCEL)\r
@@ -335,7 +338,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
        // DnD以外で書庫を開く場合、TPIを読み込み。\r
        TPI_PROCESSINFO piInfo;\r
        piInfo.fiInfo.nUnpackedSize = e.GetExtraLong();\r
-       if (e.GetInt() != 1 && ! this->LoadTPI(this->fnArchive.GetFullPath(), & piInfo.fiInfo.nUnpackedSize))\r
+       if (nMode != 2 && ! this->LoadTPI(this->fnArchive.GetFullPath(), & piInfo.fiInfo.nUnpackedSize))\r
        {\r
                procDlg.Show(false);\r
                tpi.FreeLibrary();\r
@@ -396,6 +399,18 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                                return;\r
                        }\r
 \r
+                       // 拡張子のみ設定されている場合。\r
+                       if (piInfo.fiInfo.szStoredName.IsEmpty())\r
+                       {\r
+                               piInfo.fiInfo.szStoredName = this->fnArchive.GetName();\r
+                               if (piInfo.fiInfo.fnFileName.HasExt())\r
+                               {\r
+                                       piInfo.fiInfo.szStoredName += wxT('.') + piInfo.fiInfo.fnFileName.GetExt();\r
+                               }\r
+                               piInfo.fiInfo.fnFileName = wxFileName(piInfo.fiInfo.szStoredName);\r
+                       }\r
+\r
+                       // セキュリティチェック。\r
                        // ルート記号を削除。\r
                        wxString szPath = piInfo.fiInfo.fnFileName.GetPathWithSep(wxPATH_UNIX);\r
                        if (szPath.StartsWith(wxT("/")))\r
@@ -403,11 +418,20 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                                piInfo.fiInfo.fnFileName = wxFileName(szPath.AfterFirst(wxT('/')), piInfo.fiInfo.fnFileName.GetFullName(), wxPATH_DOS);\r
                        }\r
 \r
-                       // ツリービューに反映。\r
-                       bool fDir = piInfo.fiInfo.dwAttribute & TPI_ATTRIBUTE_DIRECTORY ? true : false;\r
-                       TreeView_CheckNewerItem(this->tree_ctrl, idArcRoot, fDir ? piInfo.fiInfo.fnFileName.GetFullPath() : piInfo.fiInfo.fnFileName.GetPath(), true);\r
+                       // 改行文字/タブ文字などを削除。\r
+                       if (piInfo.fiInfo.szStoredName.Find(wxT('\r')) != wxNOT_FOUND\r
+                       ||  piInfo.fiInfo.szStoredName.Find(wxT('\n')) != wxNOT_FOUND\r
+                       ||  piInfo.fiInfo.szStoredName.Find(wxT('\t')) != wxNOT_FOUND)\r
+                       {\r
+                               wxString sz = piInfo.fiInfo.fnFileName.GetFullPath();\r
+                               sz.Replace(wxT("\r"), wxT(" "));\r
+                               sz.Replace(wxT("\n"), wxT(" "));\r
+                               sz.Replace(wxT("\t"), wxT(" "));\r
+                               piInfo.fiInfo.eDanger = TRUE;\r
+                               piInfo.fiInfo.fnFileName = wxFileName(sz);\r
+                               wxLogWarning(_("This archive may contain files whose name contains some special characters like CR(\\r), LF(\\n), Tab(\\t) and some problem would be happen if you extract these files. Don\'t extract these files carelessly.\nDanger file is:\n%s"), piInfo.fiInfo.fnFileName.GetFullPath().c_str());\r
+                       }\r
 \r
-                       // セキュリティチェック。\r
                        // DTV検査。\r
                        if (piInfo.fiInfo.fnFileName.GetPathWithSep(wxPATH_UNIX).Find(wxT("../")) != wxNOT_FOUND)\r
                        {\r
@@ -435,6 +459,10 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                                }\r
                        }\r
 \r
+                       // ツリービューに反映。\r
+                       bool fDir = piInfo.fiInfo.dwAttribute & TPI_ATTRIBUTE_DIRECTORY ? true : false;\r
+                       TreeView_CheckNewerItem(this->tree_ctrl, idArcRoot, fDir ? piInfo.fiInfo.fnFileName.GetFullPath() : piInfo.fiInfo.fnFileName.GetPath(), true);\r
+\r
                        // ディレクトリ属性を含むものについては情報を保存しない。\r
                        if (fDir)\r
                        {\r
@@ -818,6 +846,7 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                                {\r
                                        for (size_t i = 0; i < asFiles.GetCount(); i++)\r
                                        {\r
+                                               chmod(asFiles[i].ToUTF8(), 0600);\r
                                                ::wxRemoveFile(asFiles[i]);\r
                                        }\r
                                }\r