Add Debug Log

This commit is contained in:
Lako 2023-05-09 21:17:41 -04:00
parent 811ab277f0
commit 363a7326c1
8 changed files with 311 additions and 33 deletions

90
OpenFK/DebugWindow.Designer.cs generated Normal file
View File

@ -0,0 +1,90 @@

namespace OpenFK
{
partial class DebugWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.generalLog = new System.Windows.Forms.RichTextBox();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.logTab = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.logTab.SuspendLayout();
this.SuspendLayout();
//
// generalLog
//
this.generalLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.generalLog.Location = new System.Drawing.Point(3, 3);
this.generalLog.Name = "generalLog";
this.generalLog.ReadOnly = true;
this.generalLog.Size = new System.Drawing.Size(593, 423);
this.generalLog.TabIndex = 0;
this.generalLog.Text = "";
//
// tabControl1
//
this.tabControl1.Controls.Add(this.logTab);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(607, 455);
this.tabControl1.TabIndex = 1;
//
// logTab
//
this.logTab.Controls.Add(this.generalLog);
this.logTab.Location = new System.Drawing.Point(4, 22);
this.logTab.Name = "logTab";
this.logTab.Padding = new System.Windows.Forms.Padding(3);
this.logTab.Size = new System.Drawing.Size(599, 429);
this.logTab.TabIndex = 0;
this.logTab.Text = "Log";
this.logTab.UseVisualStyleBackColor = true;
//
// DebugWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(607, 455);
this.Controls.Add(this.tabControl1);
this.Name = "DebugWindow";
this.Text = "OpenFK - Debug";
this.tabControl1.ResumeLayout(false);
this.logTab.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox generalLog;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage logTab;
}
}

22
OpenFK/DebugWindow.cs Normal file
View File

@ -0,0 +1,22 @@
using OpenFK.OFK.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenFK
{
public partial class DebugWindow : Form
{
public DebugWindow()
{
InitializeComponent();
LogManager.debugLogText = generalLog;
}
}
}

