Created Development : Adding New File Formats (markdown)
parent
e2e6c22287
commit
89bbbd8dd7
77
Development-:-Adding-New-File-Formats.md
Normal file
77
Development-:-Adding-New-File-Formats.md
Normal file
@ -0,0 +1,77 @@
|
||||
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**.
|
||||
|
||||
![](https://i.imgur.com/Svr9AJR.png)
|
||||
|
||||
These allow the tool to communicate with files on opening, saving, and compressing.
|
||||
|
||||
A file example:
|
||||
```csharp
|
||||
|
||||
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.
|
||||
|
||||
![](https://i.imgur.com/XjAYqjC.png)
|
||||
|
||||
Simply add your format to the list!
|
||||
|
||||
![](https://i.imgur.com/s40twaO.png)
|
||||
|
||||
Now that is all that there is to it.
|
Loading…
Reference in New Issue
Block a user