add 1.2 files
This commit is contained in:
parent
f2e004f763
commit
445427a954
6 changed files with 1020 additions and 0 deletions
74
RSHWFile.cs
Normal file
74
RSHWFile.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue