-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60009b2
commit 46d82f8
Showing
21 changed files
with
254 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/OneWare.Essentials/PackageManager/Compatibility/CompatibilityReport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace OneWare.Essentials.PackageManager.Compatibility; | ||
|
||
public class CompatibilityReport(bool isCompatible, string? report = null) | ||
{ | ||
public bool IsCompatible { get; } = isCompatible; | ||
|
||
public string? Report { get; } = report; | ||
} |
82 changes: 82 additions & 0 deletions
82
src/OneWare.Essentials/PackageManager/Compatibility/PluginCompatibilityChecker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
namespace OneWare.Essentials.PackageManager.Compatibility; | ||
|
||
public class PluginCompatibilityChecker | ||
{ | ||
public static CompatibilityReport CheckCompatibilityPath(string path) | ||
{ | ||
try | ||
{ | ||
var pluginName = Path.GetFileName(path); | ||
|
||
var depFilePath = Path.Combine(path, "minimal-dependencies.txt"); | ||
|
||
var compatibilityIssues = ""; | ||
|
||
if (!File.Exists(depFilePath)) | ||
{ | ||
compatibilityIssues += | ||
$"Extension {pluginName} incompatible:\n\nminimal-dependencies.txt not found in plugin folder\n"; | ||
return new CompatibilityReport(false, compatibilityIssues); | ||
} | ||
|
||
return CheckCompatibility(File.ReadAllText(depFilePath)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return new CompatibilityReport(false, e.Message); | ||
} | ||
} | ||
|
||
public static CompatibilityReport CheckCompatibility(string? deps) | ||
{ | ||
try | ||
{ | ||
var compatibilityIssues = ""; | ||
|
||
if (deps == null) return new CompatibilityReport(false, "Error checking compatibility"); | ||
|
||
var depsList = deps.Trim().Split('\n'); | ||
|
||
foreach (var dep in depsList) | ||
{ | ||
var parts = dep.Split(':'); | ||
var dependencyName = parts[0].Trim(); | ||
var versionString = parts[1].Trim(); | ||
var dependencyVersion = Version.Parse(NormalizeVersion(versionString)); | ||
|
||
var coreDep = AppDomain.CurrentDomain.GetAssemblies() | ||
.SingleOrDefault(x => x.GetName().Name == dependencyName)?.GetName(); | ||
|
||
if (coreDep == null) | ||
{ | ||
compatibilityIssues += $"Dependency {dependencyName} not found\n"; | ||
continue; | ||
} | ||
|
||
if (coreDep.Version < dependencyVersion) | ||
compatibilityIssues += | ||
$"Studio {dependencyName} v{coreDep.Version} is older than Plugin v{dependencyVersion}\n"; | ||
if (coreDep.Version > dependencyVersion) | ||
compatibilityIssues += | ||
$"Studio {dependencyName} v{coreDep.Version} is newer than Plugin v{dependencyVersion}\n"; | ||
} | ||
|
||
return new CompatibilityReport(compatibilityIssues.Length == 0, compatibilityIssues); | ||
} | ||
catch (Exception e) | ||
{ | ||
return new CompatibilityReport(false, e.Message); | ||
} | ||
} | ||
|
||
static string NormalizeVersion(string version) | ||
{ | ||
string[] parts = version.Split('.'); | ||
while (parts.Length < 4) | ||
{ | ||
Array.Resize(ref parts, parts.Length + 1); | ||
parts[^1] = "0"; | ||
} | ||
return string.Join('.', parts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using OneWare.Essentials.PackageManager; | ||
using OneWare.Essentials.PackageManager.Compatibility; | ||
|
||
namespace OneWare.PackageManager.Models; | ||
|
||
public class PackageVersionModel(PackageVersion version) : ObservableObject | ||
{ | ||
private CompatibilityReport? _compatibilityReport; | ||
|
||
public PackageVersion Version { get; } = version; | ||
|
||
public bool TargetAll => Version.Targets is [{ Target: "all" }]; | ||
|
||
public CompatibilityReport? CompatibilityReport | ||
{ | ||
get => _compatibilityReport; | ||
set => SetProperty(ref _compatibilityReport, value); | ||
} | ||
} |
Oops, something went wrong.