WIP: a step to migrate (working on saves)

This commit is contained in:
2025-05-20 02:57:52 +03:00
parent f2b01d4a27
commit 4054003c29
9 changed files with 413 additions and 208 deletions

View File

@@ -0,0 +1,96 @@
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace SavedFontsConverter
{
public partial class Form1 : Form
{
//sealed class PreMergeToMergedDeserializationBinder : SerializationBinder {
// public override Type BindToType(string assemblyName, string typeName) {
// Type typeToDeserialize = null;
// // For each assemblyName/typeName that you want to deserialize to
// // a different type, set typeToDeserialize to the desired type.
// //String exeAssembly = Assembly.GetExecutingAssembly().FullName;
// String exeAssembly = "McBitFont, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null";
// //MessageBox.Show(exeAssembly);
// // The following line of code returns the type.
// typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, exeAssembly));
// return typeToDeserialize;
// }
//}
public class CustomSerializationBinder : SerializationBinder {
public override Type BindToType(string assemblyName, string typeName) {
Assembly.GetExecutingAssembly().GetType(typeName)
return Assembly.GetExecutingAssembly().GetType(typeName);
}
}
[Serializable]
public struct FrameMiniature
{
public FrameMiniature(int cc, int ww, int hh)
{
code = cc;
width = ww;
height = hh;
data = new bool[ww, hh];
}
public int code;
public int width;
public int height;
public bool[,] data;
};
[Serializable]
public struct SaveBlock
{
public bool monospaced;
public int codepage;
public int baseline;
public List<FrameMiniature> frames;
}
public Form1()
{
InitializeComponent();
}
private void oldLoad(string filename)
{
// Disable the warning.
#pragma warning disable SYSLIB0011
SaveBlock sav;
BinaryFormatter formatter = new BinaryFormatter();
formatter.Binder = new CustomSerializationBinder();
using (FileStream fs = File.Open(filename, FileMode.Open)) {
sav = (SaveBlock)formatter.Deserialize(fs);
fs.Close();
}
tbInfo.Clear();
tbInfo.AppendText("Monospaced: " + sav.monospaced.ToString() + "\n");
tbInfo.AppendText("Codepage: " + sav.codepage.ToString() + "\n");
tbInfo.AppendText("Frames: " + sav.frames.Count.ToString() + "\n");
// Re-enable the warning.
#pragma warning restore SYSLIB0011
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
lblPathOriginal.Text = dlgOpen.FileName;
oldLoad(dlgOpen.FileName);
}
}
}
}