示例#1
0
 public override void Apply(HealthAnalysis analysis, FixStatus status)
 {
     status.Description = "Fixing bad install path";
     analysis.Properties.Paths.InstallPath = analysis.AnalysisOptions.InstallPath;
     analysis.Properties.Paths.Save();
     status.Description = "Fixed bad install path";
 }
示例#2
0
        public override void Apply(HealthAnalysis analysis, FixStatus status)
        {
            status.Description = "Upgrading outdated project format";
            if (analysis.Properties.Options.Version < new Version(1, 2))
            {
                var upgrader = new UpgradeFrom_1_1();
                upgrader.Upgrade(analysis);
                status.Description = "Project format updated";
                return;
            }

            throw new InvalidOperationException(string.Format(Text.ProjectHealthDialogModel_Upgrade_BadUpgradeVersion, analysis.Properties.Options.Version));
        }
        public override void Apply(HealthAnalysis analysis, FixStatus status)
        {
            status.Description = "Restoring whitelist cache";
            var sourceFileName = Path.Combine(analysis.Properties.Paths.InstallPath, "Analyzers\\whitelist.cache");

            if (!File.Exists(sourceFileName))
            {
                throw new InvalidOperationException("Cannot find the source whitelist cache");
            }
            var targetFileName = Path.Combine(Path.GetDirectoryName(analysis.FileName), "mdk\\whitelist.cache");

            File.Copy(sourceFileName, targetFileName, true);
            Include(analysis, targetFileName);
            status.Description = "Restored whitelist cache";
        }
示例#4
0
        public override void Apply(HealthAnalysis analysis, FixStatus status)
        {
            status.Description = "Fixing bad output path";
            var path = analysis.AnalysisOptions.DefaultOutputPath;

            if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
            {
                status.Description = "Cannot find output path";
                status.Failed      = true;
                return;
            }

            analysis.Properties.Paths.OutputPath = path;
            analysis.Properties.Paths.Save();
            status.Description = "Fixed bad output path";
        }
示例#5
0
 public override void Apply(HealthAnalysis analysis, FixStatus status)
 {
     status.Description = "Restoring missing paths file";
     analysis.Properties.Paths.InstallPath = analysis.AnalysisOptions.InstallPath;
     analysis.Properties.Paths.GameBinPath = analysis.AnalysisOptions.DefaultGameBinPath;
     analysis.Properties.Paths.OutputPath  = analysis.AnalysisOptions.DefaultOutputPath;
     foreach (var reference in MDKProjectPaths.DefaultAssemblyReferences)
     {
         analysis.Properties.Paths.AssemblyReferences.Add(reference);
     }
     foreach (var reference in MDKProjectPaths.DefaultAnalyzerReferences)
     {
         analysis.Properties.Paths.AnalyzerReferences.Add(reference);
     }
     analysis.Properties.Paths.Save();
     status.Description = "Restored missing paths file";
 }
示例#6
0
        public override void Apply(HealthAnalysis analysis, FixStatus status)
        {
            status.Description = "Creating a backup in the parent folder...";
            var directory = Path.GetDirectoryName(analysis.FileName) ?? ".\\";

            if (!directory.EndsWith("\\"))
            {
                directory += "\\";
            }
            var zipFileName = $"{Path.GetFileNameWithoutExtension(analysis.FileName)}_Backup_{DateTime.Now:yyyy-MM-dd-HHmmssfff}.zip";
            var tmpZipName  = Path.Combine(Path.GetTempPath(), zipFileName);

            ZipHelper.CreateFromDirectory(directory, tmpZipName, CompressionLevel.Fastest, false, path => OnlyInterestingFiles(directory, path));
            var backupDirectory = new DirectoryInfo(Path.Combine(directory, "..\\"));

            File.Copy(tmpZipName, Path.Combine(backupDirectory.FullName, zipFileName));
            File.Delete(tmpZipName);
            status.Description = "Backup created";
        }
