OSDN Git Service

archive-inst,system32へのインストール処理をとりあえず関数として分離
authorttp <ttp@users.sourceforge.jp>
Tue, 13 Apr 2010 14:29:04 +0000 (23:29 +0900)
committerttp <ttp@users.sourceforge.jp>
Tue, 13 Apr 2010 14:29:04 +0000 (23:29 +0900)
archive-inst/Program.cs

index d191f39..934a584 100644 (file)
@@ -81,24 +81,23 @@ namespace ArchiveInstall
                        }\r
                }\r
                \r
-               private static void postInstall(string targetDir, Package package)\r
+               private static void _installDllTo(string sys32path, string srcDir, Package package)\r
                {\r
-                       // SYSTEM32へのコピーの実行\r
                        if (!string.IsNullOrEmpty(package.System32CopyFiles)) {\r
-                               if (! Directory.Exists(NaGet.Env.ArchiveSystem32)) {\r
-                                       Directory.CreateDirectory(NaGet.Env.ArchiveSystem32);\r
+                               if (! Directory.Exists(sys32path)) {\r
+                                       Directory.CreateDirectory(sys32path);\r
                                }\r
                                \r
-                               string logfile = Path.Combine(NaGet.Env.ArchiveSystem32, ".applistation.install."+package.Name+".log");\r
+                               string logfile = Path.Combine(sys32path, ".applistation.install."+package.Name+".log");\r
                                if (File.Exists(logfile)) {\r
                                        File.SetAttributes(logfile, FileAttributes.Normal);\r
                                }\r
                                using (FileStream fs = new FileStream(logfile, FileMode.Create))\r
                                using (StreamWriter sw = new StreamWriter(fs)){\r
                                        foreach (string pathpat in package.System32CopyFiles.Split(';')) {\r
-                                               foreach (string path in NaGet.Utils.ExtendWildcardFile(targetDir, pathpat)) {\r
+                                               foreach (string path in NaGet.Utils.ExtendWildcardFile(srcDir, pathpat)) {\r
                                                        if ((File.GetAttributes(path) & FileAttributes.Directory) == 0) { // もしファイルならば\r
-                                                               string destPath = Path.Combine(NaGet.Env.ArchiveSystem32, Path.GetFileName(path));\r
+                                                               string destPath = Path.Combine(sys32path, Path.GetFileName(path));\r
                                                                File.Copy(path, destPath, true);\r
                                                                \r
                                                                sw.WriteLine(Path.GetFileName(destPath));\r
@@ -108,6 +107,12 @@ namespace ArchiveInstall
                                }\r
                                File.SetAttributes(logfile, FileAttributes.Hidden);\r
                        }\r
+               }\r
+               \r
+               private static void postInstall(string targetDir, Package package)\r
+               {\r
+                       // SYSTEM32へのコピーの実行\r
+                       _installDllTo(NaGet.Env.ArchiveSystem32, targetDir, package);\r
                        \r
                        // インストールスクリプトの実行\r
                        if (! string.IsNullOrEmpty(package.InstallScript) ) {\r
@@ -182,6 +187,28 @@ namespace ArchiveInstall
                        File.SetAttributes(packageXmlFilePath, FileAttributes.Hidden | FileAttributes.ReadOnly);\r
                }\r
                \r
+               private static void _removeDllFrom(string sys32path, InstalledPackage package)\r
+               {\r
+                       if (! string.IsNullOrEmpty(package.System32CopyFiles) ) {\r
+                               string logfile = Path.Combine(sys32path, ".applistation.install."+package.Name+".log");\r
+                               \r
+                               if (File.Exists(logfile)) {\r
+                                       using (FileStream fs = new FileStream(logfile, FileMode.Open))\r
+                                       using (StreamReader sr = new StreamReader(fs)){\r
+                                               string fileName = sr.ReadLine().Trim();\r
+                                               string filePath = Path.Combine(sys32path, fileName);\r
+                                               \r
+                                               if (File.Exists(filePath)) {\r
+                                                       File.SetAttributes(filePath, FileAttributes.Normal);\r
+                                                       File.Delete(filePath);\r
+                                               }\r
+                                       }\r
+                                       File.SetAttributes(logfile, FileAttributes.Normal);\r
+                                       File.Delete(logfile);\r
+                               }\r
+                       }\r
+               }\r
+               \r
                private static void removePackage(InstalledPackage package, string targetDir)\r
                {\r
                        // アンインストールスクリプトの実行\r
@@ -205,24 +232,7 @@ namespace ArchiveInstall
                        }\r
                        \r
                        // SYSTEM32からの削除の実行\r
-                       if (! string.IsNullOrEmpty(package.System32CopyFiles) ) {\r
-                               string logfile = Path.Combine(NaGet.Env.ArchiveSystem32, ".applistation.install."+package.Name+".log");\r
-                               \r
-                               if (File.Exists(logfile)) {\r
-                                       using (FileStream fs = new FileStream(logfile, FileMode.Open))\r
-                                       using (StreamReader sr = new StreamReader(fs)){\r
-                                               string fileName = sr.ReadLine().Trim();\r
-                                               string filePath = Path.Combine(NaGet.Env.ArchiveSystem32, fileName);\r
-                                               \r
-                                               if (File.Exists(filePath)) {\r
-                                                       File.SetAttributes(filePath, FileAttributes.Normal);\r
-                                                       File.Delete(filePath);\r
-                                               }\r
-                                       }\r
-                                       File.SetAttributes(logfile, FileAttributes.Normal);\r
-                                       File.Delete(logfile);\r
-                               }\r
-                       }\r
+                       _removeDllFrom(NaGet.Env.ArchiveSystem32, package);\r
                        \r
                        try {\r
                                NaGet.Utils.SetAttributeRecursive(targetDir, FileAttributes.Normal);\r