OSDN Git Service

Linux上でのDnD展開で、ファイル名が多バイト文字になっていた場合にコピーに失敗していたバグを修正。
[tpi/lychee.git] / src / lychee / frm_main.cpp
index 3a3d9d8..b988e9a 100644 (file)
@@ -153,6 +153,7 @@ void MainFrame::OnInit(wxInitDialogEvent&)
        }\r
        wxCommandEvent e;\r
        this->OnArcClose(e);\r
+       this->SetDropTarget(new myFileDropTarget(this));\r
 \r
        // スプリッター設定。\r
        this->window_splitter->SetSashPosition(this->conf.ReadId(CONF_WINDOW_SPLITTER_POS, 200l));\r
@@ -175,7 +176,6 @@ void MainFrame::OnInit(wxInitDialogEvent&)
        this->list_ctrl->InsertColumn(9, _("No."),           wxLIST_FORMAT_RIGHT,  this->conf.ReadId(CONF_LISTVIEW_C_NO,        35l));\r
        g_nSortColumn = this->conf.ReadId(CONF_LISTVIEW_S_COLUMN, 9l);\r
        g_fSortAscend = this->conf.ReadId(CONF_LISTVIEW_S_ASCEND, true);\r
-       this->list_ctrl->SetDropTarget(new myFileDropTarget(this));\r
 \r
        // ツールバー/ステータスバー設定。\r
        int nStatusBarParts[] = {70, 70, 180, 50, -1};\r
@@ -264,14 +264,14 @@ void MainFrame::OnArcCreate(wxCommandEvent& e)
        this->fnArchive = wxFileName(mkDlg.cbDir->GetValue(), mkDlg.cbFileName->GetValue());\r
        if (! tpi.InitLibrary(mkDlg.afInfo[nSelected].szTPIName, this->fnArchive.GetFullPath(), mkDlg.afInfo[nSelected].nTypeId))\r
        {\r
-               ::wxLogError(_("Error: %s!"), wxT("InitLibrary()!"));\r
+               wxLogError(_("Error: %s!"), wxT("InitLibrary()!"));\r
                return;\r
        }\r
 \r
        // コールバック関数を設定。\r
        if (! tpi.SetCallbackProc(TPICallbackProc))\r
        {\r
-               ::wxLogError(_("Error: %s!"), wxT("SetCallbackProc()!"));\r
+               wxLogError(_("Error: %s!"), wxT("SetCallbackProc()!"));\r
        }\r
 \r
        // 処理を行う。\r
@@ -299,9 +299,7 @@ void MainFrame::OnArcCreate(wxCommandEvent& e)
        if (mkDlg.cbOpenAfter->IsChecked())\r
        {\r
                // 作成先を開く。\r
-#ifdef __WINDOWS__\r
-               ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());\r
-#endif\r
+               ::wxExecute(DIR_APP + swInfo.fnDestinationDirectory.GetFullPath());\r
        }\r
 \r
        if (mkDlg.cbExitAfter->IsChecked())\r
@@ -341,12 +339,12 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
        piInfo.eStatus = 0x1000;\r
        piInfo.nProcessedSize = 0;\r
        piInfo.fiInfo.fnFileName = this->fnArchive;\r
-       piInfo.fiInfo.nUnpackedSize = this->LoadTPI(this->fnArchive.GetFullPath());\r
+       piInfo.fiInfo.nUnpackedSize = e.GetExtraLong() != 0 ? e.GetExtraLong() : this->LoadTPI(this->fnArchive.GetFullPath());\r
        if (piInfo.fiInfo.nUnpackedSize == 0)\r
        {\r
                procDlg.Show(false);\r
                tpi.FreeLibrary();\r
-               ::wxLogError(_("No plug-in supporting this archive was found!"));\r
+               wxLogError(_("No plug-in supporting this archive was found!"));\r
                return;\r
        }\r
        procDlg.CallbackProc(TPI_NOTIFY_COMMON, & piInfo);\r
@@ -359,7 +357,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
        {\r
                procDlg.Show(false);\r
                tpi.FreeLibrary();\r
-               ::wxLogError(_("Error: %s!"), wxT("OpenArchive()"));\r
+               wxLogError(_("Error: %s!"), wxT("OpenArchive()"));\r
                return;\r
        }\r
 \r
