diff --git a/CreamInstaller/Forms/Components/CustomTreeView.cs b/CreamInstaller/Forms/Components/CustomTreeView.cs new file mode 100644 index 0000000..a883b3d --- /dev/null +++ b/CreamInstaller/Forms/Components/CustomTreeView.cs @@ -0,0 +1,50 @@ +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace CreamInstaller +{ + public class CustomTreeView : TreeView + { + protected override void WndProc(ref Message m) + { + if (m.Msg == 0x203) m.Result = IntPtr.Zero; + else base.WndProc(ref m); + } + + public CustomTreeView() : base() + { + //DrawMode = TreeViewDrawMode.OwnerDrawAll; + //DrawNode += new DrawTreeNodeEventHandler(DrawTreeNode); + + closedGlyphRenderer = new(VisualStyleElement.TreeView.Glyph.Closed); + openedGlyphRenderer = new(VisualStyleElement.TreeView.Glyph.Opened); + } + + private readonly VisualStyleRenderer closedGlyphRenderer; + private readonly VisualStyleRenderer openedGlyphRenderer; + + private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e) + { + if (!e.Node.IsVisible) return; + e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds); + + int startX = e.Bounds.X + (e.Node.Parent is null ? 22 : 41); + int startY = e.Bounds.Y; + + if (e.Node.Parent is null && e.Node.Nodes.Count > 0) + if (e.Node.IsExpanded) + openedGlyphRenderer.DrawBackground(e.Graphics, new(e.Bounds.X + startX / 2 - 8, startY, 16, 16)); + else + closedGlyphRenderer.DrawBackground(e.Graphics, new(e.Bounds.X + startX / 2 - 8, startY, 16, 16)); + + CheckBoxState checkBoxState = e.Node.TreeView.Enabled + ? (e.Node.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal) + : (e.Node.Checked ? CheckBoxState.CheckedDisabled : CheckBoxState.UncheckedDisabled); + CheckBoxRenderer.DrawCheckBox(e.Graphics, new(startX, startY + 1), checkBoxState); + + TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.NodeFont, e.Node.Bounds.Location, Color.Black); + } + } +} \ No newline at end of file diff --git a/CreamInstaller/Forms/Components/ProgramSelectionTreeView.cs b/CreamInstaller/Forms/Components/ProgramSelectionTreeView.cs deleted file mode 100644 index 40d080f..0000000 --- a/CreamInstaller/Forms/Components/ProgramSelectionTreeView.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace CreamInstaller -{ - public class ProgramSelectionTreeView : TreeView - { - protected override void WndProc(ref Message m) - { - if (m.Msg == 0x203) m.Result = IntPtr.Zero; - else base.WndProc(ref m); - } - } -} \ No newline at end of file diff --git a/CreamInstaller/Forms/MainForm.Designer.cs b/CreamInstaller/Forms/MainForm.Designer.cs index fa945c2..1bc759d 100644 --- a/CreamInstaller/Forms/MainForm.Designer.cs +++ b/CreamInstaller/Forms/MainForm.Designer.cs @@ -36,7 +36,7 @@ namespace CreamInstaller this.updateButton = new System.Windows.Forms.Button(); this.ignoreButton = new System.Windows.Forms.Button(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.changelogTreeView = new CreamInstaller.ProgramSelectionTreeView(); + this.changelogTreeView = new CreamInstaller.CustomTreeView(); this.SuspendLayout(); // // label1 @@ -116,7 +116,7 @@ namespace CreamInstaller private Button updateButton; private Button ignoreButton; private ProgressBar progressBar1; - private ProgramSelectionTreeView changelogTreeView; + private CustomTreeView changelogTreeView; } } diff --git a/CreamInstaller/Forms/SelectForm.Designer.cs b/CreamInstaller/Forms/SelectForm.Designer.cs index 33ffa36..53e81ab 100644 --- a/CreamInstaller/Forms/SelectForm.Designer.cs +++ b/CreamInstaller/Forms/SelectForm.Designer.cs @@ -36,7 +36,7 @@ namespace CreamInstaller this.label1 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.noneFoundLabel = new System.Windows.Forms.Label(); - this.treeView1 = new CreamInstaller.ProgramSelectionTreeView(); + this.treeView1 = new CreamInstaller.CustomTreeView(); this.allCheckBox = new System.Windows.Forms.CheckBox(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.label2 = new System.Windows.Forms.Label(); @@ -201,7 +201,7 @@ namespace CreamInstaller private System.Windows.Forms.CheckBox allCheckBox; private Button scanButton; private Label noneFoundLabel; - private ProgramSelectionTreeView treeView1; + private CustomTreeView treeView1; } } diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index f158ffd..8975d54 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -325,10 +325,7 @@ namespace CreamInstaller selection.ToggleAllDlc(e.Node.Checked); e.Node.Nodes.Cast().ToList().ForEach(treeNode => treeNode.Checked = e.Node.Checked); } - else - { - selection.Enabled = e.Node.Checked; - } + else selection.Enabled = e.Node.Checked; allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; allCheckBox.Checked = treeNodes.TrueForAll(treeNode => treeNode.Checked); allCheckBox.CheckedChanged += OnAllCheckBoxChanged; diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index c89c92c..c665a95 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -28,7 +28,16 @@ namespace CreamInstaller Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += new(OnApplicationExit); - Application.Run(new MainForm()); + retry: + try + { + Application.Run(new MainForm()); + } + catch (Exception e) + { + if (ExceptionHandler.OutputException(e)) goto retry; + Application.Exit(); + } } mutex.Close(); }