public ProgramOptions GetAmbientProgramOptions()
        {
            var iniLocations = _inisLocator.GetIniLocations();
            var config       = _configLoader.LoadConfig(iniLocations);

            if (config == null)
            {
                return(null);
            }

            var installPath        = config.CreationKitInstallPath;
            var scriptSourceFolder = config.Config.Papyrus?.sScriptSourceFolder ?? _defaultConfig?.Papyrus?.sScriptSourceFolder;
            var additionalImports  = config.Config.Papyrus?.sAdditionalImports ?? _defaultConfig?.Papyrus?.sAdditionalImports;

            var sourceDirectoryPath = string.IsNullOrEmpty(scriptSourceFolder) ?
                                      null :
                                      PathUtilities.GetCombinedOrRooted(installPath, scriptSourceFolder.Replace("\"", ""));

            var importPathsElementsWithSubstitutedSource = string.IsNullOrEmpty(additionalImports) ?
                                                           new List <SourceInclude>() :
                                                           additionalImports.Replace("\"", "").Split(';')
                                                           .Select(importPath => importPath.CaseInsensitiveEquals("$(source)") ? sourceDirectoryPath : importPath)
                                                           .Select(path => PathUtilities.GetCombinedOrRooted(installPath, path))
                                                           .Select(path => new SourceInclude()
            {
                Path     = path,
                IsImport = true
            })
                                                           .ToList();

            if (!string.IsNullOrEmpty(sourceDirectoryPath))
            {
                importPathsElementsWithSubstitutedSource.Add(new SourceInclude()
                {
                    Path = PathUtilities.GetCombinedOrRooted(installPath, sourceDirectoryPath)
                });
            }

            importPathsElementsWithSubstitutedSource.Reverse();

            var programOptions = new ProgramOptionsBuilder()
                                 .WithName(_ambientProgramName)
                                 .WithFlagsFileName(_flagsFileName)
                                 .WithSourceIncludes(importPathsElementsWithSubstitutedSource)
                                 .Build();

            return(programOptions);
        }
Пример #2
0
        public static ProgramOptionsBuilder WithProject(this ProgramOptionsBuilder builder, PapyrusProjectInfo projectInfo)
        {
            var projectFileDirectory = Path.GetDirectoryName(PathUtilities.Normalize(projectInfo.ProjectFile));

            builder.WithName(Path.GetFileNameWithoutExtension(projectInfo.ProjectFile))
            .WithFlagsFileName(projectInfo.Project.Flags)
            .WithSourceIncludes(projectInfo.Project.Imports.Reverse().Select(import => new SourceInclude()
            {
                IsImport = true,
                Path     = Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(import)))
            }));

            if (projectInfo.Project.Folders != null && projectInfo.Project.Folders.Length > 0)
            {
                var folder = projectInfo.Project.Folders[0];
                builder.WithSourceIncludes(new SourceInclude()
                {
                    Path      = Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(folder.Value))),
                    Recursive = !folder.NoRecurse
                });
            }
            else if (projectInfo.Project.Scripts != null && projectInfo.Project.Scripts.Length > 0)
            {
                var scriptsInclude = new SourceInclude()
                {
                    Path = projectFileDirectory
                };

                foreach (var script in projectInfo.Project.Scripts)
                {
                    var scriptWithExtension = Path.HasExtension(script) ? script : script + ".psc";
                    scriptsInclude.Scripts.Add(Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(scriptWithExtension))));
                }

                builder.WithSourceIncludes(scriptsInclude);
            }

            return(builder);
        }