Beispiel #1
0
        static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // redirect console output to parent process;
            // must be before any calls to Console.WriteLine()
            AttachConsole(ATTACH_PARENT_PROCESS);

            //check if the GUI shall be invoked
            if (args != null && args.Length > 0)
            {
                //parse command line
                var cliArguments = new CommandLineArguments();
                if (CommandLine.Parser.Default.ParseArguments(args, cliArguments))
                {
                    int returnCode = 0;
                    try
                    {
                        var md5Comparison = new Md5Comparison(cliArguments);

                        returnCode = (int)md5Comparison.Compare();
                    }
                    catch (Exception e)
                    {
                        //argument exceptions (invalid MD5 hash, ZIP file not found, directory not found)
                        Console.WriteLine(cliArguments.GetUsage());
                        Console.WriteLine("\n{0}", e.Message);
                        returnCode = (int)CompareResult.Error;
                    }

                    return(returnCode);
                }
                else
                {
                    //invalid command line arguments
                    Console.WriteLine(cliArguments.GetUsage());

                    return(0);
                }
            }
            else
            {
                //start GUI application
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());

                return(0);
            }
        }
Beispiel #2
0
        public CompareForm(string md5hash, string zipFilePath, string compareFolder)
        {
            InitializeComponent();

            var comparer = new Md5Comparison(md5hash, zipFilePath, compareFolder, new TextBoxStreamWriter(m_CompareMessages));

            Task.Run(() =>
            {
                var result = comparer.Compare();
                m_StatusTextLabel.BeginInvoke(new Action(() =>
                {
                    switch (result)
                    {
                    case CompareResult.Ok:
                        m_StatusTextLabel.Text      = "OK";
                        m_StatusTextLabel.BackColor = Color.LightGreen;
                        break;

                    case CompareResult.InvalidFileHash:
                        m_StatusTextLabel.Text      = "Invalid file MD5 hash.";
                        m_StatusTextLabel.BackColor = Color.OrangeRed;
                        break;

                    case CompareResult.InvalidZipHash:
                        m_StatusTextLabel.Text      = "Invalid ZIP MD5 hash.";
                        m_StatusTextLabel.BackColor = Color.OrangeRed;
                        break;

                    case CompareResult.Error:
                        m_StatusTextLabel.Text      = "An internal error occurred.";
                        m_StatusTextLabel.BackColor = Color.Yellow;
                        break;
                    }
                    m_OkButton.Enabled = true;
                }));
            });
        }