Skip to content

Commit

Permalink
+Added the Export Mod feature for XMSBT files.
Browse files Browse the repository at this point in the history
  • Loading branch information
IcySon55 committed Sep 29, 2016
1 parent 704c258 commit b61d7d6
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 12 deletions.
2 changes: 1 addition & 1 deletion App.config
Expand Up @@ -48,7 +48,7 @@
<applicationSettings>
<MsbtEditor.Properties.Settings>
<setting name="ApplicationName" serializeAs="String">
<value>MSBT Editor Reloaded v0.9.5b</value>
<value>MSBT Editor Reloaded v0.9.6</value>
</setting>
</MsbtEditor.Properties.Settings>
</applicationSettings>
Expand Down
74 changes: 74 additions & 0 deletions MSBT.cs
Expand Up @@ -903,5 +903,79 @@ public string ImportXMSBT(string filename, bool addNew = false)

return result;
}

public string ExportXMSBTMod(string outFilename, string sourceFilename, bool overwrite = true)
{
string result = "Successfully exported to XMSBT.";

try
{
if (!System.IO.File.Exists(outFilename) || (System.IO.File.Exists(outFilename) && overwrite))
{
if (HasLabels)
{
XmlDocument xmlDocument = new XmlDocument();

XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Encoding = FileEncoding;
xmlSettings.Indent = true;
xmlSettings.IndentChars = "\t";
xmlSettings.CheckCharacters = false;

XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", FileEncoding.WebName, null);
xmlDocument.AppendChild(xmlDeclaration);

XmlElement xmlRoot = xmlDocument.CreateElement("xmsbt");
xmlDocument.AppendChild(xmlRoot);

MSBT source = new MSBT(sourceFilename);

foreach (Label lbl in LBL1.Labels)
{
bool export = true;

foreach (Label lblSource in source.LBL1.Labels)
if (lbl.Name == lblSource.Name && lbl.String.Value.SequenceEqual(lblSource.String.Value))
{
export = false;
break;
}

if (export)
{
XmlElement xmlEntry = xmlDocument.CreateElement("entry");
xmlRoot.AppendChild(xmlEntry);

XmlAttribute xmlLabelAttribute = xmlDocument.CreateAttribute("label");
xmlLabelAttribute.Value = lbl.Name;
xmlEntry.Attributes.Append(xmlLabelAttribute);

XmlElement xmlString = xmlDocument.CreateElement("text");
xmlString.InnerText = FileEncoding.GetString(lbl.String.Value).Replace("\n", "\r\n").TrimEnd('\0').Replace("\0", @"\0");
xmlEntry.AppendChild(xmlString);
}
}

System.IO.StreamWriter stream = new StreamWriter(outFilename, false, FileEncoding);
xmlDocument.Save(XmlWriter.Create(stream, xmlSettings));
stream.Close();
}
else
{
result = "XMSBT does not currently support files without an LBL1 section.";
}
}
else
{
result = outFilename + " already exists and overwrite was set to false.";
}
}
catch (Exception ex)
{
result = "Unknown Error - " + ex.Message;
}

return result;
}
}
}
2 changes: 2 additions & 0 deletions MsbtEditor.csproj
Expand Up @@ -64,6 +64,7 @@
<Compile Include="frmSearchDirectory.Designer.cs">
<DependentUpon>frmSearchDirectory.cs</DependentUpon>
</Compile>
<Compile Include="Tools.cs" />
<Compile Include="UMSBT.cs" />
<Compile Include="frmBG4.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -140,6 +141,7 @@
<Content Include="images\menu-field-properties.png" />
<None Include="images\menu-find.png" />
<None Include="images\menu-import.png" />
<Content Include="images\menu-gamebanana.png" />
<Content Include="images\menu-gbatemp.png" />
<Content Include="images\menu-git.png" />
<Content Include="images\menu-new.png" />
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Expand Up @@ -31,4 +31,4 @@
//
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
[assembly: AssemblyVersion("0.9.5.0")]
[assembly: AssemblyVersion("0.9.6.0")]
10 changes: 10 additions & 0 deletions Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions Properties/Resources.resx
Expand Up @@ -157,6 +157,9 @@
<data name="menu_find" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\menu-find.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="menu_gamebanana" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\menu-gamebanana.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="menu_gbatemp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\menu-gbatemp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion Properties/Settings.settings
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)" />
</Setting>
<Setting Name="ApplicationName" Type="System.String" Scope="Application">
<Value Profile="(Default)">MSBT Editor Reloaded v0.9.5b</Value>
<Value Profile="(Default)">MSBT Editor Reloaded v0.9.6</Value>
</Setting>
<Setting Name="BG4OpenDirectory" Type="System.String" Scope="User">
<Value Profile="(Default)" />
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -29,6 +29,7 @@ I creataed this editor a while ago to support a translation project I was planni
* Import XMSBT files into an open MSBT file. Text is imported by matching the label names.
* Batch Export and Batch Import support all of the same features as the single file tools.
* To use the batch tools, keep the MSBT and XMSBT files in the same directory. (Export does this automatically, and Import expects it.)
* Export only the differences between two MSBT files to an XMSBT delta file using the new Export Mod feature!

### Other Features
* Find - I've added the ability to search for strings in the file making translation that much easier.
Expand Down
26 changes: 26 additions & 0 deletions Tools.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MsbtEditor
{
public static class Tools
{
public static bool SequenceEqual(this byte[] a1, byte[] b1)
{
int i = 0;

if (a1.Length == b1.Length)
{
while (i < a1.Length && (a1[i] == b1[i]))
i++;

if (i == a1.Length)
return true;
}

return false;
}
}
}
27 changes: 19 additions & 8 deletions frmMain.Designer.cs

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

31 changes: 31 additions & 0 deletions frmMain.cs
Expand Up @@ -344,6 +344,7 @@ private void UpdateForm()
exportCSVToolStripMenuItem.Enabled = _fileOpen;
exportXMSBTToolStripMenuItem.Enabled = _fileOpen;
importXMSBTToolStripMenuItem.Enabled = _fileOpen;
exportXMSBTModToolStripMenuItem.Enabled = _fileOpen;

lstStrings.Enabled = _fileOpen;
txtLabelName.Enabled = _fileOpen;
Expand Down Expand Up @@ -645,6 +646,36 @@ private void batchImportXMSBTToolStripMenuItem_Click(object sender, EventArgs e)
Settings.Default.Reload();
}

private void exportXMSBTModToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select the source MSBT File that has no changes...";
ofd.Filter = "MSBT Files (*.msbt)|*.msbt";
ofd.InitialDirectory = Settings.Default.InitialDirectory;

if (ofd.ShowDialog() == DialogResult.OK)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = _msbt.File.Name.Substring(0, _msbt.File.Name.Length - 4) + "xmsbt";
sfd.Title = "Save XMSBT As...";
sfd.Filter = "XMSBT (*.xmsbt)|*.xmsbt";
sfd.InitialDirectory = Settings.Default.XMSBTDirectory;
sfd.AddExtension = true;

if (sfd.ShowDialog() == DialogResult.OK)
{
Settings.Default.XMSBTDirectory = new FileInfo(sfd.FileName).DirectoryName;

string result = _msbt.ExportXMSBTMod(sfd.FileName, ofd.FileName);

MessageBox.Show(result, "XMSBT Mod Export Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Settings.Default.Save();
Settings.Default.Reload();
}

private void extractUMSBTToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
Expand Down
Binary file added images/menu-gamebanana.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b61d7d6

Please sign in to comment.