Beispiel #1
0
        public static OutputSetting ParseFromXML(XmlElement elem, Settings mainSettings)
        {
            OutputSetting settings = new OutputSetting();

            string useAlways = elem.GetAttribute("useAlways");

            settings.UseAlways = String.IsNullOrEmpty(useAlways) ? false : Boolean.Parse(useAlways);

            string targetPlatform = elem.GetAttribute("targetPlatform");

            if (!String.IsNullOrEmpty(targetPlatform))
            {
                settings.TargetPlatform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), targetPlatform);
            }

            string targetConfiguration = elem.GetAttribute("targetConfiguration");

            if (!String.IsNullOrEmpty(targetConfiguration))
            {
                settings.TargetConfiguration = (TargetConfiguration)Enum.Parse(typeof(TargetConfiguration), targetConfiguration);
            }

            foreach (XmlNode n in elem)
            {
                XmlElement curElem = n as XmlElement;
                if (curElem == null)
                {
                    continue;
                }

                if (curElem.Name == "includeFiles")
                {
                    settings.IncludeFiles = curElem.InnerText;
                }
                else if (curElem.Name == "excludeFiles")
                {
                    settings.ExcludeFiles = curElem.InnerText;
                }
                if (curElem.Name == "localPath")
                {
                    string path = mainSettings.ReplacePathVariables(curElem.InnerText);
                    settings.LocalPath = Settings.GetFullPathFromRelativeOrFull(mainSettings.GamePath, path, false);
                }
                else if (curElem.Name == "execute")
                {
                    string path = mainSettings.ReplacePathVariables(curElem.InnerText);
                    settings.ExecutePath = Settings.GetFullPathFromRelativeOrFull(mainSettings.GamePath, path, true);
                }
                else if (curElem.Name == "settings")
                {
                    settings.DeleteDefs     = Boolean.Parse(curElem.GetAttribute("deleteDefs"));
                    settings.DeleteComments = Boolean.Parse(curElem.GetAttribute("deleteComments"));
                    settings.DeleteWhite    = Boolean.Parse(curElem.GetAttribute("deleteWhite"));
                    settings.LineLengthMin  = Int32.Parse(curElem.GetAttribute("lineLengthMin"));
                    settings.LineLengthMax  = Int32.Parse(curElem.GetAttribute("lineLengthMax"));
                    settings.RandomCase     = Boolean.Parse(curElem.GetAttribute("randomCase"));
                }
            }
            return(settings);
        }
