+ XNB Inspector shows now colored error hints
This commit is contained in:
parent
e66216d524
commit
b8290c61a4
30
Tools/XNBInspector/InspectForm.Designer.cs
generated
30
Tools/XNBInspector/InspectForm.Designer.cs
generated
@ -35,7 +35,7 @@
|
|||||||
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
|
this.textBox = new System.Windows.Forms.RichTextBox();
|
||||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
@ -88,25 +88,25 @@
|
|||||||
this.openFileDialog.Filter = "XNB files |*.xnb";
|
this.openFileDialog.Filter = "XNB files |*.xnb";
|
||||||
this.openFileDialog.Title = "Choose XNB File";
|
this.openFileDialog.Title = "Choose XNB File";
|
||||||
//
|
//
|
||||||
// richTextBox1
|
// textBox
|
||||||
//
|
//
|
||||||
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
this.textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||||
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.textBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.richTextBox1.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.textBox.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.richTextBox1.Location = new System.Drawing.Point(0, 24);
|
this.textBox.Location = new System.Drawing.Point(0, 24);
|
||||||
this.richTextBox1.Name = "richTextBox1";
|
this.textBox.Name = "textBox";
|
||||||
this.richTextBox1.ReadOnly = true;
|
this.textBox.ReadOnly = true;
|
||||||
this.richTextBox1.Size = new System.Drawing.Size(784, 316);
|
this.textBox.Size = new System.Drawing.Size(784, 316);
|
||||||
this.richTextBox1.TabIndex = 2;
|
this.textBox.TabIndex = 2;
|
||||||
this.richTextBox1.Text = "";
|
this.textBox.Text = "";
|
||||||
this.richTextBox1.WordWrap = false;
|
this.textBox.WordWrap = false;
|
||||||
//
|
//
|
||||||
// pictureBox1
|
// pictureBox1
|
||||||
//
|
//
|
||||||
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
|
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.pictureBox1.Image = global::ANX.Tools.XNBInspector.Properties.Resources.ANX_Framework_Logo_220x58;
|
this.pictureBox1.Image = global::ANX.Tools.XNBInspector.Properties.Resources.ANX_Framework_Logo_220x58;
|
||||||
this.pictureBox1.Location = new System.Drawing.Point(552, 266);
|
this.pictureBox1.Location = new System.Drawing.Point(547, 265);
|
||||||
this.pictureBox1.Name = "pictureBox1";
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
this.pictureBox1.Size = new System.Drawing.Size(220, 58);
|
this.pictureBox1.Size = new System.Drawing.Size(220, 58);
|
||||||
this.pictureBox1.TabIndex = 3;
|
this.pictureBox1.TabIndex = 3;
|
||||||
@ -120,7 +120,7 @@
|
|||||||
this.AutoScroll = true;
|
this.AutoScroll = true;
|
||||||
this.ClientSize = new System.Drawing.Size(784, 362);
|
this.ClientSize = new System.Drawing.Size(784, 362);
|
||||||
this.Controls.Add(this.pictureBox1);
|
this.Controls.Add(this.pictureBox1);
|
||||||
this.Controls.Add(this.richTextBox1);
|
this.Controls.Add(this.textBox);
|
||||||
this.Controls.Add(this.statusStrip1);
|
this.Controls.Add(this.statusStrip1);
|
||||||
this.Controls.Add(this.menuStrip1);
|
this.Controls.Add(this.menuStrip1);
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
@ -146,7 +146,7 @@
|
|||||||
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
|
||||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||||
private System.Windows.Forms.RichTextBox richTextBox1;
|
private System.Windows.Forms.RichTextBox textBox;
|
||||||
private System.Windows.Forms.PictureBox pictureBox1;
|
private System.Windows.Forms.PictureBox pictureBox1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,23 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace ANX.Tools.XNBInspector
|
namespace ANX.Tools.XNBInspector
|
||||||
{
|
{
|
||||||
public partial class InspectForm : Form
|
public enum Severity
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Success,
|
||||||
|
Warning,
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IInspectLogger
|
||||||
|
{
|
||||||
|
void AppendFormat(Severity severity, string message, params object[] arg);
|
||||||
|
void Append(Severity severity, string message);
|
||||||
|
void AppendLine(Severity severity, string message);
|
||||||
|
void AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class InspectForm : Form, IInspectLogger
|
||||||
{
|
{
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
@ -30,10 +46,11 @@ namespace ANX.Tools.XNBInspector
|
|||||||
private void InspectFile(string filePath)
|
private void InspectFile(string filePath)
|
||||||
{
|
{
|
||||||
result.Clear();
|
result.Clear();
|
||||||
|
textBox.Text = String.Empty;
|
||||||
|
|
||||||
using (Stream input = File.OpenRead(filePath))
|
using (Stream input = File.OpenRead(filePath))
|
||||||
{
|
{
|
||||||
richTextBox1.Text = InspectReader.TryInspectXNB(input);
|
InspectReader.TryInspectXNB(input, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +91,65 @@ namespace ANX.Tools.XNBInspector
|
|||||||
{
|
{
|
||||||
this.Text += " v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
this.Text += " v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppendText(RichTextBox box, Color color, string text)
|
||||||
|
{
|
||||||
|
int start = box.TextLength;
|
||||||
|
box.AppendText(text);
|
||||||
|
int end = box.TextLength;
|
||||||
|
|
||||||
|
// Textbox may transform chars, so (end-start) != text.Length
|
||||||
|
box.Select(start, end - start);
|
||||||
|
{
|
||||||
|
box.SelectionColor = color;
|
||||||
|
// could set box.SelectionBackColor, box.SelectionFont too.
|
||||||
|
}
|
||||||
|
box.SelectionLength = 0; // clear
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendFormat(Severity severity, string message, params object[] arg)
|
||||||
|
{
|
||||||
|
Append(severity, String.Format(message, arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Append(Severity severity, string message)
|
||||||
|
{
|
||||||
|
Color color = Color.Black;
|
||||||
|
switch (severity)
|
||||||
|
{
|
||||||
|
case Severity.Success:
|
||||||
|
color = Color.Green;
|
||||||
|
break;
|
||||||
|
case Severity.Warning:
|
||||||
|
color = Color.Orange;
|
||||||
|
break;
|
||||||
|
case Severity.Error:
|
||||||
|
color = Color.Red;
|
||||||
|
break;
|
||||||
|
case Severity.None:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int start = textBox.TextLength;
|
||||||
|
textBox.AppendText(message);
|
||||||
|
int end = textBox.TextLength;
|
||||||
|
|
||||||
|
textBox.Select(start, end - start);
|
||||||
|
{
|
||||||
|
textBox.SelectionColor = color;
|
||||||
|
}
|
||||||
|
textBox.SelectionLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendLine(Severity severity, string message)
|
||||||
|
{
|
||||||
|
Append(severity, message + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendLine()
|
||||||
|
{
|
||||||
|
Append(Severity.None, "\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,8 @@ namespace ANX.Tools.XNBInspector
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string TryInspectXNB(Stream input)
|
public static string TryInspectXNB(Stream input, IInspectLogger result)
|
||||||
{
|
{
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InspectXNB(input, result);
|
InspectXNB(input, result);
|
||||||
@ -23,13 +22,13 @@ namespace ANX.Tools.XNBInspector
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
result.AppendLine(e.Message);
|
result.AppendLine(Severity.Error, e.Message);
|
||||||
result.AppendLine(e.StackTrace);
|
result.AppendLine(Severity.Error, e.StackTrace);
|
||||||
}
|
}
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void InspectXNB(Stream input, StringBuilder result)
|
public static void InspectXNB(Stream input, IInspectLogger result)
|
||||||
{
|
{
|
||||||
// read the XNB file information
|
// read the XNB file information
|
||||||
//
|
//
|
||||||
@ -58,75 +57,108 @@ namespace ANX.Tools.XNBInspector
|
|||||||
byte magicX = reader.ReadByte(); // X
|
byte magicX = reader.ReadByte(); // X
|
||||||
byte magicN = reader.ReadByte(); // N
|
byte magicN = reader.ReadByte(); // N
|
||||||
byte magicB = reader.ReadByte(); // B
|
byte magicB = reader.ReadByte(); // B
|
||||||
|
byte[] magicBytes = new byte[] { magicX, magicN, magicB };
|
||||||
|
byte[] magicWants = new byte[] { 88, 78, 66 };
|
||||||
|
|
||||||
result.AppendFormat("Format identifier: {0}\n", (char)magicX);
|
for (int i = 0; i < magicBytes.Length; i++)
|
||||||
result.AppendFormat("Format identifier: {0}\n", (char)magicN);
|
{
|
||||||
result.AppendFormat("Format identifier: {0}\n", (char)magicB);
|
result.Append(Severity.None, "Format identifier: ");
|
||||||
|
if (magicBytes[i] != magicWants[i])
|
||||||
|
{
|
||||||
|
result.AppendFormat(Severity.Error, "{0} (should be {1}[{2}])", magicBytes[i], magicWants[i], (char)magicWants[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[{1}]", magicWants[i], (char)magicWants[i]);
|
||||||
|
}
|
||||||
|
result.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
byte targetPlattform = reader.ReadByte();
|
byte targetPlattform = reader.ReadByte();
|
||||||
// w = Microsoft Windows
|
// w = Microsoft Windows
|
||||||
// m = Windows Phone 7
|
// m = Windows Phone 7
|
||||||
// x = Xbox 360
|
// x = Xbox 360
|
||||||
result.AppendFormat("Target platform : {0} ", (char)targetPlattform);
|
result.Append(Severity.None, "Target platform : ");
|
||||||
switch ((char)targetPlattform)
|
switch ((char)targetPlattform)
|
||||||
{
|
{
|
||||||
case 'w':
|
case 'w':
|
||||||
result.Append("(Microsoft Windows)");
|
result.AppendFormat(Severity.Success, "{0}[w] (Microsoft Windows)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
result.Append("(Windows Phone 7)");
|
result.AppendFormat(Severity.Success, "{0}[m] (Windows Phone 7)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
result.Append("(Xbox 360)");
|
result.AppendFormat(Severity.Success, "{0}[x] (Xbox 360)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result.Append("(Unknown)");
|
result.AppendFormat(Severity.Error, "{0} (Unknown or non XNA platform)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
byte formatVersion = reader.ReadByte();
|
byte formatVersion = reader.ReadByte();
|
||||||
// 5 = XNA Game Studio 4.0
|
// 5 = XNA Game Studio 4.0
|
||||||
result.AppendFormat("Format version : {0} ", formatVersion);
|
result.Append(Severity.None, "Format version : ");
|
||||||
switch (formatVersion)
|
switch (formatVersion)
|
||||||
{
|
{
|
||||||
|
case 1:
|
||||||
|
result.Append(Severity.Success, "1 (XNA Game Studio 1.0)");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
result.Append(Severity.Success, "2 (XNA Game Studio 2.0)");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result.Append(Severity.Success, "3 (XNA Game Studio 3.0)");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
result.Append(Severity.Success, "4 (XNA Game Studio 3.1)");
|
||||||
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
result.Append("(XNA Game Studio 4.0)");
|
result.Append(Severity.Success, "5 (XNA Game Studio 4.0)");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result.Append("(Unknown)");
|
result.AppendFormat(Severity.Warning, "{0} (Unknown or non XNA content)", formatVersion);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
byte flags = reader.ReadByte();
|
byte flags = reader.ReadByte();
|
||||||
result.AppendFormat("Flags : 0x{0:X4}\n", flags);
|
result.AppendFormat(Severity.None, "Flags : 0x{0:X4}\n", flags);
|
||||||
if ((flags & 0x01) == 0x01)
|
if ((flags & 0x01) == 0x01)
|
||||||
{
|
{
|
||||||
// HiDef Profile
|
// HiDef Profile
|
||||||
result.AppendLine(" - HiDef Profile");
|
result.AppendLine(Severity.None, " - HiDef Profile");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Reach Profile
|
// Reach Profile
|
||||||
result.AppendLine(" - Reach Profile");
|
result.AppendLine(Severity.None, " - Reach Profile");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCompressed = (flags & 0x80) != 0;
|
bool isCompressed = (flags & 0x80) != 0;
|
||||||
result.AppendFormat(" - Compressed {0}", isCompressed);
|
result.AppendFormat(Severity.None, " - Compressed {0}", isCompressed);
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
int sizeOnDisk = reader.ReadInt32();
|
int sizeOnDisk = reader.ReadInt32();
|
||||||
result.AppendFormat("Size on disk : {0,10} ({1,10} bytes)", ToHumanSize(sizeOnDisk), sizeOnDisk);
|
result.Append(Severity.None, "Size on disk : ");
|
||||||
|
if (sizeOnDisk != input.Length)
|
||||||
|
{
|
||||||
|
result.AppendFormat(Severity.Error, "{0} bytes [{1}]", sizeOnDisk, ToHumanSize(sizeOnDisk));
|
||||||
|
result.AppendFormat(Severity.Error, " (Should be {0} bytes [{1}])", input.Length, ToHumanSize(input.Length));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.AppendFormat(Severity.Success, "{0} bytes [{1}]", sizeOnDisk, ToHumanSize(sizeOnDisk));
|
||||||
|
}
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
long position = reader.BaseStream.Position;
|
|
||||||
int sizeOfdata = reader.ReadInt32();
|
|
||||||
reader.BaseStream.Seek(position, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
if (isCompressed)
|
if (isCompressed)
|
||||||
{
|
{
|
||||||
result.AppendFormat("Uncompressed : {0,10} ({1,10} bytes)", ToHumanSize(sizeOfdata), sizeOfdata);
|
long position = reader.BaseStream.Position;
|
||||||
|
int sizeOfdata = reader.ReadInt32();
|
||||||
|
reader.BaseStream.Seek(position, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
result.AppendFormat(Severity.None, "Uncompressed : {0} bytes [{1}]", sizeOfdata, ToHumanSize(sizeOfdata));
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
input = ANX.Framework.Content.Decompressor.DecompressStream(reader, input, sizeOnDisk);
|
input = ANX.Framework.Content.Decompressor.DecompressStream(reader, input, sizeOnDisk);
|
||||||
@ -134,19 +166,19 @@ namespace ANX.Tools.XNBInspector
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numTypes = reader.Read7BitEncodedInt();
|
int numTypes = reader.Read7BitEncodedInt();
|
||||||
result.AppendFormat("Type readers : {0}", numTypes);
|
result.AppendFormat(Severity.None, "Type readers : {0}", numTypes);
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
for (int i = 0; i < numTypes; i++)
|
for (int i = 0; i < numTypes; i++)
|
||||||
{
|
{
|
||||||
string readerTypeName = reader.ReadString();
|
string readerTypeName = reader.ReadString();
|
||||||
int readerVersionNumber = reader.ReadInt32();
|
int readerVersionNumber = reader.ReadInt32();
|
||||||
result.AppendFormat(" - Version: {1} Type: {2}", i, readerVersionNumber, readerTypeName);
|
result.AppendFormat(Severity.None, " - Version: {1} Type: {2}", i, readerVersionNumber, readerTypeName);
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
int numSharedResources = reader.Read7BitEncodedInt();
|
int numSharedResources = reader.Read7BitEncodedInt();
|
||||||
result.AppendFormat("Shared resources : {0}", numSharedResources);
|
result.AppendFormat(Severity.None, "Shared resources : {0}", numSharedResources);
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.2.0.0")]
|
[assembly: AssemblyVersion("0.3.0.0")]
|
||||||
[assembly: AssemblyFileVersion("0.2.0.0")]
|
[assembly: AssemblyFileVersion("0.3.0.0")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user