コード例 #1
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command  = args.Command;
            var platform = command.GetValue("platform", "p");

#if DEBUG
            //platform = "win";
#endif
            try
            {
                EngineInternal.Initialize(platform);
            }
            catch (Exception ex)
            {
                args.Writer.WriteLine("Error initializing platform: {0}", ex);
#if DEBUG
                throw;
#endif
            }

            mainthread = Platform.Instance.ThreadStart();

            args.Writer.WriteLine("Using {0} platform", Platform.Instance.ID);
            return(false);
        }
コード例 #2
0
        public override void GetHelp(ProcessCommandLineArgs args)
        {
            var writer = args.Writer;

            args.WriteOption("--convert=<FILE>, [input.ext]", "Input file to convert from");
            args.WriteOption("--out=<FILE>, [output.ext]", "Output file to convert to");
            args.WriteOption("--zoom, -z=<ZOOM>", "Sets the zoom factor (default:1.0)");
            args.WriteOption("--max-width, -w=<ZOOM>", "Sets the maximum width for the output image");
            foreach (var format in DocumentInfoCollection.Default.Values)
            {
                var options = format.Options.ToArray();
                if (options.Length > 0)
                {
                    writer.WriteLine();
                    writer.WriteLine("{0} Conversion:", format.Description);
                    writer.Indent++;
                    var formatId = format.OptionID ?? format.ID;
                    foreach (var option in options)
                    {
                        var name = string.Format("--{0}-{1}", formatId, option.ID);
                        if (option.Values != null && option.Values.Length > 0)
                        {
                            name = string.Format("{0}=[{1}]", name, string.Join("|", option.Values));
                        }
                        args.WriteOption(name, option.Comment);
                    }
                    writer.Indent--;
                }
            }
        }
コード例 #3
0
 public override void GetHelp(ProcessCommandLineArgs args)
 {
     args.WriteOption("--server, -s", "Starts a pablo server");
     args.WriteOption("--file=<FILE>, [input.ext]", "Initial file to load (or create) after starting the server");
     args.WriteOption("--port=<PORT>", "Specifies the port to use (default:14400)");
     args.WriteOption("--nat=[true|false]", "Map the port on the router using UPnP or NAT-PMP");
     args.WriteOption("--password, -pw=<PASS>", "Sets the password for regular users");
     args.WriteOption("--oppassword, -op=<PASS>", "Sets the password for operator access");
     args.WriteOption("--userlevel, -ul=[viewer|editor|operator]", "Sets the user level for users (default:viewer)");
     args.WriteOption("--autosave=<seconds>", "Interval to save the file in seconds, or 0 to turn off");
     args.WriteOption("--backup", "Backup existing file before saving");
 }
コード例 #4
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;
            var version = Assembly.GetEntryAssembly().GetName();

            args.Writer.WriteLine("{0} v{1}", version.Name, version.Version);

            if (command.GetBool("help") ?? command.IsEmpty)
            {
                args.Writer.WriteLine("Usage: PabloDraw.Console.exe [options] [input.ext] [output.ext]");
                foreach (var handler in args.Handlers)
                {
                    args.Writer.WriteLine();
                    args.Writer.WriteLine("{0}:", handler.Name);
                    args.Writer.Indent++;
                    handler.GetHelp(args);
                    args.Writer.Indent--;
                }
            }
            return(false);
        }
コード例 #5
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;
            var version = Assembly.GetEntryAssembly().GetName();

            if (command.GetBool("help", "h", "?") == true)
            {
                ProcessCommandLineArgs.ShowConsole();
                args.Writer.WriteLine("{0} v{1}", version.Name, version.Version);
                var ext = EtoEnvironment.Platform.IsWindows ? ".exe" : "";
                args.Writer.WriteLine($"Usage: PabloDraw{ext} [options] [input.ext] [output.ext]");
                foreach (var handler in args.Handlers)
                {
                    args.Writer.WriteLine();
                    args.Writer.WriteLine("{0}:", handler.Name);
                    args.Writer.Indent++;
                    handler.GetHelp(args);
                    args.Writer.Indent--;
                }
                return(true);
            }
            return(false);
        }
