OSDN Git Service

na-get-lib, 7-Zipがインストールされているならば 7z.exe で展開するコードを追加 (cab他対策)。
[applistation/AppliStation.git] / na-get-lib / NaGet.InteropServices / CommonArchiverExtracter.cs
index 1d3d3c3..714d812 100644 (file)
@@ -36,6 +36,49 @@ namespace NaGet.InteropServices
        }\r
        \r
        /// <summary>\r
+       /// アーカイバDLLを使った書庫展開のエラー\r
+       /// </summary>\r
+       public class CommonArchiverDllExtractionException : ApplicationException\r
+       {\r
+               /// <summary>\r
+               /// DLLファイル名\r
+               /// </summary>\r
+               private string dllName;\r
+               \r
+               /// <summary>\r
+               /// 戻り値\r
+               /// </summary>\r
+               private int returnValue;\r
+               \r
+               /// <summary>\r
+               /// アーカイバDLLを使った書庫展開のエラー\r
+               /// </summary>\r
+               /// <param name="message">メッセージ</param>\r
+               /// <param name="dllName">対象DLL名</param>\r
+               /// <param name="returnValue">戻り値</param>\r
+               public CommonArchiverDllExtractionException(string message, string dllName, int returnValue)\r
+                       : base(message)\r
+               {\r
+                       this.dllName = dllName;\r
+                       this.returnValue = returnValue;\r
+               }\r
+               \r
+               /// <summary>\r
+               /// DLLファイルの名称\r
+               /// </summary>\r
+               public string DllName {\r
+                       get { return dllName; }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 戻り値(非0)\r
+               /// </summary>\r
+               public int ReturnValue {\r
+                       get { return returnValue; }\r
+               }\r
+       }\r
+       \r
+       /// <summary>\r
        /// アーカイバDLLを使った書庫展開器\r
        /// </summary>\r
        public class CommonArchiverExtracter\r
@@ -114,17 +157,25 @@ namespace NaGet.InteropServices
                /// <param name="targetDir">展開先ディレクトリ</param>\r
                /// <param name="output">アーカイバDLLの展開時の標準出力を格納する</param>\r
                /// <param name="hWnd">親フレーム</param>\r
-               /// <returns>ã\82¢ã\83¼ã\82«ã\82¤ã\83\90DLLã\81®å±\95é\96\8bæ\99\82ã\81®ã\82¨ã\83©ã\83¼ã\82³ã\83¼ã\83\89(0ã\81ªã\82\89正常çµ\82äº\86)</returns>\r
-               public static int ExtractArchive(string arcFile, string targetDir, System.Text.StringBuilder output, IntPtr hWnd)\r
+               /// <returns>ã\82¢ã\83¼ã\82«ã\82¤ã\83\90DLLã\81\8cè¦\8bã\81¤ã\81\8bã\81£ã\81¦æ­£ã\81\97ã\81\8få\87¦ç\90\86ã\81§ã\81\8dã\81\9fã\82\89trueã\80\81DLLã\81\8cè¦\8bã\81¤ã\81\8bã\82\89ã\81ªã\81\8bã\81£ã\81\9fã\82\89false</returns>\r
+               public static bool ExtractArchive(string arcFile, string targetDir, System.Text.StringBuilder output, IntPtr hWnd)\r
                {\r
+                       bool ret = false;\r
+                       \r
                        foreach (CommonArchiverDllConfig config in Configs) {\r
                                try {\r
-                                       return ExtractArchiveWith(arcFile, targetDir, config, output, hWnd);\r
+                                       ret = ExtractArchiveWith(arcFile, targetDir, config, output, hWnd);\r
+                                       if (ret == true) {\r
+                                               break;\r
+                                       }\r
+                               } catch (CommonArchiverDllExtractionException) {\r
+                                       throw;\r
                                } catch (DllNotFoundException) {\r
                                } catch (ApplicationException) {\r
                                }\r
                        }\r
-                       throw new DllNotFoundException("Not found dll matched for " + arcFile);\r
+                       \r
+                       return ret;\r
                }\r
                \r
                /// <summary>\r
@@ -136,10 +187,10 @@ namespace NaGet.InteropServices
                /// <param name="output">アーカイバDLLの展開時の標準出力を格納する</param>\r
                /// <param name="hWnd">親フレーム</param>\r
                /// <returns>アーカイバDLLの展開時のエラーコード(0なら正常終了)</returns>\r
-               public static int ExtractArchiveWith(string arcFile, string targetDir, CommonArchiverDllConfig config, System.Text.StringBuilder output, IntPtr hWnd)\r
+               public static bool ExtractArchiveWith(string arcFile, string targetDir, CommonArchiverDllConfig config, System.Text.StringBuilder output, IntPtr hWnd)\r
                {\r
                        if (! File.Exists(arcFile) ) {\r
-                               throw new FileNotFoundException("File not found: ", arcFile);\r
+                               throw new FileNotFoundException(string.Format("File not found: {0}", arcFile), arcFile);\r
                        }\r
                        if (! Directory.Exists(targetDir)) {\r
                                throw new DirectoryNotFoundException("Directory not found: " + targetDir);\r
@@ -160,7 +211,13 @@ namespace NaGet.InteropServices
                        }\r
                        \r
                        string cmdLine = string.Format(config.CmdLineFmt, arcFile, targetDir);\r
-                       return ExtractArchiveWith(config.DllName, config.CmdName, cmdLine, arcFile, output, hWnd);\r
+                       int retVal = ExtractArchiveWith(config.DllName, config.CmdName, cmdLine, arcFile, output, hWnd);\r
+                       if (retVal != 0) {\r
+                               string errorMsg = string.Format("Extraction failure: {0}#{1}() returns {2}.", config.DllName, config.CmdName, retVal);\r
+                               throw new CommonArchiverDllExtractionException(errorMsg, config.DllName, retVal);\r
+                       }\r
+                       \r
+                       return true;\r
                }\r
                \r
                protected static int ExtractArchiveWith(string dllName, string cmdName, string cmdLine, string arcFile, System.Text.StringBuilder output, IntPtr hWnd)\r