OSDN Git Service

na-get-lib,パフォーマンスチューニングなど(動作変更なし)
authorttp <ttp@users.sourceforge.jp>
Sat, 24 Oct 2009 16:36:21 +0000 (01:36 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 24 Oct 2009 16:36:21 +0000 (01:36 +0900)
18 files changed:
AppliStation/AppliStation.Util/ToolStripPetitLauncherMenuItem.cs
AppliStation/PackageListViewForm.cs
archive-inst/Program.cs
na-get-lib/NaGet.InteropServices/CreateProcessCaller.cs
na-get-lib/NaGet.InteropServices/DllAccess.cs
na-get-lib/NaGet.InteropServices/PEFileInfoUtils.cs
na-get-lib/NaGet.InteropServices/ShellLink.cs
na-get-lib/NaGet.Net/DownloadScanner.cs
na-get-lib/NaGet.Net/Downloader.cs
na-get-lib/NaGet.Net/GuidEnumeratorForCategories.cs
na-get-lib/NaGet.Packages.Install/DependeciesResolver.cs
na-get-lib/NaGet.Packages.Install/Installation.cs
na-get-lib/NaGet.Packages/PackageList.cs
na-get-lib/NaGet.Packages/PackageListsManager.cs
na-get-lib/NaGet.Packages/RepositoriesList.cs
na-get-lib/NaGet.SubCommands/NaGetTask.cs
na-get-lib/NaGet.SubCommands/NaGetUpdate.cs
na-get-lib/NaGet/Utils.cs

index 353982a..be9e074 100644 (file)
@@ -93,11 +93,11 @@ Debug.Assert(! itemtext.Contains(".."), string.Format("{2} -- base:{0}, dirname:
                        \r
                        if (extension == ".exe") {\r
                                switch (NaGet.InteropServices.PEFileInfoUtils.GetPEFileType(filepath)) {\r
-                                       case NaGet.InteropServices.PEFileInfoUtils.PEFileType.WinGUI:\r
+                                       case NaGet.InteropServices.PEFileType.WinGUI:\r
                                                _addToItemsInv(CreateMenuItemForFile(filepath, itemtext));\r
                                                break;\r
-                                       case NaGet.InteropServices.PEFileInfoUtils.PEFileType.WinConsole:\r
-                                       case NaGet.InteropServices.PEFileInfoUtils.PEFileType.MSDosCom:\r
+                                       case NaGet.InteropServices.PEFileType.WinConsole:\r
+                                       case NaGet.InteropServices.PEFileType.MSDosCom:\r
                                                if (! cmdIsAdded) {\r
                                                        _insertToItemsInv(0, CreateMenuItemForCmdAt(basedir));\r
                                                        cmdIsAdded = true;\r
index 3407709..3c3263d 100644 (file)
@@ -655,7 +655,7 @@ namespace AppliStation
                        VersionComparetor verComp = new VersionComparetor();\r
                        PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
                        \r
-                       pkgs = NaGet.Utils.MeargeList(\r
+                       pkgs = NaGet.Utils.MergeList(\r
                                getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp),\r
                                getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp)\r
                        );\r
index 0014ba7..479a6f3 100644 (file)
@@ -124,7 +124,7 @@ namespace ArchiveInstall
                        \r
                        // 直下のファイルで*.exeがGUIプログラムならプログラムフォルダに登録\r
                        foreach (string exeFile in Directory.GetFiles(targetDir, "*.exe")) {\r
-                               if (NaGet.InteropServices.PEFileInfoUtils.GetPEFileType(exeFile) == NaGet.InteropServices.PEFileInfoUtils.PEFileType.WinGUI) {\r
+                               if (NaGet.InteropServices.PEFileInfoUtils.GetPEFileType(exeFile) == NaGet.InteropServices.PEFileType.WinGUI) {\r
                                        string progGrpPath = Path.Combine(NaGet.Env.ArchiveProgramGroup, package.Name);\r
                                        if (! Directory.Exists(progGrpPath)) Directory.CreateDirectory(progGrpPath);\r
                                        \r
index 7223410..af62a3a 100644 (file)
@@ -184,7 +184,7 @@ namespace NaGet.InteropServices
                        }\r
                }\r
                \r
-               private bool _CreateProcessAsNormalUser(string lpApplicationName,\r
+               private static bool _CreateProcessAsNormalUser(string lpApplicationName,\r
                        string lpCommandLine,\r
                        /* ref SECURITY_ATTRIBUTES lpProcessAttributes, */\r
                        IntPtr lpProcessAttributes,\r
@@ -203,9 +203,15 @@ namespace NaGet.InteropServices
                        \r
                        lpProcessInformation = new PROCESS_INFORMATION(); /* fake */\r
                        try {\r
+                               uint result;\r
+                               \r
                                IntPtr hwndShell = FindWindow("Progman", null);\r
                                uint dwProcessId;\r
-                               GetWindowThreadProcessId(hwndShell, out dwProcessId);\r
+                               result = GetWindowThreadProcessId(hwndShell, out dwProcessId);\r
+                               if (result == 0) {\r
+                                       throw new System.ComponentModel.Win32Exception();\r
+                               }\r
+                               \r
                                Process procShell = Process.GetProcessById((int) dwProcessId);\r
                                if (procShell == null) {\r
                                        return false;\r
@@ -294,7 +300,10 @@ namespace NaGet.InteropServices
                        if (pi.hProcess != IntPtr.Zero) {\r
                                CloseHandle(pi.hProcess);\r
                        }\r
+                       GC.SuppressFinalize(this);\r
                }\r
                \r
+               \r
+               \r
        }\r
 }\r
index bd008bb..929271a 100644 (file)
@@ -75,6 +75,15 @@ namespace NaGet.InteropServices
                                FreeLibrary(hModule);\r
                                hModule = IntPtr.Zero;\r
                        }\r
+                       GC.SuppressFinalize(this);\r
+               }\r
+               \r
+               /// <summary>\r
+               /// デストラクタ\r
+               /// </summary>\r
+               ~DllAccess()\r
+               {\r
+                       Dispose();\r
                }\r
        }\r
 }\r
index 489bcc9..9416f5c 100644 (file)
@@ -4,6 +4,29 @@ using System.Runtime.InteropServices;
 \r
 namespace NaGet.InteropServices\r
 {      \r
+       /// <summary>\r
+       /// PE\83t\83@\83C\83\8b\82Ì\8eí\97Þ\r
+       /// </summary>\r
+       public enum PEFileType : uint\r
+       {\r
+               /// <summary>\r
+               /// \95s\96¾\82È\8c`\8e®\81A\82 \82é\82¢\82ÍPE\83t\83@\83C\83\8b\83w\83b\83_\82ð\8e\9d\82½\82È\82¢\r
+               /// </summary>\r
+               Unknown = 0,\r
+               /// <summary>\r
+               /// Windows\83R\83\93\83\\81[\83\8b\83A\83v\83\8a\83P\81[\83V\83\87\83\93\r
+               /// </summary>\r
+               WinConsole = 1,\r
+               /// <summary>\r
+               /// Windows GUI\83A\83v\83\8a\83P\81[\83V\83\87\83\93\r
+               /// </summary>\r
+               WinGUI = 2,\r
+               /// <summary>\r
+               /// MS-DOS(\8by\82Ñ\83R\83}\83\93\83h\83v\83\8d\83\93\83v\83g)\82Å\82ÌCOM\83t\83@\83C\83\8b\r
+               /// </summary>\r
+               MSDosCom = 3,\r
+       }\r
+       \r
        public sealed class PEFileInfoUtils\r
        {\r
                // \8cÄ\82Ñ\8fo\82µ\8bÖ\8e~\r
@@ -12,29 +35,6 @@ namespace NaGet.InteropServices
                }\r
                \r
                /// <summary>\r
-               /// PE\83t\83@\83C\83\8b\82Ì\8eí\97Þ\r
-               /// </summary>\r
-               public enum PEFileType : uint\r
-               {\r
-                       /// <summary>\r
-                       /// \95s\96¾\82È\8c`\8e®\81A\82 \82é\82¢\82ÍPE\83t\83@\83C\83\8b\83w\83b\83_\82ð\8e\9d\82½\82È\82¢\r
-                       /// </summary>\r
-                       Unknown = 0,\r
-                       /// <summary>\r
-                       /// Windows\83R\83\93\83\\81[\83\8b\83A\83v\83\8a\83P\81[\83V\83\87\83\93\r
-                       /// </summary>\r
-                       WinConsole = 1,\r
-                       /// <summary>\r
-                       /// Windows GUI\83A\83v\83\8a\83P\81[\83V\83\87\83\93\r
-                       /// </summary>\r
-                       WinGUI = 2,\r
-                       /// <summary>\r
-                       /// MS-DOS(\8by\82Ñ\83R\83}\83\93\83h\83v\83\8d\83\93\83v\83g)\82Å\82ÌCOM\83t\83@\83C\83\8b\r
-                       /// </summary>\r
-                       MSDosCom = 3,\r
-               }\r
-               \r
-               /// <summary>\r
                /// \93n\82³\82ê\82½\8eÀ\8ds\83t\83@\83C\83\8b\82Ì\8eí\97Þ\82ð\95Ô\82·\81B\93à\95\94\82ÅSHGetFileInfo\82ð\8eg\97p\81B\r
                /// </summary>\r
                /// <param name="path">\8eÀ\8ds\83t\83@\83C\83\8b(*.exe,*.dll)\82Ö\82Ì\83p\83X</param>\r
@@ -130,7 +130,7 @@ namespace NaGet.InteropServices
                                throw new FileNotFoundException(null, pszPath);\r
                        }\r
                        \r
-                       IntPtr hSuccess = SHGetFileInfo(pszPath, 0, ref psfi, (uint)Marshal.SizeOf(psfi), (uint) uFlags);\r
+                       IntPtr hSuccess = SHGetFileInfo(pszPath, dwFileAttributes, ref psfi, (uint)Marshal.SizeOf(psfi), (uint) uFlags);\r
                        if (hSuccess == IntPtr.Zero) {\r
                                throw new IOException(string.Format("Maybe {0} is not a executable file.", pszPath));\r
                        }\r
index 12bf1eb..d013886 100644 (file)
@@ -9,7 +9,6 @@ namespace NaGet.InteropServices
        /// <summary>\r
        /// ShellLinkの更新フラグ\r
        /// </summary>\r
-       [Flags]\r
        public enum ShellLinkResolve : uint\r
        {\r
                // AnyMatch = 0x02, // winMe,win2k以降無効\r
@@ -251,6 +250,7 @@ namespace NaGet.InteropServices
                                Marshal.ReleaseComObject(shellLink);\r
                                shellLink = null;\r
                        }\r
+                       GC.SuppressFinalize(this);\r
                }\r
 \r
                /// <summary>\r
@@ -300,7 +300,7 @@ namespace NaGet.InteropServices
                        \r
                        try {\r
                                FileVersionInfo vInfo = FileVersionInfo.GetVersionInfo(exeFile);\r
-                               if (vInfo.ProductName != null && vInfo.ProductName != string.Empty\r
+                               if ( (!string.IsNullOrEmpty(vInfo.ProductName))\r
                                    && vInfo.ProductName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) < 0) {\r
                                        // 原則、製品名を採用\r
                                        return vInfo.ProductName;\r
index 5dc9b7c..f002ec8 100644 (file)
@@ -55,7 +55,7 @@ namespace NaGet.Net
                /// <summary>\r
                /// ウイルススキャナーに渡すプログラム・ホスト名。\r
                /// </summary>\r
-               public string HostName {\r
+               public static string HostName {\r
                        get {\r
                                // 実行アセンブリ名を返す\r
                                return Assembly.GetExecutingAssembly().GetName().FullName;\r
@@ -69,7 +69,10 @@ namespace NaGet.Net
                /// </summary>\r
                public DownloadScanner()\r
                {\r
-                       ComDirectAccess.CoInitialize(IntPtr.Zero);\r
+                       int result = ComDirectAccess.CoInitialize(IntPtr.Zero);\r
+                       if (result == 0) {\r
+                               throw new System.ComponentModel.Win32Exception();\r
+                       }\r
                }\r
                \r
                /// <summary>\r
@@ -79,6 +82,7 @@ namespace NaGet.Net
                {\r
                        Release();\r
                        ComDirectAccess.CoUninitialize();\r
+                       GC.SuppressFinalize(this);\r
                }\r
                \r
                /// <summary>\r
index d389381..bd74468 100644 (file)
@@ -73,7 +73,7 @@ public class Downloader : NaGetTask
        /// <summary>\r
        /// アクセスURL\r
        /// </summary>\r
-       protected string url;\r
+       protected Uri url;\r
        \r
        /// <summary>\r
        /// 保存先\r
@@ -129,7 +129,7 @@ public class Downloader : NaGetTask
        /// <param name="filepath">保存先ファイルパス</param>\r
        public void Download(string url, string filepath)\r
        {\r
-               this.url = url;\r
+               this.url = new Uri(url);\r
                this.filepath = filepath;\r
                \r
                try {\r
@@ -334,10 +334,11 @@ public class Downloader : NaGetTask
        /// <remarks>Content-Dispositionヘッダから取得あるいはURLの末尾から推定します</remarks>\r
        /// <param name="response">レスポンスオブジェクト</param>\r
        /// <returns>取得したファイル名</returns>\r
-       private string getFileNameFromWebResponse(WebResponse response)\r
+       private static string getFileNameFromWebResponse(WebResponse response)\r
        {\r
-               if (response is HttpWebResponse) {\r
-                       string contentDisposition = ((HttpWebResponse) response).Headers["Content-Disposition"];\r
+               HttpWebResponse httpresp = response as HttpWebResponse;\r
+               if (httpresp != null) {\r
+                       string contentDisposition = httpresp.Headers["Content-Disposition"];\r
                        \r
                        if (! string.IsNullOrEmpty(contentDisposition)) {\r
                                try {\r
@@ -350,7 +351,7 @@ public class Downloader : NaGetTask
                        }\r
                }\r
                \r
-               return NaGet.Utils.Url2filename(response.ResponseUri.ToString());\r
+               return NaGet.Utils.Url2filename(response.ResponseUri);\r
        }\r
 }\r
 \r
index e778d54..be84966 100644 (file)
@@ -27,6 +27,7 @@ namespace NaGet.Net
                        if (key != null) {\r
                                key.Close();\r
                        }\r
+                       GC.SuppressFinalize(this);\r
                }\r
                \r
                \r
index 2399bf6..b6332db 100644 (file)
@@ -45,7 +45,7 @@ namespace NaGet.Packages.Install
                        List<Installation> reqInsts = new List<Installation>();\r
                        \r
                        foreach (Entry entry in DeleteDuplicatedEntries(CreateRequiresEntries(insts))) {\r
-                               List<InstalledPackage> instPkgs = NaGet.Utils.MeargeList<InstalledPackage>(\r
+                               List<InstalledPackage> instPkgs = NaGet.Utils.MergeList<InstalledPackage>(\r
                                        pkgListsMan.installedPkgList.GetPackagesForEntry(entry),\r
                                        pkgListsMan.systemInstalledPkgList.GetPackagesForEntry(entry)\r
                                );\r
index de5d2a1..95def52 100644 (file)
@@ -394,7 +394,7 @@ namespace NaGet.Packages.Install
                        Package package = this.InstalledPackage;\r
                        \r
                        string folderName = string.Format("{0}({1})", package.Name, package.Version);\r
-                       string fileName = NaGet.Utils.Url2filename(package.Installer[0].Url.Href);\r
+                       string fileName = NaGet.Utils.Url2filename(new Uri(package.Installer[0].Url.Href));\r
                        \r
                        string folder = Path.Combine(NaGet.Env.ArchiveFolderPath, folderName);\r
                        \r
@@ -490,7 +490,7 @@ namespace NaGet.Packages.Install
                /// <param name="outputReceived">標準出力用リスナ(null可)</param>\r
                /// <param name="errorReceived">エラー出力用リスナ(null可)</param>\r
                /// <returns>実行プロセス</returns>\r
-               private Process createExtractArchiveProcess(string archiveInstArgs,\r
+               private static Process createExtractArchiveProcess(string archiveInstArgs,\r
                                                  EventHandler<NaGet.Utils.AnyDataEventArgs<string>> outputReceived,\r
                                                  EventHandler<NaGet.Utils.AnyDataEventArgs<string>> errorReceived)\r
                {\r
index bbe3a5b..cc27f11 100644 (file)
@@ -41,12 +41,21 @@ namespace NaGet.Packages
                        }\r
                        set\r
                        {\r
-                               packageArrayList = new List<TPackage>();\r
-                               if (value != null) {\r
-                                       foreach (TPackage package in value) {\r
-                                               packageArrayList.Add(package);\r
-                                       }\r
-                               }\r
+                               SetPackages(value);\r
+                       }\r
+               }\r
+               \r
+               #region パッケージの追加/削除とイテレーション\r
+               \r
+               /// <summary>\r
+               /// パッケージの中身を書き換える。\r
+               /// </summary>\r
+               /// <param name="pkgs"></param>\r
+               public void SetPackages(IEnumerable<TPackage> pkgs)\r
+               {\r
+                       packageArrayList.Clear();\r
+                       if (pkgs != null) {\r
+                               packageArrayList.AddRange(pkgs);\r
                        }\r
                }\r
                \r
@@ -69,17 +78,6 @@ namespace NaGet.Packages
                }\r
                \r
                /// <summary>\r
-               /// パッケージリストの各PackageListNameを設定する\r
-               /// </summary>\r
-               /// <param name="pkgList">設定するパッケージが入っているパッケージリスト</param>\r
-               public void FixPackageListName()\r
-               {\r
-                       foreach (TPackage pkg in packageArrayList) {\r
-                               pkg.PackageListName = this.Name;\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
                /// パッケージをリストにマージ(追加)する\r
                /// </summary>\r
                /// <param name="package">追加するパッケージ</param>\r
@@ -106,6 +104,8 @@ namespace NaGet.Packages
                        packageArrayList.Remove(package);\r
                }\r
                \r
+               #endregion\r
+               \r
                #region パッケージ検索\r
                \r
                #region 検索用Predicate\r
@@ -223,5 +223,16 @@ namespace NaGet.Packages
                }\r
                \r
                #endregion\r
+               \r
+               /// <summary>\r
+               /// パッケージリストの各PackageListNameを設定する\r
+               /// </summary>\r
+               /// <param name="pkgList">設定するパッケージが入っているパッケージリスト</param>\r
+               public void FixPackageListName()\r
+               {\r
+                       foreach (TPackage pkg in packageArrayList) {\r
+                               pkg.PackageListName = this.Name;\r
+                       }\r
+               }\r
        }\r
 }\r
index ebe080d..51e16b1 100644 (file)
@@ -185,7 +185,8 @@ namespace NaGet.Packages
                                        }\r
                                }\r
                        }\r
-                       this.systemInstalledPkgList.Packages = installedPkgList.ToArray();\r
+                       \r
+                       this.systemInstalledPkgList.SetPackages(installedPkgList);\r
                }\r
                \r
                #endregion\r
@@ -226,7 +227,7 @@ namespace NaGet.Packages
                /// </summary>\r
                /// <param name="pkg">判定する指定パッケージ</param>\r
                /// <returns>Predicate</returns>\r
-               private Predicate<InstallationLog> createPackageNamePredicator(Package pkg)\r
+               private static Predicate<InstallationLog> createPackageNamePredicator(Package pkg)\r
                {\r
                        return delegate(InstallationLog log) {\r
                                return log.Package.Name == pkg.Name;\r
index 5b72218..5479a96 100644 (file)
@@ -26,11 +26,13 @@ namespace NaGet.Packages
                /// 有効なレポジトリの配列を返す\r
                /// </summary>\r
                [XmlIgnore]\r
-               public RepositoryInfo[] EnabledRepositories {\r
+               public IEnumerable<RepositoryInfo> EnabledRepositories {\r
                        get {\r
-                               return Array.FindAll(Repositories, delegate(RepositoryInfo repo) {\r
-                                                       return repo.Enabled;\r
-                                                    });\r
+                               foreach (RepositoryInfo repo in Repositories) {\r
+                                       if (repo.Enabled) {\r
+                                               yield return repo;\r
+                                       }\r
+                               }\r
                        }\r
                }\r
                \r
index 10a75b9..d17e94c 100644 (file)
@@ -15,6 +15,7 @@ namespace NaGet.SubCommands
                public string TaskMessage;\r
        }\r
        \r
+       [Serializable()]\r
        public class NaGetTaskCanceledException : Exception\r
        {\r
                public NaGetTaskCanceledException(string msg)\r
index 5c9d5fc..6198921 100644 (file)
@@ -97,7 +97,8 @@ namespace NaGet.SubCommands
                                                        RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, "ネットワークに接続できませんでした。ネットワークが切断されているか、ファイアウォールによって遮断された可能性があります。");\r
                                                }\r
                                        } finally {\r
-                                               currentTaskSetIndex = repoList.EnabledRepositories.Length + 1;\r
+                                               int numOfEnabledRepos = NaGet.Utils.IEnumerable2Array(repoList.EnabledRepositories).Length;\r
+                                               currentTaskSetIndex = numOfEnabledRepos + 1;\r
                                        }\r
                                        packageListsDownloaded = true;\r
                                }\r
index 55fafd8..ed97de8 100644 (file)
@@ -85,7 +85,7 @@ namespace NaGet
                /// </summary>\r
                /// <param name="enus">元となる複数のイテレータ</param>\r
                /// <returns>結合されたイテレータ</returns>\r
-               public static List<T> MeargeList<T>(params IEnumerable<T>[] enus)\r
+               public static List<T> MergeList<T>(params IEnumerable<T>[] enus)\r
                {\r
                        List<T> list = new List<T>();\r
                        \r
@@ -104,11 +104,17 @@ namespace NaGet
                /// <param name="enu">元となるイテレータ</param>\r
                /// <returns>変換された配列</returns>\r
                public static T[] IEnumerable2Array<T>(IEnumerable<T> enu) {\r
-                       if (enu is T[]) {\r
-                               return (T[]) enu;\r
-                       } else {\r
-                               return ((enu is List<T>)? ((List<T>)enu):new List<T>(enu)).ToArray();\r
+                       T[] retval = enu as T[];\r
+                       \r
+                       if (retval == null) {\r
+                               List<T> list = enu as List<T>;\r
+                               if (list == null) {\r
+                                       list = new List<T>(enu);\r
+                               }\r
+                               retval = list.ToArray();\r
                        }\r
+                       \r
+                       return retval;\r
                }\r
                \r
                /// <summary>\r
@@ -173,9 +179,9 @@ namespace NaGet
                /// URLからそのファイル名を生成する\r
                /// </summary>\r
                /// <param name="url">対象のurl</param>\r
-               public static string Url2filename(string url)\r
+               public static string Url2filename(Uri url)\r
                {\r
-                       string filename = Path.GetFileName(System.Web.HttpUtility.UrlDecode(url, Encoding.UTF8));\r
+                       string filename = Path.GetFileName(System.Web.HttpUtility.UrlDecode(url.ToString(), Encoding.UTF8));\r
                        \r
                        int pos;\r
                        if ((pos = filename.IndexOfAny(Path.GetInvalidFileNameChars())) >= 0) {\r