public static byte[] Decompress(string file, CompressionType cmp) { byte[] ret = new byte[0]; try { switch (cmp) { case CompressionType.Uncompressed: ret = File.ReadAllBytes(file); break; case CompressionType.Kosinski: ret = Kosinski.Decompress(file); break; case CompressionType.KosinskiM: ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian); break; case CompressionType.Nemesis: ret = Nemesis.Decompress(file); break; case CompressionType.Enigma: ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian); break; case CompressionType.SZDD: ret = SZDDComp.SZDDComp.Decompress(file); break; case CompressionType.Comper: ret = Comper.Decompress(file); break; case CompressionType.KosinskiPlus: ret = KosinskiPlus.Decompress(file); break; case CompressionType.KosinskiPlusM: ret = ModuledKosinskiPlus.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian); break; default: throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!"); } } catch { LevelData.Log("Unable to read file \"" + file + "\" with compression " + cmp.ToString() + ":"); throw; } return(ret); }
/// <summary> /// Verify button click /// </summary> private void btnVerify_Click(object sender, EventArgs e) { txtResult.Clear(); int from = (int)numFrom.Value; int to = (int)numTo.Value; int length = to - from; byte[] range = GetBytes(from, length, _data); try { byte[] result = Nemesis.Decompress(range); txtResult.Text = "Nemesis (" + length + " bytes)"; return; } catch { } try { byte[] result = Enigma.Decompress(range, Endianness.BigEndian); txtResult.Text = "Enigma (" + length + " bytes)"; return; } catch { } try { byte[] result = Kosinski.Decompress(range); txtResult.Text = "Kosinski (" + length + " bytes)"; return; } catch { } txtResult.Text = "Not Compressed (" + length + " bytes)"; }
static void Main(string[] args) { LongOpt[] opts = new[] { new LongOpt("help", Argument.No, null, 'h'), new LongOpt("compress", Argument.Required, null, 'c'), new LongOpt("decompress", Argument.Required, null, 'd'), new LongOpt("recompress", Argument.Required, null, 'r'), new LongOpt("same-filename", Argument.No, null, 's'), new LongOpt("little-endian", Argument.No, null, 'l'), new LongOpt("no-size", Argument.No, null, 'n') }; Getopt getopt = new Getopt("KensSharp", args, Getopt.digest(opts), opts); Mode? mode = null; CompressionType?type = null; Endianness endian = Endianness.BigEndian; bool size = true; bool samefilename = false; int opt = getopt.getopt(); while (opt != -1) { switch (opt) { case 'h': ShowHelp(); return; case 'c': mode = Mode.Compress; type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true); break; case 'd': mode = Mode.Decompress; type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true); break; case 'r': mode = Mode.Recompress; type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true); break; case 's': samefilename = true; break; case 'l': endian = Endianness.LittleEndian; break; case 'n': size = false; break; } opt = getopt.getopt(); } if (mode == null || type == null || getopt.Optind + (mode == Mode.Recompress | samefilename ? 0 : 1) >= args.Length) { ShowHelp(); return; } string input = args[getopt.Optind]; string output; if (getopt.Optind + 1 == args.Length) { output = input; } else { output = args[getopt.Optind + 1]; } if (samefilename && input != "-") { switch (mode) { case Mode.Compress: switch (type) { case CompressionType.Kosinski: output = Path.ChangeExtension(input, "kos"); break; case CompressionType.Enigma: output = Path.ChangeExtension(input, "eni"); break; case CompressionType.Nemesis: output = Path.ChangeExtension(input, "nem"); break; case CompressionType.Saxman: output = Path.ChangeExtension(input, "sax"); break; case CompressionType.KosinskiModuled: output = Path.ChangeExtension(input, "kosm"); break; } break; case Mode.Decompress: output = Path.ChangeExtension(input, "unc"); break; } } byte[] indata = ReadInput(input); byte[] outdata = null; switch (mode) { case Mode.Compress: switch (type) { case CompressionType.Kosinski: outdata = Kosinski.Compress(indata); break; case CompressionType.Enigma: outdata = Enigma.Compress(indata, endian); break; case CompressionType.Nemesis: outdata = Nemesis.Compress(indata); break; case CompressionType.Saxman: outdata = Saxman.Compress(indata, size); break; case CompressionType.ModuledKosinski: outdata = ModuledKosinski.Compress(indata, endian); break; } break; case Mode.Decompress: switch (type) { case CompressionType.Kosinski: outdata = Kosinski.Decompress(indata); break; case CompressionType.Enigma: outdata = Enigma.Decompress(indata, endian); break; case CompressionType.Nemesis: outdata = Nemesis.Decompress(indata); break; case CompressionType.Saxman: outdata = Saxman.Decompress(indata); break; case CompressionType.ModuledKosinski: outdata = ModuledKosinski.Decompress(indata, endian); break; } break; case Mode.Recompress: switch (type) { case CompressionType.Kosinski: outdata = Kosinski.Compress(Kosinski.Decompress(indata)); break; case CompressionType.Enigma: outdata = Enigma.Compress(Enigma.Decompress(indata, endian), endian); break; case CompressionType.Nemesis: outdata = Nemesis.Compress(Nemesis.Decompress(indata)); break; case CompressionType.Saxman: outdata = Saxman.Compress(Saxman.Decompress(indata), size); break; case CompressionType.ModuledKosinski: outdata = ModuledKosinski.Compress(ModuledKosinski.Decompress(indata, endian), endian); break; } break; } WriteOutput(output, outdata); }
private void Execute() { if (this.compressRadioButton.Checked) { switch (this.formatListBox.SelectedIndex) { case 0: // Kosinski Kosinski.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 1: // Moduled Kosinski ModuledKosinski.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex); break; case 2: // Enigma Enigma.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex); break; case 3: // Nemesis Nemesis.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 4: // Saxman (with size) Saxman.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, true); break; case 5: // Saxman (without size) Saxman.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, false); break; case 6: // Comper Comper.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 7: // Kosinski+ KosinskiPlus.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 8: // Moduled Kosinski+ ModuledKosinskiPlus.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; } } else if (this.decompressRadioButton.Checked) { switch (this.formatListBox.SelectedIndex) { case 0: // Kosinski Kosinski.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 1: // Moduled Kosinski ModuledKosinski.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex); break; case 2: // Enigma Enigma.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex); break; case 3: // Nemesis Nemesis.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 4: // Saxman (with size) Saxman.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 5: // Saxman (without size) Saxman.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (long)this.sizeParameterNumericUpDown.Value); break; case 6: // Comper Comper.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 7: // Kosinski+ KosinskiPlus.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; case 8: // Moduled Kosinski+ ModuledKosinskiPlus.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName); break; } } }