Exemplo n.º 1
0
        private void CheckAndClose()
        {
            double d;

            if (!NumDiffUtil.TryParseTollerance(textBoxTollerance.Text, out d))
            {
                MessageBox.Show("Tollerance is not a valid number");
                return;
            }

            NumDiff.Properties.Settings.Default.Tollerance = d;
            NumDiff.Properties.Settings.Default.Separators.Clear();

            if (checkBoxTab.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add("TAB");
            }

            if (checkBoxSpace.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(" ");
            }

            if (checkBoxComma.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(",");
            }

            if (checkBoxSemicolon.Checked)
            {
                NumDiff.Properties.Settings.Default.Separators.Add(";");
            }

            NumDiff.Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("usage: NumDiff <path1> <path2> [options]");
                Console.WriteLine();
                Console.WriteLine("options:");
                Console.WriteLine("-dir: paths refer to two directories)");
                Console.WriteLine("-toll <value>: tollerance value (default: " + DEFAULT_TOLLERANCE + ")");
                Console.WriteLine("-sep <TAB|SPACE|any char>: field separator (default: TAB)");
                Console.WriteLine("-name <column num>: print the row name which is in specified the 0-based column number (default: 1)");
                //Console.WriteLine("-jnd: Just print Number of Differences");
                return(0);
            }

            string path1 = args[0];
            string path2 = args[1];

            double tollerance = DEFAULT_TOLLERANCE;

            if (HasArg(args, "-toll"))
            {
                string val = GetArgPar(args, "-toll", 1);
                if (!NumDiffUtil.TryParseTollerance(val, out tollerance))
                {
                    Console.WriteLine("Tollerance is not a valid number");
                    return(1);
                }
            }

            string[] separators = new string[1];
            separators[0] = DEFAULT_SEPARATOR;
            if (HasArg(args, "-sep"))
            {
                string val = GetArgPar(args, "-sep", 1);
                if (val == "TAB")
                {
                    separators[0] = "\t";
                }
                else if (val == "SPACE")
                {
                    separators[0] = " ";
                }
                else
                {
                    separators[0] = val;
                }
            }

            int nameColumnIndex = 1;

            if (HasArg(args, "-name"))
            {
                string val = GetArgPar(args, "-name", 1);
                if (!int.TryParse(val, out nameColumnIndex))
                {
                    Console.WriteLine("Column number is not a valid number");
                    return(1);
                }
            }

            if (HasArg(args, "-dir"))
            {
                string dir1     = Path.GetDirectoryName(path1);
                string pattern1 = Path.GetFileName(path1);
                if (pattern1 == "")
                {
                    pattern1 = "*.*";
                }

                string dir2     = Path.GetDirectoryName(path2);
                string pattern2 = Path.GetFileName(path2);
                if (pattern2 == "")
                {
                    pattern2 = "*.*";
                }

                string[] files1 = Directory.GetFiles(dir1, pattern1);
                for (int i = 0; i < files1.Count(); i++)
                {
                    string filePath1 = files1[i];
                    string filePath2 = Path.Combine(dir2, Path.GetFileName(filePath1));

                    Console.WriteLine();
                    Console.WriteLine("========================================= " + (i + 1));
                    if (File.Exists(filePath2))
                    {
                        ManageCompareFiles(filePath1, filePath2, nameColumnIndex, tollerance, separators);
                    }
                    else
                    {
                        Console.WriteLine("File does not exists: " + filePath2);
                    }
                }

                // check for files existing only path2
                string[] files2 = Directory.GetFiles(dir2, pattern2);
                for (int i = 0; i < files2.Count(); i++)
                {
                    string filePath2 = files2[i];
                    string filePath1 = Path.Combine(dir1, Path.GetFileName(filePath2));

                    if (!File.Exists(filePath1))
                    {
                        Console.WriteLine();
                        Console.WriteLine("========================================= " + (files1.Count() + i + 1));

                        Console.WriteLine("File does not exists: " + filePath1);
                    }
                }

                return(0);
            }

            ManageCompareFiles(path1, path2, nameColumnIndex, tollerance, separators);

            return(0);
        }