OSDN Git Service

AppliStation,パフォーマンスチューニング,SendMessage引数型修正など(動作変更なし)
authorttp <ttp@users.sourceforge.jp>
Sun, 25 Oct 2009 10:12:12 +0000 (19:12 +0900)
committerttp <ttp@users.sourceforge.jp>
Sun, 25 Oct 2009 10:12:12 +0000 (19:12 +0900)
12 files changed:
AppliStation/AppliStation.Util/ExceptionDialogForm.cs
AppliStation/AppliStation.Util/ExecutionProgressViewer.cs
AppliStation/AppliStation.Util/GUIUtils.cs
AppliStation/AppliStation.Util/NativeMethods.cs
AppliStation/AppliStation.Util/SprashScreenLayered.cs
AppliStation/AppliStation.Util/ToolStripPetitLauncherMenuItem.cs
AppliStation/AppliStation.Util/ToolStripWeb2LikeTextBox.cs
AppliStation/PackageListView.cs
AppliStation/PackageListViewForm.cs
AppliStation/PackageUninstallConfirmForm.Designer.cs
AppliStation/Program.cs
AppliStation/UserPrefForm.cs

index 82bcec4..3d9c5e0 100644 (file)
@@ -17,7 +17,7 @@ namespace AppliStation.Util
                        InitializeComponent();\r
                }\r
                \r
