mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Add DatFile serialization
This commit is contained in:
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -6253,6 +6254,42 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Serialization
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serialze the current object to file
|
||||||
|
/// </summary>
|
||||||
|
public static void Serialize(DatFile df)
|
||||||
|
{
|
||||||
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
|
Stream output = File.Open((String.IsNullOrEmpty(df.Name) ? "default" : df.Name) + ".bin", FileMode.Create);
|
||||||
|
bf.Serialize(output, df);
|
||||||
|
output.Flush();
|
||||||
|
output.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Repopulate the current object from a file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">Name of the input file to populate from</param>
|
||||||
|
public static DatFile Deserialize(string input)
|
||||||
|
{
|
||||||
|
if (!File.Exists(input))
|
||||||
|
{
|
||||||
|
return new DatFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
|
Stream output = File.Open(input, FileMode.Open);
|
||||||
|
DatFile df = (DatFile)bf.Deserialize(output);
|
||||||
|
|
||||||
|
output.Flush();
|
||||||
|
output.Dispose();
|
||||||
|
return df;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user