Log.Initialize("log.txt", LogLevel.All, true); // If you wanna log what you're doing..
STGDatabase db = new STGDatabase(@"D:\test.stg");
db.Headers.AddNewHeader(db.Data.WriteData(Encoding.UTF8.GetBytes("This is a test"), "Test")); // Adds a new header. When you read it it will not display the last character.... idk why?
db.Headers.AddNewHeader(db.Data.WriteData(Encoding.UTF8.GetBytes("This is a test 2"), "Test2")); // Same ^.
db.Commit(); // Updates the archive.
Log.WriteAway(); // Flushes the log data into the text file.
Header h = db.Headers.FindHeader("Test2")[0]; // Finds every header corresponding to the given name. Not case sensitive.
string hhh = Encoding.UTF8.GetString(db.Data.ReadData(h)); // The string we've wrote in the storage above.
// This is the start of any database file
struct tag_DBHead{
// Total headers in the lookup table
// Use short because it's highly unlikely someone is ever going to use > 65536 entries
// Optionally, use a define for it. ( Large/Small tables )
uint16_t totalEntries;
// The rva pointer to the start of the file table
uint16_t ptrFileTable;
};
struct tag_EntryHead{
// Use hashes when defining entry names since it's unlikely duplication will occur
uint32_t hash;
// Encoded buffer defining type used -- 3 bits
// bit 00 - bool
// bit 01 - int
// bit 10 - float
// bit 100 - double
// bit 101 - string
// bit 110 - char
// bit 111 - raw blob
uchar_t encodeType : 3;
// Next 5 bits would then carry on to the next tag_EntryHead structure or based on the database
// type, describe the length of the variable ( In the case of a string, blob etc. )
};
/*
So basically, your file ends up looking like this:
+0x0000 { tag_DBHead } -----------------> +0x???? { rawTableBuffer[] }
+0x0004 { tag_EntryHead[] } ---------------------------^ ( Descriptor + Length )
*/