コード例 #6
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;

            try
            {
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => UnhandledExceptionReporter(e.ExceptionObject);

#if MAC
                MacStyles.Apply();
#endif
                var app = new Pablo.Interface.PabloApplication();
                // app.UnhandledException += (sender, e) => UnhandledExceptionReporter(e.ExceptionObject);

                string fileName = command.GetValue("file", "f") ?? command.GenericCommand;
                bool?  editMode = null;

                // if (string.IsNullOrEmpty(fileName))
                // {
                //  var activationArguments = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
                //  if (activationArguments != null)
                //  {
                //      var args = activationArguments.ActivationData;
                //      if (args != null && args.Length > 0)
                //      {
                //          if (!args[0].EndsWith(".application", StringComparison.InvariantCultureIgnoreCase))
                //              fileName = args[0];
                //      }
                //  }
                // }
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = command.GetValue("edit", "e");
                    editMode = true;
                }

                if (!string.IsNullOrEmpty(fileName))
                {
                    app.Initialized += delegate
                    {
                        //ClickOnceUpdate.CheckForUpdate ();
                        app.Main.LoadFile(fileName, true, editMode: editMode);
                    };
                }

                /*
                 * else {
                 *      app.Initialized += delegate
                 *      {
                 *              ClickOnceUpdate.CheckForUpdate ();
                 *      };
                 * }*/
                app.Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred.  Please report this information to https://github.com/cwensley/pablodraw/issues:\n {ex}");
                ShowErrorDialog(ex);
                throw;
            }

            return(true);
        }
コード例 #7
0
 public override void GetHelp(ProcessCommandLineArgs args)
 {
     args.WriteOption("--file=<FILE>, -f=<FILE>, [input.ext]", "Initial file to view");
     args.WriteOption("--edit=<FILE>, -e=<FILE>", "Initial file to edit");
 }
コード例 #8
0
 public override void GetHelp(ProcessCommandLineArgs args)
 {
     args.WriteOption("--help", "Show options and help");
 }
コード例 #9
0
 public override void GetHelp(ProcessCommandLineArgs args)
 {
     args.WriteOption("--platform, -p=[gtk|win|wpf|mac|auto]", "Platform to load (default:auto)");
 }
コード例 #10
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;

            if (command.GetBool("server", "s") != true)
            {
                return(false);
            }

            EnableBackups = command.GetBool("backup") ?? true;
            var password         = command.GetValue("password", "pw");
            var operatorPassword = command.GetValue("op", "oppassword", "oppw");
            var port             = command.GetInt("port") ?? 14400;
            var nat       = command.GetBool("nat") ?? false;
            var userLevel = command.GetEnum <UserLevel>("userlevel", "ul") ?? UserLevel.Viewer;

            var fileName = command.GetValue("file", "generic:0");

            if (!string.IsNullOrEmpty(fileName))
            {
                if (File.Exists(fileName))
                {
                    using (var stream = File.OpenRead(fileName))
                    {
                        LoadFile(fileName, stream, true);
                    }
                }
                else
                {
                    var format = DocumentInfos.FindFormat(fileName);
                    if (format == null)
                    {
                        throw new InvalidOperationException(string.Format("Unrecognized format for file name '{0}'", fileName));
                    }
                    var doc = format.Info.Create();
                    doc.FileName = fileName;
                    doc.EditMode = true;
                    SetDocument(doc);
                }
            }

            var autosaveInterval = command.GetInt("autosave") ?? 0;

            if (autosaveInterval > 0)
            {
                // turn on autosaving
            }

            var backup = command.GetBool("backup") ?? false;

            if (backup)
            {
                // turn on backups
            }

            args.Writer.WriteLine("Starting PabloDraw server on port {0}...", port);
            StartServer(port, password, operatorPassword, nat, userLevel, args.Writer);

            args.Writer.WriteLine("Started!");
            ConsoleHelper.Run(args);

            args.Writer.WriteLine("Stopping...");
            StopServer();
            return(true);
        }
