Ejemplo n.º 1
0
        public static int Run(string[] stringArgs)
        {
            CramSettings settings = new CramSettings();

            Queue<String> queue = new Queue<String>(stringArgs);
            bool outputSpecified = false;

            while (queue.Count > 0)
            {
                string arg = queue.Dequeue();
                switch (arg)
                {
                    case "-o":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -o");
                            settings.XmlFilename = queue.Dequeue();
                            outputSpecified = true;
                        }
                        break;

                    case "-colorkey":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -colorkey");
                            string param = queue.Dequeue();
                            Color specificColor;
                            if (param == "auto")
                            {
                                settings.ColorKeyMode = ColorKeyMode.Automatic;
                            }
                            else if (param == "none")
                            {
                                settings.ColorKeyMode = ColorKeyMode.Disabled;
                            }
                            else if (Util.ParseColor(param, out specificColor))
                            {
                                settings.ColorKeyMode = ColorKeyMode.Manual;
                                settings.ColorKeyColor = specificColor;
                            }
                            else
                                Bail("Invalid parameter for -colorkey: {0}", param);
                        }
                        break;

                    case "-size":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -size");
                            string param = queue.Dequeue();
                            if (!Util.ParseSize(param, out settings.PageSize))
                                Bail("Invalid parameter for -size: {0}", param);
                        }
                        break;

                    case "-bg":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -bg");
                            string param = queue.Dequeue();
                            if (!Util.ParseColor(param, out settings.BackgroundColor))
                                Bail("Invalid parameter for -bg: {0}", param);
                        }
                        break;

                    case "-border":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -border");
                            string param = queue.Dequeue();
                            int size;
                            if (!Int32.TryParse(param, out size) || size < 0)
                                Bail("Invalid parameter for -border: {0}", param);
                            settings.Border = size;
                        }
                        break;

                    case "-fallbacks":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -fallbacks");
                            string param = queue.Dequeue();
                            int size;
                            if (!Int32.TryParse(param, out size) || size < 0)
                                Bail("Invalid parameter for -fallbacks: {0}", param);
                            if (size == 0)
                            {
                                settings.AllowFallbacks = false;
                                settings.MaxFallbacks = 0;
                            }
                            else
                            {
                                settings.AllowFallbacks = true;
                                settings.MaxFallbacks = size;
                            }
                        }
                        break;

                    case "-fbsizes":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -fbsizes");
                            string param = queue.Dequeue();
                            if (!Util.ParseSizeList(param, out settings.FallbackSizes) || settings.FallbackSizes.Count < 0)
                                Bail("Invalid parameter for -fbsizes: {0}", param);
                        }
                        break;

                    case "-crop":
                        settings.Crop = true;
                        break;

                    case "-rotate":
                        settings.Rotate = true;
                        break;

                    case "-unique":
                        settings.Unique = true;
                        break;

                    case "-?":
                    case "-help":
                    case "-h":
                    case "--help":
                        ShowUsage();
                        System.Environment.Exit(0);
                        break;

                    case "-v":
                    case "-version":
                        Console.WriteLine("Sprite Crammer {0}", VersionInfo.Version);
                        Console.WriteLine("Copyright (C) 2008 Scott Hilbert");
                        Console.WriteLine("http://www.shilbert.com/");
                        System.Environment.Exit(0);
                        break;

                    case "-ipath":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -ipath");
                            string param = queue.Dequeue();
                            string paramLower = param.ToLower();
                            if (paramLower == "short")
                                settings.PathMode = PathMode.Short;
                            else if (paramLower == "full")
                                settings.PathMode = PathMode.Full;
                            else if (paramLower.StartsWith("rel:") && param.Length > 4)
                            {
                                settings.PathMode = PathMode.Relative;
                                settings.RelativePathBase = param.Substring(4);
                            }
                            else
                                Bail("Invalid parameter for -ipath: {0}", param);
                        }
                        break;

                    case "-config":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -config");
                            string param = queue.Dequeue();
                            settings = CramSettings.Load(param);
                            outputSpecified = true;
                            if (settings == null)
                                Bail("Cannot load config file: {0}", param);
                        }
                        break;

                    case "-clean":
                        settings.Clean = true;
                        break;

                    default:
                        if (arg.StartsWith("-"))
                        {
                            Console.WriteLine("Unknown option: {0}", arg);
                            System.Environment.Exit(0);
                        }
                        else
                            settings.SourceImages.Add(arg);
                        break;
                }
            }

            settings.FallbackSizes.Sort(Util.CompareFallbackSizes);

            if (!outputSpecified)
            {
                BailWithUsage("No output file specified. Use -o to specify output file path.");
            }

            SpriteCrammer crammer = new SpriteCrammer();
            crammer.Settings = settings;
            crammer.LogEvent += new ProgressLog(crammer_LogEvent);

            bool result = crammer.Run();

            return result ? 0 : 1;
        }
Ejemplo n.º 2
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            CramSettings settings;
            if (!GetSettingsFromControls(out settings))
                return;

            outputTextBox.Clear();
            SpriteCrammer crammer = new SpriteCrammer();
            crammer.LogEvent += new ProgressLog(crammer_LogEvent);
            crammer.Settings = settings;
            crammer.Run();
        }