Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.GeneticLogicRoot"/> class.
        /// </summary>
        /// <param name="file">File path.</param>
        public GeneticLogicRoot(string filePath)
        {
            lock (CommonHelperMethods.GlobalFileIOLock)
            {
                if (FileIOManager.DiskUsePermitted)
                {
                    using (FileIOManager reader = FileIOManager.OpenDiskFileForRead(filePath))
                        while (!reader.EndOfStream)
                        {
                            // Fast forward to the next RootStatement start
                            string nextLine = reader.ReadNextContentLineAndTrim();
                            if (CommonHelperMethods.StringStartsWith(nextLine, RootStatement.Name))
                            {
                                RootStatement nextRootStatement = null;

                                try
                                {
                                    nextRootStatement = new RootStatement(reader);
                                }
                                catch (StatementParseException ex)
                                {
                                    // Throw this section of the logic on disk out.
                                    // This is expected to happen due to version updates or human
                                    // error when handling files representing genetic logic.
                                    LogUtility.LogWarningFormat(
                                        "Line {0} of file {1} did not parse correctly.  The corresponsing root statement will be thrown out.  Message: {2} CallStack: {3}",
                                        reader.LineNumber,
                                        filePath,
                                        ex.Message,
                                        ex.StackTrace);

                                    nextRootStatement = null;
                                }

                                if (nextRootStatement != null)
                                {
                                    // Root statement was successfully parsed.
                                    this.rootStatementList.Add(nextRootStatement);
                                }
                            }
                        }
                }
                else
                {
                    // Disk use not permitted
                    this.rootStatementList.AddRange(FileIOManager.ReadNonDiskFile(filePath));
                }
            }
        }