dual gb: xml creator doohickey now works
This commit is contained in:
parent
f96a37857d
commit
0f5cc4ed25
|
@ -91,20 +91,24 @@
|
|||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(323, 20);
|
||||
this.textBoxName.TabIndex = 0;
|
||||
this.textBoxName.TextChanged += new System.EventHandler(this.textBoxName_TextChanged);
|
||||
//
|
||||
// buttonOK
|
||||
//
|
||||
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonOK.Enabled = false;
|
||||
this.buttonOK.Location = new System.Drawing.Point(12, 477);
|
||||
this.buttonOK.Name = "buttonOK";
|
||||
this.buttonOK.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonOK.TabIndex = 3;
|
||||
this.buttonOK.Text = "OK";
|
||||
this.buttonOK.UseVisualStyleBackColor = true;
|
||||
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.buttonCancel.Location = new System.Drawing.Point(272, 477);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
|
@ -157,8 +161,10 @@
|
|||
this.textBoxXML.Multiline = true;
|
||||
this.textBoxXML.Name = "textBoxXML";
|
||||
this.textBoxXML.ReadOnly = true;
|
||||
this.textBoxXML.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.textBoxXML.Size = new System.Drawing.Size(323, 212);
|
||||
this.textBoxXML.TabIndex = 0;
|
||||
this.textBoxXML.WordWrap = false;
|
||||
//
|
||||
// dualGBFileSelector2
|
||||
//
|
||||
|
@ -168,6 +174,7 @@
|
|||
this.dualGBFileSelector2.Name = "dualGBFileSelector2";
|
||||
this.dualGBFileSelector2.Size = new System.Drawing.Size(323, 29);
|
||||
this.dualGBFileSelector2.TabIndex = 0;
|
||||
this.dualGBFileSelector2.NameChanged += new System.EventHandler(this.dualGBFileSelector2_NameChanged);
|
||||
//
|
||||
// dualGBFileSelector1
|
||||
//
|
||||
|
@ -177,6 +184,7 @@
|
|||
this.dualGBFileSelector1.Name = "dualGBFileSelector1";
|
||||
this.dualGBFileSelector1.Size = new System.Drawing.Size(323, 29);
|
||||
this.dualGBFileSelector1.TabIndex = 0;
|
||||
this.dualGBFileSelector1.NameChanged += new System.EventHandler(this.dualGBFileSelector1_NameChanged);
|
||||
//
|
||||
// DualGBXMLCreator
|
||||
//
|
||||
|
|
|
@ -55,41 +55,82 @@ namespace BizHawk.MultiClient.GBtools
|
|||
|
||||
bool Recalculate()
|
||||
{
|
||||
string PathLeft = dualGBFileSelector1.GetName();
|
||||
string PathRight = dualGBFileSelector2.GetName();
|
||||
string Name = textBoxName.Name;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(PathLeft) || string.IsNullOrWhiteSpace(PathRight) || string.IsNullOrWhiteSpace(Name))
|
||||
return false;
|
||||
|
||||
List<char> NewPathL = new List<char>();
|
||||
|
||||
for (int i = 0; i < PathLeft.Length && i < PathRight.Length; i++)
|
||||
try
|
||||
{
|
||||
if (PathLeft[i] == PathRight[i])
|
||||
NewPathL.Add(PathLeft[i]);
|
||||
else
|
||||
break;
|
||||
string PathLeft = dualGBFileSelector1.GetName();
|
||||
string PathRight = dualGBFileSelector2.GetName();
|
||||
string Name = textBoxName.Text;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(PathLeft) || string.IsNullOrWhiteSpace(PathRight) || string.IsNullOrWhiteSpace(Name))
|
||||
throw new Exception("Blank Names");
|
||||
|
||||
List<char> NewPathL = new List<char>();
|
||||
|
||||
for (int i = 0; i < PathLeft.Length && i < PathRight.Length; i++)
|
||||
{
|
||||
if (PathLeft[i] == PathRight[i])
|
||||
NewPathL.Add(PathLeft[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
string BasePath = new string(NewPathL.ToArray());
|
||||
if (string.IsNullOrWhiteSpace(BasePath))
|
||||
throw new Exception("Common path?");
|
||||
BasePath = Path.GetDirectoryName(BasePath);
|
||||
PathLeft = GetRelativePath(BasePath, PathLeft);
|
||||
PathRight = GetRelativePath(BasePath, PathRight);
|
||||
|
||||
BasePath = Path.Combine(BasePath, Name) + ".xml";
|
||||
|
||||
StringWriter XML = new StringWriter();
|
||||
XML.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
|
||||
XML.WriteLine("<BizHawk-XMLGame System=\"DGB\" Name=\"{0}\">", Name);
|
||||
XML.WriteLine(" <LoadAssets>");
|
||||
XML.WriteLine(" <LeftRom FileName=\"{0}\"/>", PathLeft);
|
||||
XML.WriteLine(" <RightRom FileName=\"{0}\"/>", PathRight);
|
||||
XML.WriteLine(" </LoadAssets>");
|
||||
XML.WriteLine("</BizHawk-XMLGame>");
|
||||
|
||||
textBoxOutputDir.Text = BasePath;
|
||||
textBoxXML.Text = XML.ToString();
|
||||
buttonOK.Enabled = true;
|
||||
return true;
|
||||
}
|
||||
string BasePath = new string(NewPathL.ToArray());
|
||||
if (string.IsNullOrWhiteSpace(BasePath))
|
||||
catch (Exception e)
|
||||
{
|
||||
textBoxOutputDir.Text = "";
|
||||
textBoxXML.Text = "Failed!\n" + e.ToString();
|
||||
buttonOK.Enabled = false;
|
||||
return false;
|
||||
BasePath = System.IO.Path.GetDirectoryName(BasePath);
|
||||
PathLeft = GetRelativePath(BasePath, PathLeft);
|
||||
PathRight = GetRelativePath(BasePath, PathRight);
|
||||
}
|
||||
}
|
||||
|
||||
StringWriter XML = new StringWriter();
|
||||
XML.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
|
||||
XML.WriteLine("<BizHawk-XMLGame System=\"DGB\" Name=\"{0}\">", Name);
|
||||
XML.WriteLine(" <LoadAssets>");
|
||||
XML.WriteLine(" <LeftRom FileName=\"{0}\"/>", PathLeft);
|
||||
XML.WriteLine(" <RightRom FileName=\"{0}\"/>", PathRight);
|
||||
XML.WriteLine(" </LoadAssets>");
|
||||
XML.WriteLine("</BizHawk-XMLGame>");
|
||||
private void textBoxName_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
textBoxOutputDir.Text = BasePath;
|
||||
textBoxXML.Text = XML.ToString();
|
||||
return true;
|
||||
private void dualGBFileSelector1_NameChanged(object sender, EventArgs e)
|
||||
{
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
private void dualGBFileSelector2_NameChanged(object sender, EventArgs e)
|
||||
{
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
private void buttonOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Recalculate())
|
||||
{
|
||||
using (var sw = new StreamWriter(textBoxOutputDir.Text))
|
||||
{
|
||||
sw.Write(textBoxXML.Text);
|
||||
}
|
||||
DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue