OSDN Git Service

C++11のrange-based forを用いて書き直し。
[tpi/lychee.git] / src / lychee / frm_main.cpp
index 52134ce..beafc25 100644 (file)
@@ -277,11 +277,13 @@ void MainFrame::OnArcCreate(wxCommandEvent& e)
                mkDlg.files = * (wxArrayString *) e.GetClientData();\r
                swInfo.fnDestinationDirectory = wxFileName::DirName(wxFileName(mkDlg.files[0]).GetPath());\r
                // 相対パスに変換。\r
+//             for (auto s : mkDlg.files)\r
                for (size_t n = 0; n < mkDlg.files.GetCount(); n++)\r
                {\r
-                       wxFileName fn(mkDlg.files[n]);\r
+                       wxString & s = mkDlg.files[n];\r
+                       wxFileName fn(s);\r
                        fn.MakeRelativeTo(swInfo.fnDestinationDirectory.GetPath());\r
-                       mkDlg.files[n] = fn.GetFullPath();\r
+                       s = fn.GetFullPath();\r
                }\r
        }\r
 \r
@@ -432,7 +434,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                idArcRoot = this->tree_ctrl->AppendItem(idRoot, wxT("-----"), 0, 1);\r
 \r
        // 巨大書庫のときにファイル名検査を省略するか。\r
-       bool bDTVCheck = piInfo.fiInfo.nUnpackedSize < 10000 || 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) == wxNO;\r
+       bool bDTVCheck = true;//piInfo.fiInfo.nUnpackedSize < 10000 || 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) == wxNO;\r
 \r
        // ファイル情報をロード。\r
        if (tpi.GetFileInformation(& piInfo.fiInfo, true))\r
@@ -451,93 +453,98 @@ 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
+                       this->fileinfo.Add(piInfo.fiInfo);\r
+               }\r
+               while (tpi.GetFileInformation(& piInfo.fiInfo));\r
+       }\r
+\r
+       // GetFileInformationがエラー終了した場合。\r
+       this->ErrorCheck(tpi.nErrorCode, wxT("GetFileInformation"));\r
 \r