Beispiel #2
0
        private void ReadSettings()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(_settingsFile);

            foreach (XmlNode curNode in doc.DocumentElement.ChildNodes)
            {
                XmlElement curElem = curNode as XmlElement;
                if (curElem == null)
                {
                    continue;
                }

                switch (curElem.Name)
                {
                case "scriptInfoDir":
                    SIsFSGameFolder = curElem.InnerText;
                    break;

                case "sourceRaw":
                    SourceRaw = curElem.GetAttribute("path");
                    if (!String.IsNullOrEmpty(SourceRaw))
                    {
                        _sourceRawFoldersSettings = curElem;
                        BuildSourceRawFolders(SourceRaw, _sourceRawFolders, curElem);
                    }
                    break;

                case "sourceFSGame":
                    SourceFSGame = curElem.GetAttribute("path");
                    if (!String.IsNullOrEmpty(SourceFSGame))
                    {
                        _sourceFSGameFoldersSettings = curElem;
                        BuildSourceRawFolders(SourceFSGame, _sourceFSGameFolders, curElem);
                    }
                    break;

                case "outputRaw":
                    _outputRaws.Add(OutputSetting.ParseFromXML(curElem, this));
                    break;

                case "outputFSGame":
                    _outputFSGames.Add(OutputSetting.ParseFromXML(curElem, this));
                    break;

                case "targetPlatform":
                    _targetPlatform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), curElem.InnerText);
                    break;

                case "targetConfiguration":
                    _targetConfiguration = (TargetConfiguration)Enum.Parse(typeof(TargetConfiguration), curElem.InnerText);
                    break;

                case "isVersionIntFromDate":
                    _isVersionIntFromDate = Boolean.Parse(curElem.InnerText);
                    break;

                case "versionInt":
                    _versionInt = String.IsNullOrEmpty(curElem.InnerText) ? 0 : Int32.Parse(curElem.InnerText);
                    break;

                case "versionStr":
                    _versionStr = curElem.InnerText;
                    break;

                default:
                    throw new XmlException("Unknown settings node '" + curElem.Name + "'");
                }
            }

            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "Settings");
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "=========================");
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "WorkingPath: " + WorkingPath);
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SIs' Path: " + SIsPath);
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SIs' FSGame folder: " + SIsFSGameFolder);
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "GamePath: " + GamePath);

            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SourceFSGame Path: " + SourceFSGame);

            foreach (string curFolder in _sourceFSGameFolders)
            {
                _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SourceFSGame: " + curFolder);
            }

            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SourceRaw Path: " + SourceRaw);

            foreach (string curFolder in _sourceRawFolders)
            {
                _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "SourceRaw: " + curFolder);
            }

            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "TargetPlatform: " + TargetPlatform.ToString());
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "TargetConfiguration: " + TargetConfiguration.ToString());
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "IsVersionIntFromDate: " + IsVersionIntFromDate.ToString());
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "VersionInt: " + VersionInt.ToString());
            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "VersionStr: " + VersionStr);

            _scrManager.Trace.TraceEvent(TraceEventType.Verbose, 0, "=========================");

            _scrManager.Trace.Flush();
        }
Beispiel #3
0
        public void CompileAssemblySF_Finish(RawType raw)
        {
            OutputSetting setting = Settings.GetPrimaryOutput(raw);

            setting.FinishCompile();
        }
Beispiel #4
0
        public string CompileOutput(OutputSetting outputSetting)
        {
            StringBuilder sb       = new StringBuilder();
            MoveInfo      treeInfo = new MoveInfo(this, SearchTree.ChildrenTree, 0, _sf);
            IElement      cur      = treeInfo.Current;

            string curStr = null;

            Queue <IElement> tokenQueue = new Queue <IElement>();

            Random rnd = new Random();

            int curLineLength = 0;

            bool goIntoCurrent = true;

            while (cur != null)
            {
                while (true) // "goto" -> always broken
                {
                    // defs
                    if (outputSetting.DeleteDefs)
                    {
                        if (cur is ConstDef || cur is OverwriteConstDef || cur is UsingDef || cur is PreProcessorRegion || cur is AccessModifier)
                        {
                            goIntoCurrent = false; // ignore whole block
                            break;
                        }
                        else if (cur is FuncDefParam)
                        {
                            tokenQueue.Enqueue(((FuncDefParam)cur).VarName.GetChildren()[0]);
                            goIntoCurrent = false;
                            break;
                        }
                    }

                    if (cur is Token)
                    {
                        // comments
                        if (outputSetting.DeleteComments)
                        {
                            if (cur.IsTT(TokenType.LineComment) || cur.IsTT(TokenType.XMLComment))
                            {
                                break;
                            }
                            else if (cur.IsTT(TokenType.BlockComment)) // fix for line numbers
                            {
                                string commentContent = ((Token)cur).StringContent;
                                int    eolCount       = commentContent.Count(a => a == '\n');
                                for (int i = 0; i < eolCount; i++)
                                {
                                    tokenQueue.Enqueue(Token.EOL);
                                }

                                break;
                            }
                        }

                        // white space
                        if (outputSetting.DeleteWhite &&
                            cur.IsTT(TokenType.WhiteSpace))
                        {
                            break;
                        }

                        if (outputSetting.RandomCase &&
                            cur.IsTT(TokenType.Word))
                        {
                            // random case
                            StringBuilder curRndStr = new StringBuilder(cur.ToString());
                            for (int i = 0; i < curRndStr.Length; i++)
                            {
                                if (rnd.Next() % 2 == 0)
                                {
                                    curRndStr[i] = Char.ToLowerInvariant(curRndStr[i]);
                                }
                                else
                                {
                                    curRndStr[i] = Char.ToUpperInvariant(curRndStr[i]);
                                }
                            }
                            curStr = curRndStr.ToString();
                        }
                        else
                        {
                            curStr = cur.ToString();
                        }

                        if (curStr == "\r\n" || curStr == "\r" || curStr == "\n")
                        {
                            // line length
                            if (outputSetting.LineLengthMin != 0 && outputSetting.LineLengthMax != 0 &&
                                curLineLength < outputSetting.LineLengthMin)    // do not add EOL
                            {
                                curStr = "";
                            }
                            else
                            {
                                curLineLength = 0;
                            }
                        }
                        else
                        {
                            curLineLength += curStr.Length;
                        }

                        // line length
                        if (outputSetting.LineLengthMin != 0 && outputSetting.LineLengthMax != 0)
                        {
                            if (curLineLength > outputSetting.LineLengthMax)
                            {
                                curLineLength = curStr.Length;
                                curStr        = curStr.Insert(0, "\r\n");
                            }
                        }

                        sb.Append(curStr);
                    }

                    break;
                }

                if (tokenQueue.Count != 0)
                {
                    cur = tokenQueue.Dequeue();
                }
                else
                {
                    cur           = treeInfo.Move(SearchDirection.LeftToRight, goIntoCurrent);
                    goIntoCurrent = true;
                }
            }

            return(sb.ToString());
        }
