Impl IPlugin.InstallTime

This commit is contained in:
Aigio Liu
2023-07-11 13:28:50 +08:00
parent 3237ef31e5
commit de2faef6b2
4 changed files with 29 additions and 2 deletions
@@ -66,4 +66,9 @@ partial interface IPlugin
/// 插件显示图标图片资源路径,值为 <see langword="null"/> 时使用默认图片
/// </summary>
string? Icon { get; }
/// <summary>
/// 插件安装时间
/// </summary>
DateTimeOffset InstallTime { get; }
}
@@ -32,8 +32,6 @@ partial class PluginBase
public string CacheDirectory => mCacheDirectory.Value;
public virtual string? Icon => null;
//static byte[][] OfficialPluginHashDatas => Array.Empty<byte[]>();
bool? mIsOfficial;
@@ -93,6 +91,25 @@ partial class PluginBase
//return false;
}
}
public virtual string? Icon => null;
DateTimeOffset GetInstallTime()
{
try
{
var location = AssemblyLocation;
var time = new FileInfo(location).CreationTime;
return time;
}
catch
{
}
return default;
}
public DateTimeOffset InstallTime => mInstallTime.Value;
}
partial class PluginBase<TPlugin>
@@ -7,11 +7,13 @@ public abstract partial class PluginBase : IPlugin
{
readonly Lazy<string> mAppDataDirectory;
readonly Lazy<string> mCacheDirectory;
readonly Lazy<DateTimeOffset> mInstallTime;
public PluginBase()
{
mAppDataDirectory = new(() => GetPluginsDirectory(Name, IOPath.AppDataDirectory));
mCacheDirectory = new(() => GetPluginsDirectory(Name, IOPath.CacheDirectory));
mInstallTime = new(GetInstallTime);
}
public virtual IEnumerable<TabItemViewModel>? GetMenuTabItems() => null;
@@ -49,6 +49,8 @@ public static class PluginsCore
public string? Icon { get; private set; }
public DateTimeOffset InstallTime { get; private set; }
public void SetValue(IPlugin plugin)
{
Name = plugin.Name;
@@ -63,6 +65,7 @@ public static class PluginsCore
CacheDirectory = plugin.CacheDirectory;
IsOfficial = plugin.IsOfficial;
Icon = plugin.Icon;
InstallTime = plugin.InstallTime;
}
public void ConfigureDemandServices(IServiceCollection services, Startup startup)