PluginInfo.cs 2.6 KB
Newer Older
C
chao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
using Jvedio.Core.Enums;
using JvedioLib.Security;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Jvedio.Core.Plugins
{
    public class PluginInfo
    {


        public string ServerName { get; set; }
        public string InfoType { get; set; }
        public string Name { get; set; }
        public string Version { get; set; }
        public string Categories { get; set; }
        public string Image { get; set; }
        public string Author { get; set; }
        public string Email { get; set; }
        public string Description { get; set; }
        public string MarkDown { get; set; }
        public string License { get; set; }
        public string PublishDate { get; set; }


        // 不在 dll 内的字段
        public bool Enabled { get; set; }
        public bool HasNewVersion { get; set; }
        public bool Installed { get; set; }
        public string NewVersion { get; set; }
        public string FileHash { get; set; }
        public string FileName { get; set; }
        public string ImageUrl { get; set; }

        public PluginType Type { get; set; }


        public string _Path;
        public string Path
        {
            get { return _Path; }

            set
            {
                _Path = value;
                FileHash = Encrypt.GetFileMD5(value);
            }
        }

        public PluginInfo()
        {
            Enabled = true;
        }


        public static PluginInfo ParseDict(Dictionary<string, string> dict)
        {
            if (dict == null || dict.Count <= 0) return null;
            PluginInfo result = new PluginInfo();
            PropertyInfo[] propertyInfos = typeof(PluginInfo).GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                string name = propertyInfo.Name;
                if (dict.ContainsKey(name))
                    propertyInfo.SetValue(result, dict[name]);
            }
            return result;
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            PluginInfo other = obj as PluginInfo;
            if (other == null) return false;
            if (other.ServerName == null || other.Name == null) return false;
            return other.ServerName.Equals(ServerName) && other.Name.Equals(Name);
        }

        public string getUID()
        {
            return $"{ServerName}.{Name}";
        }

        public override int GetHashCode()
        {
            return ServerName.GetHashCode() ^ Name.GetHashCode();
        }

    }
}