Beispiel #1
0
        private void UseProcessor(Type processor)
        {
            var proc = Activator.CreateInstance(processor, Mod, _module, Language);

            var contents =
                (IReadOnlyList <Content>)processor.GetMethod(nameof(Processor <Content> .DumpContents))?.Invoke(proc, new object[0]);

            if (contents == null)
            {
                Logger.Warn(Strings.ProcNotUsed, processor.Name);
                return;
            }

            Logger.Debug("Using " + processor.Name);

            foreach (var val in contents.GroupBy(x => x.Namespace, x => x))
            {
                File.WriteAllText(
                    DefaultConfigurations.GetPath(Mod, processor, val.Key + ".json"),
                    JsonConvert.SerializeObject(val.ToList(), Formatting.Indented)
                    );

                Logger.Info(Strings.DumpNamespace, val.Key);
            }
        }
        private void Dump(IEnumerable <Type> processors)
        {
            LocalizationSourcePath = LocalizationSourcePath ?? Mod.Name;

            if (Directory.Exists(LocalizationSourcePath) &&
                DefaultConfigurations.FolderMapper.Values.Any(dir =>
            {
                var path = Path.Combine(LocalizationSourcePath, dir);

                return(Directory.Exists(path) && Directory.GetFiles(path).Length > 0);
            }))
            {
                throw new Exception("Non-empty source folder as output path");
            }

            Directory.CreateDirectory(LocalizationSourcePath);
            foreach (var folder in DefaultConfigurations.FolderMapper.Values)
            {
                Directory.CreateDirectory(Path.Combine(LocalizationSourcePath, folder));
            }

            _logger.Warn("Directory created: {0}", Mod.Name);

            var module = AssemblyDef.Load(Mod.GetMainAssembly()).Modules.Single();

            foreach (var processor in processors)
            {
                try
                {
                    var proc = Activator.CreateInstance(processor, this, module);

                    var contents =
                        (IReadOnlyList <Content>)processor.GetMethod(nameof(Processor <Content> .DumpContents))?.Invoke(proc, new object[0]);

                    if (contents == null)
                    {
                        _logger.Warn(Strings.ProcNotUsed, processor.Name);
                        continue;
                    }

                    _logger.Debug("Using " + processor.Name);

                    foreach (var val in contents.GroupBy(x => x.Namespace, x => x))
                    {
                        File.WriteAllText(
                            DefaultConfigurations.GetPath(Mod, processor, val.Key + ".json"),
                            JsonConvert.SerializeObject(val.ToList(), Formatting.Indented)
                            );

                        _logger.Info(Strings.DumpNamespace, val.Key);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Warn(Strings.ProcExceptionOccur, processor.FullName);
                    _logger.Error(ex);
                }
            }
        }
Beispiel #3
0
        private static void Dump(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors)
        {
            var module = AssemblyDef.Load(modFile.GetMainAssembly()).Modules.Single();

            foreach (var processor in processors)
            {
                try
                {
                    var proc = Activator.CreateInstance(processor, modFile, module, _language);

                    var contents =
                        (IReadOnlyList <Content>)processor.GetMethod(nameof(Processor <Content> .DumpContents))?.Invoke(proc, new object[0]);

                    if (contents == null)
                    {
                        Logger.Warn(Strings.ProcNotUsed, processor.Name);
                        continue;
                    }

                    Logger.Debug("Using " + processor.Name);

                    foreach (var val in contents.GroupBy(x => x.Namespace, x => x))
                    {
                        File.WriteAllText(
                            DefaultConfigurations.GetPath(modFile, processor, val.Key + ".json"),
                            JsonConvert.SerializeObject(val.ToList(), Formatting.Indented)
                            );

                        Logger.Info(Strings.DumpNamespace, val.Key);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warn(Strings.ProcExceptionOccur, processor.FullName);
                    Logger.Error(ex);
                }
            }
        }