Skip to content

Commit

Permalink
+added logfile functionality (only in debug)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahstrike committed Sep 20, 2021
1 parent c333269 commit 3afca58
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Matt.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 61 additions & 2 deletions Matt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
using Smith;

namespace Matt
{
{
public partial class Matt : Form
{
public static Matt inst;

public enum Format
{
Solid,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -217,6 +233,8 @@ private void gobColormap_SelectedIndexChanged(object sender, EventArgs e)

void UpdateCMP()
{
Log.Print("UpdateCMP");

Colormap cmp = GetCurrentColormap();
if(cmp == null)
{
Expand Down Expand Up @@ -398,6 +416,8 @@ unsafe static Bitmap LoadBMP_ARGB(string filename)

public void ReloadOriginal(bool autoChangeOptions=false)
{
Log.Print($"ReloadOriginal({autoChangeOptions})");

try
{
if (autoChangeOptions)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
}
15 changes: 15 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 3afca58

Please sign in to comment.