示例#7
0
        public void Upgrade(HealthAnalysis project)
        {
            XDocument    document;
            XmlNameTable nameTable;

            using (var streamReader = File.OpenText(project.FileName))
            {
                var readerSettings = new XmlReaderSettings
                {
                    IgnoreWhitespace = true
                };

                var xmlReader = XmlReader.Create(streamReader, readerSettings);
                document  = XDocument.Load(xmlReader);
                nameTable = xmlReader.NameTable;
                if (nameTable == null)
                {
                    throw new InvalidOperationException(Text.UpgradeFrom1_1_Upgrade_ErrorLoadingProject);
                }
            }

            var nsm = new XmlNamespaceManager(nameTable);

            nsm.AddNamespace("m", Xmlns);

            var assemblies = MDKProjectPaths.DefaultAssemblyReferences;
            var analyzers  = MDKProjectPaths.DefaultAnalyzerReferences;

            RemoveOldElements(document, assemblies, analyzers, nsm);
            AddNewElements(document.Root, nsm);

            project.Properties.Save();
            document.Save(project.FileName);

            var oldOptionsFileName = Path.Combine(Path.GetDirectoryName(project.FileName) ?? ".\\", "MDK\\MDK.options");

            if (File.Exists(oldOptionsFileName))
            {
                File.Delete(oldOptionsFileName);
            }
        }
示例#8
0
 public override bool IsApplicableTo(HealthAnalysis project) => project.Problems.Any(NeedsBackup);
 public override bool IsApplicableTo(HealthAnalysis project) => project.Problems.Any(p => p.Code == HealthCode.MissingWhitelist || p.Code == HealthCode.OutdatedWhitelist);
示例#10
0
 public virtual bool IsApplicableTo(HealthAnalysis project) => project.Problems.Any(p => p.Code == Code);
示例#11
0
        protected void Include(HealthAnalysis analysis, string fileName)
        {
            XDocument    document;
            XmlNameTable nameTable;

            using (var streamReader = File.OpenText(analysis.FileName))
            {
                var readerSettings = new XmlReaderSettings
                {
                    IgnoreWhitespace = true
                };

                var xmlReader = XmlReader.Create(streamReader, readerSettings);
                document  = XDocument.Load(xmlReader);
                nameTable = xmlReader.NameTable;
                if (nameTable == null)
                {
                    throw new InvalidOperationException(Text.UpgradeFrom1_1_Upgrade_ErrorLoadingProject);
                }
            }

            var nsm = new XmlNamespaceManager(nameTable);

            nsm.AddNamespace("m", Xmlns);

            var projectBasePath = Path.GetDirectoryName(Path.GetFullPath(analysis.FileName)) ?? ".";

            if (!projectBasePath.EndsWith("\\"))
            {
                projectBasePath += "\\";
            }
            fileName = Path.Combine(projectBasePath, fileName);
            if (fileName.StartsWith(projectBasePath))
            {
                fileName = fileName.Substring(projectBasePath.Length);
            }
            else
            {
                fileName = Path.GetFullPath(fileName);
            }

            var existingElement = document.Descendants(XName.Get("AdditionalFiles", Xmlns))
                                  .FirstOrDefault(e => string.Equals((string)e.Attribute("Include"), fileName, StringComparison.CurrentCultureIgnoreCase));

            if (existingElement != null)
            {
                return;
            }

            var itemGroupElement = document.Descendants(XName.Get("ItemGroup", Xmlns)).LastOrDefault();

            if (itemGroupElement == null)
            {
                itemGroupElement = new XElement(XName.Get("ItemGroup", Xmlns));
                document.Root?.Add(itemGroupElement);
            }

            var fileElement = new XElement(XName.Get("AdditionalFiles", Xmlns),
                                           new XAttribute("Include", fileName),
                                           new XElement(XName.Get("CopyToOutputDirectory", Xmlns), new XText("Always"))
                                           );

            itemGroupElement.Add(fileElement);
            document.Save(analysis.FileName);
        }
示例#12
0
 public abstract void Apply(HealthAnalysis analysis, FixStatus status);