class TJCRDIR - Tricky1975/JCR6_Sharp GitHub Wiki
This class typically contains all references to the files inside a JCR6 reference, and more. It also contains the functions which will help you to open the files stored in a JCR6 resource. It's all pretty easy, actually ;)
This is basically the dictionary containing all the file references. It's best NOT to alter this data, as it might cause some funny effects. The key-strings are always the names of the files in full caps. Due to it being a SortedDictionary the files should therefore always pop ot in alphabetic order.
var d = JCR6.Dir("MyJCRFile.JCR");
foreach(string k in d.Keys){
var e=d[k];
Console.WriteLine($"{e.Entry} has {e.Size} bytes which were compressed to {e.CompressedSize} bytes with the {e.Storage} algorithm.");
}
This is a simple piece of code to make a list of contents. ;) The TJCREntry class document will go into the deep of this.
The most famous game making use of a similar feature would be DOOM. Do you remember playing DOOM with levels made by amateurs all over the world? Using Patch WAD files that only replaced that data needed to play the level, and left the rest in its original form. Well the PatchFile method does just that. You can use this to allow players of a game you made to add their own content in a similar way DOOM does it, but there's more you can do with this. If you have Lua scripts in your JCR6 file that are bugged, you can just create a JCR6 file with the fixed scripts and this routine will replace them accordingly. PatchFile will not alter the data in the JCR6 files themselves. It will only alter the stuff in the memory to change references.
var d = JCR6.Dir("Unpatched.JCR");
Console.WriteLine( d.LoadString("hello.txt") );
d.PatchFile("Patched.JCR");
Console.WriteLine( d.LoadString("hello.txt") );
If both JCR files contain a file named "hello.txt" with different content the outcome of the WriteLine calls should change.
Basically the same as PatchFile, but now with an already loaded TJCRDIR reference class, in stead of loading it.
The B in JCR B stood for "Bank", which is a leftover from the original BlitzMax versions of JCR5 and JCR6, where Banks were the easiest way to get some important buffering done. As for C#, JCR_B reads the entire content of an entry in a JCR6 resource and returns it as a byte array.
var d = JCR6.Dir("MyResource.JCR");
var b = d.JCR_B("Hello.txt");
As the name suggests it loads the content of an entry in a JCR6 resource and returns it as a string.
If you are uncool with the sophisticated routines JCR6 provides and would rather revert back to the routines C# provides by itself, hey, here's your way to go. AsMemoryStream extracts the file from the JCR6 resource into the memory and returns it as a MemoryStream you can then use in the same manner as you can use streams in general in C#. Please note, although I deem it likely you can write to these memory streams, doing so will NOT affect the JCR6 file in anyway.
As as AsMemoryStream, but it's returned as a QuickStream as provided by TrickyUnits. As QuickStream is not part of JCR6 itself but of TrickyUnits, the documentation about it should sooner or later be put there.
Well this only works on textfiles stored in a JCR6 file, but I guess its working is obvious. Loads the content of a file stored in a JCR6 resource and returns it split in lines. It's not super sophisticated, but it should be able to tell the difference between a DOS-based text file (as used in Windows) and a Unix based text file (as used in MacOS and Linux).
var d = JCR6.Dir("MyResource.JCR")
foreach(string line in d.ReadLines("hello.txt")){
Console.WriteLine(line);
}