120
OpenFK/DebugWindow.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,6 +1,7 @@
using AxShockwaveFlashObjects;
using DiscordRPC;
using Microsoft.Win32;
using OpenFK.OFK.Common;
using OpenFK.Properties;
using System;
using System.Collections.Generic;
@ -77,9 +78,14 @@ namespace OpenFK
public DiscordRpcClient client;
private FileSystemWatcher watcher;
public Form1()
public Form1(string[] args)
{
InitializeComponent();
if (args.Contains("/debug"))
{
DebugWindow debug = new DebugWindow();
debug.Show();
}
}
private void Form1_Load(object sender, EventArgs e)
@ -109,7 +115,7 @@ namespace OpenFK
AS2Container.ScaleMode = Settings.Default.ScaleMode;
AS2Container.Movie = Directory.GetCurrentDirectory() + @"\Main.swf"; //Sets Main.swf as the Flash Movie to Play.
AS2Container.Play(); //Plays Main.swf
Debug.WriteLine("[AS2Container] Main.swf is Loaded");
LogManager.LogToForm("[AS2Container] Main.swf is Loaded");
AS2Container.FSCommand += new _IShockwaveFlashEvents_FSCommandEventHandler(flashPlayer_FSCommand); //This sets up the FSCommand handler, which CCommunicator likes to use a lot.
try
@ -118,13 +124,13 @@ namespace OpenFK
AS3Container.Quality2 = "High";
AS3Container.ScaleMode = Settings.Default.ScaleMode;
AS3Container.Movie = Directory.GetCurrentDirectory() + @"\MainAS3.swf"; //Sets MainAS3.swf as the Flash Movie to Play.
Debug.WriteLine("[AS3Container] MainAS3.swf is Loaded");
LogManager.LogToForm("[AS3Container] MainAS3.swf is Loaded");
AS3Container.FSCommand += new _IShockwaveFlashEvents_FSCommandEventHandler(flashPlayerAS3_FSCommand);
AS3Container.FlashCall += new _IShockwaveFlashEvents_FlashCallEventHandler(flashPlayerAS3_FlashCall);
}
catch
{
Debug.WriteLine("[AS3Container] AS3 Failed to Load! Potentially an older version.");
LogManager.LogToForm("[AS3Container] AS3 Failed to Load! Potentially an older version.");
}
//End of Flash initialization
@ -167,7 +173,7 @@ namespace OpenFK
private void flashPlayerAS3_FSCommand(object sender, _IShockwaveFlashEvents_FSCommandEvent e)
{
Debug.WriteLine("[AS3] [SendMsg] " + e.args);
LogManager.LogToForm("[AS3] [SendMsg] " + e.args);
if(e.args.Contains("<save_jpeg ")) //Saving jpegs for UG game thumbnails or game over backgrounds.
{
XmlDocument request = new XmlDocument(); //e.args to xml
@ -235,7 +241,7 @@ namespace OpenFK
if (s != usbBittyID) //If it's still the same, it won't repeat the actions
{
usbBittyID = s;
Debug.WriteLine("[Bitty] USB bitty - " + s);
LogManager.LogToForm("[Bitty] USB bitty - " + s);
setBitty(s);
}
}
@ -251,7 +257,7 @@ namespace OpenFK
private void flashPlayerAS3_FlashCall(object sender, _IShockwaveFlashEvents_FlashCallEvent e)
{
Debug.WriteLine("[AS3] [FlashCall] " + e.request);
LogManager.LogToForm("[AS3] [FlashCall] " + e.request);
if(e.request.Contains("<as3_loaded "))
{
setVar(@"<?xml version=""1.0"" encoding=""UTF - 8""?><commands><as3_loaded id=""1"" path=""MainAS3.swf"" result=""0"" err="""" /></commands>");
@ -279,7 +285,7 @@ namespace OpenFK
void flashPlayer_FSCommand(object sender, _IShockwaveFlashEvents_FSCommandEvent e) //FSCommand Handler
{
Debug.WriteLine("[AS2] [SendMsg] " + e.args);
LogManager.LogToForm("[AS2] [SendMsg] " + e.args);
//
// XML LOAD COMMANDS
@ -298,7 +304,7 @@ namespace OpenFK
//XML LOADING
filename = xn.Attributes["section"].Value;
foldername = xn.Attributes["name"].Value;
Debug.WriteLine("[Load] File Requested - {1}/{0}", filename, foldername);
LogManager.LogToForm("[Load] File Requested - " + filename + "/" + foldername);
loadFile(filename, foldername);
//Rich Prescense
@ -388,7 +394,7 @@ namespace OpenFK
{
filename = xn.Attributes["section"].Value;
foldername = xn.Attributes["name"].Value;
Debug.WriteLine("[Save] File Requested - {1}/{0}", filename, foldername); //debug output
LogManager.LogToForm("[Save] File Requested - " + filename + "/" + foldername); //debug output
XDocument args = XDocument.Parse(e.args);
@ -411,7 +417,7 @@ namespace OpenFK
File.WriteAllBytes(Directory.GetCurrentDirectory() + @"\data\" + foldername + @"\" + filename + ".rdf", iso_8859_1.GetBytes(RDFTool.encode(iso_8859_1.GetString(RDFData))));
}
else File.WriteAllText(Directory.GetCurrentDirectory() + @"\data\" + foldername + @"\" + filename + ".xml", output.ToString()); //saves
Debug.WriteLine("[Save] Successfully saved - " + foldername + "/" + filename); //Debug Output
LogManager.LogToForm("[Save] Successfully saved - " + foldername + "/" + filename); //Debug Output
}
}
@ -501,7 +507,7 @@ namespace OpenFK
var updateprocess = Process.Start(updatescript);
}
Application.Exit(); //Closes OpenFK
Debug.WriteLine("[OpenFK] Radicaclose was called"); //Debug output
LogManager.LogToForm("[OpenFK] Radicaclose was called"); //Debug output
}
//
@ -554,7 +560,7 @@ namespace OpenFK
//HTTP POST (CRIB SAVING + POSTCARDS)
if (e.args.Contains("<netcommands"))
{
Debug.WriteLine("[Network] Netcommand called.");
LogManager.LogToForm("[Network] Netcommand called.");
string tnurl = "";
if(e.args.Contains("<save_level "))
@ -592,7 +598,7 @@ namespace OpenFK
string localVerNum = "1.8";
string fslocalVersion = "";
string fslocalVerNum = "1.0";
Debug.WriteLine("[Network] [Update] Update Requested");
LogManager.LogToForm("[Network] [Update] Update Requested");
setVar(@"<progress percent=""0.25"" />");
try
{
@ -602,21 +608,21 @@ namespace OpenFK
}
catch
{
Debug.WriteLine("[Network] [Update] Update.xml was not found");
LogManager.LogToForm("[Network] [Update] Update.xml was not found");
}
setVar(@"<progress percent=""25.00"" />");
try
{
Debug.WriteLine("[Network] [Update] Downloading Update.xml from GitHub");
LogManager.LogToForm("[Network] [Update] Downloading Update.xml from GitHub");
netStore = XDocument.Parse(Get(@"https://raw.githubusercontent.com/GittyMac/OpenFK/master/update.xml"));
Debug.WriteLine("[Network] [Update] Update.xml was downloaded");
LogManager.LogToForm("[Network] [Update] Update.xml was downloaded");
string netVersion = netStore.Root.Attribute("name").Value;
string netVersionNum = netStore.Root.Attribute("version").Value;
string netVersionSize = netStore.Root.Attribute("size").Value;
setVar(@"<progress percent=""50.00"" />");
if (localVersion != netVersion)
{
Debug.WriteLine("[Network] [Update] An update is needed");
LogManager.LogToForm("[Network] [Update] An update is needed");
netStore.Save(Directory.GetCurrentDirectory() + @"\update.xml");
setVar(@"<checkupdate result=""2"" reason=""New version of OpenFK found."" version=""2009_07_16_544"" size=""" + netVersionSize + @""" curversion=""" + localVerNum + @""" extversion=""" + netVersionNum + @""" extname=""" + netVersion + @""" />");
}
@ -630,14 +636,14 @@ namespace OpenFK
}
catch
{
Debug.WriteLine("[Network] [Update] FSGUI Update.xml was not found");
LogManager.LogToForm("[Network] [Update] FSGUI Update.xml was not found");
}
setVar(@"<progress percent=""75.00"" />");
try
{
Debug.WriteLine("[Network] [Update] Downloading FSGUI Update.xml from GitHub");
LogManager.LogToForm("[Network] [Update] Downloading FSGUI Update.xml from GitHub");
fsnetStore = XDocument.Parse(Get(@"https://raw.githubusercontent.com/GittyMac/FunkeySelectorGUI/master/update.xml"));
Debug.WriteLine("[Network] [Update] FSGUI Update.xml was downloaded");
LogManager.LogToForm("[Network] [Update] FSGUI Update.xml was downloaded");
string fsnetVersion = fsnetStore.Root.Attribute("name").Value;
string fsnetVersionNum = fsnetStore.Root.Attribute("version").Value;
string fsnetVersionSize = fsnetStore.Root.Attribute("size").Value;
@ -651,9 +657,9 @@ namespace OpenFK
}
catch
{
Debug.WriteLine("[Network] [Update] Cannot close FSGUI");
LogManager.LogToForm("[Network] [Update] Cannot close FSGUI");
}
Debug.WriteLine("[Network] [Update] A FSGUI update is needed");
LogManager.LogToForm("[Network] [Update] A FSGUI update is needed");
setVar(@"<checkupdate result=""2"" reason=""New version of FSGUI found."" version=""2009_07_16_544"" size=""" + fsnetVersionSize + @""" curversion=""" + fslocalVerNum + @""" extversion=""" + fsnetVersionNum + @""" extname=""" + fsnetVersion + @""" />");
}
else
@ -663,7 +669,7 @@ namespace OpenFK
}
catch
{
Debug.WriteLine("[Network] [Update] No FSGUI update");
LogManager.LogToForm("[Network] [Update] No FSGUI update");
setVar(@"<checkupdate result=""1"" reason=""Could not find the FunkeySelectorGUI update!"" />");
}
}
@ -674,7 +680,7 @@ namespace OpenFK
}
catch
{
Debug.WriteLine("[Network] [Update] No update");
LogManager.LogToForm("[Network] [Update] No update");
setVar(@"<checkupdate result=""1"" reason=""Could not find the OpenFK update!"" />");
}
}
@ -753,7 +759,7 @@ namespace OpenFK
savepassword = xn.Attributes["savepassword"].Value;
hintq = xn.Attributes["hintq"].Value;
hinta = xn.Attributes["hinta"].Value;
Debug.WriteLine("[Load] File Requested - system/users");
LogManager.LogToForm("[Load] File Requested - system/users");
loadFile("users", "system");
string userString = userData.OuterXml;
string data2send = userString.Replace("</users>", "") + @"<user gname=""" + username + @""" hinta=""" + hinta + @""" hintq=""" + hintq + @""" savepassword=""" + savepassword + @""" password=""" + password + @""" name=""" + username + @""" /></users>";
@ -768,7 +774,7 @@ namespace OpenFK
File.WriteAllBytes(Directory.GetCurrentDirectory() + @"\data\" + "system" + @"\" + "users" + ".rdf", iso_8859_1.GetBytes(RDFTool.encode(iso_8859_1.GetString(RDFData))));
}
else File.WriteAllText(Directory.GetCurrentDirectory() + @"\data\" + "system" + @"\" + "users" + ".xml", data2send.ToString()); //saves
Debug.WriteLine("[UserAdd] Successfully added user - " + username); //Debug Output
LogManager.LogToForm("[UserAdd] Successfully added user - " + username); //Debug Output
}
}
@ -910,7 +916,7 @@ namespace OpenFK
index = @"<commands><load section=""" + file + @""" name=""" + folder + @""" result=""1"" reason=""Error loading file!"" /></commands>"; //I would just let dotNET handle this, but UGLevels needs an error to continue.
}
setVar(index.ToString()); //Sends XML data to the game
Debug.WriteLine("[Load] Successfully loaded - " + folder + "/" + file); //Debug Output
LogManager.LogToForm("[Load] Successfully loaded - " + folder + "/" + file); //Debug Output
}
//
@ -923,6 +929,7 @@ namespace OpenFK
public void setVar(string msg)
{
LogManager.LogToForm("[SetVar/Return] Returned Message - " + msg);
AS2Container.SetVariable("msg", msg); //Sends message (msg) to the game
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenFK.OFK.Common
{
static class LogManager
{
public static RichTextBox debugLogText;
public static void LogToForm(string logElement)
{
if(debugLogText != null)
{
try
{
debugLogText.AppendText("\n" + logElement);
}
catch
{
Debug.WriteLine(logElement);
}
}
}
}
}

View File

@ -117,6 +117,12 @@
<Compile Include="ConfigForm.Designer.cs">
<DependentUpon>ConfigForm.cs</DependentUpon>
</Compile>
<Compile Include="DebugWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="DebugWindow.Designer.cs">
<DependentUpon>DebugWindow.cs</DependentUpon>
</Compile>
<Compile Include="FlashRightClick.cs">
<SubType>Component</SubType>
</Compile>
@ -126,12 +132,16 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="OFK.Common\LogManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RDFTool.cs" />
<EmbeddedResource Include="ConfigForm.resx">
<DependentUpon>ConfigForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DebugWindow.resx">
<DependentUpon>DebugWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>

View File

@ -45,7 +45,7 @@ namespace OpenFK
{
try
{
Application.Run(new Form1());
Application.Run(new Form1(args));
}
catch
{
@ -57,7 +57,7 @@ namespace OpenFK
{
try
{
Application.Run(new Form1());
Application.Run(new Form1(args));
}
catch
{

View File

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GittyMac")]
[assembly: AssemblyProduct("OpenFK")]
[assembly: AssemblyCopyright("Copyright © GittyMac 2022")]
[assembly: AssemblyCopyright("Copyright © GittyMac 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]