Beispiel #5
0
        public List <ScriptFile> CompileAssemblySFs_GetFiles(RawType raw, bool compareDate)
        {
            UpdateAssemblySFs();

            OutputSetting primarySetting = Settings.GetPrimaryOutput(raw);

            bool includeAll  = String.IsNullOrEmpty(primarySetting.IncludeFiles);
            bool excludeNone = String.IsNullOrEmpty(primarySetting.ExcludeFiles);

            List <ScriptFile> sourceFiles = new List <ScriptFile>(GetAllSFs().Count);

            foreach (ScriptFile sf in GetAllSFs())
            {
                if (!sf.IsExtern && sf.RawType == raw)
                {
                    if (includeAll ||
                        (!includeAll && Regex.IsMatch(sf.SFPath, primarySetting.IncludeFiles)))
                    {
                        if (!excludeNone && Regex.IsMatch(sf.SFPath, primarySetting.ExcludeFiles))
                        {
                            sf.Compile_IsExcluded = true;
                        }
                        else
                        {
                            sf.Compile_IsExcluded = false;
                        }
                    }
                    else
                    {
                        sf.Compile_IsExcluded = true;
                    }

                    sourceFiles.Add(sf);
                }
            }

            // select files for compile...
            List <ScriptFile> processFiles = new List <ScriptFile>(sourceFiles.Count);

            foreach (ScriptFile sf in sourceFiles)
            {
                string sourceFile = sf.SFFullPath;
                string outputFile = Path.Combine(primarySetting.LocalPath, sf.SFPath + "." + sf.FileExt.ToString());

                if (compareDate) // compare date
                {
                    DateTime sourceTime = File.GetLastWriteTime(sourceFile);
                    DateTime outputTime = File.Exists(outputFile) ? File.GetLastWriteTime(outputFile) : DateTime.MinValue;
                    if (sourceTime >= outputTime)
                    {
                        processFiles.Add(sf);
                    }
                }
                else
                {
                    processFiles.Add(sf);
                }
            }

            Trace.TraceEvent(TraceEventType.Information, 0, "Files for compile: " + processFiles.Count);
            foreach (ScriptFile sf in processFiles)
            {
                Trace.TraceEvent(TraceEventType.Verbose, 0, sf.ToString());
            }

            Trace.TraceEvent(TraceEventType.Information, 0, "============================");

            return(processFiles);
        }