@@ -411,13 +409,13 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                        if (piInfo.fiInfo.fnFileName.GetPathWithSep().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
+                               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
                        {\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
+                               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
                        }\r
                        // Unicode制御文字を検査。\r
                        for (wxChar c = 0x200c; c <= 0x206f; c++)\r
@@ -425,7 +423,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
                                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
+                                       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
@@ -443,19 +441,19 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
        // GetFileInformationがエラー終了した場合。\r
        if (tpi.nErrorCode != TPI_ERROR_S_ENDOFDATA)\r
        {\r
-               ::wxLogError(_("Error: %s!"), wxT("GetFileInformation()"));\r
+               wxLogError(_("Error: %s!"), wxT("GetFileInformation()"));\r
        }\r
 \r
        // 書庫の情報を取得。\r
        if (! tpi.GetArchiveInformation(& this->aiArchive))\r
        {\r
-               ::wxLogError(_("Error: %s!"), wxT("GetArchiveInformation()"));\r
+               wxLogError(_("Error: %s!"), wxT("GetArchiveInformation()"));\r
        }\r
 \r
        // 書庫を閉じる。\r
        if (! tpi.CloseArchive())\r
        {\r
-               ::wxLogError(_("Error: %s!"), wxT("CloseArchive()"));\r
+               wxLogError(_("Error: %s!"), wxT("CloseArchive()"));\r
        }\r
 \r
        // 以下、UI処理。\r
@@ -486,7 +484,7 @@ void MainFrame::OnArcOpen(wxCommandEvent& e)
        procDlg.Show(false);\r
 }\r
 \r
-void MainFrame::OnArcClose(wxCommandEvent&)\r
+void MainFrame::OnArcClose(wxCommandEvent& e)\r
 {\r
        // ツリービュー・リストビュー設定。\r
        this->tree_ctrl->DeleteAllItems();\r
@@ -518,7 +516,12 @@ void MainFrame::OnArcClose(wxCommandEvent&)
        g_hIconT.RemoveAll();\r
        g_hIconLL.RemoveAll();\r
        g_hIconLS.RemoveAll();\r
-       this->tpi.FreeLibrary();\r
+\r
+       // DnDで書庫を開くときは既に読み込まれているTPIを用いるので、解放してはいけない。\r
+       if (e.GetExtraLong() == 0)\r
+       {\r
+               this->tpi.FreeLibrary();\r
+       }\r
 }\r
 \r
 void MainFrame::OnArcAdd(wxCommandEvent& e)\r
@@ -583,9 +586,7 @@ void MainFrame::OnArcAdd(wxCommandEvent& e)
        if (mkDlg.cbOpenAfter->IsChecked())\r
        {\r
                // 作成先を開く。\r
-#ifdef __WINDOWS__\r
-               ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());\r
-#endif\r
+               ::wxExecute(DIR_APP + swInfo.fnDestinationDirectory.GetFullPath());\r
        }\r
 \r
        if (mkDlg.cbExitAfter->IsChecked())\r
@@ -654,7 +655,7 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                                ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(this->conf.ReadId(CONF_DEFAULT_EXT, (wxString) wxT("txt")));\r
                                if (! ftFile)\r
                                {\r
-                                       ::wxLogError(_("Unable to get the file type!"));\r
+                                       wxLogError(_("Unable to get the file type!"));\r
                                        return;\r
                                }\r
                        }\r
@@ -663,15 +664,16 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                // 作業ディレクトリ作成。\r
                swInfo.fStoreDirectoryPathes = false;\r
                wxString szDestDirBase = nMode == 3 ? this->tree_ctrl->GetItemText(this->tree_ctrl->GetSelection()) : wxT("tpi_tmp");\r
+               wxStandardPaths p;\r
                if (szDestDirBase == wxT("-----"))\r
                {\r
                        // 書庫ルートのときは書庫名にしておく。\r
                        szDestDirBase = this->fnArchive.GetName();\r
                }\r
-               swInfo.fnDestinationDirectory = MakeDirPath(wxFileName::DirName(::wxGetCwd()), szDestDirBase, true);\r
+               swInfo.fnDestinationDirectory = MakeDirPath(wxFileName::DirName(p.GetTempDir()), szDestDirBase, true);\r
                if (! swInfo.fnDestinationDirectory.IsOk())\r
                {\r
-                       ::wxLogError(_("Unable to make the temporary directory!"));\r
+                       wxLogError(_("Unable to make the temporary directory!"));\r
                        return;\r
                }\r
        }\r
