Exemplo n.º 1
0
        static int RunWindows(ConverterCommandLines commandLines,
                              bool isMainWindow)
        {
            MainApplication theApp = new MainApplication();

            theApp.CommandLines = commandLines;
            theApp.InitializeComponent(isMainWindow);

            return(theApp.Run());
        }
Exemplo n.º 2
0
        static int RunConsoleHelp(ConverterCommandLines commandLines,
                                  bool isQuiet, bool startedInConsole, Process process)
        {
            ConsoleApplication theApp = new ConsoleApplication(process);

            theApp.CommandLines = commandLines;
            theApp.InitializeComponent(startedInConsole, isQuiet);

            return(theApp.Help());
        }
        public void Update(ConverterCommandLines commands)
        {
            if (commands == null)
            {
                return;
            }

            _textAsGeometry   = commands.TextAsGeometry;
            _includeRuntime   = commands.IncludeRuntime;
            _saveXaml         = commands.SaveXaml;
            _saveZaml         = commands.SaveZaml;
            _generateImage    = commands.SaveImage;
            _generalWpf       = _saveXaml || _saveZaml;
            _customXamlWriter = commands.UseCustomXamlWriter;
            if (_generateImage)
            {
                switch (commands.Image.ToLower())
                {
                case "bmp":
                    _encoderType = ImageEncoderType.BmpBitmap;
                    break;

                case "png":
                    _encoderType = ImageEncoderType.PngBitmap;
                    break;

                case "jpeg":
                case "jpg":
                    _encoderType = ImageEncoderType.JpegBitmap;
                    break;

                case "tif":
                case "tiff":
                    _encoderType = ImageEncoderType.TiffBitmap;
                    break;

                case "gif":
                    _encoderType = ImageEncoderType.GifBitmap;
                    break;

                case "wdp":
                    _encoderType = ImageEncoderType.WmpBitmap;
                    break;
                }
            }
        }
Exemplo n.º 4
0
        static int RunWindows(ConverterCommandLines commandLines, 
            bool isMainWindow)
        {
            MainApplication theApp = new MainApplication();
            theApp.CommandLines = commandLines;
            theApp.InitializeComponent(isMainWindow);

            return theApp.Run();
        }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            // 1. Get a pointer to the foreground window.  The idea here is that
            // If the user is starting our application from an existing console
            // shell, that shell will be the uppermost window.  We'll get it
            // and attach to it.
            // Uses this idea from, Jeffrey Knight, since it fits our model instead
            // of the recommended ATTACH_PARENT_PROCESS (DWORD)-1 parameter
            bool startedInConsole = false;
            IntPtr ptr = ConverterWindowsAPI.GetForegroundWindow();
            int processId = -1;
            ConverterWindowsAPI.GetWindowThreadProcessId(ptr, out processId);
            Process process = Process.GetProcessById(processId);

            startedInConsole = (process != null && String.Equals(
                process.ProcessName, "cmd", StringComparison.OrdinalIgnoreCase));

            // 2. Parse the command-line options to determine the requested task...
            ConverterCommandLines commandLines = new ConverterCommandLines(args);
            bool parseSuccess = commandLines.Parse(startedInConsole);

            ConverterUIOption uiOption = commandLines.Ui;
            bool isQuiet = (uiOption == ConverterUIOption.None);
            // 3. If the parsing is successful...
            if (parseSuccess)
            {
                // A test for possible file drag/drop on application icon
                int sourceCount = 0;
                if (commandLines != null && !commandLines.IsEmpty)
                {
                    IList<string> sourceFiles = commandLines.SourceFiles;
                    if (sourceFiles != null)
                    {
                        sourceCount = sourceFiles.Count;
                    }
                    else
                    {
                        string sourceFile = commandLines.SourceFile;
                        if (!String.IsNullOrEmpty(sourceFile) &&
                            File.Exists(sourceFile))
                        {
                            sourceCount = 1;
                        }
                    }
                }

                // For the console or quiet mode...
                if (startedInConsole)
                {
                    // If explicitly asked for a Windows GUI...
                    if (uiOption == ConverterUIOption.Windows)
                    {
                        if (args != null && args.Length != 0 &&
                            args.Length == sourceCount)
                        {
                            // if it passes our simple drag/drop test, show
                            // the minimal window for quick conversion of files...
                            return MainStartup.RunWindows(commandLines, false);
                        }
                        else
                        {
                            //...otherwise, display the main window.
                            return MainStartup.RunWindows(commandLines, true);
                        }
                    }
                    else
                    {
                        int exitCode = MainStartup.RunConsole(commandLines,
                            isQuiet, startedInConsole, process);

                        // Exit the application...
                        ConverterWindowsAPI.ExitProcess((uint)exitCode);

                        return exitCode;
                    }
                }
                else if (isQuiet || uiOption == ConverterUIOption.Console)
                {
                    int exitCode = MainStartup.RunConsole(commandLines,
                        isQuiet, startedInConsole, process);

                    // Exit the application...
                    ConverterWindowsAPI.ExitProcess((uint)exitCode);

                    return exitCode;
                }
                else //...for the GUI Windows mode...
                {
                    if (args != null && args.Length != 0 &&
                        args.Length == sourceCount)
                    {
                        // if it passes our simple drag/drop test, show
                        // the minimal window for quick conversion of files...
                        return MainStartup.RunWindows(commandLines, false);
                    }
                    else
                    {
                        //...otherwise, display the main window.
                        return MainStartup.RunWindows(commandLines, true);
                    }
                }
            }
            else //... else if the parsing failed...
            {
                if (commandLines != null)
                {
                    commandLines.ShowHelp = true;
                }

                if (startedInConsole ||
                    (commandLines != null && uiOption == ConverterUIOption.Console))
                {
                    int exitCode = MainStartup.RunConsoleHelp(commandLines,
                        isQuiet, startedInConsole, process);

                    // Exit the application...
                    ConverterWindowsAPI.ExitProcess((uint)exitCode);

                    return exitCode;
                }
                else
                {
                    return MainStartup.RunWindows(commandLines, true);
                }
            }
        }
