Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Fixed a bunch of annoying 3rd party reference problems, and improved …
Browse files Browse the repository at this point in the history
…the project upgrade tool.
  • Loading branch information
malware-dev committed May 1, 2023
1 parent d7d7869 commit d6e0d27
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 370 deletions.
13 changes: 13 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Source/MDK/MDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down Expand Up @@ -135,9 +138,11 @@
<Compile Include="Views\MessageEventType.cs" />
<Compile Include="Views\Options\EnumToStringConverter.cs" />
<Compile Include="Views\ProjectHealth\Fixes\BackupFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\BadDotNetVersionFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\BadOutputPathFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\BadGamePathFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\BadInstallPathFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\DeleteBinObjFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\Fix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\MissingPathsFileFix.cs" />
<Compile Include="Views\ProjectHealth\Fixes\MissingOrOutdatedWhitelistFix.cs" />
Expand Down Expand Up @@ -404,9 +409,6 @@
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.5.33428.388" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading">
<Version>17.5.22</Version>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.5.4074">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
11 changes: 10 additions & 1 deletion Source/MDK/Resources/Text.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/MDK/Resources/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@
<data name="ProjectHealthDialogModel_RunUpgrades_Description" xml:space="preserve">
<value>The upgrade process has been completed. It is recommended to restart Visual Studio in order to reload the extensions and analyzers.</value>
</data>
<data name="BadDotNetVersionFix_Apply_NoTargetFrameworkProperty" xml:space="preserve">
<value>Unable to specify .NET version 4.8 because the project has no such property.</value>
</data>
</root>
24 changes: 14 additions & 10 deletions Source/MDK/Views/ProjectHealth/Fixes/BackupFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO.Compression;
using System.Linq;
using Malware.MDKServices;
using System.Threading.Tasks;

namespace MDK.Views.ProjectHealth.Fixes
{
Expand Down Expand Up @@ -87,18 +88,21 @@ static bool NeedsBackup(HealthProblem healthProblem)

public BackupFix() : base(0, HealthCode.Healthy) { }

public override void Apply(HealthAnalysis analysis, FixStatus status)
public override async Task ApplyAsync(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);
await Task.Run(() =>
{
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";
}

Expand Down
35 changes: 35 additions & 0 deletions Source/MDK/Views/ProjectHealth/Fixes/BadDotNetVersionFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Malware.MDKServices;
using Microsoft.VisualStudio.Shell;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace MDK.Views.ProjectHealth.Fixes
{
class BadDotNetVersionFix: Fix
{
const string Xmlns = "http://schemas.microsoft.com/developer/msbuild/2003";
static readonly XName PropertyGroup = XName.Get("PropertyGroup", Xmlns);
static readonly XName TargetFrameworkVersion = XName.Get("TargetFrameworkVersion", Xmlns);

public BadDotNetVersionFix(): base(2000, HealthCode.BadDotNetVersion) { }

public override async Task ApplyAsync(HealthAnalysis analysis, FixStatus status)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
status.Description = "Specifying .NET 4.8";
var document = XDocument.Load(analysis.FileName);
var targetFrameworkElement = document.Root?.Elements(PropertyGroup).Select(e => e.Element(TargetFrameworkVersion)).FirstOrDefault();
if (targetFrameworkElement?.Value.Trim() != "v4.8")
targetFrameworkElement.Value = "v4.8";
{
var relativeGroup = document.Root.Elements(PropertyGroup).LastOrDefault();
if (relativeGroup != null)
relativeGroup.AddAfterSelf(new XElement(PropertyGroup, new XElement(TargetFrameworkVersion, "v4.8")));
else
document.Root.Add(new XElement(PropertyGroup, new XElement(TargetFrameworkVersion, "v4.8")));
}
document.Save(analysis.FileName);
}
}
}
7 changes: 4 additions & 3 deletions Source/MDK/Views/ProjectHealth/Fixes/BadGamePathFix.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
using System.IO;
using Malware.MDKServices;
using Malware.MDKUtilities;
using System.Threading.Tasks;

namespace MDK.Views.ProjectHealth.Fixes
{
class BadGamePathFix : Fix
{
public BadGamePathFix() : base(3000, HealthCode.BadGamePath) { }

public override void Apply(HealthAnalysis analysis, FixStatus status)
public override Task ApplyAsync(HealthAnalysis analysis, FixStatus status)
{
status.Description = "Fixing bad game path";
var path = analysis.AnalysisOptions.DefaultGameBinPath;
if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
{
status.Description = "Cannot find game path";
status.Failed = true;
return;
return Task.CompletedTask;
}

analysis.Properties.Paths.GameBinPath = path;
analysis.Properties.Paths.Save();
status.Description = "Fixed bad game path";
return Task.CompletedTask;
}
}
}
13 changes: 5 additions & 8 deletions Source/MDK/Views/ProjectHealth/Fixes/BadInstallPathFix.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Malware.MDKServices;
using System.Threading.Tasks;
using Malware.MDKServices;

namespace MDK.Views.ProjectHealth.Fixes
{
class BadInstallPathFix: Fix
{
public BadInstallPathFix() : base(3000, HealthCode.BadInstallPath) { }
public BadInstallPathFix(): base(3000, HealthCode.BadInstallPath) { }

public override void Apply(HealthAnalysis analysis, FixStatus status)
public override Task ApplyAsync(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";
return Task.CompletedTask;
}
}
}
}
6 changes: 4 additions & 2 deletions Source/MDK/Views/ProjectHealth/Fixes/BadOutputPathFix.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using System.IO;
using Malware.MDKServices;
using System.Threading.Tasks;