-                       // セキュリティチェック。\r
-                       // ルート記号を削除。\r
-                       wxString szPath = piInfo.fiInfo.fnFileName.GetPathWithSep(wxPATH_UNIX);\r
-                       if (szPath.StartsWith(wxT("/")) || szPath.StartsWith(wxT("./")))\r
+//     for (auto f : this->fileinfo)\r
+       for (size_t i = 0; i < this->fileinfo.GetCount(); i++)\r
+       {\r
+               TPI_FILEINFO & f = this->fileinfo[i];\r
+               // 拡張子のみ設定されている場合。\r
+               if (f.szStoredName.IsEmpty())\r
+               {\r
+                       f.szStoredName = this->fnArchive.GetName();\r
+                       if (f.fnFileName.HasExt())\r
                        {\r
-                               piInfo.fiInfo.fnFileName = wxFileName(szPath.AfterFirst(wxT('/')), piInfo.fiInfo.fnFileName.GetFullName(), wxPATH_DOS);\r
+                               f.szStoredName += wxT('.') + f.fnFileName.GetExt();\r
                        }\r
-                       // ルートメンバの情報は無視する。\r
-                       if (piInfo.fiInfo.fnFileName.GetFullPath().IsEmpty() || piInfo.fiInfo.fnFileName.GetFullPath() == wxT("."))\r
+                       f.fnFileName = wxFileName(f.szStoredName);\r
+               }\r
+\r
+               // セキュリティチェック。\r
+               // ルート記号を削除。\r
+               wxString szPath = f.fnFileName.GetPathWithSep(wxPATH_UNIX);\r
+               if (szPath.StartsWith(wxT("/")) || szPath.StartsWith(wxT("./")))\r
+               {\r
+                       f.fnFileName = wxFileName(szPath.AfterFirst(wxT('/')), f.fnFileName.GetFullName(), wxPATH_DOS);\r
+               }\r
+               // ルートメンバの情報は無視する。\r
+               if (f.fnFileName.GetFullPath().IsEmpty() || f.fnFileName.GetFullPath() == wxT("."))\r
+               {\r
+                       continue;\r
+               }\r
+\r
+               // 改行文字/タブ文字などを削除。\r
+               if (f.szStoredName.Find(wxT('\r')) != wxNOT_FOUND\r
+               ||  f.szStoredName.Find(wxT('\n')) != wxNOT_FOUND\r
+               ||  f.szStoredName.Find(wxT('\t')) != wxNOT_FOUND)\r
+               {\r
+                       wxString sz = f.fnFileName.GetFullPath();\r
+                       sz.Replace(wxT("\r"), wxT(" "));\r
+                       sz.Replace(wxT("\n"), wxT(" "));\r
+                       sz.Replace(wxT("\t"), wxT(" "));\r
+                       f.eDanger = TRUE;\r
+                       f.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"), f.fnFileName.GetFullPath().c_str());\r
+               }\r
+\r
+               if (bDTVCheck)\r
+               {\r
+                       // DTV検査。\r
+                       if (f.fnFileName.GetPathWithSep(wxPATH_UNIX).Find(wxT("../")) != wxNOT_FOUND)\r
                        {\r
-                               continue;\r
+                               f.eDanger = TRUE;\r
+                               wxLogWarning(_("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%s"), f.fnFileName.GetFullPath().c_str());\r
                        }\r
-\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
+                       if (f.fnFileName.GetFullName().Find(wxT("        ")) != 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
+                               f.eDanger = TRUE;\r
+                               wxLogWarning(_("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%s"), f.fnFileName.GetFullPath().c_str());\r
                        }\r
-\r
-                       if (bDTVCheck)\r
+                       // Unicode制御文字を検査。\r
+                       for (wxChar c = 0x200c; c <= 0x206f; c++)\r
                        {\r
-                               // DTV検査。\r
-                               if (piInfo.fiInfo.fnFileName.GetPathWithSep(wxPATH_UNIX).Find(wxT("../")) != wxNOT_FOUND)\r
-                               {\r
-                                       piInfo.fiInfo.eDanger = TRUE;\r
-                                       wxLogWarning(_("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%s"), piInfo.fiInfo.fnFileName.GetFullPath().c_str());\r
-                               }\r
-                               // 空白の連続による拡張子偽装を検査。\r
-                               if (piInfo.fiInfo.fnFileName.GetFullName().Find(wxT("        ")) != wxNOT_FOUND)\r
+                               if (f.fnFileName.GetFullName().Find(c) != wxNOT_FOUND)\r
                                {\r
-                                       piInfo.fiInfo.eDanger = TRUE;\r
-                                       wxLogWarning(_("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%s"), piInfo.fiInfo.fnFileName.GetFullPath().c_str());\r
+                                       f.eDanger = TRUE;\r
+                                       wxLogWarning(_("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%s"), f.fnFileName.GetFullPath().c_str());\r
                                }\r
-                               // Unicode制御文字を検査。\r
-                               for (wxChar c = 0x200c; c <= 0x206f; c++)\r
+                               switch (c)\r
                                {\r
-                                       if (piInfo.fiInfo.fnFileName.GetFullName().Find(c) != wxNOT_FOUND)\r
-                                       {\r
-                                               piInfo.fiInfo.eDanger = TRUE;\r
-                                               wxLogWarning(_("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%s"), piInfo.fiInfo.fnFileName.GetFullPath().c_str());\r
-                                       }\r
-                                       switch (c)\r
-                                       {\r
-                                       case 0x200f: c = 0x2027; break;\r
-                                       case 0x202e: c = 0x2060; break;\r
-                                       }\r
+                               case 0x200f: c = 0x2027; break;\r
+                               case 0x202e: c = 0x2060; break;\r
                                }\r
                        }\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
-                               continue;\r
-                       }\r
+               // ツリービューに反映。\r
+               bool fDir = f.dwAttribute & TPI_ATTRIBUTE_DIRECTORY ? true : false;\r
+               TreeView_CheckNewerItem(this->tree_ctrl, idArcRoot, fDir ? f.fnFileName.GetFullPath() : f.fnFileName.GetPath(), true);\r
 \r
-                       // 情報を保存してカウントアップ。\r
-                       this->fileinfo.Add(piInfo.fiInfo);\r
+               // ディレクトリ属性を含むものについては情報を保存しない。\r
+               if (fDir)\r
+               {\r
+                       continue;\r
                }\r
-               while (tpi.GetFileInformation(& piInfo.fiInfo));\r
        }\r
 \r
-       // GetFileInformationがエラー終了した場合。\r
-       this->ErrorCheck(tpi.nErrorCode, wxT("GetFileInformation"));\r
-\r
        // 書庫の情報を取得。\r
        tpi.GetArchiveInformation(& this->aiArchive);\r
        this->ErrorCheck(tpi.nErrorCode, wxT("GetArchiveInformation"));\r
@@ -552,17 +559,17 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
 \r
        // 以下、UI処理。\r
        this->fileinfo.Shrink();\r
-       if (this->fileinfo.Count() < 10000)\r
+//     if (this->fileinfo.Count() < 10000)\r
        {\r
                this->tree_ctrl->ExpandAll();\r
                this->tree_ctrl->SelectItem(idArchive);\r
        }\r