Exemplo n.º 6
0
        static int RunConsoleHelp(ConverterCommandLines commandLines, 
            bool isQuiet, bool startedInConsole, Process process)
        {
            ConsoleApplication theApp = new ConsoleApplication(process);
            theApp.CommandLines = commandLines;
            theApp.InitializeComponent(startedInConsole, isQuiet);

            return theApp.Help();
        }
Exemplo n.º 7
0
        public MainWindow()
        {
            InitializeComponent();

            this.MinWidth  = 640;
            this.MinHeight = 700;

            this.Width  = 720;
            this.Height = 700;

            _startTabIndex = 0;

            _options = new ConverterOptions();
            MainApplication theApp = (MainApplication)Application.Current;

            Debug.Assert(theApp != null);
            if (theApp != null)
            {
                ConverterCommandLines commandLines = theApp.CommandLines;
                if (commandLines != null)
                {
                    if (commandLines.IsEmpty)
                    {
                        IList <string> sources = commandLines.Arguments;
                        _displayHelp = commandLines.ShowHelp ||
                                       (sources != null && sources.Count != 0);
                    }
                    else
                    {
                        _options.Update(commandLines);
                    }
                }
                else
                {
                    _displayHelp = true;
                }

                if (!_displayHelp)
                {
                    string sourceFile = commandLines.SourceFile;
                    if (!String.IsNullOrEmpty(sourceFile) && File.Exists(sourceFile))
                    {
                        _startTabIndex = 1;
                    }
                    else
                    {
                        string sourceDir = commandLines.SourceDir;
                        if (!String.IsNullOrEmpty(sourceDir) && Directory.Exists(sourceDir))
                        {
                            _startTabIndex = 3;
                        }
                        else
                        {
                            IList <string> sourceFiles = commandLines.SourceFiles;
                            if (sourceFiles != null && sourceFiles.Count != 0)
                            {
                                _startTabIndex = 2;
                            }
                        }
                    }
                }
            }

            _filesPage             = new FileConverterPage();
            _filesPage.Options     = _options;
            _filesPage.ParentFrame = filesFrame;
            _filesPage.Subscribe(this);

            filesFrame.Content = _filesPage;

            _filesListPage             = new FileListConverterPage();
            _filesListPage.Options     = _options;
            _filesListPage.ParentFrame = filesListFrame;
            _filesListPage.Subscribe(this);

            filesListFrame.Content = _filesListPage;

            _directoriesPage             = new DirectoryConverterPage();
            _directoriesPage.Options     = _options;
            _directoriesPage.ParentFrame = directoriesFrame;
            _directoriesPage.Subscribe(this);

            directoriesFrame.Content = _directoriesPage;

            _optionsPage         = new OptionsPage();
            _optionsPage.Options = _options;

            optionsFrame.Content = _optionsPage;

            this.Loaded   += new RoutedEventHandler(OnWindowLoaded);
            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);

            this.Closing += new CancelEventHandler(OnWindowClosing);
        }
