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; } } }