@@ -694,7 +696,7 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                        swInfo.fnDestinationDirectory = MakeDirPath(swInfo.fnDestinationDirectory, this->fnArchive.GetName(), true);\r
                        if (! swInfo.fnDestinationDirectory.IsOk())\r
                        {\r
-                               ::wxLogError(_("Unable to make the destination directory!"));\r
+                               wxLogError(_("Unable to make the destination directory!"));\r
                                return;\r
                        }\r
                }\r
@@ -725,9 +727,7 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                if (mkDlg.cbOpenAfter->IsChecked())\r
                {\r
                        // 展開先を開く。\r
-#ifdef __WINDOWS__\r
-                       ::wxExecute(wxT("explorer ") + swInfo.fnDestinationDirectory.GetFullPath());\r
-#endif\r
+                       ::wxExecute(DIR_APP + swInfo.fnDestinationDirectory.GetFullPath());\r
                }\r
 \r
                if (mkDlg.cbExitAfter->IsChecked())\r
@@ -755,8 +755,12 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                }\r
                else\r
                {\r
-                       // 展開対象を決定。\r
+                       // 展開対象を決定。wxGTKのwxFileDataObjectでは多バイト文字の扱いに問題があるので代替。\r
+#ifdef __LINUX__\r
+                       myFileDataObject objFile;\r
+#else\r
                        wxFileDataObject objFile;\r
+#endif\r
                        for (size_t i = 0; i < mkDlg.files.GetCount(); i++)\r
                        {\r
                                wxString szFileName = swInfo.fnDestinationDirectory.GetPathWithSep() + wxFileName(mkDlg.files[i], wxPATH_DOS).GetFullName();\r
@@ -772,15 +776,20 @@ void MainFrame::OnArcExtract(wxCommandEvent& e)
                                objFile.AddFile(swInfo.fnDestinationDirectory.GetPath());\r
                        }\r
 \r
+                       // 自身にドロップされると煩雑なので、一時的にドロップを受け付けないようにしておく。\r
+                       this->SetDropTarget(NULL);\r
+\r
                        // DnD開始。\r
                        wxDropSource dropSource(objFile, this);\r
-                       if (dropSource.DoDragDrop() != wxDragMove)\r
+                       wxDragResult drResult = dropSource.DoDragDrop(wxDrag_DefaultMove);\r
+                       if (drResult != wxDragCancel && drResult != wxDragNone && drResult != wxDragMove)\r
                        {\r
 #ifdef __LINUX__\r
                                // Linuxではまだ処理が終わっていない(コンテキストメニューが表示されている)ので、とりあえず3秒だけ待つ。\r
                                sleep(3);\r
 #endif\r
                        }\r
+                       this->SetDropTarget(new myFileDropTarget(this));\r
                }\r
 \r
                // ファイルと一時ディレクトリを削除。\r
@@ -852,7 +861,7 @@ void MainFrame::OnArcTest(wxCommandEvent&)
 \r
        if (bIsCorrect)\r
        {\r
-               ::wxLogMessage(_("This is a correct archive."));\r
+               wxLogMessage(_("This is a correct archive."));\r
        }\r
        else\r
        {\r
@@ -1046,14 +1055,14 @@ int MainFrame::ErrorCheck(int nErrorCode)
        case TPI_CALLBACK_CONTINUE:\r
                break;\r
        case TPI_ERROR_D_UNSUPPORTED:\r
-               ::wxLogError(_("Sorry, this function is not supported yet."));\r
+               wxLogError(_("Sorry, this function is not supported yet."));\r
                break;\r
        case TPI_ERROR_D_SKIPPED:\r
        case TPI_CALLBACK_CANCEL:\r
-               ::wxLogError(_("This operation is canceled by the user."));\r
+               wxLogError(_("This operation is canceled by the user."));\r
                break;\r
        default:\r
-               ::wxLogError(_("Error code: %d"), nErrorCode);\r
+               wxLogError(_("Error code: %d"), nErrorCode);\r
        }\r
        return nErrorCode;\r
 }\r