Пример #1
0
    /// <summary>
    /// tes3cmd multipatch
    /// Merge LEVI and LEVC
    /// </summary>
    /// <exception cref="Exception"></exception>
    private static void Multipatch()
    {
        using var ssw = new ScopedStopwatch();

        MergeAction.Merge(
            new MergeAction.Settings(
                true,
                new List <string>()
        {
            "LEVI", "LEVC", "CREA", "CELL"
        },
                null,
                Util.EPatch.All,
                false,
                true,
                "multipatch.esp"));
    }
 public void ProcessModCollectionLanceSlotEligibility(IModCollection modCollection)
 {
     this.logger.Info("Processing Lance Slot Eligibility...");
     using (var scopedStopwatch = new ScopedStopwatch(this.logger))
     {
         var lanceSlots = modCollection.GetReferenceableObjects()
                          .Where(o => o.ObjectType == ObjectType.LanceDef).Cast <LanceDefObjectDefinition>()
                          .SelectMany(definition => definition.LanceSlots);
         lanceSlots
         //.AsParallel().ForAll(
         .ToList().ForEach(
             o =>
         {
             this.logger.Debug($"Processing lance slot eligibility for Lance [{o.LanceDefObjectDefinition.Id}] - Slot [{o.LanceSlotNumber}]...");
             o.LoadEligibleUnitsAndPilots(modCollection);
         });
     }
 }
Пример #3
0
        public IEnumerable <Tuple <string, Exception> > ValidateJsonFiles(string root)
        {
            var invalidJsonFiles = new List <Tuple <string, Exception> >();

            void RecurseDirectories(DirectoryInfo di, int maxDepth, int depth = 0)
            {
                this.logger.Info($"Testing all JSON files in [{di.FullName}]] for validity...");
                di.GetFiles("*.json").AsParallel().ForAll(
                    info =>
                {
                    try
                    {
                        this.logger.Debug($"Testing JSON file [{info.FullName}]]...");
                        dynamic modConfig = JsonConvert.DeserializeObject(File.ReadAllText(info.FullName));
                    }
                    catch (Exception ex)
                    {
                        this.logger.Warn(
                            $"JSON file [{info.FullName}]] tested invalid, error = [{ex.ToString()}].");

                        lock (invalidJsonFiles)
                        {
                            invalidJsonFiles.Add(new Tuple <string, Exception>(info.FullName, ex));
                        }
                    }
                });

                if (maxDepth == -1 || depth != maxDepth)
                {
                    di.GetDirectories().Where(info => !info.Attributes.HasFlag(FileAttributes.Hidden)).AsParallel().ForAll(subDi => RecurseDirectories(subDi, depth++, maxDepth));
                }
            }

            using (var timer = new ScopedStopwatch(this.logger))
            {
                RecurseDirectories(new DirectoryInfo(root), -1);
            }

            return(invalidJsonFiles.AsEnumerable());
        }
Пример #4
0
    /// <summary>
    /// Verifies all active esps in the current Morrowind directory
    /// Parses all enabled records of the plugin and checks paths if the file exists
    /// </summary>
    /// <exception cref="Exception"></exception>
    private static void Verify()
    {
        ArgumentNullException.ThrowIfNull(CurrentInstallation);

        using var ssw = new ScopedStopwatch();
        LoadConfig();
        ArgumentNullException.ThrowIfNull(Configuration);

        // get merge tags
        var(supportedMergeTags, objectIdFilters) = GetMergeTags();

        // Shorthand install access.
        var sortedMasters = CurrentInstallation.GameFiles;

        // Go through and build a record list.
        var reportDict = new ConcurrentDictionary <string, Dictionary <string, List <string> > >();

        WriteToLogAndConsole($"Parsing plugins ... ");
        //foreach (var sortedMaster in sortedMasters)
        Parallel.ForEach(sortedMasters, sortedMaster =>
        {
            // this can be enabled actually
            if (Path.GetExtension(sortedMaster) == ".esm")
            {
                //continue;
                return;
            }

            var map = new Dictionary <string, List <string> >();

            // go through all records
            WriteToLogAndConsole($"Parsing input file: {sortedMaster}");
            var fullGameFilePath = Path.Combine(CurrentInstallation.RootDirectory, "Data Files", $"{sortedMaster}");
            var file             = TES3.TES3Load(fullGameFilePath, supportedMergeTags);
            foreach (var record in file.Records)
            {
                #region checks

                if (record is null)
                {
                    continue;
                }
                if (record.GetType().Equals(typeof(TES3Lib.Records.TES3)))
                {
                    continue;
                }
                var editorId = record.GetEditorId().Replace("\0", string.Empty);
                if (string.IsNullOrEmpty(editorId))
                {
                    continue;
                }

                // Check against object filters.
                var allow   = true;
                var lowerId = editorId.ToLower();
                foreach (var kv in objectIdFilters)
                {
                    try
                    {
                        if (Regex.Match(lowerId, kv.Key).Success)
                        {
                            allow = kv.Value;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                if (!allow)
                {
                    continue;
                }

                #endregion

                // verify here
                GetPathsInRecord(record, map);
            }

            if (map.Count > 0)
            {
                reportDict.AddOrUpdate(sortedMaster, map, (key, oldValue) => map);
            }
        }
                         );

        // pretty print
        WriteToLogAndConsole($"\n------------------------------------");
        WriteToLogAndConsole($"Results:\n");
        foreach (var(plugin, val) in reportDict)
        {
            WriteToLogAndConsole($"\n{plugin} ({val.Count})");
            foreach (var(recordID, list) in val)
            {
                foreach (var item in list)
                {
                    //Console.WriteLine("{0,-20} {1,5}\n", "Name", "Hours");
                    WriteToLogAndConsole(string.Format("\t{0,-40} {1,5}", recordID, item));
                }
            }
        }
        // serialize to file
        WriteToLogAndConsole($"\n");
        var reportPath = Path.Combine(CurrentInstallation.RootDirectory, "Data Files", "report.json");
        WriteToLogAndConsole($"Writing report to: {reportPath}");
        {
            using var fs = new FileStream(reportPath, FileMode.Create);
            JsonSerializer.Serialize(fs, reportDict, new JsonSerializerOptions()
            {
                WriteIndented = true
            });
        }
    }