From 3afca58d66f69f274b9aa9f27c01315d08b55e16 Mon Sep 17 00:00:00 2001 From: bahstrike Date: Mon, 20 Sep 2021 02:53:11 -0400 Subject: [PATCH] +added logfile functionality (only in debug) --- Matt.Designer.cs | 13 ++++++++++ Matt.cs | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- Program.cs | 15 ++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/Matt.Designer.cs b/Matt.Designer.cs index 2d482f5..dac2970 100644 --- a/Matt.Designer.cs +++ b/Matt.Designer.cs @@ -51,6 +51,7 @@ private void InitializeComponent() this.originalNeedColormap = new System.Windows.Forms.Label(); this.previewNeedColormap = new System.Windows.Forms.Label(); this.fillTransparent = new System.Windows.Forms.CheckBox(); + this.logList = new System.Windows.Forms.ListBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.groupBox2.SuspendLayout(); @@ -307,12 +308,22 @@ private void InitializeComponent() this.fillTransparent.UseVisualStyleBackColor = true; this.fillTransparent.CheckedChanged += new System.EventHandler(this.fillTransparent_CheckedChanged); // + // logList + // + this.logList.FormattingEnabled = true; + this.logList.Location = new System.Drawing.Point(93, 12); + this.logList.Name = "logList"; + this.logList.SelectionMode = System.Windows.Forms.SelectionMode.None; + this.logList.Size = new System.Drawing.Size(279, 121); + this.logList.TabIndex = 14; + // // Matt // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.logList); this.Controls.Add(this.fillTransparent); this.Controls.Add(this.previewNeedColormap); this.Controls.Add(this.originalNeedColormap); @@ -328,6 +339,7 @@ private void InitializeComponent() this.Name = "Matt"; this.Text = "Matt - BAH 2021"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Matt_FormClosing); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Matt_FormClosed); this.Load += new System.EventHandler(this.Matt_Load); this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Matt_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Matt_DragEnter); @@ -367,6 +379,7 @@ private void InitializeComponent() private System.Windows.Forms.Label originalNeedColormap; private System.Windows.Forms.Label previewNeedColormap; private System.Windows.Forms.CheckBox fillTransparent; + public System.Windows.Forms.ListBox logList; } } diff --git a/Matt.cs b/Matt.cs index 548b247..8a01b17 100644 --- a/Matt.cs +++ b/Matt.cs @@ -14,9 +14,11 @@ using Smith; namespace Matt -{ +{ public partial class Matt : Form { + public static Matt inst; + public enum Format { Solid, @@ -94,9 +96,23 @@ public Matt() { InitializeComponent(); + inst = this; + + + + // lets begin + Log.Print("-------------------------------------"); + Log.Print(" Matt Startup"); + Log.Print("-------------------------------------"); + + #if !SUPPORTINDY bitdepth4444.Visible = false; #endif + +#if !DEBUG + logList.Visible = false; +#endif } Colormap GetCurrentColormap() @@ -217,6 +233,8 @@ private void gobColormap_SelectedIndexChanged(object sender, EventArgs e) void UpdateCMP() { + Log.Print("UpdateCMP"); + Colormap cmp = GetCurrentColormap(); if(cmp == null) { @@ -398,6 +416,8 @@ unsafe static Bitmap LoadBMP_ARGB(string filename) public void ReloadOriginal(bool autoChangeOptions=false) { + Log.Print($"ReloadOriginal({autoChangeOptions})"); + try { if (autoChangeOptions) @@ -494,9 +514,11 @@ public void ReloadOriginal(bool autoChangeOptions=false) public void Reprocess(bool fromReloadOriginal=false) { + Log.Print($"Reprocess({fromReloadOriginal})"); + // if not from reloadoriginal, maybe we just want to run that instead. // could be optimized if only changing output settings.. but who cares PCs are fast now - if(!fromReloadOriginal) + if (!fromReloadOriginal) { ReloadOriginal(); return; @@ -874,5 +896,42 @@ private void fillTransparent_CheckedChanged(object sender, EventArgs e) { Reprocess(); } + + private void Matt_FormClosed(object sender, FormClosedEventArgs e) + { + + + Log.Print(" **** GRACEFUL FORM CLOSE ****"); + inst = null; + } + } + + + + public static class Log + { + public const string Filename = "Matt.log"; + + public static void Print(string s) + { +#if !DEBUG + return; +#endif + + File.AppendAllText(Filename, s + "\n"); + + if (Matt.inst != null) + { + ListBox loglb = Matt.inst.logList; + + while (loglb.Items.Count > 100) + loglb.Items.RemoveAt(0); + + int i = loglb.Items.Add(s); + loglb.TopIndex = i; + + loglb.Update(); + } + } } } diff --git a/Program.cs b/Program.cs index 868b9a3..0afbafd 100644 --- a/Program.cs +++ b/Program.cs @@ -17,6 +17,21 @@ static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Matt()); + +#if DEBUG + // if we're done, then kill temp files + foreach (string tmpfile in new string[] { Log.Filename }) + { + try + { + System.IO.File.Delete(tmpfile); + } + catch + { + + } + } +#endif } } }