Example #1
0
        static void Main(string[] args)
        {
            BiffViewerOptions options = ParseCommandLine(args);

            if (options != null)
            {
                if (args.Length == 0)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainWindow());
                }
                else
                {
                    try
                    {
                        BiffViewer viewer = new BiffViewer(options);
                        viewer.DoTheMagic();
                    }
                    catch (CommandLineException cex)
                    {
                        Console.WriteLine(cex.Message);
                        PrintUsage();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An unexpected error occurred.");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Example #2
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            BiffViewerOptions options = e.Argument as BiffViewerOptions;
            BiffViewer        viewer  = new BiffViewer(options);

            try
            {
                viewer.DoTheMagic(worker);
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "BiffView++", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                throw;
            }

            if (worker.CancellationPending)
            {
                e.Cancel = true;
            }
        }
Example #3
0
        private void cmdCreate_Click(object sender, EventArgs e)
        {
            if (!this.backgroundWorker.IsBusy)
            {
                BiffViewerOptions options = new BiffViewerOptions();
                options.ShowErrors     = true;
                options.UseTempFolder  = true;
                options.OutputFileName = options.GetTempFileName(txtFileName.Text);
                options.ShowInBrowser  = true;
                options.InputDocument  = txtFileName.Text;

                this.toolStripProgressBar1.Value = 0;

                backgroundWorker.RunWorkerAsync(options);

                // Disable the button for the duration of the download.
                this.cmdCreate.Text = "Cancel";
            }
            else
            {
                this.cmdCreate.Enabled = false;
                this.backgroundWorker.CancelAsync();
            }
        }
Example #4
0
 public BiffViewer(BiffViewerOptions options)
 {
     this._options = options;
 }
Example #5
0
        private static BiffViewerOptions ParseCommandLine(string[] args)
        {
            BiffViewerOptions options = new BiffViewerOptions();

            options.UseTempFolder = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLowerInvariant())
                {
                case "-o":
                case "/o":
                case "--out":
                    if (++i == args.Length)
                    {
                        throw new CommandLineException("Output file not specified.");
                    }
                    options.OutputFileName = args[i];
                    break;

                case "-s":
                case "/s":
                case "--show":
                    options.ShowInBrowser = true;
                    break;

                case "-t":
                case "/t":
                case "--text":
                    options.PrintTextOnly = true;
                    break;

                case "-r":
                case "/r":
                case "--range":
                    if (++i == args.Length)
                    {
                        throw new CommandLineException("Start position for range not specified.");
                    }
                    long dummy;
                    if (long.TryParse(args[i], out dummy))
                    {
                        options.StartPosition = dummy;
                    }

                    if (i + 1 != args.Length)
                    {
                        if (long.TryParse(args[i + 1], out dummy))
                        {
                            options.EndPosition = dummy;
                        }
                    }
                    break;

                case "-v":
                case "/v":
                case "--version":
                    Console.WriteLine("{0} {1}", Util.AssemblyProduct, Util.AssemblyVersion);
                    return(null);

                case "-h":
                case "/h":
                case "/?":
                case "--help":
                    PrintUsage();
                    return(null);

                default:
                    if (!String.IsNullOrEmpty(options.InputDocument))
                    {
                        throw new CommandLineException("Wrong command line parameters.");
                    }
                    options.InputDocument = args[i];
                    break;
                }
            }
            return(options);
        }
Example #6
0
        private static BiffViewerOptions ParseCommandLine(string[] args)
        {
            BiffViewerOptions options = new BiffViewerOptions();

            options.UseTempFolder = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLowerInvariant())
                {
                case "-o":
                case "/o":
                case "--out":
                    if (++i == args.Length)
                    {
                        throw new CommandLineException("Output file not specified.");
                    }
                    options.OutputFileName = args[i];
                    break;

                case "-s":
                case "/s":
                case "--show":
                    options.ShowInBrowser = true;
                    break;

                case "-t":
                case "/t":
                case "--text":
                    options.PrintTextOnly = true;
                    break;

                case "-r":
                case "/r":
                case "--range":
                    if (++i == args.Length)
                    {
                        throw new CommandLineException("Start position for range not specified.");
                    }
                    string       unparsedNumber;
                    long         parsedNumber;
                    NumberStyles styles;

                    unparsedNumber = args[i].StartsWith("0x") ? args[i].Substring(2) : args[i];
                    styles         = args[i].StartsWith("0x") ? NumberStyles.HexNumber : NumberStyles.None;

                    if (long.TryParse(unparsedNumber, styles, CultureInfo.InvariantCulture, out parsedNumber))
                    {
                        options.StartPosition = parsedNumber;
                    }

                    if (i + 1 <= args.Length)
                    {
                        unparsedNumber = args[i + 1].StartsWith("0x") ? args[i + 1].Substring(2) : args[i + 1];
                        styles         = args[i + 1].StartsWith("0x") ? NumberStyles.HexNumber : NumberStyles.None;

                        if (long.TryParse(unparsedNumber, styles, CultureInfo.InvariantCulture, out parsedNumber))
                        {
                            options.EndPosition = parsedNumber;
                            i++;
                        }
                    }
                    break;

                case "-v":
                case "/v":
                case "--version":
                    Console.WriteLine("{0} {1}", Util.AssemblyProduct, Util.AssemblyVersion);
                    return(null);

                case "-h":
                case "/h":
                case "/?":
                case "--help":
                    if (!AttachConsole(-1))
                    {                   // Attach to a parent process console
                        AllocConsole(); // Alloc a new console
                    }
                    PrintUsage();
                    return(null);

                default:
                    if (!String.IsNullOrEmpty(options.InputDocument))
                    {
                        throw new CommandLineException("Wrong command line parameters.");
                    }
                    options.InputDocument = args[i];
                    break;
                }
            }
            return(options);
        }