I'm looking to make my own file format .
that format should contains pictures/pdf/and other files ...
also need to know how I can packer-unpacker for this format to unpack files from it/pack in it & reading the pictures from my own format to picture boxes on my WinForm for example.
I've searched but didn't really found what I'am looking for
I hope someone can help me , thank you
Zip is an excellent choice. Because you can encrypt the file and of course reduce the file size in some cases (text and uncompressed things). But if you want to create your own file format you can easily decide rules for your storage and order inside the file. Then serialize the info into the file. For example by object serialization or by writing the binary date to file object by object .
if you really want to write your own file format then I would suggest one of two things. One, you could do it entirely in binary at which point you would want to do a 'chunk' format. Chunk format is to basically have a header to each subsection. The header contains the size of both the header as well as the size of the payload. Create a serialization class for your header then add the bytes to the filestream from your payload. Actually pretty easy to do.
Second (and easier) way to do this would be to create an XML format. Create a master class for your format then add all of the data as collections of sub classes under that. Once you have that, use any of .net xml serialization classes to serialize it out to disk.
You can also use SQLite for your purposes. It provides dbms power without needing server. That is popular solution for your problem.
System.Data.SQLite is an ADO.NET adapter for SQLite.
Related
I have been programming a map editor to use when making 2D games. I have nearly completed it, however I can't load maps.
I have multiple options for saving and loading maps. I have:
DAT File
BIN File
MAP File
XML File
XML isn't the issue but the other file types are. I need to be able to read and write image data to these other 3 file types. I would suggest just removing these file types, but sometimes having maps that aren't XML are useful.
UPDATE:
I'm not asking to follow an algorithm that is already produced. What I mean is to write the image data to a file, and then read the data back into a bitmap object.
It sounds like what you're talking about is having a proprietary format for your game map data.
What you want to do is take a look at Object Relational Mapping (you could start here: http://en.wikipedia.org/wiki/Object-relational_mapping). You want to come up with a good way to structure your object (map image) in a store (a binary file). You'll want to write up some kind of class that follows this kind of interface:
public interface ORMap
{
public void Save(MyMap map, string fileIdentifier);
}
It sounds like you've already done this for XML.
You could the implement that interface to transform and/or serialize your MyMap object to the desired format and write it to disk using fileIdentifier as the name.
There is no one standard way of doing this, but if you have examples from other similar games you could try to look at their API and/or file structure and imitate it.
When we convert an image to binary data, (let's say a .png image) is there a way to get the extension back while converting the binary to image again in .net?
Short answer, no. You can't get the name either. The file name is not generally stored in image data.
If you know what the image format is you can use either a sensible, generally recognised extension or a file extension registered to that file type on your system. Hopefully, these will not differ.
If you don't know the format perhaps you could read it before serialising to binary and prefix it to the representation.
For a less general answer please expand your question.
EDIT
I guess you could attempt to display the image using a set of potential formats, then visually assess all succesful decodes to choose the correct format. Somehow, it seems easier to just include the original extension in the binary serialization.
I have to create a fix length record file using C#. I read the records from database and then after some business logic I would like to write some of the fields into a text file.
I researched this and some recommend using an XML to define the file, while others format the string and then write that into a file.
Is there a proper way to do this? I would like to keep this object oriented.
Thanks for any hints.
take a look at http://www.filehelpers.com/ to export the data to a fixed file format. you may also want to look at http://hibernatingrhinos.com/open-source/rhino-etl to create a process that runs the export for you. rhino.etl includes operations for FileHelpers.
You can use Jet to parse fixed length records in a text file. This is a decent overview that should be able to get you started:
http://msmvps.com/blogs/deborahk/archive/2009/08/25/reading-fixed-length-files.aspx
In the past when i've done this, I pull the data out of SQL as a Char(Length) so that the padding is handled by SQL. This makes the C# pretty easy to put together. You can do this by casting or converting the data when you select it, or by creating a table that is the exact format of your file and inserting the data in there before pulling it out into C#.
I have two TextRanges from two different RichTextBoxes, and four strings from regular textboxes. I would like to save all this information in one file, and then be able to load it later. Whats the best approach?
I've been reading some about it, and it seems that reading all into one memorystream and then save it to a file is one way to do it. And then parse this content later.
Anyone that want to share some experience, and simple code?
For a simple approach consider creating a class with string properties for each of your textbox texts. You could then set the properties when you want to save your text, use XML serialization to save the class to an XML formatted file, and then read it back at a later time.
The advantage of this approach is that you will not need to hande low-level file handling or parsing yourself.
Searching for C# and XML Serialization will yield plenty of code examples.
One solution is already provided by you: save in file and read after.
Another could be, in case if the data is too big, is using http://msdn.microsoft.com/en-us/library/dd997372.aspx Memory Mapped Fies.
I have a large raw data file (up to 1GB) which contains raw samples from a USB data logger.
I need to store extra information relating to the file (sample rate, description, trigger point, last seek position etc) and was looking into adding this as a some sort of header.
The header file should ideally be human readable and flexible so I've so far ruled out some sort of binary serialization into a header.
I also want to avoid two separate files as they could end up separated when copied or backed up. I remembered somebody telling me that newer *.*x Microsoft Office documents are actually a number of files in a zip. Is there a simple way to achieve this? Could I still keep the quick seek times to the raw file?
Update
I started using the binary serializer and found it to be a pain. I ended up using the xml serializer as I'm more comfortable using it.
I reserve some space at the start of the files for the xml. Simple
When you say you want to make the header human readable, this suggests opening the file in a text editor. Do you really want to do this considering the file size and (I'm assuming), the remainder of the file being non-human readable binary data? If it is, just write the text header data to the start of the binary file - it will be visible when the file is opened but, of course, the remainder of the file will look like garbage.
You could create an uncompressed ZIP archive, which may allow you to seek directly to the binary data. See this for information on creating a ZIP archive: http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx