Esempio n. 1
0
        ScriptProjectAnalysisResult AnalyzeProject(Project project, ScriptUpgradeAnalysisOptions options)
        {
            if (!project.IsLoaded())
            {
                return(ScriptProjectAnalysisResult.NonScriptProjectResult);
            }
            var projectInfo = ProjectScriptInfo.Load(project.FullName, project.Name);

            if (!projectInfo.IsValid)
            {
                return(ScriptProjectAnalysisResult.NonScriptProjectResult);
            }
            var expectedGamePath    = projectInfo.GetActualGameBinPath(options.DefaultGameBinPath).TrimEnd('\\');
            var expectedInstallPath = options.InstallPath.TrimEnd('\\');

            var badReferences = ImmutableArray.CreateBuilder <BadReference>();
            var projectFile   = new FileInfo(projectInfo.FileName);
            var projectDir    = projectFile.Directory ?? throw new InvalidOperationException($"Unexpected error: Could not determine the directory of the project {projectInfo.FileName}");
            var document      = XDocument.Load(projectInfo.FileName);
            var xmlns         = new XmlNamespaceManager(new NameTable());

            xmlns.AddNamespace("ms", Xmlns);

            AnalyzeReferences(options, document, xmlns, projectDir, expectedGamePath, expectedInstallPath, badReferences);
            AnalyzeFiles(options, document, xmlns, projectDir, expectedGamePath, expectedInstallPath, badReferences);

            return(new ScriptProjectAnalysisResult(projectInfo, document, badReferences.ToImmutable()));
        }
Esempio n. 2
0
        ScriptProjectAnalysisResult AnalyzeProject(Project project, ScriptUpgradeAnalysisOptions options)
        {
            if (!project.IsLoaded())
            {
                return(ScriptProjectAnalysisResult.NonScriptProjectResult);
            }
            var projectInfo = ProjectScriptInfo.Load(project.FullName, project.Name);

            if (!projectInfo.IsValid)
            {
                return(ScriptProjectAnalysisResult.NonScriptProjectResult);
            }
            var expectedGamePath    = projectInfo.GetActualGameBinPath(options.DefaultGameBinPath).TrimEnd('\\');
            var expectedInstallPath = options.InstallPath.TrimEnd('\\');

            var badReferences = ImmutableArray.CreateBuilder <BadReference>();
            var projectFile   = new FileInfo(projectInfo.FileName);
            var projectDir    = projectFile.Directory;
            var document      = XDocument.Load(projectInfo.FileName);
            var xmlns         = new XmlNamespaceManager(new NameTable());

            xmlns.AddNamespace("ms", Xmlns);

            AnalyzeReferences(options, document, xmlns, projectDir, expectedGamePath, expectedInstallPath, badReferences);
            AnalyzeFiles(options, document, xmlns, projectDir, expectedGamePath, expectedInstallPath, badReferences);
            var whitelist = VerifyWhitelist(document, projectDir, expectedInstallPath);

            return(new ScriptProjectAnalysisResult(project, projectInfo, document, whitelist, badReferences.ToImmutable()));
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new instance of <see cref="ScriptProjectAnalysisResult"/>
 /// </summary>
 /// <param name="projectInfo">Basic information about the analyzed project</param>
 /// <param name="projectDocument">The source XML document of the project file</param>
 /// <param name="badReferences">A list of bad file- or assembly references</param>
 public ScriptProjectAnalysisResult(ProjectScriptInfo projectInfo, XDocument projectDocument, ImmutableArray <BadReference> badReferences)
 {
     ProjectInfo     = projectInfo;
     ProjectDocument = projectDocument;
     BadReferences   = badReferences;
     IsScriptProject = projectInfo != null;
     IsValid         = BadReferences.Length == 0;
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new instance of <see cref="ScriptProjectAnalysisResult"/>
 /// </summary>
 /// <param name="project"></param>
 /// <param name="projectInfo">Basic information about the analyzed project</param>
 /// <param name="projectDocument">The source XML document of the project file</param>
 /// <param name="whitelist">Whitelist verification results</param>
 /// <param name="badReferences">A list of bad file- or assembly references</param>
 public ScriptProjectAnalysisResult(EnvDTE.Project project, ProjectScriptInfo projectInfo, XDocument projectDocument, WhitelistReference whitelist, ImmutableArray <BadReference> badReferences)
 {
     Project         = project;
     ProjectInfo     = projectInfo;
     ProjectDocument = projectDocument;
     BadReferences   = badReferences;
     Whitelist       = whitelist;
     IsScriptProject = projectInfo != null;
     IsValid         = BadReferences.Length == 0 && whitelist.IsValid;
 }
Esempio n. 5
0
        /// <summary>
        /// Loads script information from the given project file.
        /// </summary>
        /// <param name="projectFileName">The file name of this project</param>
        /// <param name="projectName">The display name of this project</param>
        /// <returns></returns>
        public static ProjectScriptInfo Load([NotNull] string projectFileName, string projectName = null)
        {
            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(projectFileName));
            }
            var fileName = Path.GetFullPath(projectFileName);
            var name     = projectName ?? Path.GetFileNameWithoutExtension(projectFileName);

            if (!File.Exists(fileName))
            {
                return(new ProjectScriptInfo(fileName, name, false));
            }
            var mdkOptionsFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options"));

            if (!File.Exists(mdkOptionsFileName))
            {
                return(new ProjectScriptInfo(fileName, name, false));
            }

            try
            {
                var document = XDocument.Load(mdkOptionsFileName);
                var root     = document.Element("mdk");

                // Check if this is a template options file
                if ((string)root?.Attribute("version") == "$mdkversion$")
                {
                    return(new ProjectScriptInfo(fileName, name, false));
                }

                var      useManualGameBinPath = ((string)root?.Element("gamebinpath")?.Attribute("enabled") ?? "no").Trim().Equals("yes", StringComparison.CurrentCultureIgnoreCase);
                var      gameBinPath          = (string)root?.Element("gamebinpath");
                var      installPath          = (string)root?.Element("installpath");
                var      outputPath           = (string)root?.Element("outputpath");
                var      minify         = ((string)root?.Element("minify") ?? "no").Trim().Equals("yes", StringComparison.CurrentCultureIgnoreCase);
                var      trimTypes      = ((string)root?.Element("trimtypes") ?? "no").Trim().Equals("yes", StringComparison.CurrentCultureIgnoreCase);
                string[] ignoredFolders = null;
                string[] ignoredFiles   = null;
                var      ignoreElement  = root?.Element("ignore");
                if (ignoreElement != null)
                {
                    ignoredFolders = ignoreElement.Elements("folder").Select(e => (string)e).ToArray();
                    ignoredFiles   = ignoreElement.Elements("file").Select(e => (string)e).ToArray();
                }

                var result = new ProjectScriptInfo(fileName, name, true)
                {
                    UseManualGameBinPath = useManualGameBinPath,
                    GameBinPath          = gameBinPath,
                    InstallPath          = installPath,
                    OutputPath           = outputPath,
                    Minify    = minify,
                    TrimTypes = trimTypes
                };
                if (ignoredFolders != null)
                {
                    foreach (var item in ignoredFolders)
                    {
                        result.IgnoredFolders.Add(item);
                    }
                }
                if (ignoredFiles != null)
                {
                    foreach (var item in ignoredFiles)
                    {
                        result.IgnoredFiles.Add(item);
                    }
                }
                result.Commit();
                return(result);
            }
            catch (Exception e)
            {
                throw new ProjectScriptInfoException($"An error occurred while attempting to load project information from {fileName}.", e);
            }
        }