-               private static void Application_ThrowException(Exception e)\r
+               public static void Application_ThrowException(Exception e)\r
                {\r
                        try {\r
                                ExceptionDialogForm form = new ExceptionDialogForm();\r
index 54e6d86..b6d90d0 100644 (file)
@@ -19,7 +19,7 @@ namespace AppliStation.Util
                /// <summary>\r
                /// 終了時に何を行うかのフラグ\r
                /// </summary>\r
-               public enum ActionOnDoneFlags {\r
+               private enum ActionOnDoneFlags {\r
                        None = 0,\r
                        FlashWindow = 1,\r
                        AutoCloseOnSuccess = 2,\r
@@ -28,7 +28,7 @@ namespace AppliStation.Util
                /// <summary>\r
                /// 終了時に何を行うか\r
                /// </summary>\r
-               public ActionOnDoneFlags ActionOnDone = ActionOnDoneFlags.FlashWindow;\r
+               private ActionOnDoneFlags ActionOnDone = ActionOnDoneFlags.FlashWindow;\r
                                \r
                public ExecutionProgressViewer()\r
                {\r
index 22bff09..ee3f014 100644 (file)
@@ -39,11 +39,13 @@ namespace AppliStation.Util
                /// シェルからフォルダーアイコンを生成して返す\r
                /// </summary>\r
                /// <returns>フォルダーアイコン</returns>\r
-               public static Icon GetShellIconForFolder()\r
+               public static Icon ShellIconForFolder\r
                {\r
-                       // Vista以降ならば、SHGetStockIconInfo(SIID_FOLDER, SHGSI_ICON, &sInfo); をP/Invoke呼び出しするのが王道かと\r
-                       string windir = Environment.GetEnvironmentVariable("windir");\r
-                       return NativeMethods.ExtractIcon(null, Path.Combine(windir, @"system32\shell32.dll"), 3);\r
+                       get {\r
+                               // Vista以降ならば、SHGetStockIconInfo(SIID_FOLDER, SHGSI_ICON, &sInfo); をP/Invoke呼び出しするのが王道かと\r
+                               string windir = Environment.GetEnvironmentVariable("windir");\r
+                               return NativeMethods.ExtractIcon(null, Path.Combine(windir, @"system32\shell32.dll"), 3);\r
+                       }\r
                }\r
                \r
                #endregion\r
index 5a5d015..9bf00f2 100644 (file)
@@ -31,7 +31,7 @@ namespace AppliStation.Util
                        try {\r
                                // status := (PBST_NORMAL | PBST_ERROR | PBST_PAUSED)\r
                                // SendMessage(progressBar.Handle, PBM_SETSTATE, state, 0);\r
-                               SendMessage(progBar.Handle, 0x410, state, 0);\r
+                               SendMessage(progBar.Handle, 0x410, new IntPtr(state), IntPtr.Zero);\r
                        } catch (Exception) {\r
                        }\r
 #endif\r
@@ -120,7 +120,7 @@ namespace AppliStation.Util
                {\r
                        try {\r
                                // SendMessage(listView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER, bEnable? LVS_EX_DOUBLEBUFFER:0);\r
-                               SendMessage(listView.Handle, 0x1036, 0x00010000, ((bEnable)? 0x00010000u:0x0u));\r
+                               SendMessage(listView.Handle, 0x1036, new IntPtr(0x00010000), new IntPtr((bEnable)? 0x00010000u:0x0u));\r
                        } catch (Exception) {\r
                        }\r
                }\r
@@ -156,7 +156,7 @@ namespace AppliStation.Util
 #if USE_VISTA_EFFECTS\r
                        try {\r
                                // SendMessage(listView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_AUTOCHECKSELECT, bAutoCheckSelect?LVS_EX_AUTOCHECKSELECT:0);\r
-                               SendMessage(listView.Handle, 0x1036, 0x08000000, (bAutoCheckSelect)?0x08000000u:0x0u);\r
+                               SendMessage(listView.Handle, 0x1036, new IntPtr(0x08000000), new IntPtr((bAutoCheckSelect)?0x08000000u:0x0u));\r
                        } catch (Exception) {\r
                        }\r
 #endif\r
@@ -178,12 +178,6 @@ namespace AppliStation.Util
                        public int     iOrder;\r
                }\r
                \r
-               internal static IntPtr ListView_GetHeader(ListView listview)\r
-               {\r
-                       // SendMessage(hWnd, LVM_GETHEADER, 0, NULL);\r
-                       return SendMessage(listview.Handle, 0x101E, 0, 0);\r
-               }\r
-               \r
                /// <summary>\r
                /// WinXP以降、ソートの矢印を表示\r
                /// </summary>\r
@@ -194,13 +188,13 @@ namespace AppliStation.Util
                {\r
                        try {\r
                                // SendMessage(hWnd, LVM_GETHEADER, NULL, NULL);\r
-                               IntPtr hWnd = SendMessage(listView.Handle, 0x101F, 0, 0);\r
+                               IntPtr hWnd = SendMessage(listView.Handle, 0x101F, IntPtr.Zero, IntPtr.Zero);\r
                                \r
                                HD_ITEM hdi = new HD_ITEM();\r
                                hdi.mask = 0x0004; // HDI_FORMAT;\r
                                for (int i = 0; i < listView.Columns.Count; i++) {\r
                                        // SendMessage(hWnd, HDM_GETITEMW, i, &hdi);\r
-                                       SendMessage(hWnd, 0x120b, i, ref hdi);\r
+                                       SendMessage(hWnd, 0x120b, new IntPtr(i), ref hdi);\r
                                        \r
                                        const int HDF_SORTUP = 0x400;\r
                                        const int HDF_SORTDOWN = 0x200;\r
@@ -214,7 +208,7 @@ namespace AppliStation.Util
                                        }\r
                                        \r
                                        // SendMessage(hWnd, HDM_SETITEMW, i, &hdi);\r
-                                       SendMessage(hWnd, 0x120c, i, ref hdi);\r
+                                       SendMessage(hWnd, 0x120c, new IntPtr(i), ref hdi);\r
                                }\r
                        } catch (Exception) {\r
                        }\r
@@ -295,7 +289,7 @@ namespace AppliStation.Util
                        cfmt.dwEffects = dwEffect;\r
                        \r
                        //SendMessage(richTextBox.Handle, EM_SETCHARFORMAT, SCF_SELECTION, ref cfmt);\r
-                       SendMessage(richTextBox.Handle, 0x0444, 0x0001, ref cfmt);\r
+                       SendMessage(richTextBox.Handle, 0x0444, new IntPtr(0x0001), ref cfmt);\r
                }\r
                /// <summary>\r
                /// リッチテキストにテキストリンクを追加する\r
@@ -368,7 +362,7 @@ namespace AppliStation.Util
                        if (Environment.OSVersion.Version.Major >= 6) {\r
                                button.FlatStyle = FlatStyle.System;\r
                                // SendMessage(hWnd, BCM_SETSHIELD, 0, required);\r
-                               SendMessage(button.Handle, 0x160C, 0, (required)? 1u : 0u);\r
+                               SendMessage(button.Handle, 0x160C, IntPtr.Zero, new IntPtr((required)? 1u : 0u));\r
                        } else { // Legacy OS\r
                                // FlatStyle.System に設定されている場合、Image プロパティに割り当てられているイメージは表示されない対策\r
                                if (button.FlatStyle == FlatStyle.System) {\r
@@ -386,14 +380,14 @@ namespace AppliStation.Util
                \r
                #endregion\r
                \r
-               [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
-               internal static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);\r
+               [DllImport("user32.dll", CharSet = CharSet.Auto)]\r
+               internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);\r
                \r
                [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
-               private static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, int wParam, ref HD_ITEM lParam);\r
+               private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref HD_ITEM lParam);\r
                \r
                [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
-               private static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, int wParam, ref CHARFORMAT2 lParam);\r
+               private static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, ref CHARFORMAT2 lParam);\r
 \r
                [DllImport("uxtheme.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]\r
                internal static extern int SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);\r
index aa3da3f..75e57c5 100644 (file)
@@ -56,7 +56,10 @@ namespace AppliStation.Util
                public void ReleaseHdc()\r
                {\r
                        if (this.isGottenDc) { // GetDC 関数を使って取得した場合\r
-                               ReleaseDC(hWnd, hDc);\r
+                               int result = ReleaseDC(hWnd, hDc);\r
+                               if (result != 1) {\r
+                                       throw new System.ComponentModel.Win32Exception();\r
+                               }\r
                        } else {\r
                                DeleteObject(hDc);\r
                        }\r
@@ -65,6 +68,7 @@ namespace AppliStation.Util
                public void Dispose()\r
                {\r
                        ReleaseHdc();\r
+                       GC.SuppressFinalize(this);\r
                }\r
                \r
                /// <summary>\r
@@ -95,6 +99,7 @@ namespace AppliStation.Util
                private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);\r
                \r
                [DllImport("gdi32.dll")]\r
+               [return: MarshalAs(UnmanagedType.Bool)]\r
                private static extern bool DeleteObject(IntPtr hObject);\r
                \r
                #endregion\r
@@ -102,26 +107,27 @@ namespace AppliStation.Util
        \r
        public class SprashScreenLayered : Form\r
        {\r
-               public static Form CreateSprashScreenLayered(Bitmap bitmap, Color bgColor)\r
+               public static Form CreateSprashScreenLayered(Image img, Color bgColor)\r
                {\r
                        Form form;\r
+                       SprashScreenLayered ss = null;\r
                        \r
                        if (OSFeature.Feature.IsPresent(OSFeature.LayeredWindows)) {\r
-                               form = new SprashScreenLayered();\r
-                               form.BackgroundImage = bitmap;\r
+                               form = ss = new SprashScreenLayered();\r
+                               form.BackgroundImage = img;\r
                        } else {\r
                                form = new Form();\r
-                               form.BackgroundImage = bitmap;\r
+                               form.BackgroundImage = img;\r
                                form.BackColor = bgColor;\r
                        }\r
                        //form.ShowInTaskbar = false;\r
                        form.ControlBox = false;\r
                        form.FormBorderStyle = FormBorderStyle.None;\r
                        form.StartPosition = FormStartPosition.CenterScreen;\r
-                       form.Size = bitmap.Size;\r
+                       form.Size = img.Size;\r
                        \r
-                       if (form is SprashScreenLayered) {\r
-                               ((SprashScreenLayered) form).CenterToScreen2();\r
+                       if (ss != null) {\r
+                               ss.CenterToScreen2();\r
                        }\r
                        \r
                        return form;\r
@@ -155,6 +161,7 @@ namespace AppliStation.Util
                #region UpdateLayeredWindow関連\r
                \r
                [DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]\r
+               [return: MarshalAs(UnmanagedType.Bool)]\r
                private static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst,\r
                                                               [In] ref Point pptDst, [In] ref Size psize,\r
                                                               IntPtr hdcSrc, [In] ref Point pptSrc,\r
@@ -162,15 +169,16 @@ namespace AppliStation.Util
                                                               [In] ref BLENDFUNCTION pblend,\r
                                                               uint dwFlags);\r
                \r
-               private Bitmap convertBitmap(Image img)\r
+               private static Bitmap convertBitmap(Image img)\r
                {\r
-                       if (img is Bitmap) {\r
-                               return (Bitmap) img;\r
-                       } else {\r
-                               Bitmap bitmap = new Bitmap(img.Width, img.Height, img.PixelFormat);\r
+                       Bitmap bitmap;\r
+                       \r
+                       bitmap = img as Bitmap;\r
+                       if (bitmap == null) {\r
+                               bitmap = new Bitmap(img.Width, img.Height, img.PixelFormat);\r
                                Graphics.FromImage(bitmap).DrawImage(img, 0, 0);\r
-                               return bitmap;\r
                        }\r
+                       return bitmap;\r
                }\r
                \r
                protected void updateLayeredWindow()\r
@@ -210,7 +218,7 @@ namespace AppliStation.Util
                }\r
                \r
                [StructLayout(LayoutKind.Sequential, Pack=1)]\r
-               protected struct BLENDFUNCTION\r
+               protected internal struct BLENDFUNCTION\r
                {\r
                        public byte BlendOp;\r
                        public byte BlendFlags;\r
index 7366b06..39723ae 100644 (file)
@@ -149,7 +149,7 @@ Debug.Assert(! itemtext.Contains(".."), string.Format("{2} -- base:{0}, dirname:
                public static ToolStripMenuItem CreateMenuItemForFolder(string folderPath)\r
                {\r
                        ToolStripMenuItem item = CreateMenuItemForFile(folderPath, "フォルダーを開く(&O)");\r
-                       item.Image = GUIUtils.GetShellIconForFolder().ToBitmap();\r
+                       item.Image = GUIUtils.ShellIconForFolder.ToBitmap();\r
                        item.ShowShortcutKeys = true;\r
                        return item;\r
                }\r
@@ -173,7 +173,7 @@ Debug.Assert(! itemtext.Contains(".."), string.Format("{2} -- base:{0}, dirname:
                                \r
                                StringBuilder sb = new StringBuilder();\r
                                sb.AppendFormat("場所: {0}", Path.GetDirectoryName(filePath));\r
-                               try {\r
+                               if (File.Exists(filePath)) {\r
                                        FileVersionInfo vInfo = FileVersionInfo.GetVersionInfo(filePath);\r
                                        \r
                                        if (! string.IsNullOrEmpty(vInfo.FileDescription))\r
@@ -182,7 +182,7 @@ Debug.Assert(! itemtext.Contains(".."), string.Format("{2} -- base:{0}, dirname:
                                                sb.AppendFormat("\r\n会社: {0}", vInfo.CompanyName);\r
                                        if (! string.IsNullOrEmpty(vInfo.FileVersion))\r
                                                sb.AppendFormat("\r\nファイルバージョン: {0}", vInfo.FileVersion);\r
-                               } catch (Exception) {}\r
+                               }\r
                                item.ToolTipText = sb.ToString();\r
                        } else {\r
                                item.ToolTipText = filePath;\r
index b15fb81..d4de736 100644 (file)
@@ -9,9 +9,9 @@ namespace AppliStation.Util
        {\r
                public ToolStripWeb2LikeTextBox() : base()\r
                {\r
-                       this.Text = string.Empty;\r
+                       textIsEmpty = true;\r
                }\r
-                               \r
+               \r
                [Category("Action")]\r
                public event EventHandler TextChangedTriggerFired;\r
                \r
@@ -52,7 +52,7 @@ namespace AppliStation.Util
                /// </summary>\r
                protected Timer textChangeTriggerTimer = null;\r
                \r
-               private void onTextUpdate(bool force)\r
+               private void onTextUpdate()\r
                {\r
                        textChangeTriggerTimerStop();\r
                        \r
@@ -80,13 +80,13 @@ namespace AppliStation.Util
                        base.OnTextChanged(e);\r
                        \r
                        if (Focused) {\r
-                               onTextUpdate(false);\r
+                               onTextUpdate();\r
                        }\r
                }\r
                \r
                #endregion\r
                \r
-               protected bool textIsEmpty = true;\r
+               protected bool textIsEmpty;\r
                \r
                public override string Text {\r
                        get { return textIsEmpty? string.Empty : base.Text; }\r
index 71f496b..bfc7d25 100644 (file)
@@ -12,9 +12,9 @@ namespace AppliStation
        /// PackageListViewの表示フィルタ\r
        /// </summary>\r
        [Flags]\r
-       public enum PackageListViewPkgTypeFilter : uint\r
+       public enum PackageListViewPkgTypeFilter\r
        {\r
-               ViewNothing = 0,\r
+               None = 0,\r
                NotInstalled = 1,\r
                InstalledAS = 2,\r
                InstalledSys = 4,\r
@@ -120,7 +120,7 @@ namespace AppliStation
                \r
                #region データ領域作成メソッド群\r
                \r
-               private ListViewItem createListViewItemForPackage(Package pkg, ImageCategory imageKey)\r
+               private static ListViewItem createListViewItemForPackage(Package pkg, ImageCategory imageKey)\r
                {\r
                        string[] labels = new string[]{\r
                                pkg.Name, pkg.Version, pkg.Summary,\r
@@ -180,7 +180,7 @@ namespace AppliStation
                        this.Refresh();\r
                }\r
                \r
-               protected enum ImageCategory : uint {\r
+               protected enum ImageCategory {\r
                        Available,\r
                        AvailableNew,\r
                        Installed,\r
@@ -245,7 +245,7 @@ namespace AppliStation
                        // ソート対象列の色付け\r
                        try {\r
                                // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
-                               AppliStation.Util.NativeMethods.SendMessage(this.Handle, 0x1000+140, (uint) e.Column, 0);\r
+                               AppliStation.Util.NativeMethods.SendMessage(this.Handle, 0x1000+140, new IntPtr(e.Column), IntPtr.Zero);\r
                        } catch (Exception) {   \r
                        }\r
                }\r
index 30132c4..5c4b7b1 100644 (file)
@@ -13,7 +13,7 @@ namespace AppliStation
        /// </summary>\r
        public partial class PackageListViewForm : Form\r
        {\r
-               protected PackageListsManager pkgListsMan = null;\r
+               private PackageListsManager pkgListsMan = null;\r
                \r
                public PackageListViewForm()\r
                {\r
@@ -48,8 +48,10 @@ namespace AppliStation
                                }\r
                                detailBox.AppendText("\r\n");\r
                        }\r
-                       if (pkg is InstalledPackage) {\r
-                               InstalledPackage iPkg = (InstalledPackage) pkg;\r
+                       \r
+                       // インストール済みパッケージの場合\r
+                       InstalledPackage iPkg = pkg as InstalledPackage;\r
+                       if (iPkg != null) {\r
                                System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
                                if (iPkg.UninstallInfo.InstallDate != null) {\r
                                        sb.AppendFormat("インストールした日: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
@@ -498,7 +500,7 @@ namespace AppliStation
                        bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
                        if (selectionIsOnlyOne) {\r
                                Package pkg = packageListView.SelectedPackage;\r
-                               bool isInstalledPackage = (pkg is InstalledPackage);\r
+                               InstalledPackage iPkg = pkg as InstalledPackage;\r
                                \r
                                webResourcesToolStripMenuItem.Text = string.Format(\r
                                        webResourcesToolStripMenuItem.Tag.ToString(),\r
@@ -506,15 +508,16 @@ namespace AppliStation
                                webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
                                // webGoogleSearchToolStripMenuItem always active.\r
                                \r
-                               if (isInstalledPackage) {\r
+                               // インストール済みパッケージのとき\r
+                               if (iPkg != null) {\r
                                        bool installedDirectoryStripMenuItemVisible = \r
                                                (pkg.Type == InstallerType.ARCHIVE) ||\r
                                                (pkg.Type == InstallerType.ITSELF) ||\r
-                                               Directory.Exists(((InstalledPackage) pkg).discoverInstalledLocation());\r
+                                               Directory.Exists(iPkg.discoverInstalledLocation());\r
                                        \r
                                        installedDirectoryStripMenuItem.Visible = installedDirectoryStripMenuItemVisible;\r
                                        if (installedDirectoryStripMenuItemVisible) {\r
-                                               buildInstalledDirectoryMenuItemStripChildren((InstalledPackage) pkg);\r
+                                               buildInstalledDirectoryMenuItemStripChildren(iPkg);\r
                                        }\r
                                } else {\r
                                        installedDirectoryStripMenuItem.Visible = false;\r
index f666976..58d7c66 100644 (file)
@@ -29,7 +29,6 @@ namespace AppliStation
                /// </summary>\r
                private void InitializeComponent()\r
                {\r
-                       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageUninstallConfirmForm));\r
                        this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();\r
                        this.label = new System.Windows.Forms.Label();\r
                        this.btnPanel = new System.Windows.Forms.FlowLayoutPanel();\r
index a861a15..4f7219e 100644 (file)
@@ -16,8 +16,6 @@ namespace AppliStation
                /// </summary>\r
                Dictionary<string, object> appArgs;\r
                \r
-               string[] restAppArgs;\r
-               \r
                public Program()\r
                {\r
                        appArgs = new Dictionary<string, object>();\r
@@ -184,7 +182,7 @@ namespace AppliStation
                private void parseArgs(string[] args)\r
                {\r
                        NaGet.ArgParser parser = new NaGet.ArgParser(appArgs);\r
-                       restAppArgs = parser.Parse(args);\r
+                       string[] restAppArgs = parser.Parse(args);\r
                }\r
                \r
                private static Form createAndOpenSplashScreen()\r
index c909c68..d9b7baf 100644 (file)
@@ -71,7 +71,7 @@ namespace AppliStation
                /// </summary>\r
                /// <param name="repo">対象レポジトリ</param>\r
                /// <returns>ListBoxに表示すべき文字列</returns>\r
-               private string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
+               private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
                        return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);\r
                }\r
 \r