public override void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText) { _settingsLoaded = false; ParentTabPage = pluginScreenSpace; StatusLabel = pluginStatusText; ParentTabPage.Text = "Chatting Translate"; try { Controller = new MainController(); Settings = new SettingsHolder(); Settings.AttachToAct(this); OverlayWPF = new TranslateWindow(); ElementHost.EnableModelessKeyboardInterop(OverlayWPF); OverlayWPF.AttachToAct(this); OverlayWPF.Show(); SettingsTab = new FFXIVTranslateTabControl(); SettingsTab.AttachToAct(this); Controller.ChannelFilterChanged += ControllerOnChannelFilterChanged; Controller.ChannelColorChanged += ControllerOnChannelColorChanged; Controller.ChannelLabelChanged += ControllerOnChannelLabelChanged; Controller.ActivatedProcessPathChanged += ControllerOnActivatedProcessPathChanged; Controller.ClipboardContentChanged += ControllerOnClipboardContentChanged; ProxyFactory.Instance.AttachToAct(this); TranslateService.AttachToAct(this); _windowsMessagePump.AttachToAct(this); UpdateChecker.AttachToAct(this); _shortkeyManager = new ShortkeyManager <MainController, FFXIVTranslatePlugin>(); _shortkeyManager.AttachToAct(this); Settings.PostAttachToAct(this); OverlayWPF.PostAttachToAct(this); SettingsTab.PostAttachToAct(this); ProxyFactory.Instance.PostAttachToAct(this); TranslateService.PostAttachToAct(this); _windowsMessagePump.PostAttachToAct(this); UpdateChecker.PostAttachToAct(this); _shortkeyManager.PostAttachToAct(this); Settings.Load(); _settingsLoaded = true; DoLocalization(); ActGlobals.oFormActMain.LogFileChanged += OFormActMainOnLogFileChanged; _workingThread.StartWorkingThread(ActGlobals.oFormActMain.LogFilePath); Settings.NotifySettingsLoaded(); StatusLabel.Text = "Init Success. >w<"; } catch (Exception ex) { StatusLabel.Text = "Init Failed: " + ex; if (_settingsLoaded) { MessageBox.Show($"Init failed!\nCaused by:\n{ex}"); } else { MessageBox.Show($"Init failed before settings are loaded. Settings won't be saved until next successfully initialization to prevent settings lost!\nCaused by:\n{ex}"); } } }
public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText) { ParentTabPage = pluginScreenSpace; StatusLabel = pluginStatusText; ParentTabPage.Text = "Chatting Translate"; try { // Load FFXIV plugin's assembly if needed AppDomain.CurrentDomain.AssemblyResolve += (o, e) => { var simpleName = new string(e.Name.TakeWhile(x => x != ',').ToArray()); if (simpleName == "FFXIV_ACT_Plugin") { var query = ActGlobals.oFormActMain.ActPlugins.Where( x => x.lblPluginTitle.Text == "FFXIV_ACT_Plugin.dll"); var plugin = query.FirstOrDefault(); if (plugin != null) { return(System.Reflection.Assembly.LoadFrom(plugin.pluginFile.FullName)); } } return(null); }; Controller = new MainController(); Settings = new PluginSettings(this); Overlay = new TranslateForm(); Overlay.AttachToAct(this); Overlay.Show(); SettingsTab = new FFXIVTranslateTabControl(); SettingsTab.AttachToAct(this); Controller.ChannelFilterChanged += ControllerOnChannelFilterChanged; Controller.ChannelColorChanged += ControllerOnChannelColorChanged; Controller.ChannelLabelChanged += ControllerOnChannelLabelChanged; Controller.LanguageChanged += ControllerOnLanguageChanged; Controller.OverlayFontChanged += ControllerOnOverlayFontChanged; Controller.TranslateProviderChanged += ControllerOnTranslateProviderChanged; TranslateService.AttachToAct(this); Settings.Load(); DoLocalization(); ActGlobals.oFormActMain.LogFileChanged += OFormActMainOnLogFileChanged; _workingThread.StartWorkingThread(ActGlobals.oFormActMain.LogFilePath); try { Controller.NotifyOverlayFontChanged(false, (Font)TypeDescriptor.GetConverter(typeof(Font)).ConvertFromString(OverlayFont)); } catch (Exception) { Controller.NotifyOverlayFontChanged(true, new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular)); } Controller.NotifyTranslateProviderChanged(false, TranslateProvider, TranslateApiKey, TranslateLangFrom, TranslateLangTo); StatusLabel.Text = "Init Success. >w<"; } catch (Exception ex) { StatusLabel.Text = "Init Failed: " + ex.ToString(); } }