46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using ModVersionChecker.enums;
|
|
using ModVersionChecker.managers.interfaces;
|
|
using ModVersionChecker.model;
|
|
using ModVersionChecker.service.interfaces;
|
|
using ModVersionChecker.utils;
|
|
using NuGet.Versioning;
|
|
|
|
namespace ModVersionChecker.service
|
|
{
|
|
public class VersionService: IVersionService
|
|
{
|
|
private readonly Config _globalConfig;
|
|
|
|
public VersionService(
|
|
IConfigRepository configManager
|
|
) {
|
|
_globalConfig = configManager.Load() ?? new Config();
|
|
}
|
|
|
|
public string GetCurrentVersion(App app)
|
|
{
|
|
var typeConfig = _globalConfig.Types.FirstOrDefault(t => t.ShortName == app.Type);
|
|
if (typeConfig == null)
|
|
{
|
|
throw new InvalidOperationException($"No type config found for app type: {app.Type}");
|
|
}
|
|
return VersionUtils.GetCurrentVersion(app, typeConfig);
|
|
}
|
|
|
|
public bool IsUpdateAvailable(string currentVersion, string latestVersion)
|
|
{
|
|
try
|
|
{
|
|
var current = NuGetVersion.Parse(currentVersion);
|
|
var latest = NuGetVersion.Parse(latestVersion);
|
|
return latest.CompareTo(current) == 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Failed to compare versions: {ex.Message}");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|