示例#1
0
文件: Program.cs 项目: rstarkov/i4c
        /// <summary>
        /// Processes the "compress/decompress single file" command-line command.
        /// </summary>
        private static void command_Single(string algName, string filename, RVariant[] algArgs)
        {
            Compressor compr = GetCompressor(algName);

            if (compr == null)
            {
                return;
            }

            WaitFormShow("processing...");

            compr.Configure(algArgs);
            CompressDecompressSingle(compr, filename);

            WaitFormHide();
        }
示例#2
0
文件: MainForm.cs 项目: rstarkov/i4c
        private void Compressor_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi      = (ToolStripMenuItem)sender;
            var        compressorName = mi.Text.Replace("&", "");
            Compressor compr          = Program.GetCompressor(compressorName);
            var        input          = InputBox.GetLine("Please enter the arguments for this compressor:", Program.Settings.LastArgs.Get(compressorName, ""));

            if (input == null)
            {
                return;
            }
            Program.Settings.LastArgs[compressorName] = input;
            Program.Settings.Save();
            var args = input.Split(' ');

            compr.Configure(args.Skip(1).Select(val => (RVariant)val).ToArray());
            ThreadPool.QueueUserWorkItem(dummy => Program.CompressDecompressSingle(compr, args[0]));
        }
示例#3
0
文件: Program.cs 项目: rstarkov/i4c
        /// <summary>
        /// Processes the "benchmark algorithm on all files" command-line command.
        /// </summary>
        private static void command_Benchmark(string algName, RVariant[] algArgs)
        {
            WaitFormShow("benchmarking...");

            Dictionary <string, Compressor> compressors = new Dictionary <string, Compressor>();

            foreach (var file in Directory.GetFiles(".", "*.png"))
            {
                compressors.Add(file, GetCompressor(algName));
            }

            // Queue all jobs...
            foreach (var file in compressors.Keys)
            {
                Compressor compr = compressors[file];
                compr.Configure(algArgs);
                compr.CanonicalFileName = Path.GetFileNameWithoutExtension(file);
                string sourcePath = file;
                string destDir    = PathUtil.AppPathCombine("i4c-output", "benchmark.{0},{1}".Fmt(algName, compr.ConfigString), compr.CanonicalFileName);
                string destFile   = "{0}.{1},{2}.i4c".Fmt(compr.CanonicalFileName, algName, compr.ConfigString);

                Func <Compressor, string, string, string, WaitCallback> makeCallback =
                    (v1, v2, v3, v4) => (dummy2 => CompressFile(v1, v2, v3, v4));
                ThreadPool.QueueUserWorkItem(makeCallback(compr, sourcePath, destDir, destFile));
            }
            // ...and wait until they're finished.
            int worker = 0, dummy;

            while (worker < Environment.ProcessorCount)
            {
                Thread.Sleep(200);
                ThreadPool.GetAvailableThreads(out worker, out dummy);
            }

            // Compute stats totals
            Dictionary <string, double> totals = new Dictionary <string, double>();

            foreach (var file in compressors.Keys)
            {
                var counters = compressors[file].Counters;
                foreach (var key in counters.Keys)
                {
                    if (totals.ContainsKey(key))
                    {
                        totals[key] += counters[key];
                    }
                    else
                    {
                        totals.Add(key, counters[key]);
                    }
                }
            }

            // Write stats totals to a text file
            TextTable table = new TextTable {
                ColumnSpacing = 3, MaxWidth = int.MaxValue, DefaultAlignment = HorizontalTextAlignment.Right
            };

            table.SetCell(1, 0, "TOTAL");
            int colnum = 2;
            int rownum = 2;

            foreach (var str in compressors.Values.Select(val => val.CanonicalFileName).Order())
            {
                table.SetCell(colnum++, 0, str);
            }
            int indent_prev = 0;

            foreach (var key in totals.Keys.Order())
            {
                int indent = 4 * key.ToCharArray().Count(c => c == '|');
                if (indent < indent_prev)
                {
                    rownum++;
                }
                indent_prev = indent;
                table.SetCell(0, rownum, new string(' ', indent) + key.Split('|').Last(), alignment: HorizontalTextAlignment.Left);
                table.SetCell(1, rownum, Math.Round(totals[key], 3).ToString("#,0"));
                colnum = 2;
                foreach (var compr in compressors.Values.OrderBy(c => c.CanonicalFileName))
                {
                    if (compr.Counters.ContainsKey(key))
                    {
                        table.SetCell(colnum++, rownum, Math.Round(compr.Counters[key], 3).ToString("#,0"));
                    }
                    else
                    {
                        table.SetCell(colnum++, rownum, "N/A");
                    }
                }
                rownum++;
            }
            File.WriteAllText(PathUtil.AppPathCombine("i4c-output", "benchmark.{0},{1}.txt".Fmt(algName, compressors.Values.First().ConfigString)), table.ToString());

            WaitFormHide();
        }