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())); }
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())); }
ScriptProjectAnalysisResult_Legacy AnalyzeProject(Project project, ScriptUpgradeAnalysisOptions options) { if (!project.IsLoaded()) { return(ScriptProjectAnalysisResult_Legacy.NonScriptProjectResult); } var projectInfo = MDKProjectProperties.Load(project.FullName, project.Name); if (!projectInfo.IsValid) { return(ScriptProjectAnalysisResult_Legacy.NonScriptProjectResult); } if (projectInfo.Options.Version < new Version(1, 2)) { return(new ScriptProjectAnalysisResult_Legacy(project, projectInfo, null, default, ImmutableArray <BadReference> .Empty, false));
void AnalyzeReferences(ScriptUpgradeAnalysisOptions options, XDocument document, XmlNamespaceManager xmlns, DirectoryInfo projectDir, string expectedGamePath, string expectedInstallPath, ImmutableArray <BadReference> .Builder badReferences) { foreach (var element in document.XPathSelectElements("/ms:Project/ms:ItemGroup/ms:Reference", xmlns)) { var include = (string)element.Attribute("Include"); var hintPath = (string)element.Element(XName.Get("HintPath", Xmlns)); var gameAssemblyName = options.GameAssemblyNames.FirstOrDefault(dll => dll == include); if (gameAssemblyName != null) { CheckAssemblyReference(projectDir, element, expectedGamePath, hintPath, gameAssemblyName, badReferences); } var utilityAssemblyName = options.UtilityAssemblyNames.FirstOrDefault(dll => dll == include); if (utilityAssemblyName != null) { CheckAssemblyReference(projectDir, element, expectedInstallPath, hintPath, utilityAssemblyName, badReferences); } } }
void AnalyzeFiles(ScriptUpgradeAnalysisOptions options, XDocument document, XmlNamespaceManager xmlns, DirectoryInfo projectDir, string expectedGamePath, string expectedInstallPath, ImmutableArray <BadReference> .Builder badReferences) { foreach (var element in document.XPathSelectElements("/ms:Project/ms:ItemGroup/ms:*", xmlns)) { var include = (string)element.Attribute("Include"); var file = ResolvePath(projectDir, include); var gameFile = options.GameFiles.FirstOrDefault(fileName => file.EndsWith(fileName, StringComparison.CurrentCultureIgnoreCase)); if (gameFile != null) { CheckFileReference(element, expectedGamePath, file, gameFile, badReferences); } var utilityFile = options.UtilityFiles.FirstOrDefault(fileName => file.EndsWith(fileName, StringComparison.CurrentCultureIgnoreCase)); if (utilityFile != null) { CheckFileReference(element, expectedInstallPath, file, utilityFile, badReferences); } } }
ScriptProjectAnalysisResult AnalyzeProject(Project project, ScriptUpgradeAnalysisOptions options) { if (!project.IsLoaded()) { return(ScriptProjectAnalysisResult.NotAScriptProject); } var projectInfo = MDKProjectProperties.Load(project.FullName, project.Name); if (!projectInfo.IsValid) { return(ScriptProjectAnalysisResult.NotAScriptProject); } if (projectInfo.Options.Version < new Version(1, 2)) { return(ScriptProjectAnalysisResult.For(project, projectInfo).AsLegacyProject()); } return(ScriptProjectAnalysisResult.For(project, projectInfo)); }
/// <summary> /// Analyzes the given project, attempting to find irregularities like bad assembly- or file references. /// </summary> /// <param name="project"></param> /// <param name="options"></param> /// <returns></returns> public ScriptSolutionAnalysisResult Analyze([NotNull] Project project, ScriptUpgradeAnalysisOptions options) { BeginBusy(); try { var result = AnalyzeProject(project, options); if (!result.IsScriptProject) { return(ScriptSolutionAnalysisResult.NoScriptProjectsResult); } if (!result.IsValid) { return(new ScriptSolutionAnalysisResult(ImmutableArray <ScriptProjectAnalysisResult> .Empty.Add(result))); } else { return(new ScriptSolutionAnalysisResult(ImmutableArray <ScriptProjectAnalysisResult> .Empty)); } } finally { EndBusy(); } }
/// <summary> /// Analyzes all the projects in the given solution, attempting to find irregularities like bad assembly- or file references. /// </summary> /// <param name="solution"></param> /// <param name="options"></param> /// <returns></returns> public async Task <ScriptSolutionAnalysisResult> AnalyzeAsync([NotNull] Solution solution, ScriptUpgradeAnalysisOptions options) { BeginBusy(); try { var results = (await Task.WhenAll(solution.Projects.Cast <Project>().Select(project => Task.Run(() => AnalyzeProject(project, options))))) .Where(a => a.IsScriptProject) .ToArray(); if (!results.Any()) { return(ScriptSolutionAnalysisResult.NoScriptProjectsResult); } return(new ScriptSolutionAnalysisResult(results.Where(r => !r.IsValid).ToImmutableArray())); } finally { EndBusy(); } }
/// <summary> /// Analyzes the given project, attempting to find irregularities like bad assembly- or file references. /// </summary> /// <param name="project"></param> /// <param name="options"></param> /// <returns></returns> public async Task <ScriptSolutionAnalysisResult> AnalyzeAsync([NotNull] Project project, ScriptUpgradeAnalysisOptions options) { BeginBusy(); try { return(await Task.Run(() => Analyze(project, options))); } finally { EndBusy(); } }
/// <summary> /// Analyzes a single project for problems. /// </summary> /// <param name="project"></param> /// <param name="options"></param> /// <returns></returns> public async Task <ScriptSolutionAnalysisResult> AnalyzeAsync(Project project, ScriptUpgradeAnalysisOptions options) { BeginBusy(); try { return(await Task.Run(() => { var result = AnalyzeProject(project, options); if (!result.IsScriptProject) { return ScriptSolutionAnalysisResult.NoScriptProjectsResult; } if (!result.IsValid) { return new ScriptSolutionAnalysisResult(ImmutableArray <ScriptProjectAnalysisResult> .Empty.Add(result)); } else { return new ScriptSolutionAnalysisResult(ImmutableArray <ScriptProjectAnalysisResult> .Empty); } })); } finally { EndBusy(); } }