コード例 #11
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;
            var inFile  = command.GetValue("convert", "generic:0");
            var outFile = command.GetValue("out", "output", "generic:1");

            if (string.IsNullOrEmpty(inFile) && string.IsNullOrEmpty(outFile))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(inFile))
            {
                args.Writer.WriteLine("Input file name not specified");
                return(true);
            }
            if (string.IsNullOrEmpty(outFile))
            {
                args.Writer.WriteLine("Output file name not specified");
                return(true);
            }

            var formats = DocumentInfoCollection.Default;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var sourceFormat = formats.FindFormat(inFile);

            if (sourceFormat == null)
            {
                args.Writer.WriteLine("Error: Cannot find format to use for file '{0}'", inFile);
                return(false);
            }

            var destinationFormat = sourceFormat.Info.GetCompatibleDocuments().FindFormat(outFile);

            if (destinationFormat == null)
            {
                args.Writer.WriteLine("Error: Cannot find format conversion from '{0}.{1}' format to file '{2}'", sourceFormat.Info.ID, sourceFormat.ID, outFile);
                return(false);
            }

            args.Writer.WriteLine("Converting '{0}' ({1}.{2}) to '{3}' ({4}.{5})", inFile, sourceFormat.Info.ID, sourceFormat.ID, outFile, destinationFormat.Info.ID, destinationFormat.ID);

            var sourceDoc = sourceFormat.Info.Create(Platform.Instance);

            sourceDoc.Info.SetOption("animation", "false");
            var sourceHandler = sourceDoc.CreateHandler();

            sourceHandler.Zoom = command.GetFloat("zoom", "z") ?? 1.0f;
            var maxWidth = command.GetInt("max-width", "w");

            var formatId = sourceDoc.Info.OptionID ?? sourceDoc.Info.ID;

            foreach (var option in sourceDoc.Info.Options)
            {
                var val = command.GetValue(string.Format("{0}-{1}", formatId, option.ID));
                if (val != null)
                {
                    sourceDoc.Info.SetOption(option.ID, val);
                }
            }

            /**
             * var iters = 300;
             * var sw2 = new Stopwatch ();
             * sw2.Start ();
             * for (int i = 0; i < iters; i++) {
             * /**/
            sourceDoc.Load(inFile, sourceFormat, sourceHandler);

            /**
             * }
             * sw2.Stop ();
             * args.Writer.WriteLine ("Convertion rate: {0}, total seconds: {1}", iters / sw2.Elapsed.TotalSeconds, sw2.Elapsed.TotalSeconds);
             * /**/

            using (var destinationStream = new FileStream(outFile, FileMode.Create, FileAccess.Write))
            {
                sourceHandler.Save(destinationStream, destinationFormat);
            }
            stopwatch.Stop();

            args.Writer.WriteLine("Succesfully converted in {0} seconds", stopwatch.Elapsed.TotalSeconds);
            return(true);
        }
コード例 #12
0
        public override bool Process(ProcessCommandLineArgs args)
        {
            var command = args.Command;

            if (command.GetBool("server", "s") != true)
            {
                return(false);
            }

            EnableBackups = command.GetBool("backup") ?? true;
            var password         = command.GetValue("password", "pw");
            var operatorPassword = command.GetValue("op", "oppassword", "oppw");

            _port = command.GetInt("port") ?? 14400;
            var nat       = command.GetBool("nat") ?? false;
            var userLevel = command.GetEnum <UserLevel>("userlevel", "ul") ?? UserLevel.Viewer;

            var fileName = command.GetValue("file", "generic:0");

            if (!string.IsNullOrEmpty(fileName))
            {
                if (File.Exists(fileName))
                {
                    using (var stream = File.OpenRead(fileName))
                    {
                        LoadFile(fileName, stream, true);
                    }
                }
                else
                {
                    var format = DocumentInfos.FindFormat(fileName);
                    if (format == null)
                    {
                        throw new InvalidOperationException(string.Format("Unrecognized format for file name '{0}'", fileName));
                    }
                    var doc = format.Info.Create();
                    doc.FileName = fileName;
                    doc.EditMode = true;
                    SetDocument(doc);
                }
            }

            _autosaveInterval = command.GetInt("autosave") ?? 0;
            if (_autosaveInterval > 0)
            {
                if (!Directory.Exists(_port.ToString()))
                {
                    Directory.CreateDirectory(_port.ToString( )); // Store AutoSave in its port number folder so that multiple instances don't overwrite each other.
                }
                _autosaveInterval *= 1000;                        // Convert to seconds.
                _autoSaveTimer     = new Timer(TimerCallback, null, _autosaveInterval, Timeout.Infinite);
            }

            _backup = command.GetBool("backup") ?? false;


            args.Writer.WriteLine("Starting PabloDraw server on port {0}...", _port);
            StartServer(_port, password, operatorPassword, nat, userLevel, args.Writer);

            args.Writer.WriteLine("Started! Press any key to stop");
            System.Console.Read();

            args.Writer.WriteLine("Stopping...");
            StopServer();
            return(true);
        }