Store the date a build is created

This commit is contained in:
flightlevel
2018-10-28 18:27:10 +11:00
parent 7cc19212f5
commit 93d5acd355
3 changed files with 40 additions and 12 deletions

View File

@@ -211,4 +211,11 @@
</EmbeddedResource>
</ItemGroup>
<!-- Save the compiled date so that we know if the user is running an old version of Jackett -->
<ItemGroup>
<AssemblyAttribute Include="Jackett.Common.Utils.BuildDateAttribute">
<_Parameter1>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,27 @@
using System;
using System.Globalization;
using System.Reflection;
namespace Jackett.Common.Utils
{
public static class BuildDate
{
public static DateTime GetBuildDateTime()
{
Assembly commonAssembly = Assembly.GetExecutingAssembly();
var attribute = commonAssembly.GetCustomAttribute<BuildDateAttribute>();
return attribute?.DateTime ?? default(DateTime);
}
}
[AttributeUsage(AttributeTargets.Assembly)]
public class BuildDateAttribute : Attribute
{
public BuildDateAttribute(string value)
{
DateTime = DateTime.ParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
}
public DateTime DateTime { get; }
}
}

View File

@@ -261,14 +261,9 @@ namespace Jackett.Server.Services
//Warn user that they are using an old version of Jackett
try
{
string appFolder = configService.ApplicationFolder();
string dllPath = Path.Combine(appFolder, "Jackett.Common.dll");
DateTime compiledData = BuildDate.GetBuildDateTime();
if (File.Exists(dllPath))
{
DateTime creation = File.GetCreationTime(dllPath);
if (creation < DateTime.Now.AddMonths(-3))
if (compiledData < DateTime.Now.AddMonths(-3))
{
string version = configService.GetVersion();
string notice = $"Your version of Jackett v{version} is very old. Multiple indexers are likely to fail when using an old version. Update to the latest version of Jackett.";
@@ -276,7 +271,6 @@ namespace Jackett.Server.Services
logger.Error(notice);
}
}
}
catch (Exception e)
{
logger.Error(e, "Error while checking build date of Jackett.Common");