74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System.Reflection;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.Runtime.Serialization;
|
|
|
|
sealed class LoadingBinder : System.Runtime.Serialization.SerializationBinder
|
|
{
|
|
public override Type BindToType(string assemblyName, string typeName)
|
|
{
|
|
return Type.GetType(String.Format("rshwFormat, " + Assembly.GetExecutingAssembly().FullName));
|
|
}
|
|
}
|
|
|
|
|
|
public class SavingBinder : SerializationBinder
|
|
{
|
|
public override Type BindToType(string assemblyName, string typeName)
|
|
{
|
|
if (assemblyName.Equals("Transmutate"))
|
|
return Type.GetType(typeName);
|
|
else
|
|
return defaultBinder.BindToType(assemblyName, typeName);
|
|
}
|
|
|
|
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
|
|
{
|
|
// specify a neutral code for the assembly name to be recognized by the BindToType method.
|
|
assemblyName = "Assembly-CSharp";
|
|
typeName = serializedType.FullName;
|
|
}
|
|
|
|
private static SerializationBinder defaultBinder = new BinaryFormatter().Binder;
|
|
|
|
private static object locker = new object();
|
|
private static SavingBinder _default = null;
|
|
|
|
public static SavingBinder Default
|
|
{
|
|
get
|
|
{
|
|
lock (locker)
|
|
{
|
|
if (_default == null)
|
|
_default = new SavingBinder();
|
|
}
|
|
return _default;
|
|
}
|
|
}
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class rshwFormat
|
|
{
|
|
public byte[]? audioData { get; set; }
|
|
public int[]? signalData { get; set; }
|
|
public byte[]? videoData { get; set; }
|
|
|
|
public static rshwFormat Load(string path)
|
|
{
|
|
BinaryFormatter formatter = new BinaryFormatter();
|
|
formatter.Binder = new LoadingBinder();
|
|
FileStream stream = File.OpenRead(path);
|
|
return (rshwFormat)formatter.Deserialize(stream);
|
|
}
|
|
|
|
public static void Save(string path, rshwFormat file)
|
|
{
|
|
BinaryFormatter formatter = new BinaryFormatter();
|
|
formatter.Binder = new SavingBinder();
|
|
FileStream stream = File.Open(path, FileMode.Create);
|
|
formatter.Serialize(stream, file);
|
|
stream.Close();
|
|
}
|
|
}
|
|
|