Skip to content

Commit

Permalink
Fix: save func now work with loaded ogf in memory & ogf export info a…
Browse files Browse the repository at this point in the history
…dded
  • Loading branch information
mortany committed Apr 23, 2022
1 parent bc6acd2 commit 7d767b3
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 20 deletions.
199 changes: 195 additions & 4 deletions OGF tool/Form1.Designer.cs

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

55 changes: 39 additions & 16 deletions OGF tool/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public partial class Form1 : Form

// File sytem
public OGF_Children OGF_V = null;
public byte[] Current_OGF = null;
public List<byte> file_bytes = new List<byte>();
public string FILE_NAME = "";

// Input
public bool bKeyIsDown = false;


public Form1()
{
InitializeComponent();
Expand Down Expand Up @@ -155,6 +156,11 @@ private void CopyParams()
OGF_V.refs.refs0 = new List<string>();
OGF_V.refs.refs0.AddRange(richTextBox1.Lines);
}
else
{
OGF_V.refs.refs0 = null;
}


if(richTextBox2.Text != "" && OGF_V.usertdata!=null)
{
Expand All @@ -179,7 +185,11 @@ private void button2_Click(object sender, EventArgs e)
private void SaveFile(string filename)
{
file_bytes.Clear();
using (var fileStream = new BinaryReader(File.OpenRead(filename)))

if(Current_OGF == null) return;


using (var fileStream = new BinaryReader(new MemoryStream(Current_OGF)))
{
byte[] temp = fileStream.ReadBytes((int)(OGF_V.pos));
file_bytes.AddRange(temp);
Expand Down Expand Up @@ -238,7 +248,6 @@ private void SaveFile(string filename)

if (OGF_V.refs.refs0 != null)
{

if (OGF_V.refs.refs0.Count() > 1)
{
file_bytes.AddRange(BitConverter.GetBytes((uint)OGF.OGF4_S_MOTION_REFS_1));
Expand Down Expand Up @@ -297,9 +306,13 @@ private void OpenFile(string filename)

OGF_V = new OGF_Children();

using (var r = new BinaryReader(File.OpenRead(filename)))
Current_OGF = File.ReadAllBytes(filename);


using (var r = new BinaryReader(new MemoryStream(Current_OGF)))
{


xr_loader.SetStream(r.BaseStream);

uint size = xr_loader.find_chunkSize((int)OGF.OGF_HEADER);
Expand All @@ -320,20 +333,30 @@ private void OpenFile(string filename)
uint m_creation_time = xr_loader.ReadUInt32();
string m_exportm_modif_name_tool = xr_loader.read_stringZ();
uint m_modified_time = xr_loader.ReadUInt32();
//System.DateTime dt_e = new System.DateTime(1970, 1, 1).AddSeconds(m_export_time);
//System.DateTime dt_c = new System.DateTime(1970, 1, 1).AddSeconds(m_creation_time);
//System.DateTime dt_m = new System.DateTime(1970, 1, 1).AddSeconds(m_modified_time);
//MessageBox.Show("Source: " + m_source + "\n" +
// "Export Tool: " + m_export_tool + "\n" +
// "Owner Name: " + m_owner_name + "\n" +
// "Export modifed Tool:" + m_exportm_modif_name_tool);
//MessageBox.Show("Export Time: " + dt_e +"\n" +
// "Creation Time: " + dt_c + "\n"+
// "Modified Time: " + dt_m);
System.DateTime dt_e = new System.DateTime(1970, 1, 1).AddSeconds(m_export_time);
System.DateTime dt_c = new System.DateTime(1970, 1, 1).AddSeconds(m_creation_time);
System.DateTime dt_m = new System.DateTime(1970, 1, 1).AddSeconds(m_modified_time);

SourceTBox.Text = m_source;
UserTBox.Text = m_export_tool;
OwnerTBox.Text = m_owner_name;
LastExpTBox.Text = m_exportm_modif_name_tool;

maskedTextBox1.Text = dt_e.ToShortDateString();
maskedTextBox2.Text = dt_c.ToShortDateString();
maskedTextBox3.Text = dt_m.ToShortDateString();

//MessageBox.Show("Source: " + m_source + "\n" +
// "Export Tool: " + m_export_tool + "\n" +
// "Owner Name: " + m_owner_name + "\n" +
// "Export modifed Tool:" + m_exportm_modif_name_tool);
//MessageBox.Show("Export Time: " + dt_e +"\n" +
// "Creation Time: " + dt_c + "\n"+
// "Modified Time: " + dt_m);



if (!xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk((int)OGF.OGF4_CHILDREN, false, true))) return;
if (!xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk((int)OGF.OGF4_CHILDREN, false, true))) return;

OGF_V.pos = xr_loader.chunk_pos;

Expand Down Expand Up @@ -390,5 +413,5 @@ private void OpenFile(string filename)
}
}
}
}
}
}

0 comments on commit 7d767b3

Please sign in to comment.