Exemple #1
0
        public void InitPlugin(
            IActPluginV1 plugin,
            TabPage pluginScreenSpace,
            Label pluginStatusText)
        {
            // タイトルをセットする
            pluginScreenSpace.Text = "YUKKURI";

            EnvironmentMigrater.Migrate();
            MasterFilePublisher.Publish();
            WPFHelper.Start();
            WPFHelper.BeginInvoke(async() =>
            {
                AppLog.LoadConfiguration(AppLog.HojoringConfig);
                this.Logger?.Trace(Assembly.GetExecutingAssembly().GetName().ToString() + " start.");

                try
                {
                    this.PluginStatusLabel = pluginStatusText;

                    if (!EnvironmentHelper.IsValidPluginLoadOrder())
                    {
                        pluginStatusText.Text = "Plugin Initialize Error";
                        return;
                    }

                    EnvironmentHelper.GarbageLogs();
                    EnvironmentHelper.StartActivator(() =>
                    {
                        ConfigBaseView.Instance.SetActivationStatus(false);
                        this.DeInitPlugin();
                    });

                    this.Logger.Trace("[YUKKURI] Start InitPlugin");

                    var pluginInfo = ActGlobals.oFormActMain.PluginGetSelfData(plugin);
                    if (pluginInfo != null)
                    {
                        this.PluginDirectory = pluginInfo.pluginFile.DirectoryName;
                    }

                    // .NET FrameworkとOSのバージョンを確認する
                    if (!UpdateChecker.IsAvailableDotNet() ||
                        !UpdateChecker.IsAvailableWindows())
                    {
                        NotSupportedView.AddAndShow(pluginScreenSpace);
                        return;
                    }

                    // 外部リソースをダウンロードする
                    if (!ResourcesDownloader.Instance.IsReady())
                    {
                        await ResourcesDownloader.Instance.DownloadAsync();
                    }

                    // 設定ファイルを読み込む
                    Settings.Default.Load();
                    Settings.Default.StatusAlertSettings.EnabledTPAlert = false;

                    // 設定ファイルをバックアップする
                    await EnvironmentHelper.BackupFilesAsync(
                        Settings.FilePath);

                    // 漢字変換を初期化する
                    KanjiTranslator.Default.Initialize();

                    // TTSキャッシュの移行とGarbageを行う
                    await Task.Run(() =>
                    {
                        this.MigrateTTSCache();
                        this.GarbageTTSCache();
                    });

                    // HojoringのSplashを表示する
                    WPFHelper.Start();
                    UpdateChecker.ShowSplash();

                    EnvironmentHelper.WaitInitActDone();

                    await Task.Run(() =>
                    {
                        // TTSを初期化する
                        SpeechController.Default.Initialize();

                        // FF14監視スレッドを初期化する
                        FFXIVWatcher.Initialize();
                    });

                    // 設定Panelを追加する
                    pluginScreenSpace.Controls.Add(new ElementHost()
                    {
                        Child = new ConfigBaseView(),
                        Dock  = DockStyle.Fill,
                    });

                    // TTSメソッドを置き換える
                    this.StartReplaceTTSMethodTimer();

                    await Task.Run(() =>
                    {
                        // DISCORD BOT クライアントを初期化する
                        DiscordClientModel.Model.Initialize();

                        // AutoJoinがONならば接続する
                        if (Settings.Default.DiscordSettings.AutoJoin)
                        {
                            DiscordClientModel.Model.Connect(true);
                        }
                    });

                    await Task.Run(() =>
                    {
                        // VOICEROIDを起動する
                        if (SpeechController.Default is VoiceroidSpeechController ctrl)
                        {
                            ctrl.Start();
                        }
                    });

                    // Bridgeにメソッドを登録する
                    PlayBridge.Instance.SetBothDelegate((message, voicePalette, isSync, volume) => this.Speak(message, PlayDevices.Both, voicePalette, isSync, volume));
                    PlayBridge.Instance.SetMainDeviceDelegate((message, voicePalette, isSync, volume) => this.Speak(message, PlayDevices.Main, voicePalette, isSync, volume));
                    PlayBridge.Instance.SetSubDeviceDelegate((message, voicePalette, isSync, volume) => this.Speak(message, PlayDevices.Sub, voicePalette, isSync, volume));
                    PlayBridge.Instance.SetSyncStatusDelegate(() => Settings.Default.Player == WavePlayerTypes.WASAPIBuffered);

                    // テキストコマンドの購読を登録する
                    this.SubscribeTextCommands();

                    // サウンドデバイスを初期化する
                    SoundPlayerWrapper.Init();
                    SoundPlayerWrapper.LoadTTSCache();

                    // CeVIOをアイコン化する
                    if (Settings.Default.TTS == TTSType.Sasara)
                    {
                        CevioTrayManager.Start();
                        CevioTrayManager.ToIcon();
                    }

                    PluginStatusLabel.Text = "Plugin Started";

                    this.Logger.Trace("[YUKKURI] End InitPlugin");

                    // 共通ビューを追加する
                    CommonViewHelper.Instance.AddCommonView(
                        pluginScreenSpace.Parent as TabControl);

                    this.isLoaded = true;

                    // アップデートを確認する
                    await Task.Run(() => this.Update());
                }
                catch (Exception ex)
                {
                    this.Logger.Error(ex, "InitPlugin error.");

                    ModernMessageBox.ShowDialog(
                        "Plugin init error !",
                        "ACT.TTSYukkuri",
                        System.Windows.MessageBoxButton.OK,
                        ex);

                    // TTSをゆっくりに戻す
                    Settings.Default.TTS = TTSType.Yukkuri;
                    Settings.Default.Save();
                }
            });
        }