Example #1
0
 /// <summary>
 /// 异步检查版本号
 /// </summary>
 /// <param name="plugin">要执行检查的插件</param>
 public static void Check(DMPlugin plugin)
 {
     new System.Threading.Thread(() =>
     {
         try
         {
             var versionChecker = new VersionChecker("SendDanmaku");
             if (versionChecker.FetchInfo())
             {
                 if (versionChecker.hasNewVersion(plugin.PluginVer))
                 {
                     plugin.Log("插件有新版本了!最新版本:" + versionChecker.Version + ",当前版本" + plugin.PluginVer +
                                ",更新时间:" + versionChecker.UpdateTime.ToString("yyyy.MM.dd") + "\r\n" + "下载地址:" + versionChecker.WebPageUrl);
                 }
             }
             else
             {
                 plugin.Log("版本检查失败:" + versionChecker.lastException.Message);
             }
         }
         catch (Exception)
         { }// 以防万一
     })
     {
         Name = "VersionChecker", IsBackground = true
     }.Start();
 }
Example #2
0
        private void InjectDGJ()
        {
            Assembly dgjAssembly = Assembly.GetAssembly(typeof(SearchModule)); //如果没有点歌姬插件,插件的构造方法会抛出异常,无需考虑这里的assembly == null的情况
            Assembly dmAssembly  = Assembly.GetAssembly(Application.Current.MainWindow.GetType());
            Type     appType     = dmAssembly.ExportedTypes.FirstOrDefault(p => p.FullName == "Bililive_dm.App");
            ObservableCollection <DMPlugin> Plugins = (ObservableCollection <DMPlugin>)appType.GetField("Plugins", BindingFlags.GetField | BindingFlags.Static | BindingFlags.Public).GetValue(null);
            DMPlugin dgjPlugin = Plugins.FirstOrDefault(p => p.ToString() == "DGJv3.DGJMain");
            object   dgjWindow = null;

            try
            {
                dgjWindow = dgjAssembly.DefinedTypes.FirstOrDefault(p => p.Name == "DGJMain").GetField("window", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dgjPlugin);
            }
            catch (ReflectionTypeLoadException Ex) // 缺少登录中心时
            {
                dgjWindow = Ex.Types.FirstOrDefault(p => p.Name == "DGJMain").GetField("window", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dgjPlugin);
            }
            object searchModules = dgjWindow.GetType().GetProperty("SearchModules", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public).GetValue(dgjWindow);
            ObservableCollection <SearchModule> searchModules2 = (ObservableCollection <SearchModule>)searchModules.GetType().GetProperty("Modules", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public).GetValue(searchModules);
            SearchModule nullModule = (SearchModule)searchModules.GetType().GetProperty("NullModule", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance).GetValue(searchModules);
            SearchModule lwlModule  = searchModules2.FirstOrDefault(p => p != nullModule);

            if (lwlModule != null)
            {
                Action <string> logHandler = (Action <string>)lwlModule.GetType().GetProperty("_log", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(lwlModule);
                ExtendNeteaseModule.SetLogHandler(logHandler);
            }
            searchModules2.Insert(2, ExtendNeteaseModule);
        }
Example #3
0
        static IEnumerable <DMPlugin> InitializePlugin(Assembly assembly)
        {
            int count = 0;

            foreach (Type type in assembly.GetTypes())
            {
                var pluginFQDN = type.Module.FullyQualifiedName;
                var modelFQDN  = typeof(DMPlugin).Module.FullyQualifiedName;
                Console.WriteLine($"Plugin Injector: {pluginFQDN}/{modelFQDN}");
                if (typeof(DMPlugin).IsAssignableFrom(type))
                {
                    DMPlugin result = Activator.CreateInstance(type) as DMPlugin;
                    if (result != null)
                    {
                        result.Initialize(new PluginHelper(result));
                        count++;
                        yield return(result);
                    }
                }
            }

            if (count == 0)
            {
                /*string availableTypes = string.Join(",", assembly.GetTypes().Select(t => t.FullName));
                 * throw new ApplicationException(
                 *  $"Can't find any type which implements DMPlugin in {assembly} from {assembly.Location}.\n" +
                 *  $"Available types: {availableTypes}");*/
            }
        }
Example #4
0
 internal static async Task <bool> DoAuth(DMPlugin plugin)
 {
     if (!CheckLoginCenter())
     {
         return(false);
     }
     return(await warpper.doAuthorization(plugin));
 }
Example #5
0
 internal static bool CheckAuth(DMPlugin plugin)
 {
     if (!CheckLoginCenter())
     {
         return(false);
     }
     return(warpper.checkAuthorization(plugin) == true);
 }
Example #6
0
        public static void PluginExceptionHandler(Exception ex, DMPlugin plugin=null)
        {
           
                if (plugin != null)
                {
                    MessageBox.Show(
                        "插件" + plugin.PluginName + "遇到了不明錯誤: 日誌已經保存在桌面, 請有空發給該插件作者 " + plugin.PluginAuth + ", 聯繫方式 " +
                        plugin.PluginCont);
                    try
                    {
                        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


                        using (
                            StreamWriter outfile = new StreamWriter(path + @"\B站彈幕姬插件" + plugin.PluginName + "錯誤報告.txt")
                            )
                        {
                            outfile.WriteLine("請有空發給聯繫方式 " + plugin.PluginCont + " 謝謝");
                            outfile.WriteLine(DateTime.Now + " " + plugin.PluginName + " " + plugin.PluginVer);
                            outfile.Write(ex.ToString());
                        }

                    }
                    catch (Exception)
                    {

                    }
                }
                else
                {
                    MessageBox.Show(
               "遇到了不明錯誤: 日誌已經保存在桌面, 請有空發給 [email protected] ");
                    try
                    {
                        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


                        using (StreamWriter outfile = new StreamWriter(path + @"\B站彈幕姬錯誤報告.txt"))
                        {
                            outfile.WriteLine("請有空發給 [email protected] 謝謝");
                            outfile.WriteLine(DateTime.Now + "");
                            outfile.Write(ex.ToString());
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
           
        }
Example #7
0
        public static void PluginExceptionHandler(Exception ex, DMPlugin plugin = null)
        {
            if (plugin != null)
            {
                MessageBox.Show(
                    "插件" + plugin.PluginName + "遇到了不明错误: 日志已经保存在桌面, 请有空发给该插件作者 " + plugin.PluginAuth + ", 联系方式 " +
                    plugin.PluginCont);
                try
                {
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


                    using (
                        StreamWriter outfile = new StreamWriter(path + @"\B站弹幕姬插件" + plugin.PluginName + "错误报告.txt")
                        )
                    {
                        outfile.WriteLine("请有空发给联系方式 " + plugin.PluginCont + " 谢谢");
                        outfile.WriteLine(DateTime.Now + " " + plugin.PluginName + " " + plugin.PluginVer);
                        outfile.Write(ex.ToString());
                    }
                }
                catch (Exception)
                {
                }
            }
            else
            {
                MessageBox.Show(
                    "遇到了不明错误: 日志已经保存在桌面, 请有空发给 [email protected] ");
                try
                {
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);


                    using (StreamWriter outfile = new StreamWriter(path + @"\B站弹幕姬错误报告.txt"))
                    {
                        outfile.WriteLine("请有空发给 [email protected] 谢谢");
                        outfile.WriteLine(DateTime.Now + "");
                        outfile.Write(ex.ToString());
                    }
                }
                catch (Exception)
                {
                }
            }
        }
 private void InjectDGJ()
 {
     try
     {
         Assembly dgjAssembly = Assembly.GetAssembly(typeof(SearchModule)); //如果没有点歌姬插件,插件的构造方法会抛出异常,无需考虑这里的assembly == null的情况
         DMPlugin dgjPlugin   = Douyulive_dm.App.Plugins.FirstOrDefault(p => p.GetType() == typeof(DGJMain));
         if (dgjPlugin == null)                                             // 没有点歌姬
         {
             throw new DllNotFoundException();
         }
         object dgjWindow = null;
         try
         {
             dgjWindow = dgjAssembly.DefinedTypes.FirstOrDefault(p => p.Name == "DGJMain").GetField("window", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dgjPlugin);
         }
         catch (ReflectionTypeLoadException Ex) // 缺少登录中心时
         {
             dgjWindow = Ex.Types.FirstOrDefault(p => p.Name == "DGJMain").GetField("window", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dgjPlugin);
         }
         object searchModules = dgjWindow.GetType().GetProperty("SearchModules", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public).GetValue(dgjWindow);
         ObservableCollection <SearchModule> searchModules2 = (ObservableCollection <SearchModule>)searchModules.GetType().GetProperty("Modules", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public).GetValue(searchModules);
         SearchModule nullModule = (SearchModule)searchModules.GetType().GetProperty("NullModule", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance).GetValue(searchModules);
         SearchModule coelModule = searchModules2.FirstOrDefault(p => p != nullModule);
         ExtendNeteaseModule = new ExtendNeteaseModule();
         if (coelModule != null)
         {
             Action <string> logHandler = (Action <string>)coelModule.GetType().GetProperty("_log", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(coelModule);
             ExtendNeteaseModule.SetLogHandler(logHandler);
         }
         searchModules2.Insert(2, ExtendNeteaseModule);
     }
     catch (DllNotFoundException)
     {
         throw;
     }
     catch (Exception Ex)
     {
         MessageBox.Show($"注入到点歌姬失败了喵\n{Ex}", "本地网易云喵块", 0, MessageBoxImage.Error);
         throw;
     }
 }
Example #9
0
 internal PluginHelper(DMPlugin Plugin)
 {
     this.Plugin = Plugin;
     this.logger = App.LogFactory.GetLogger(Plugin.Slug);
 }
Example #10
0
        public async Task <bool> doAuthorization(DMPlugin plugin)
        {
            var result = await LoginCenterAPI.doAuthorization(plugin);

            return(result == AuthorizationResult.Success);
        }
Example #11
0
 public bool checkAuthorization(DMPlugin plugin)
 {
     return(LoginCenterAPI.checkAuthorization(plugin) == LoginCenter.API.AuthorizationResult.Success);
 }