static void OutputCompressedFile(string input, string output, string type) { if (File.Exists(input)) { if (!(output == "")) { int lztype = -1; try {//if there is no error, then its an LZ type (Lunar) lztype = int.Parse(type); byte[] file = File.ReadAllBytes(input); byte[] outbyte = null; LCompress.Compress(file, out outbyte, LCompress.GetLZType(type)); File.WriteAllBytes(output, outbyte); } catch { switch (type.ToLower()) { case "sbm5": Console.WriteLine("Commencing Compression with Super Bomberman 5 RLE Type..."); BM5RLE.Compress(input, output); break; case "sfcw": Console.WriteLine("Commencing Compression with Super Famicom Wars LZ/RLE Type..."); byte[] data = SFCWRLE.Compress(File.ReadAllBytes(input)); File.WriteAllBytes(output, data); break; default: Console.WriteLine("Type argument was invalid. Failed."); break; } } } else { Console.WriteLine("Missing output file argument. Failed."); //message - output file required } } else { Console.WriteLine("Invalid input file argument. Failed."); //message- input file required } }
//new function- allow me to decompress files (or areas in files)...but just files for now!! static void DeCompressFile(string[] args) { string input = ""; string output = ""; string type = ""; int lztype = -1; string rletype = ""; string offs = ""; int offset = 0; string len = ""; int length = -1; Console.WriteLine("Parsing arguments..."); foreach (string a in args) { string ar = a.Trim().ToLower(); if (ar.StartsWith("/input:")) { int idx = ar.IndexOf(':') + 1; input = ar.Substring(idx); } else if (ar.StartsWith("/type:")) { int idx = ar.IndexOf(':') + 1; type = ar.Substring(idx).ToLower(); if (type.StartsWith("lz")) { string t = type.Replace("lz", ""); lztype = (int)LCompress.GetLZType(t); } } else if (ar.StartsWith("/output:")) { int idx = ar.IndexOf(':') + 1; output = ar.Substring(idx); } } OutputDecompressedFile(input, output, type, lztype, offset, length); }
static uint GetLZType(section s) { return(LCompress.GetLZType(s.LZType)); }