Trying to solve save problems
This commit is contained in:
@@ -67,7 +67,7 @@ namespace BMGEditor
|
|||||||
{
|
{
|
||||||
public ExternalFile(string filename, bool create)
|
public ExternalFile(string filename, bool create)
|
||||||
{
|
{
|
||||||
Stream = File.Open(filename, create ? FileMode.Create : FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
|
Stream = File.Open(filename, create ? FileMode.Create : FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ namespace BMGEditor
|
|||||||
private void InitRW()
|
private void InitRW()
|
||||||
{
|
{
|
||||||
//Original code
|
//Original code
|
||||||
Reader = m_BigEndian ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding);
|
//Reader = m_BigEndian ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding);
|
||||||
Writer = m_BigEndian ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding);
|
//Writer = m_BigEndian ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding);
|
||||||
|
|
||||||
//Reader = Tests.isBE ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding);
|
Reader = Tests.isBE ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding);
|
||||||
//Writer = Tests.isBE ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding);
|
Writer = Tests.isBE ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ namespace BMGEditor
|
|||||||
m_File.Close();
|
m_File.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Flush()
|
||||||
|
{
|
||||||
|
m_File.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override bool DirectoryExists(string directory)
|
public override bool DirectoryExists(string directory)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -137,11 +137,6 @@ namespace BMGEditor
|
|||||||
|
|
||||||
Array.Resize(ref data, decompSize + 1);
|
Array.Resize(ref data, decompSize + 1);
|
||||||
output.CopyTo(data, 0);
|
output.CopyTo(data, 0);
|
||||||
|
|
||||||
FileStream test = File.OpenWrite("./test.bin");
|
|
||||||
test.Write(output);
|
|
||||||
test.Flush();
|
|
||||||
test.Close();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace BMGEditor
|
|||||||
public static class Tests
|
public static class Tests
|
||||||
{
|
{
|
||||||
//Not a good place to put this I know but I'm trying to figure it out
|
//Not a good place to put this I know but I'm trying to figure it out
|
||||||
public static bool isBE = false;
|
public static bool isBE = true;
|
||||||
}
|
}
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ namespace BMGEditor
|
|||||||
{
|
{
|
||||||
private void openEditor()
|
private void openEditor()
|
||||||
{
|
{
|
||||||
Form txtEditForm = new TextEntryEditorForm(m_File.Entries[entriesListBox.SelectedIndex]);
|
Form txtEditForm = new TextEntryEditorForm(m_BMG.Entries[entriesListBox.SelectedIndex]);
|
||||||
txtEditForm.Show();
|
txtEditForm.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshEntriesList()
|
private void RefreshEntriesList()
|
||||||
{
|
{
|
||||||
entriesListBox.Items.Clear();
|
entriesListBox.Items.Clear();
|
||||||
foreach (BMG.TextEntry txtEntry in m_File.Entries)
|
foreach (BMG.TextEntry txtEntry in m_BMG.Entries)
|
||||||
{
|
{
|
||||||
entriesListBox.Items.Add(txtEntry.entryName);
|
entriesListBox.Items.Add(txtEntry.entryName);
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ namespace BMGEditor
|
|||||||
|
|
||||||
private void Save()
|
private void Save()
|
||||||
{
|
{
|
||||||
m_File.Entries.Sort((x, y) =>
|
m_BMG.Entries.Sort((x, y) =>
|
||||||
{
|
{
|
||||||
string entryNameA = x.entryName, entryNameB = y.entryName;
|
string entryNameA = x.entryName, entryNameB = y.entryName;
|
||||||
return String.CompareOrdinal(entryNameA, entryNameB);
|
return String.CompareOrdinal(entryNameA, entryNameB);
|
||||||
@@ -30,7 +30,7 @@ namespace BMGEditor
|
|||||||
|
|
||||||
m_BCSV.Entries.Clear();
|
m_BCSV.Entries.Clear();
|
||||||
|
|
||||||
foreach (BMG.TextEntry txtEntry in m_File.Entries)
|
foreach (BMG.TextEntry txtEntry in m_BMG.Entries)
|
||||||
{
|
{
|
||||||
Bcsv.Entry entry = new Bcsv.Entry();
|
Bcsv.Entry entry = new Bcsv.Entry();
|
||||||
m_BCSV.Entries.Add(entry);
|
m_BCSV.Entries.Add(entry);
|
||||||
@@ -76,19 +76,20 @@ namespace BMGEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_BCSV.Flush();
|
m_BCSV.Flush();
|
||||||
m_File.Entries.Sort((x, y) =>
|
m_BMG.Entries.Sort((x, y) =>
|
||||||
{
|
{
|
||||||
int entryIndexA = x.entryNo, entryIndexB = y.entryNo;
|
int entryIndexA = x.entryNo, entryIndexB = y.entryNo;
|
||||||
return entryIndexA.CompareTo(entryIndexB);
|
return entryIndexA.CompareTo(entryIndexB);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_File.WriteToFile();
|
m_BMG.WriteToFile();
|
||||||
}
|
}
|
||||||
private void CloseArchive()
|
private void CloseArchive()
|
||||||
{
|
{
|
||||||
m_File.Close();
|
m_BMG.Close();
|
||||||
m_BCSV.Close();
|
m_BCSV.Close();
|
||||||
m_ARC.Close();
|
m_ARC.Close();
|
||||||
|
m_File.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,12 @@ namespace BMGEditor
|
|||||||
{
|
{
|
||||||
public partial class BMGEditForm : Form
|
public partial class BMGEditForm : Form
|
||||||
{
|
{
|
||||||
|
private ExternalFile m_File = null;
|
||||||
private RarcFilesystem m_ARC = null;
|
private RarcFilesystem m_ARC = null;
|
||||||
private BMG m_File = null;
|
private BMG m_BMG = null;
|
||||||
private Bcsv m_BCSV = null;
|
private Bcsv m_BCSV = null;
|
||||||
private bool arcOpen = false;
|
private bool arcOpen = false;
|
||||||
|
|
||||||
[Obsolete]
|
|
||||||
public BMGEditForm(RarcFilesystem m_ARC)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
Text = $"Text editor - {Variables.softwareName} {Variables.softwareVersion}";
|
|
||||||
if (Variables.isBeta) Text += " [BETA]";
|
|
||||||
|
|
||||||
deleteEntryBtn.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BMGEditForm()
|
public BMGEditForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -50,7 +41,7 @@ namespace BMGEditor
|
|||||||
|
|
||||||
private void addEntryBtn_Click(object sender, EventArgs e)
|
private void addEntryBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Form newEntryForm = new NewEntryForm(m_File);
|
Form newEntryForm = new NewEntryForm(m_BMG);
|
||||||
newEntryForm.ShowDialog();
|
newEntryForm.ShowDialog();
|
||||||
RefreshEntriesList();
|
RefreshEntriesList();
|
||||||
|
|
||||||
@@ -69,10 +60,13 @@ namespace BMGEditor
|
|||||||
private void saveBMGbtn_Click(object sender, EventArgs e)
|
private void saveBMGbtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Save();
|
Save();
|
||||||
|
m_ARC.Flush();
|
||||||
|
m_File.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void quitBtn_Click(object sender, EventArgs e)
|
private void quitBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
CloseArchive();
|
||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +89,8 @@ namespace BMGEditor
|
|||||||
{
|
{
|
||||||
fileName = openARCDialog.FileName;
|
fileName = openARCDialog.FileName;
|
||||||
File.Copy(fileName, fileName + ".backup", true);
|
File.Copy(fileName, fileName + ".backup", true);
|
||||||
m_ARC = new RarcFilesystem(new ExternalFile(fileName, false));
|
m_File = new ExternalFile(fileName, false);
|
||||||
|
m_ARC = new RarcFilesystem(m_File);
|
||||||
if (m_ARC.FileExists($"{m_ARC.rootName}/message.bmg") && m_ARC.FileExists($"{m_ARC.rootName}/messageid.tbl"))
|
if (m_ARC.FileExists($"{m_ARC.rootName}/message.bmg") && m_ARC.FileExists($"{m_ARC.rootName}/messageid.tbl"))
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -108,11 +103,12 @@ namespace BMGEditor
|
|||||||
MessageBoxButtons.OK,
|
MessageBoxButtons.OK,
|
||||||
MessageBoxIcon.Error);
|
MessageBoxIcon.Error);
|
||||||
m_ARC.Close();
|
m_ARC.Close();
|
||||||
|
m_File.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arcOpen = true;
|
arcOpen = true;
|
||||||
m_BCSV = new Bcsv(m_ARC.OpenFile($"{m_ARC.rootName}/messageid.tbl"));
|
m_BCSV = new Bcsv(m_ARC.OpenFile($"{m_ARC.rootName}/messageid.tbl"));
|
||||||
m_File = new BMG(m_ARC.OpenFile($"{m_ARC.rootName}/message.bmg"), m_BCSV);
|
m_BMG = new BMG(m_ARC.OpenFile($"{m_ARC.rootName}/message.bmg"), m_BCSV);
|
||||||
RefreshEntriesList();
|
RefreshEntriesList();
|
||||||
|
|
||||||
saveFileBtn.Enabled = true;
|
saveFileBtn.Enabled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user