コード例 #1
0
        public SwcBuild()
        {
            Compiler = null;

            Asdoc        = new bool?();
            CompilerPath = null;
            Debug        = new bool?();
            KeepAsdoc    = new bool?();
            Library      = null;
            ProjectPath  = null;

            compilerDirectory = null;
            sdkName           = null;
            sdkVersion        = null;
        }
コード例 #2
0
        private bool InitializeArguments(string[] args, out ExitCodes exitCode)
        {
            if (args.Length == 0)
            {
                ErrorHelper.MissingProjectPath(out exitCode);
                WriteLine();
                ShowHelp();
                return(true);
            }

            ProjectPath = args[0];

            if (ProjectPath.Length == 0 || ProjectPath[0] == '-')
            {
                return(ErrorHelper.MissingProjectPath(out exitCode));
            }

            //if (!Path.IsPathRooted(ProjectPath))
            ProjectPath = Path.Combine(Directory.GetCurrentDirectory(), ProjectPath);

            if (!File.Exists(ProjectPath))
            {
                if (!Path.HasExtension(ProjectPath) && File.Exists(ProjectPath + String.As3Proj))
                {
                    ProjectPath += String.As3Proj;
                }
                else
                {
                    return(ErrorHelper.InvalidPathToProjectFile(out exitCode, ProjectPath));
                }
            }

            Directory.SetCurrentDirectory(Path.GetDirectoryName(ProjectPath));
            ProjectPath = Path.GetFileName(ProjectPath);

            for (int i = 1; i < args.Length; i++)
            {
                string arg = args[i];

                if (arg.Length == 0)
                {
                    continue;
                }

                if (arg[0] != '-')
                {
                    return(ErrorHelper.ExpectedArgument(out exitCode));
                }

                int equalIndex = arg.IndexOf('=');

                if (equalIndex == -1)
                {
                    string key = arg.Substring(1).ToLower();

                    switch (key)
                    {
                    case Argument.Asdoc:
                    case Argument.AsdocAlias:
                        if (Asdoc.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        Asdoc = new bool?(true);
                        break;

                    case Argument.Debug:
                    case Argument.DebugAlias:
                        if (Debug.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        Debug = new bool?(true);
                        break;

                    case Argument.KeepAsdoc:
                    case Argument.KeepAsdocAlias:
                        if (KeepAsdoc.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        KeepAsdoc = new bool?(true);
                        break;

                    case Argument.Compiler:
                    case Argument.CompilerAlias:
                    case Argument.Library:
                    case Argument.LibraryAlias:
                        return(ErrorHelper.ValueExpected(out exitCode, key));

                    default:
                        return(ErrorHelper.UnexpectedArgument(out exitCode, key));
                    }
                }
                else
                {
                    string key   = arg.Substring(1, equalIndex - 1).ToLower();
                    string value = arg.Substring(equalIndex + 1);

                    switch (key)
                    {
                    case Argument.Asdoc:
                    case Argument.AsdocAlias:
                        if (Asdoc.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        switch (value.ToLower())
                        {
                        case Value.Empty:
                        case Value.False:
                            Asdoc = new bool?(false);
                            break;

                        case Value.True:
                            Asdoc = new bool?(true);
                            break;

                        default:
                            return(ErrorHelper.IncorrectArgumentValue(out exitCode, key, value));
                        }
                        break;

                    case Argument.Compiler:
                    case Argument.CompilerAlias:
                        if (CompilerPath != null)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }
                        if (value == Value.Empty)
                        {
                            return(ErrorHelper.EmptyValue(out exitCode, key));
                        }

                        string tempPath;

                        if (File.Exists(tempPath = Path.Combine(value, String.Bin, String.CompcBat)) ||  //$(CompilerPath)
                            File.Exists(tempPath = Path.Combine(value, String.CompcBat)) ||     //$(CompilerPath)\bin
                            Path.GetFileName(tempPath = value) == String.CompcBat && File.Exists(value) ||     //$(CompilerPath)\bin\compc.bat
                            File.Exists(tempPath = Path.ChangeExtension(value, String.Bat)))        //$(CompilerPath)\bin\compc.*
                        {
                            Compiler = ActionScriptCompiler.ASC2;
                        }
                        else if (File.Exists(tempPath = Path.Combine(value, String.Bin, String.CompcExe)) ||  //$(CompilerPath)
                                 File.Exists(tempPath = Path.Combine(value, String.CompcExe)) ||     //$(CompilerPath)\bin
                                 Path.GetFileName(tempPath = value) == String.CompcExe && File.Exists(value) ||     //$(CompilerPath)\bin\compc.exe
                                 File.Exists(tempPath = Path.ChangeExtension(value, String.Exe)))        //$(CompilerPath)\bin\compc.*
                        {
                            Compiler = ActionScriptCompiler.ASC1;
                        }
                        else
                        {
                            return(ErrorHelper.InvalidPathToCompiler(out exitCode, value));
                        }

                        compilerDirectory = Path.GetDirectoryName(Path.GetDirectoryName(tempPath));
                        CompilerPath      = tempPath;
                        break;

                    case Argument.Debug:
                    case Argument.DebugAlias:
                        if (Debug.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        switch (value.ToLower())
                        {
                        case Value.Empty:
                        case Value.False:
                        case Value.Release:
                            Debug = new bool?(false);
                            break;

                        case Value.True:
                        case Value.Debug:
                            Debug = new bool?(true);
                            break;

                        default:
                            return(ErrorHelper.IncorrectArgumentValue(out exitCode, key, value));
                        }
                        break;

                    case Argument.KeepAsdoc:
                    case Argument.KeepAsdocAlias:
                        if (KeepAsdoc.HasValue)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }

                        switch (value.ToLower())
                        {
                        case Value.Empty:
                        case Value.False:
                            KeepAsdoc = new bool?(false);
                            break;

                        case Value.True:
                            KeepAsdoc = new bool?(true);
                            break;

                        default:
                            return(ErrorHelper.IncorrectArgumentValue(out exitCode, key, value));
                        }
                        break;

                    case Argument.Library:
                    case Argument.LibraryAlias:
                        if (Library != null)
                        {
                            return(ErrorHelper.RepeatedArgument(out exitCode, key));
                        }
                        if (value == Value.Empty)
                        {
                            return(ErrorHelper.EmptyValue(out exitCode, key));
                        }
                        if (!Directory.Exists(value))
                        {
                            return(ErrorHelper.InvalidPathToLibrary(out exitCode, value));
                        }

                        Library = value;
                        break;

                    default:
                        return(ErrorHelper.UnexpectedArgument(out exitCode, key));
                    }
                }
            }

            if (compilerDirectory == null)
            {
                return(ErrorHelper.MissingCompilerDir(out exitCode));
            }

            if (!Asdoc.HasValue)
            {
                Asdoc = new bool?(false);
            }

            if (!Debug.HasValue)
            {
                Debug = new bool?(false);
            }

            if (!KeepAsdoc.HasValue)
            {
                KeepAsdoc = new bool?(false);
            }

            if (!string.IsNullOrEmpty(Library))
            {
                Library = Path.Combine(Library, "AS3", "classes");
            }

            exitCode = 0;
            return(false);
        }