Пример #1
0
        private bool CreateIcon(string[] args)
        {
            IconImage iconImg   = new IconImage();
            string    framePath = null;
            string    titlePath = null;
            string    outPath   = null;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "create-icon":
                    break;

                case "-frame":
                    if (i + 1 < args.Length && framePath == null)
                    {
                        framePath = args[++i];
                        break;
                    }
                    else
                    {
                        Cll.Log.WriteLine("Error in the \"-frame\" option.");
                        return(false);
                    }

                case "-title":
                    if (i + 1 < args.Length && titlePath == null)
                    {
                        titlePath = args[++i];
                        break;
                    }
                    else
                    {
                        Cll.Log.WriteLine("Error in the \"-title\" option.");
                        return(false);
                    }

                case "-out":
                    if (i + 1 < args.Length && outPath == null)
                    {
                        outPath = args[++i];
                        break;
                    }
                    else
                    {
                        Cll.Log.WriteLine("Error in the \"-out\" option.");
                        return(false);
                    }

                default:
                    Cll.Log.WriteLine("Invalid option \"" + args[i] + "\".");
                    return(false);
                }
            }

            if (framePath != null && !File.Exists(framePath))
            {
                Cll.Log.WriteLine("The frame image \"" + framePath + "\" not exists.");
                return(false);
            }
            if (titlePath != null && !File.Exists(titlePath))
            {
                Cll.Log.WriteLine("The title screen \"" + titlePath + "\" not exists.");
                return(false);
            }
            if (outPath != null)
            {
                if (!Directory.Exists(outPath))
                {
                    Cll.Log.WriteLine("The \"" + outPath + "\" folder not exist.");
                    return(false);
                }
            }
            else
            {
                outPath = Environment.CurrentDirectory;
            }

            outPath += "\\icon.png";
            Cll.Log.WriteLine("Creating icon -----------------------------------------------------------------");
            if (titlePath != null)
            {
                Cll.Log.WriteLine("title: " + titlePath);
            }
            if (framePath != null)
            {
                Cll.Log.WriteLine("frame: " + framePath);
            }
            if (outPath != null)
            {
                Cll.Log.WriteLine("out: " + outPath);
            }

            System.Drawing.Bitmap icon = null;
            try
            {
                if (framePath != null)
                {
                    iconImg.Frame = new System.Drawing.Bitmap(framePath);
                }
                if (titlePath != null)
                {
                    iconImg.TitleScreen = new System.Drawing.Bitmap(titlePath);
                }
                icon = iconImg.Create();
                icon.Save(outPath, System.Drawing.Imaging.ImageFormat.Png);
                icon.Dispose();
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                iconImg.Dispose();
                if (icon != null)
                {
                    icon.Dispose();
                }
            }
        }