Exemplo n.º 8
0
        public void Update(ConverterCommandLines commands)
        {
            if (commands == null)
            {
                return;
            }

            _textAsGeometry   = commands.TextAsGeometry;
            _includeRuntime   = commands.IncludeRuntime;
            _saveXaml         = commands.SaveXaml;
            _saveZaml         = commands.SaveZaml;
            _generateImage    = commands.SaveImage;
            _generalWpf       = _saveXaml || _saveZaml;
            _customXamlWriter = commands.UseCustomXamlWriter;
            if (_generateImage)
            {
                switch (commands.Image.ToLower())
                {
                    case "bmp":
                        _encoderType = ImageEncoderType.BmpBitmap;
                        break;
                    case "png":
                        _encoderType = ImageEncoderType.PngBitmap;
                        break;
                    case "jpeg":
                    case "jpg":
                        _encoderType = ImageEncoderType.JpegBitmap;
                        break;
                    case "tif":
                    case "tiff":
                        _encoderType = ImageEncoderType.TiffBitmap;
                        break;
                    case "gif":
                        _encoderType = ImageEncoderType.GifBitmap;
                        break;
                    case "wdp":
                        _encoderType = ImageEncoderType.WmpBitmap;
                        break;
                }
            }
        }
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            MainApplication theApp = (MainApplication)Application.Current;
            Debug.Assert(theApp != null);
            if (theApp != null && _commandLines == null)
            {
                _commandLines = theApp.CommandLines;
                if (_commandLines != null && !_commandLines.IsEmpty)
                {
                    // this will remove the watermark...
                    txtSourceFile.Focus();

                    string sourceFile = _commandLines.SourceFile;
                    if (!String.IsNullOrEmpty(sourceFile) && File.Exists(sourceFile))
                    {
                        txtSourceFile.Text = sourceFile;
                    }
                    txtOutputDir.Text = _commandLines.OutputDir;
                }
            }

            Debug.Assert(_options != null);

            if (!_isConversionError)
            {
                this.UpdateStatus();
            }
        }
Exemplo n.º 10
0
        static int Main(string[] args)
        {
            // 1. Get a pointer to the foreground window.  The idea here is that
            // If the user is starting our application from an existing console
            // shell, that shell will be the uppermost window.  We'll get it
            // and attach to it.
            // Uses this idea from, Jeffrey Knight, since it fits our model instead
            // of the recommended ATTACH_PARENT_PROCESS (DWORD)-1 parameter
            bool   startedInConsole = false;
            IntPtr ptr       = ConverterWindowsAPI.GetForegroundWindow();
            int    processId = -1;

            ConverterWindowsAPI.GetWindowThreadProcessId(ptr, out processId);
            Process process = Process.GetProcessById(processId);

            startedInConsole = (process != null && string.Equals(
                                    process.ProcessName, "cmd", StringComparison.OrdinalIgnoreCase));

            // 2. Parse the command-line options to determine the requested task...
            ConverterCommandLines commandLines = new ConverterCommandLines(args);
            bool parseSuccess = commandLines.Parse(startedInConsole);

            ConverterUIOption uiOption = commandLines.Ui;
            bool isQuiet = (uiOption == ConverterUIOption.None);

            // 3. If the parsing is successful...
            if (parseSuccess)
            {
                // A test for possible file drag/drop on application icon
                int sourceCount = 0;
                if (commandLines != null && !commandLines.IsEmpty)
                {
                    IList <string> sourceFiles = commandLines.SourceFiles;
                    if (sourceFiles != null)
                    {
                        sourceCount = sourceFiles.Count;
                    }
                    else
                    {
                        string sourceFile = commandLines.SourceFile;
                        if (!string.IsNullOrWhiteSpace(sourceFile) &&
                            File.Exists(sourceFile))
                        {
                            sourceCount = 1;
                        }
                    }
                }

                // For the console or quiet mode...
                if (startedInConsole)
                {
                    // If explicitly asked for a Windows GUI...
                    if (uiOption == ConverterUIOption.Windows)
                    {
                        if (args != null && args.Length != 0 &&
                            args.Length == sourceCount)
                        {
                            // if it passes our simple drag/drop test, show
                            // the minimal window for quick conversion of files...
                            return(MainStartup.RunWindows(commandLines, false));
                        }
                        else
                        {
                            //...otherwise, display the main window.
                            return(MainStartup.RunWindows(commandLines, true));
                        }
                    }
                    else
                    {
                        int exitCode = MainStartup.RunConsole(commandLines,
                                                              isQuiet, startedInConsole, process);

                        // Exit the application...
                        ConverterWindowsAPI.ExitProcess((uint)exitCode);

                        return(exitCode);
                    }
                }
                else if (isQuiet || uiOption == ConverterUIOption.Console)
                {
                    int exitCode = MainStartup.RunConsole(commandLines,
                                                          isQuiet, startedInConsole, process);

                    // Exit the application...
                    ConverterWindowsAPI.ExitProcess((uint)exitCode);

                    return(exitCode);
                }
                else //...for the GUI Windows mode...
                {
                    if (args != null && args.Length != 0 &&
                        args.Length == sourceCount)
                    {
                        // if it passes our simple drag/drop test, show
                        // the minimal window for quick conversion of files...
                        return(MainStartup.RunWindows(commandLines, false));
                    }
                    else
                    {
                        //...otherwise, display the main window.
                        return(MainStartup.RunWindows(commandLines, true));
                    }
                }
            }
            else //... else if the parsing failed...
            {
                if (commandLines != null)
                {
                    commandLines.ShowHelp = true;
                }

                if (startedInConsole ||
                    (commandLines != null && uiOption == ConverterUIOption.Console))
                {
                    int exitCode = MainStartup.RunConsoleHelp(commandLines,
                                                              isQuiet, startedInConsole, process);

                    // Exit the application...
                    ConverterWindowsAPI.ExitProcess((uint)exitCode);

                    return(exitCode);
                }
                else
                {
                    return(MainStartup.RunWindows(commandLines, true));
                }
            }
        }