namespace MDK.Views.ProjectHealth.Fixes
{
class BadOutputPathFix : Fix
{
public BadOutputPathFix() : base(3000, HealthCode.BadOutputPath) { }

public override void Apply(HealthAnalysis analysis, FixStatus status)
public override Task ApplyAsync(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;
return Task.CompletedTask;
}

analysis.Properties.Paths.OutputPath = path;
analysis.Properties.Paths.Save();
status.Description = "Fixed bad output path";
return Task.CompletedTask;
}
}
}
39 changes: 39 additions & 0 deletions Source/MDK/Views/ProjectHealth/Fixes/DeleteBinObjFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Malware.MDKServices;
using System.IO;
using System.Threading.Tasks;

namespace MDK.Views.ProjectHealth.Fixes
{
class DeleteBinObjFix: Fix
{
public DeleteBinObjFix(): base(int.MaxValue) { }

public override async Task ApplyAsync(HealthAnalysis analysis, FixStatus status)
{
status.Description = "Deleting bin/obj caches";
await Task.Run(() =>
{
var projectFolder = Path.GetDirectoryName(analysis.FileName)!;
var binFolder = Path.Combine(projectFolder, "bin");
var objFolder = Path.Combine(projectFolder, "obj");
try
{
Directory.Delete(binFolder, true);
}
catch
{
// Ignore this for now.
}

try
{
Directory.Delete(objFolder, true);
}
catch
{
// Ignore this for now.
}
});
}
}
}
37 changes: 26 additions & 11 deletions Source/MDK/Views/ProjectHealth/Fixes/Fix.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
using System;
using Malware.MDKServices;
using MDK.Resources;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Malware.MDKServices;
using MDK.Resources;

namespace MDK.Views.ProjectHealth.Fixes
{
abstract class Fix
{
const string Xmlns = "http://schemas.microsoft.com/developer/msbuild/2003";

protected Fix(int sortIndex, HealthCode code)
/// <summary>
/// Create a fix that is always applied. See <seealso cref="Fix(int, HealthCode, bool)" />
/// to make a healthcode violation specific fix.
/// </summary>
/// <param name="sortIndex"></param>
/// <param name="needsLoadedProject"></param>
protected Fix(int sortIndex, bool needsLoadedProject = false): this(sortIndex, HealthCode.Healthy, needsLoadedProject) { }

/// <summary>
/// Create a fix that is applied when a specific healthcode violation is detected.
/// See <seealso cref="Fix(int, bool)" /> to make a fix that is always applied.
/// </summary>
/// <param name="sortIndex"></param>
/// <param name="code"></param>
/// <param name="needsLoadedProject"></param>
protected Fix(int sortIndex, HealthCode code, bool needsLoadedProject = false)
{
SortIndex = sortIndex;
Code = code;
NeedsLoadedProject = needsLoadedProject;
}

public int SortIndex { get; }
public HealthCode? Code { get; }
public bool NeedsLoadedProject { get; }

public abstract void Apply(HealthAnalysis analysis, FixStatus status);
public abstract Task ApplyAsync(HealthAnalysis analysis, FixStatus status);

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 readerSettings = new XmlReaderSettings { IgnoreWhitespace = true };

var xmlReader = XmlReader.Create(streamReader, readerSettings);
document = XDocument.Load(xmlReader);
Expand Down Expand Up @@ -73,6 +88,6 @@ protected void Include(HealthAnalysis analysis, string fileName)
document.Save(analysis.FileName);
}

public virtual bool IsApplicableTo(HealthAnalysis project) => project.Problems.Any(p => p.Code == Code);
public virtual bool IsApplicableTo(HealthAnalysis project) => Code == HealthCode.Healthy || project.Problems.Any(p => p.Code == Code);
}
}
}
Loading

0 comments on commit d6e0d27

Please sign in to comment.