Skip to content

Development : Adding New File Formats

KillzXGaming edited this page Jul 30, 2019 · 1 revision

I store most formats under the File_Format_Library project. You can also create an additional plugin, which will be explained in another section.

In the project, there's a FileFormats folder. Currently organization, and namespaces are all very wip, I suggest adding your formats in there, and in either the categories, or if it is multi purpose, you can make it it's own folder.

Create a class file and name it the type of file format, either by extension or it's file magic.

File formats all use an interface, called IFileFormat.

These allow the tool to communicate with files on opening, saving, and compressing.

A file example:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Toolbox.Library;
using Toolbox.Library.Forms;

namespace FirstPlugin
{
    public class BFLYT : IFileFormat
    {
        public FileType FileType { get; set; } = FileType.Layout;

        public bool CanSave { get; set; }
        public string[] Description { get; set; } = new string[] { "Cafe Layout (GUI)" };
        public string[] Extension { get; set; } = new string[] { "*.bflyt" };
        public string FileName { get; set; }
        public string FilePath { get; set; }
        public IFileInfo IFileInfo { get; set; }

        public bool Identify(System.IO.Stream stream)
        {
            using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
            {
                //Checking the file magic is the best way. If not possible, do file extension!
                return reader.CheckSignature(4, "FLYT") || Utils.HasExtension(FileName, ".bflyt");
            }
        }

        public Type[] Types
        {
            get
            {
                List<Type> types = new List<Type>();
                return types.ToArray();
            }
        }

        public void Load(System.IO.Stream stream) 
        {
        }
        public void Unload() //This is used when the file format is disposed of
        {

        }
        public byte[] Save() //Returns a file to save. Note this is without compression as that is done later!
        {
            return null;
        }
    }
}

You can copy and edit this template. To add the format, simply go to Main.cs of the Project. This loads all of the file formats when the tool is opened.

Simply add your format to the list!

Now that is all that there is to it.