-       else\r
+/*     else\r
        {\r
                // ファイル数が多いとソートに時間がかかるので、書庫のルートを表示させる。\r
                this->tree_ctrl->Expand(idArcRoot);\r
                this->tree_ctrl->SelectItem(idArcRoot);\r
-       }\r
+       }*/\r
        // ツリービューの位置合わせ。\r
        this->tree_ctrl->ScrollTo(idArchive);\r
        this->tree_ctrl->SetScrollPos(wxHORIZONTAL, 0);\r
@@ -713,11 +720,13 @@ void MainFrame::OnArcAdd(wxCommandEvent& e)
                mkDlg.files = * (wxArrayString *) e.GetClientData();\r
                swInfo.fnDestinationDirectory = wxFileName::DirName(wxFileName(mkDlg.files[0]).GetPath());\r
                // 相対パスに変換。\r
+//             for (auto s : mkDlg.files)\r
                for (size_t n = 0; n < mkDlg.files.GetCount(); n++)\r
                {\r
-                       wxFileName fn(mkDlg.files[n]);\r
+                       wxString & s = mkDlg.files[n];\r
+                       wxFileName fn(s);\r
                        fn.MakeRelativeTo(swInfo.fnDestinationDirectory.GetPath());\r
-                       mkDlg.files[n] = fn.GetFullPath();\r
+                       s = fn.GetFullPath();\r
                }\r
        }\r
 \r
@@ -919,9 +928,11 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                        wxArrayString asFiles;\r
                        myFileDataObject * objFile = new myFileDataObject();\r
                        objFile->szTempDir = nMode == 3 ? swInfo.fnDestinationDirectory.GetPath() : swInfo.fnDestinationDirectory.GetFullPath();\r
-                       for (size_t i = 0; i < mkDlg.files.GetCount(); i++)\r
+//                     for (auto s : mkDlg.files)\r
+                       for (size_t n = 0; n < mkDlg.files.GetCount(); n++)\r
                        {\r
-                               wxString szFileName = swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName(mkDlg.files[i], wxPATH_DOS).GetFullName();\r
+                               wxString & s = mkDlg.files[n];\r
+                               wxString szFileName = swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName(s, wxPATH_DOS).GetFullName();\r
                                if (nMode == 3)\r
                                {\r
                                        asFiles.Add(szFileName);\r
@@ -961,10 +972,12 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                                // ディレクトリDnDのときは、先にディレクトリの中のファイルを消しておく。\r
                                if (nMode == 3)\r
                                {\r
+//                                     for (auto s : asFiles)\r
                                        for (size_t i = 0; i < asFiles.GetCount(); i++)\r
                                        {\r
-                                               chmod(asFiles[i].ToUTF8(), 0600);\r
-                                               ::wxRemoveFile(asFiles[i]);\r
+                                               wxString & s = asFiles[i];\r
+                                               chmod(s.ToUTF8(), 0600);\r
+                                               ::wxRemoveFile(s);\r
                                        }\r
                                }\r
 \r
@@ -1103,24 +1116,26 @@ void MainFrame::OnTreeChanged(wxTreeEvent& e)
        this->list_ctrl->SetImageList(& g_hIconLS, wxIMAGE_LIST_SMALL);\r
 \r
        // 配列と比較し、パスが一致しなければ消す。\r
+//     for (auto f : this->fileinfo)\r
        for (size_t i = 0; i < this->fileinfo.GetCount(); i++)\r
        {\r
                // パスを比較。\r
-               if (szNodePath == wxT("*") || szNodePath == this->fileinfo[i].fnFileName.GetPath())\r
+               TPI_FILEINFO & f = this->fileinfo[i];\r
+               if (szNodePath == wxT("*") || szNodePath == f.fnFileName.GetPath())\r
                {\r
                        // 項目がフォルダであるなら無視。\r
-                       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))\r
+                       if (f.fnFileName.IsDir() || ! TreeView_CheckNewerItem(this->tree_ctrl, this->tree_ctrl->GetLastChild(this->tree_ctrl->GetRootItem()), f.fnFileName.GetFullPath(), false))\r
                        {\r
                                continue;\r
                        }\r
 \r
                        // フィルタにかからなければ無視。\r
-                       if (this->fileinfo[i].fnFileName.GetFullName().MakeLower().Find(this->tcFilter->GetValue().MakeLower()) == wxNOT_FOUND)\r
+                       if (f.fnFileName.GetFullName().MakeLower().Find(this->tcFilter->GetValue().MakeLower()) == wxNOT_FOUND)\r
                        {\r
                                continue;\r
                        }\r
 \r
-                       this->list_ctrl->apShowFile.Add(& this->fileinfo[i]);\r
+                       this->list_ctrl->apShowFile.Add(& f);\r
                }\r
        }\r
 \r