using System.Collections.Specialized;
using System.Configuration;
using System.Diagnostics;
using System.Drawing.Text;
using System.Reflection;


namespace DragonVideoPlayer
{

    public class SettingsForm : Form
    {
      private CheckBox check_seek_osd;
        private CheckBox check_ytdlp_login;
        private CheckBox check_force_window;
        private CheckBox check_idle;
        private CheckBox check_mpv_add_comand;
        private CheckBox check_osd;
        private CheckBox check_vr360;
        private Color selectedColor = Color.White;
        private Button btnFontColor;
        private Button btnborderColor;
        private CheckBox checkOverClocked;
        private CheckBox check_srt;
        private TextBox textBox_font;
        private TextBox textBox_fontsize;
        private TextBox mpv_add_comand_Box;
        private TextBox textBox_sub_border_color;

        private TextBox textBox_font_coler;
        private TextBox textBox_sub_pos;
        private TextBox textBox_border_size;
        private TextBox  textBox_shadow_offset;
        private CheckBox check_crop;
        private TextBox crop_textBox;
        private ComboBox combo_glsl;

        private TabControl tabControl;
        private ComboBox comboFonts;
   

        private TextBox txt_vo;

        private ComboBox cmb_vo;
        private CheckBox chk_vo;
        private CheckBox check_glsl;
        private CheckBox check_tips;
     

        private CheckBox check_ab_bt;
     
        private CheckBox check_img_bt;
        private CheckBox check_search;
        private CheckBox check_task_tray;



        private CheckBox check_mpv_log;
        private CheckBox check_error_log;
        private CheckBox check_command_log;


        private CheckBox check_start_Speed;
        private TextBox speed_start_textBox;


        private CheckBox check_volume_save;
        private TextBox volume_su_Box;
        private CheckBox check_rireki;
        private CheckBox check_ranking;

        private CheckBox check_db_update;

        private List<RadioButton> folder_sort_Radios = new List<RadioButton>();
        private List<RadioButton> db_sort_Radios = new List<RadioButton>();
        private List<RadioButton> db_sort_desc = new List<RadioButton>();
        private CheckBox check_multi_sub_audio;
        private List<RadioButton> folder_sort_desc = new List<RadioButton>();

        private List<RadioButton> DVD_lang_select_Radios = new List<RadioButton>();

        private List<RadioButton> Login_Radios = new List<RadioButton>();


        private CheckBox check_DVD_auto_select;


        private TextBox dvdBox;

        private CheckBox check_mpv_Resume;

        private CheckBox check_audio_eq;
        private CheckBox check_mid_play;

        private TextBox mid_play_textBox;

        private CheckBox checkDelete;
        private CheckBox checkDelete_mes;

       
  
    

        private CheckBox check_panscan;
        private CheckBox check_zoom;
        private TextBox zoom_textBox;

        private CheckBox check_audio_pitch;
        private TextBox seek_su_textBox;


        private TextBox speed_su_textBox;


        private CheckBox check_af_save;
        private TextBox lavfi_textBox;
        private CheckBox check_vf_save;
        private TextBox af_textBox;

      
        private CheckBox check_cap;

        private CheckBox checkThread;

        private TextBox Thread_su_Box;

        private CheckBox check_video_eq;


    
        private CheckBox checkThumb;

  
        private CheckBox check_playlist;
        private TextBox streamlink_seiki_Box;

        private CheckBox checkmov3;




        private CheckBox checkWheelMouse;

  
        private CheckBox check_cap_next;
        private CheckBox checkResume;
        private TextBox txtHistory;
    
        private TextBox video_regexBox;
        private TextBox txtRank;
        private TextBox txt_glslPath;
        private CheckBox chk_hwdec;
        private Label lbl_hwdec;
     
        private CheckBox check_stop_bt;
        private CheckBox check_speed_slider_bt;
        private CheckBox check_volume_bt;
        private CheckBox check_seed_bt;
        private CheckBox check_flame_step;
   

        private CheckBox check_ss_bt;
        private CheckBox check_mute_bt;
        private CheckBox check_open_bt;
        private CheckBox check_pause_bt;
        private CheckBox check_full_sc_bt;

        private CheckBox check_utako;
        private CheckBox check_rakuten;
        private CheckBox check_arva;
        private ComboBox cmb_hwdec;
        private TextBox txt_hwdec;

        private CheckBox chk_gpuapi;
        private Label lbl_gpuapi;
        private ComboBox cmb_gpuapi;
        private TextBox txt_gpuapi;

        private CheckBox check_down_bt;
        private CheckBox chk_scale;
        private Label lbl_scale;
        private ComboBox cmb_scale;
        private TextBox txt_scale;

        private CheckBox chk_interpolation;
        private Label lbl_interpolation;
        private ComboBox cmb_interpolation;
        private TextBox txt_interpolation;
        private RadioButton radioFolder;
        private RadioButton radioDB;
        private RadioButton radioPrimehome;
        private RadioButton radio_utako;
        private RadioButton radio_rakuten;
        private RadioButton radio_arva;



        private CheckBox checkFolderAdd;
        private RadioButton radioAbema;

     
        private CheckBox checkSingleClick;
        private TextBox widthBox;
        private TextBox heightBox;
   
        private CheckBox checkCacheWait;

        private TextBox cache_size_Box;

        private TextBox cache_sc_Box;

        private CheckBox checkCache;
        private CheckBox check_primehome;

        private CheckBox check_abema_low;
        private CheckBox check_abema_high;
       
        private CheckBox check_radiko;

        private CheckBox checkDoubleClick;
        private List<RadioButton> SingleClickRadios = new List<RadioButton>();

        private List<RadioButton> StartWindowSizeRadios = new List<RadioButton>();




        private List<RadioButton> MouseWheelRadios = new List<RadioButton>();
        private List<RadioButton> endModeRadios = new List<RadioButton>();
        public SettingsForm()
        {
            Text = "設定";
            Width = 700;
            Height = 600;
            BackColor = Color.FromArgb(229, 229, 229);
           
            this.tabControl = new System.Windows.Forms.TabControl();
      
        InitializeUI();
            this.Load += Form1_Load;
            this.FormClosing += new FormClosingEventHandler(formClosing);
        }

        private void InitializeUI()
        {
            tabControl = new TabControl();
            tabControl.Multiline = true;   // タブを二段以上に表示可能に
            tabControl.SizeMode = TabSizeMode.Fixed;  // 各タブの幅を自動調整
            tabControl.Location = new Point(10, 10);
            tabControl.Size = new Size(700, 600);
            tabControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

            this.Controls.Add(tabControl);
            //tabControl = new TabControl();
            //tabControl.Location = new Point(30, 20);
            //tabControl.Size = new Size(750, 550);
            //tabControl.SelectedIndexChanged += TabControl_SelectionChanged;
            //Controls.Add(tabControl);
            try
            {
                CreateSettingsTabs();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
      
        }
        // C# WinForms 設定画面 完全リファクタ版
        // 既存の CreateTab1 ～ CreateTab14 を置き換え
        // カテゴリー別 8 タブ構成 / 全設定項目を移植しやすい土台

        private void CreateSettingsTabs()
        {
            tabControl.TabPages.Clear();

            CreateGeneralTab();      // 基本
            CreateOperationTab();    // 操作
            CreateSystemTab();
            CreatePlaybackTab();     // 再生
            CreateWindowTab();       // 画面・ウインドウ
            CreateMpvTab();          // mpv / GPU / GLSL
            CreateSubtitleDvdTab();  // 字幕 / DVD
            CreateServiceTab();      // 配信サービス
            CreateToolbarTab();      // ボタン表示
            CreateDatabaseTab();
            CreateDvdTab();
            CreateEffectTab();
            CreateFileManageTab();
            CreateStreamTab();
             CreateListTab();
            CreateExternalPathTab();
            Login_Tab();
        }

   
        private TabPage NewTab(string title)
        {
            return new TabPage(title)
            {
                BackColor = BackColor
            };
        }

        private GroupBox NewGroup(string text, int x, int y, int w, int h)
        {
            return new GroupBox
            {
                Text = text,
                Location = new Point(x, y),
                Size = new Size(w, h)
            };
        }

        private CheckBox NewCheck(string text, int x, int y, bool value = false, int width = 220)
        {
            return new CheckBox
            {
                Text = text,
                Location = new Point(x, y),
                Checked = value,
                Width = width
            };
        }

        private Label NewLabel(string text, int x, int y)
        {
            return new Label
            {
                Text = text,
                Location = new Point(x, y),
                AutoSize = true
            };
        }

        private TextBox NewText(string value, int x, int y, int width = 120)
        {
            return new TextBox
            {
                Text = value,
                Location = new Point(x, y),
                Width = width
            };
        }
        
        private void CreateFileManageTab()
        {
            var tab = NewTab("ファイル管理");

            checkDelete = NewCheck("削除機能を有効", 20, 20);
            checkDelete_mes = NewCheck("削除で確認する", 20, 50);

            // ★追加：サムネイル作成
            checkThumb = NewCheck("サムネイル作成", 20, 80, false, 150);

            tab.Controls.AddRange(new Control[]
            {
        checkDelete,
        checkDelete_mes,
        checkThumb
            });

            tabControl.TabPages.Add(tab);
        }
     
        private void CreateGeneralTab()
        {
            var tab = NewTab("その他");


            var regex = NewGroup("動画取得", 20, 20, 380, 110);
            regex.Controls.Add(NewLabel("拡張子正規表現", 10, 25));
            video_regexBox = NewText(".(mp4|mkv|iso|wmv|ts|webm|mpg|3gp|avi|flv)", 10, 50, 340);
            regex.Controls.Add(video_regexBox);
           

            tab.Controls.AddRange(new Control[] { regex });
            tabControl.TabPages.Add(tab);
        }
        
        private void CreateListTab()
        {
            // タブ作成
            var tab = NewTab("リスト");

            // 起動時のリスト グループ
            var startup = NewGroup("起動時のリスト", 20, 20, 170, 210);

            radioFolder = new RadioButton { Text = "フォルダ", Location = new Point(10, 20), Checked = true };
            radioDB = new RadioButton { Text = "動画DB", Location = new Point(10, 45) };
            radioAbema = new RadioButton { Text = "AbemaTV", Location = new Point(10, 70) };
            radioPrimehome = new RadioButton { Text = "Primehome", Location = new Point(10, 95) };
            radio_utako = new RadioButton { Text = "utako", Location = new Point(10, 120) };
            radio_rakuten= new RadioButton { Text = "楽天", Location = new Point(10, 145) };
            radio_arva= new RadioButton { Text = "arva", Location = new Point(10, 170) };

            startup.Controls.AddRange(new Control[] { radioFolder, radioDB, radioAbema, radioPrimehome, radio_utako, radio_rakuten, radio_arva });

            tab.Controls.Add(startup);

            // ソート設定
            GroupBox group_folder_sort = new GroupBox();
            group_folder_sort.Text = "フォルダ動画のソート";
            group_folder_sort.Location = new Point(200, 100);
            group_folder_sort.Size = new Size(150, 120);

            string[] sortModes =
            {
        "ファイル更新日",
        "ファイル作成日",
        "ファイル名順",
        "ファイルサイズ順",
  
    };

            for (int i = 0; i < sortModes.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = sortModes[i];
                rb.Width = 190;
                rb.Location = new Point(10, 20 + i * 25);
                if (i == 0) rb.Checked = true;

                group_folder_sort.Controls.Add(rb);
                folder_sort_Radios.Add(rb);
            }

            tab.Controls.Add(group_folder_sort);

            // 昇順降順
            GroupBox group_folder_desc = new GroupBox();
            group_folder_desc.Text = "フォルダリストのソート順";
            group_folder_desc.Location = new Point(10, 240);
            group_folder_desc.Size = new Size(140, 90);

            string[] sortOrders =
            {
        "降順（DESC）",
        "昇順（ASC）"
    };

            for (int i = 0; i < sortOrders.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = sortOrders[i];
                rb.Width = 120;
                rb.Location = new Point(10, 20 + i * 25);
                if (i == 0) rb.Checked = true;

                group_folder_desc.Controls.Add(rb);
                folder_sort_desc.Add(rb);
            }

            tab.Controls.Add(group_folder_desc);

           
            // フォルダ追加チェック
            checkFolderAdd = NewCheck("再生時にフォルダ動画をリスト追加", 220, 20, true, 280);
            tab.Controls.Add(checkFolderAdd);

            checkOverClocked = NewCheck("OverClockedReMixをリスト追加", 220, 50, false, 280);
            tab.Controls.Add(checkOverClocked);

            // タブ追加
            tabControl.TabPages.Add(tab);
        }
    
        private void CreateOperationTab()
        {
            var tab = NewTab("操作");

            // ===== シングルクリック =====
            var click = NewGroup("シングルクリック", 20, 20, 150, 140);
            string[] singleModes = { "次の動画", "フルスクリーン", "ポーズ", "ミュート" };

            for (int i = 0; i < singleModes.Length; i++)
            {
                var rb = new RadioButton
                {
                    Text = singleModes[i],
                    Location = new Point(10, 20 + i * 25),
                    Checked = i == 0
                };

                click.Controls.Add(rb);
                SingleClickRadios.Add(rb);
            }

            // ===== マウスホイール動作 =====
            var groupMouseWheel = NewGroup("マウスホイールの動作", 180, 20, 170, 150);

            string[] mouseWheels =
            {
        "次の動画",
        "シーク",
        "ボリューム",
        "ZOOM",
        "再生速度"
    };

            for (int i = 0; i < mouseWheels.Length; i++)
            {
                var rb = new RadioButton
                {
                    Text = mouseWheels[i],
                    Location = new Point(10, 20 + i * 25),
                    Checked = i == 0
                };

                groupMouseWheel.Controls.Add(rb);
                MouseWheelRadios.Add(rb);
            }

            // ===== 操作系チェック =====
            checkSingleClick = NewCheck("シングルクリック有効", 380, 20);
            checkDoubleClick = NewCheck("ダブルクリックでフルスクリーン", 380, 50, true, 220);
            check_seek_osd = NewCheck("シークでOSDバー表示", 380, 80);

            checkWheelMouse = NewCheck("マウスホイールを有効", 380, 110);
            check_osd = NewCheck("OSD有効", 380, 140,true);

            // ===== シーク量 =====
            tab.Controls.Add(NewLabel("シークする時の飛ばすフレーム数", 20, 190));
            seek_su_textBox = NewText("200", 20, 215, 120);

            // ===== 速度変更量 =====
            tab.Controls.Add(NewLabel("SpeedUP/Down数", 20, 255));
            speed_su_textBox = NewText("0.1", 20, 280, 120);

            // ===== コントロール追加 =====
            tab.Controls.AddRange(new Control[]
            {
        click,
        groupMouseWheel,
        checkSingleClick,
        checkDoubleClick,
        check_seek_osd,
        checkWheelMouse,
        seek_su_textBox,
        speed_su_textBox,
        check_osd
            });

            tabControl.TabPages.Add(tab);
        }
        

        private void CreateDatabaseTab()
        {
            var tab = NewTab("データベース");

            // DB基本設定
            checkResume = NewCheck("DBでレジューム有効", 20, 20);
            check_db_update = NewCheck("再生時にDB更新を有効", 20, 50);

            tab.Controls.Add(checkResume);
            tab.Controls.Add(check_db_update);

            // ソート設定
            GroupBox group_DB_sort = new GroupBox();
            group_DB_sort.Text = "動画DBのソート";
            group_DB_sort.Location = new Point(20, 100);
            group_DB_sort.Size = new Size(220, 180);

            string[] sortModes =
            {
        "ファイル更新日",
        "ファイル作成日",
        "再生数順",
        "パス名順",
        "登録日時順",
        "動画のファイルサイズ順"
    };

            for (int i = 0; i < sortModes.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = sortModes[i];
                rb.Width = 190;
                rb.Location = new Point(10, 20 + i * 25);
                if (i == 0) rb.Checked = true;

                group_DB_sort.Controls.Add(rb);
                db_sort_Radios.Add(rb);
            }

            tab.Controls.Add(group_DB_sort);

            // 昇順降順
            GroupBox group_DB_desc = new GroupBox();
            group_DB_desc.Text = "DBリストのソート順";
            group_DB_desc.Location = new Point(270, 100);
            group_DB_desc.Size = new Size(160, 90);

            string[] sortOrders =
            {
        "降順（DESC）",
        "昇順（ASC）"
    };

            for (int i = 0; i < sortOrders.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = sortOrders[i];
                rb.Width = 120;
                rb.Location = new Point(10, 20 + i * 25);
                if (i == 0) rb.Checked = true;

                group_DB_desc.Controls.Add(rb);
                db_sort_desc.Add(rb);
            }

            tab.Controls.Add(group_DB_desc);

            tabControl.TabPages.Add(tab);
        }
   
        private void CreatePlaybackTab()
        {
            var tab = NewTab("再生");

            // ===== 左側：再生基本 =====
            check_start_Speed = NewCheck("起動時に再生速度変更", 20, 20);
            tab.Controls.Add(check_start_Speed);

            tab.Controls.Add(NewLabel("起動時の再生速度", 20, 50));
            speed_start_textBox = NewText("1.1", 20, 75);
            tab.Controls.Add(speed_start_textBox);

            check_volume_save = NewCheck("ボリュームを保存", 20, 110);
            tab.Controls.Add(check_volume_save);

            tab.Controls.Add(NewLabel("ボリューム", 20, 140));
            volume_su_Box = NewText("100", 20, 165);
            tab.Controls.Add(volume_su_Box);

            check_audio_pitch = NewCheck("SpeedUP/Downしても音程を維持する", 20, 200, true, 200);
            tab.Controls.Add(check_audio_pitch);

            check_panscan = NewCheck("起動時にパンスキャン", 20, 235);
            tab.Controls.Add(check_panscan);

            check_zoom = NewCheck("再生時に縮小再生する", 20, 270);
            tab.Controls.Add(check_zoom);

            tab.Controls.Add(NewLabel("縮小する倍率", 20, 300));
            zoom_textBox = NewText("-0.1", 20, 325);
            tab.Controls.Add(zoom_textBox);

            check_mid_play = NewCheck("再生開始時に途中から再生する", 20, 360, false, 180);
            tab.Controls.Add(check_mid_play);

            tab.Controls.Add(NewLabel("開始する時間(分単位)", 20, 390));
            mid_play_textBox = NewText("20", 20, 415, 120);
            tab.Controls.Add(mid_play_textBox);

            check_mpv_Resume = NewCheck("MPV標準機能でレジューム", 20, 450, false, 150);
            tab.Controls.Add(check_mpv_Resume);

            // ===== 右上：キャッシュ =====
            checkCache = NewCheck("キャッシュ有効", 300, 20, false, 80);
            checkCacheWait = NewCheck("キャッシュが溜まるまで待つ", 300, 50, false, 150);

            cache_size_Box = NewText("600", 300, 100);
            cache_sc_Box = NewText("4", 300, 150);

            tab.Controls.AddRange(new Control[]
            {
        checkCache,
        checkCacheWait,
        NewLabel("キャッシュ量(MB)", 300, 80),
        cache_size_Box,
        NewLabel("キャッシュ秒数", 300, 130),
        cache_sc_Box
            });

            // ===== 右中央：スレッド =====
            checkThread = NewCheck("スレッドを有効", 300, 190);
            tab.Controls.Add(checkThread);

            tab.Controls.Add(NewLabel("スレッド数", 300, 220));
            Thread_su_Box = NewText("4", 300, 245, 120);
            tab.Controls.Add(Thread_su_Box);

            // ===== 右下：終了後の動作 =====
            var groupEnd = NewGroup("終了後の動作", 300, 290, 170, 130);

            string[] endModes =
            {
        "次の動画",
        "同じ動画の繰り返し",
        "ランダム",
        "停止"
    };

            for (int i = 0; i < endModes.Length; i++)
            {
                var rb = new RadioButton
                {
                    Text = endModes[i],
                    Width = 170,
                    Location = new Point(10, 20 + i * 25),
                    Checked = i == 0
                };

                groupEnd.Controls.Add(rb);
                endModeRadios.Add(rb);
            }

            tab.Controls.Add(groupEnd);

             tabControl.TabPages.Add(tab);
        }


        private void CreateWindowTab()
        {
            var tab = NewTab("画面");

            widthBox = NewText("600", 20, 45);
            heightBox = NewText("800", 20, 105);
            tab.Controls.Add(NewLabel("起動時 width", 20, 20));
            tab.Controls.Add(widthBox);
            tab.Controls.Add(NewLabel("起動時 height", 20, 80));
            tab.Controls.Add(heightBox);

            check_task_tray = NewCheck("タスクトレイに常駐", 20, 150);
            check_task_tray.Width = 120;
            tab.Controls.Add(check_task_tray);

            var sizeMode = NewGroup("起動時のウインドウサイズ", 220, 20, 260, 170);
            string[] modes =
            {
        "サイズを設定",
        "最後に閉じた解像度を復元",
        "フルスクリーン",
        "最大化",
        "デスクトップ解像度に合わせる"
    };
            for (int i = 0; i < modes.Length; i++)
            {
                var rb = new RadioButton
                {
                    Text = modes[i],
                    Width = 220,
                    Location = new Point(10, 20 + i * 25),
                    Checked = i == 0
                };
                sizeMode.Controls.Add(rb);
                StartWindowSizeRadios.Add(rb);
            }

            tab.Controls.Add(sizeMode);
            tabControl.TabPages.Add(tab);
        }
        
        private void CreateDvdTab()
        {
            var tab = NewTab("DVD/ブルーレイ");

            // 自動選択
            check_DVD_auto_select = NewCheck("DVDの音声と字幕の自動選択を有効", 20, 20);
            check_DVD_auto_select.Width = 240;
            tab.Controls.Add(check_DVD_auto_select);

            // 自動選択ルール
            GroupBox groupDVD_lang_select = new GroupBox();
            groupDVD_lang_select.Text = "DVDの自動選択設定";
            groupDVD_lang_select.Location = new Point(20, 60);
            groupDVD_lang_select.Size = new Size(220, 80);

            string[] modes =
            {
        "日本語音声で字幕無し",
        "英語音声で日本語字幕"
    };

            for (int i = 0; i < modes.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = modes[i];
                rb.Location = new Point(10, 20 + i * 25);
                rb.Width = 180;
                if (i == 0) rb.Checked = true;

                groupDVD_lang_select.Controls.Add(rb);
                DVD_lang_select_Radios.Add(rb);
            }

            tab.Controls.Add(groupDVD_lang_select);

            // DVDドライブ
            tab.Controls.Add(NewLabel("DVDドライブ", 20, 160));
            dvdBox = NewText(@"d:\", 20, 190, 120);
            tab.Controls.Add(dvdBox);

            tabControl.TabPages.Add(tab);
        }
        private void Login_Tab()
        {
            var tab = NewTab("ログイン認証");

            // 自動選択
            check_ytdlp_login = NewCheck("yt-dlpでログインする", 20, 20);
            check_ytdlp_login.Width = 150;
            tab.Controls.Add(check_ytdlp_login);

            // 自動選択ルール
            GroupBox login_select = new GroupBox();
            login_select.Text = "ログイン方法";
            login_select.Location = new Point(20, 60);
            login_select.Size = new Size(120, 120);

            string[] modes =
            {
        "Firefoxのクッキー",
         "Chromeのクッキー",

        "cookies.txt"
    };

            for (int i = 0; i < modes.Length; i++)
            {
                RadioButton rb = new RadioButton();
                rb.Text = modes[i];
                rb.Location = new Point(10, 20 + i * 25);
                rb.Width = 180;
                if (i == 0) rb.Checked = true;

                login_select.Controls.Add(rb);
                Login_Radios.Add(rb);
            }

            tab.Controls.Add(login_select);

         
            tabControl.TabPages.Add(tab);
        }

        private void CreateMpvTab()
        {
            var tab = NewTab("GPU/GLSL");

            // GLSL有効
            check_glsl = NewCheck("glslを有効", 20, 20);
            txt_glslPath = NewText("", 20, 50, 320);

            combo_glsl = new ComboBox
            {
                Location = new Point(360, 50),
                Width = 260,
                DropDownStyle = ComboBoxStyle.DropDownList
            };

            combo_glsl.SelectedIndexChanged += (s, e) =>
            {
                if (combo_glsl.SelectedItem != null)
                    txt_glslPath.Text = combo_glsl.SelectedItem.ToString();
            };

            // 各種チェックボックスとコンボボックス
            chk_hwdec = NewCheck("hwdecを有効", 20, 100);
            cmb_hwdec = new ComboBox { Location = new Point(20, 130), Width = 150 };
            cmb_hwdec.SelectedIndexChanged += (s, e) =>
            {
                txt_hwdec.Text = cmb_hwdec.Text;
            };
            txt_hwdec = NewText("", 190, 130);

            chk_gpuapi = NewCheck("gpu-apiを有効", 20, 170);
            cmb_gpuapi = new ComboBox { Location = new Point(20, 200), Width = 150 };
            cmb_gpuapi.SelectedIndexChanged += (s, e) =>
            {
                txt_gpuapi.Text = cmb_gpuapi.Text;
            };

            txt_gpuapi = NewText("", 190, 200);

            chk_scale = NewCheck("scaleを有効", 20, 240);
            cmb_scale = new ComboBox { Location = new Point(20, 270), Width = 150 };
            cmb_scale.SelectedIndexChanged += (s, e) =>
            {
                txt_scale.Text = cmb_scale.Text;
            };
            txt_scale = NewText("", 190, 270);

            chk_interpolation = NewCheck("FPS補完", 20, 310);
            cmb_interpolation = new ComboBox { Location = new Point(20, 340), Width = 150 };
            cmb_interpolation.SelectedIndexChanged += (s, e) =>
            {
                txt_interpolation.Text = cmb_interpolation.Text;
            };
            txt_interpolation = NewText("", 190, 340);

            chk_vo = NewCheck("vo設定を有効", 360, 100);
            cmb_vo = new ComboBox { Location = new Point(360, 130), Width = 150 };
            cmb_vo.SelectedIndexChanged += (s, e) =>
            {
                txt_vo.Text = cmb_vo.Text;
            };
            txt_vo = NewText("", 530, 130);

            tab.Controls.AddRange(new Control[]
            {
        check_glsl, txt_glslPath, combo_glsl,
        chk_hwdec, cmb_hwdec, txt_hwdec,
        chk_gpuapi, cmb_gpuapi, txt_gpuapi,
        chk_scale, cmb_scale, txt_scale,
        chk_interpolation, cmb_interpolation, txt_interpolation,
        chk_vo, cmb_vo, txt_vo
            });

            // ==== ここからボタン追加 ====
            int leftText = 360; // ボタン配置の左位置
            int top = 20;       // txt_glslPath の上位置

            Button btnOpen = new Button();
            btnOpen.Text = "開く";
            btnOpen.Location = new Point(leftText, top + 60);
            btnOpen.Click += (s, e) =>
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "Shader files (*.glsl;*.hook)|*.glsl;*.hook|GLSL files (*.glsl)|*.glsl|Hook files (*.hook)|*.hook|All files (*.*)|*.*";
                ofd.Title = "GLSL / Hook ファイルを選択";

                if (ofd.ShowDialog() == DialogResult.OK)
                    txt_glslPath.Text = ofd.FileName;
            };
            tab.Controls.Add(btnOpen);

            Button btnCheckAll = new Button();
            btnCheckAll.Text = "全部チェック";
            btnCheckAll.Location = new Point(leftText + 90, top + 60);
            btnCheckAll.Width = 100;
            btnCheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = true;
                }
            };
            tab.Controls.Add(btnCheckAll);

            Button btnUncheckAll = new Button();
            btnUncheckAll.Text = "全部外す";
            btnUncheckAll.Location = new Point(leftText + 200, top + 60);
            btnUncheckAll.Width = 100;
            btnUncheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = false;
                }
            };
            tab.Controls.Add(btnUncheckAll);
            // ==== ボタン追加ここまで ====

            tabControl.TabPages.Add(tab);

            LoadGlslFiles();
        }
        
        private void CreateEffectTab()
        {
            var tab = NewTab("エフェクト");

            // ビデオエフェクト保存
            check_vf_save = NewCheck("ビデオエフェクトを保存して読み込みする", 20, 20);
            check_vf_save.Width = 260;
            tab.Controls.Add(check_vf_save);

            // ★追加：ビデオEQ保存
            check_video_eq = NewCheck("ビデオイコライザーを保存", 20, 50, false, 220);
            tab.Controls.Add(check_video_eq);

            // ビデオエフェクト文字列
            tab.Controls.Add(NewLabel("ビデオエフェクト", 20, 85));
            lavfi_textBox = NewText("", 20, 110, 300);
            tab.Controls.Add(lavfi_textBox);

            // オーディオエフェクト保存
            check_af_save = NewCheck("オーディオエフェクトを保存して読み込みする", 20, 160);
            check_af_save.Width = 260;
            tab.Controls.Add(check_af_save);

            // オーディオEQ保存
            check_audio_eq = NewCheck("オーディオイコライザーを保存", 20, 190, false, 220);
            tab.Controls.Add(check_audio_eq);

            // オーディオエフェクト文字列
            tab.Controls.Add(NewLabel("オーディオエフェクト", 20, 225));
            af_textBox = NewText("", 20, 250, 300);
            tab.Controls.Add(af_textBox);

          
            check_crop = NewCheck("cropを起動時に実行", 20, 280, false, 220);
            tab.Controls.Add(check_crop);

        
            tab.Controls.Add(NewLabel("crop", 20, 310));
            crop_textBox = NewText("", 20, 340, 150);
            tab.Controls.Add(crop_textBox);
            check_vr360 = NewCheck("起動時に360度VRモード有効", 20, 380, false, 180);
            tab.Controls.Add(check_vr360);

            tabControl.TabPages.Add(tab);
        }
      
        private void CreateSubtitleDvdTab()
        {
            var tab = NewTab("字幕");

            check_srt = NewCheck("SRT字幕設定を有効", 20, 20);
            tab.Controls.Add(check_srt);

            // フォント名
            tab.Controls.Add(NewLabel("フォント", 20, 50));
            textBox_font = NewText("Meiryo UI", 20, 70, 220);
            tab.Controls.Add(textBox_font);

            comboFonts = new ComboBox();
            comboFonts.Location = new Point(20, 100);
            comboFonts.Width = 300;
            comboFonts.DropDownStyle = ComboBoxStyle.DropDownList;
            comboFonts.SelectedIndexChanged += (s, e) =>
            {
                if (comboFonts.SelectedItem != null)
                    textBox_font.Text = comboFonts.SelectedItem.ToString();
            };
            tab.Controls.Add(comboFonts);

            // フォントサイズ
            tab.Controls.Add(NewLabel("サイズ", 20, 140));
            textBox_fontsize = NewText("40", 20, 160);
            tab.Controls.Add(textBox_fontsize);

            // フォントカラー
            tab.Controls.Add(NewLabel("SRT字幕のフォントカラー", 20, 200));
            textBox_font_coler = NewText("", 20, 230, 120);
            tab.Controls.Add(textBox_font_coler);

            btnFontColor = new Button();
            btnFontColor.Text = "カラー選択";
            btnFontColor.Location = new Point(20, 260);
            btnFontColor.Click += BtnFontColor_Click;
            tab.Controls.Add(btnFontColor);

            // 字幕縦位置
            tab.Controls.Add(NewLabel("SRT字幕の縦位置(0-100)", 20, 300));
            textBox_sub_pos = NewText("", 20, 330, 120);
            tab.Controls.Add(textBox_sub_pos);

            // 枠サイズ
            tab.Controls.Add(NewLabel("SRT字幕の枠の大きさ(0-10)", 20, 370));
            textBox_border_size = NewText("", 20, 400, 120);
            tab.Controls.Add(textBox_border_size);


            // 枠色
            tab.Controls.Add(NewLabel("SRT字幕の枠の色", 220, 140));
            textBox_sub_border_color = NewText("", 220, 170, 120);
            tab.Controls.Add(textBox_sub_border_color);

            btnborderColor = new Button();
            btnborderColor.Text = "カラー選択";
            btnborderColor.Location = new Point(220, 200);
            btnborderColor.Click += btnbordertColor_Click;
            tab.Controls.Add(btnborderColor);


            // 影オフセット
            tab.Controls.Add(NewLabel("SRT字幕の影のオフセット(0-10)", 220, 230));
            textBox_shadow_offset = NewText("", 220, 260);
            tab.Controls.Add(textBox_shadow_offset);
            tabControl.TabPages.Add(tab);
        }
        private void CreateStreamTab()
        {
            // 新しいタブ作成
            var tab = NewTab("ストリーム設定");

            // ラベル
            Label streamlink_Label = new Label();
            streamlink_Label.Text = "streamlinkで取得するURLの正規表現";
            streamlink_Label.Location = new Point(20, 20);
            streamlink_Label.AutoSize = true;
            tab.Controls.Add(streamlink_Label);

            // テキストボックス
            streamlink_seiki_Box = new TextBox();
            streamlink_seiki_Box.Text = "(abema.tv\\/now\\-on\\-air|radiko.jp|ok.ru)";
            streamlink_seiki_Box.Location = new Point(20, 50);
            streamlink_seiki_Box.Width = 400;
            tab.Controls.Add(streamlink_seiki_Box);

            // タブに追加
            tabControl.TabPages.Add(tab);
        }
        private TextBox txtMpvPath;
        private TextBox txtStreamlinkPath;
        private TextBox txtYtDlpPath;

        private void CreateExternalPathTab()
        {
            var tab = NewTab("実行ファイルのパス");

            // ===== mpv =====
            tab.Controls.Add(NewLabel("mpvのパス", 20, 20));
            txtMpvPath = NewText("mpv.exe", 20, 45, 350);
            EnableFileDrop(txtMpvPath);

            Button btnMpv = new Button
            {
                Text = "開く",
                Location = new Point(380, 43),
                Width = 80
            };
            btnMpv.Click += (s, e) => SelectExeFile(txtMpvPath, "mpv.exe");

            // ===== streamlink =====
            tab.Controls.Add(NewLabel("streamlinkのパス", 20, 100));
            txtStreamlinkPath = NewText("./bin/streamlink.exe", 20, 125, 350);
            EnableFileDrop(txtStreamlinkPath);

            Button btnStream = new Button
            {
                Text = "開く",
                Location = new Point(380, 123),
                Width = 80
            };
            btnStream.Click += (s, e) => SelectExeFile(txtStreamlinkPath, "streamlink.exe");

            // ===== yt-dlp =====
            tab.Controls.Add(NewLabel("yt-dlpのパス", 20, 180));
            txtYtDlpPath = NewText("yt-dlp.exe", 20, 205, 350);
            EnableFileDrop(txtYtDlpPath);

            Button btnYt = new Button
            {
                Text = "開く",
                Location = new Point(380, 203),
                Width = 80
            };
            btnYt.Click += (s, e) => SelectExeFile(txtYtDlpPath, "yt-dlp.exe");

            tab.Controls.AddRange(new Control[]
            {
        txtMpvPath, btnMpv,
        txtStreamlinkPath, btnStream,
        txtYtDlpPath, btnYt
            });

            tabControl.TabPages.Add(tab);
        }
        private void CreateSystemTab()
        {
            var tab = NewTab("システム / ログ");

           

            check_command_log = NewCheck("mpvのコマンドのログを取る", 20, 20);
            check_command_log.Width = 150;
            tab.Controls.Add(check_command_log);

            check_mpv_log = NewCheck("mpvのログを有効", 20, 50);
            check_mpv_log.Width = 120;
            tab.Controls.Add(check_mpv_log);

            check_error_log = NewCheck("エラーログを有効", 20, 80);
            check_error_log.Width = 120;
            tab.Controls.Add(check_error_log);

            check_force_window = NewCheck("--force-window=yesを起動引数に入れる", 20, 110);
            check_force_window.Width = 250;
            tab.Controls.Add(check_force_window);

            check_idle = NewCheck("--idle=yesを起動引数に入れる", 20, 140);
            check_idle.Width = 180;
            tab.Controls.Add(check_idle);

            check_mpv_add_comand = NewCheck("mpvの追加起動コマンドを有効", 20, 170);
            check_mpv_add_comand.Width = 180;
            tab.Controls.Add(check_mpv_add_comand);

            // ラベル
            Label mpv_comand_Label = new Label();
            mpv_comand_Label.Text = "mpvの追加起動コマンド";
            mpv_comand_Label.Location = new Point(20, 200);
            mpv_comand_Label.AutoSize = true;
            tab.Controls.Add(mpv_comand_Label);

            // テキストボックス
            mpv_add_comand_Box = new TextBox();
            mpv_add_comand_Box.Text = "";
            mpv_add_comand_Box.Location = new Point(20, 230);
            mpv_add_comand_Box.Width = 600;
            tab.Controls.Add(mpv_add_comand_Box);

            // タブに追加
          
            tabControl.TabPages.Add(tab);
        }


        private void CreateServiceTab()
        {
            var tab = NewTab("UI/上部メニュー");

            // ===== 基本メニュー =====
            check_primehome = NewCheck("primehomeを有効", 20, 20, true);
            check_abema_low = NewCheck("AbemaTV低画質を有効", 20, 50, true);
            check_abema_high = NewCheck("AbemaTV高画質を有効", 20, 80, true);
            check_radiko = NewCheck("ラジコを有効", 20, 110, true);
            check_utako = NewCheck("utakoを有効", 20, 140, true);
            check_rakuten = NewCheck("楽天を有効", 20, 170, true);
            check_arva = NewCheck("arvaを有効", 20, 200, true);

            // ===== 履歴 =====
            check_rireki = NewCheck("履歴を有効", 20, 230,false);
            check_ranking = NewCheck("ランキングを有効", 20, 260, false);

            var history = NewGroup("履歴", 220, 20, 180, 110);
            history.Controls.Add(NewLabel("履歴数", 10, 25));
            txtHistory = NewText("20", 90, 20, 60);
            history.Controls.Add(txtHistory);

            history.Controls.Add(NewLabel("ランキング数", 10, 55));
            txtRank = NewText("20", 90, 50, 60);
            history.Controls.Add(txtRank);

            tab.Controls.Add(history);

            // ===== メニュー表示 =====
            check_cap = NewCheck("チャプターを上部メニューに表示", 20, 260, false);
            check_cap.Width = 260;

            check_multi_sub_audio = NewCheck("字幕と音声選択メニューを表示", 20, 290, false);
            check_multi_sub_audio.Width = 260;

            check_playlist = NewCheck("プレイリストをメニューに表示", 20, 320, false);
            check_search = NewCheck("検索窓を有効", 20, 350, false);
            checkmov3 = NewCheck("mov3を有効", 20, 380, true);

            // ===== ボタン追加 =====
            Button btnCheckAll = new Button();
            btnCheckAll.Text = "全部選択";
            btnCheckAll.Location = new Point(220, 150);
            btnCheckAll.Width = 100;
            btnCheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = true;
                }
            };

            Button btnUncheckAll = new Button();
            btnUncheckAll.Text = "全部解除";
            btnUncheckAll.Location = new Point(330, 150);
            btnUncheckAll.Width = 100;
            btnUncheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = false;
                }
            };

            tab.Controls.AddRange(new Control[]
            {
        check_primehome,
        check_abema_low,
        check_abema_high,
        check_radiko,
        check_utako,
        check_rakuten,
        check_arva,
        check_rireki,
        check_ranking,
        check_cap,
        check_multi_sub_audio,
        check_search,
        check_playlist,
        checkmov3,
        btnCheckAll,
        btnUncheckAll
            });

            tabControl.TabPages.Add(tab);
        }
        

        
        private void CreateToolbarTab()
        {
            var tab = NewTab("UIボタン追加");

            check_seed_bt = NewCheck("スピードUPボタン", 20, 20, false);
            check_ss_bt = NewCheck("スクリーンショットボタン", 20, 50, true);
            check_mute_bt = NewCheck("ミュートボタン", 20, 80, true);
            check_open_bt = NewCheck("開くボタン", 20, 110, true);
            check_pause_bt = NewCheck("ポーズボタン", 20, 140, true);
            check_full_sc_bt = NewCheck("フルスクリーンボタン", 20, 170, true);
            check_stop_bt = NewCheck("停止ボタン", 20, 200, true);
            check_speed_slider_bt = NewCheck("速度スライダー", 20, 230, false);
            check_volume_bt = NewCheck("ボリュームスライダー", 20, 260, true);
            check_flame_step = NewCheck("コマ送りボタン", 20, 290, false);

            // ===== 追加分 =====
            check_cap_next = NewCheck("チャプター移動ボタン", 20, 320, false);
            check_down_bt = NewCheck("録画ボタン", 250, 20   );
            check_img_bt = NewCheck("ボタンに画像を使う", 250, 50, true);
            check_ab_bt = NewCheck("ABループボタン", 250, 80, false);
            check_tips = NewCheck("tooltipsを有効", 250, 110, false);

            // ===== 全選択 =====
            Button btnCheckAll = new Button();
            btnCheckAll.Text = "全部選択";
            btnCheckAll.Location = new Point(250, 160);
            btnCheckAll.Width = 100;
            btnCheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = true;
                }
            };

            // ===== 全解除 =====
            Button btnUncheckAll = new Button();
            btnUncheckAll.Text = "全部解除";
            btnUncheckAll.Location = new Point(250, 195);
            btnUncheckAll.Width = 100;
            btnUncheckAll.Click += (s, e) =>
            {
                foreach (Control c in tab.Controls)
                {
                    if (c is CheckBox cb)
                        cb.Checked = false;
                }
            };

            tab.Controls.AddRange(new Control[]
            {
        check_seed_bt,
        check_ss_bt,
        check_mute_bt,
        check_open_bt,
        check_pause_bt,
        check_full_sc_bt,
        check_stop_bt,
        check_speed_slider_bt,
        check_volume_bt,
        check_flame_step,
        check_cap_next,
        check_tips,
        check_down_bt,
        check_img_bt,
        check_ab_bt,
        btnCheckAll,
        btnUncheckAll
            });

            tabControl.TabPages.Add(tab);
        }

        private void SelectExeFile(TextBox target, string defaultName)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "実行ファイル (*.exe)|*.exe";
                ofd.FileName = defaultName;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    target.Text = ofd.FileName;
                }
            }
        }

        private void EnableFileDrop(TextBox textBox)
        {
            textBox.AllowDrop = true;

            textBox.DragEnter += (s, e) =>
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                    e.Effect = DragDropEffects.Copy;
            };

            textBox.DragDrop += (s, e) =>
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (files.Length > 0)
                    textBox.Text = files[0];
            };
        }
        private void LoadFonts()
        {
            InstalledFontCollection fonts = new InstalledFontCollection();

            foreach (FontFamily font in fonts.Families.OrderBy(f => f.Name))
            {
                comboFonts.Items.Add(font.Name);
            }

            // 初期選択
            if (comboFonts.Items.Count > 0)
            {
                comboFonts.SelectedItem = "Meiryo";
                if (comboFonts.SelectedIndex == -1)
                    comboFonts.SelectedIndex = 0;
            }
        }

        private void BtnFontColor_Click(object sender, EventArgs e)
        {
            using (ColorDialog colorDialog = new ColorDialog())
            {
                colorDialog.Color = selectedColor;
                colorDialog.FullOpen = true;

                if (colorDialog.ShowDialog() == DialogResult.OK)
                {
                    selectedColor = colorDialog.Color;
                    textBox_font_coler.Text = ToMpvColor(selectedColor);
                }
            }
        }
        private void btnbordertColor_Click(object sender, EventArgs e)
        {
            using (ColorDialog colorDialog = new ColorDialog())
            {
                colorDialog.Color = selectedColor;
                colorDialog.FullOpen = true;

                if (colorDialog.ShowDialog() == DialogResult.OK)
                {
                    selectedColor = colorDialog.Color;
                    textBox_sub_border_color.Text = ToMpvColor(selectedColor);
                }
            }
        }
        private string ToMpvColor(Color c)
        {
            return $"#{c.A:X2}{c.B:X2}{c.G:X2}{c.R:X2}";
        }
        private void LoadGlslFiles()
        {
            string dir = Path.Combine(Application.StartupPath, "glsl");

            if (!Directory.Exists(dir))
                return;

            var files = Directory.GetFiles(dir, "*.*")
                .Where(f =>
                    f.EndsWith(".glsl", StringComparison.OrdinalIgnoreCase) ||
                    f.EndsWith(".hook", StringComparison.OrdinalIgnoreCase))
                .OrderBy(f => f);

            combo_glsl.Items.Clear();

            foreach (string file in files)
            {
                string name = Path.GetFileName(file);
                string relative = "./glsl/" + name;

                combo_glsl.Items.Add(relative);
            }
        }
        private void LoadCombo(ComboBox combo, string file)
        {
            if (!File.Exists(file)) return;

            foreach (var line in File.ReadAllLines(file))
            {
                if (!string.IsNullOrWhiteSpace(line))
                    combo.Items.Add(line);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadFonts();
            LoadCombo(cmb_hwdec, "hwdec.txt");
            LoadCombo(cmb_gpuapi, "gpu-api.txt");
            LoadCombo(cmb_scale, "scale.txt");
            LoadCombo(cmb_interpolation, "interpolation.txt");
            LoadCombo(cmb_vo, "vo.txt");
           read_config_file();

        }
        private void read_config_file()
        {

            if (System.IO.File.Exists("./DragonVideoPlayer.dll.config"))
            {
                try
                {

                    NameValueCollection appSettings = ConfigurationManager.AppSettings;

                    string[] keys = null;



                    int int_conf1 = 0;
                    keys = appSettings.GetValues("DVDの自動選択設定");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        DVD_lang_select_Radios[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        DVD_lang_select_Radios[1].Checked = true;
                    }

                    keys = appSettings.GetValues("ログイン方法");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        Login_Radios[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        Login_Radios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        Login_Radios[2].Checked = true;
                    }

                 

                    keys = appSettings.GetValues("起動時のリスト");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        radioFolder.Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        radioDB.Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        radioAbema.Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        radioPrimehome.Checked = true;
                    }
                    if (int_conf1 == 5)
                    {
                        radio_utako.Checked = true;
                    }
                    if (int_conf1 == 6)
                    {
                        radio_rakuten.Checked = true;
                    }
                    if (int_conf1 == 7)
                    {
                        radio_arva.Checked = true;
                    }
                    keys = appSettings.GetValues("動画DBのソートの順序");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        db_sort_desc[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        db_sort_desc[1].Checked = true;
                    }

                    keys = appSettings.GetValues("フォルダ動画のソートの順序");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        folder_sort_desc[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        folder_sort_desc[1].Checked = true;
                    }

                    keys = appSettings.GetValues("フォルダ動画のソート");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        folder_sort_Radios[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        folder_sort_Radios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        folder_sort_Radios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        folder_sort_Radios[3].Checked = true;
                    }
                  

                    keys = appSettings.GetValues("動画DBのソート");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {
                        db_sort_Radios[0].Checked = true;
                    }
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 2)
                    {
                        db_sort_Radios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        db_sort_Radios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        db_sort_Radios[3].Checked = true;
                    }
                    if (int_conf1 == 5)
                    {
                        db_sort_Radios[4].Checked = true;
                    }
                    if (int_conf1 == 6)
                    {
                        db_sort_Radios[5].Checked = true;
                    }


                    int_conf1 = 0;
                    // hwdec
                    keys = appSettings.GetValues("mpvの追加起動コマンドを有効");
                    check_mpv_add_comand.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("mpvの追加起動コマンド");
                    mpv_add_comand_Box.Text = keys[0].ToString();

                    keys = appSettings.GetValues("hwdecを有効");
                    chk_hwdec.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("hwdecの値");
                    txt_hwdec.Text = keys[0].ToString();

                    // gpu-api
                    keys = appSettings.GetValues("gpu-apiを有効");
                    chk_gpuapi.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("gpu-apiの値");
                    txt_gpuapi.Text = keys[0].ToString();

                    keys = appSettings.GetValues("yt-dlpでログインする");
                    check_ytdlp_login.Checked = bool_to_text.to_bool(keys[0].ToString());

                  
                    keys = appSettings.GetValues("起動時に360度VRモード有効");
                    check_vr360.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("voを有効");
                    chk_vo.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("SRT字幕の設定を有効");
                    check_srt.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("force-window=yesを起動引数に入れる");
                    check_force_window.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("idle=yesを起動引数に入れる");
                    check_idle.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("字幕のフォント名");
                    textBox_font.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕のフォントサイズ");
                    textBox_fontsize.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕のフォントカラー");
                    textBox_font_coler.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕の縦位置");
                    textBox_sub_pos.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕の枠の大きさ");
                    textBox_border_size.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕の影のオフセット");
                    textBox_shadow_offset.Text = keys[0].ToString();
                    keys = appSettings.GetValues("字幕の枠の色");
                    textBox_sub_border_color.Text = keys[0].ToString();

                    keys = appSettings.GetValues("シークバーのOSDを有効");
                    check_seek_osd.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("OSDを有効");
                    check_osd.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("voの値");
                    txt_vo.Text = keys[0].ToString();

                    keys = appSettings.GetValues("cropを起動時に実行");
                    check_crop.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("crop");
                    crop_textBox.Text = keys[0].ToString();

                 

                    keys = appSettings.GetValues("再生時にDB更新を有効");
                    check_db_update.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("MPV標準機能でレジューム");
                    check_mpv_Resume.Checked = bool_to_text.to_bool(keys[0].ToString());



                    // scale
                    keys = appSettings.GetValues("scaleを有効");
                    chk_scale.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("scaleの値");
                    txt_scale.Text = keys[0].ToString();

                    keys = appSettings.GetValues("mpvのパス");
                    txtMpvPath.Text = keys[0].ToString();
                    keys = appSettings.GetValues("streamlinkのパス");
                    txtStreamlinkPath.Text = keys[0].ToString();
                    keys = appSettings.GetValues("yt-dlpのパス");
                    txtYtDlpPath.Text = keys[0].ToString();

        

                    // interpolation
                    keys = appSettings.GetValues("interpolationを有効");
                    chk_interpolation.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("interpolationの値");
                    txt_interpolation.Text = keys[0].ToString();

                  

                    keys = appSettings.GetValues("glslを有効");
                    check_glsl.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("glslのパス");
                    txt_glslPath.Text = keys[0].ToString();

                    keys = appSettings.GetValues("動画取得の拡張子の正規表現");
                    video_regexBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("streamlinkで取得するURLの正規表現");
                    streamlink_seiki_Box.Text = keys[0].ToString();

                    keys = appSettings.GetValues("録画ボタンを有効");
                    check_down_bt.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("サムネイル作成");
                    checkThumb.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("ABループボタンを有効");
                    check_ab_bt.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("検索窓を有効");
                    check_search.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("DVDの音声と字幕の自動選択を有効");
                    check_DVD_auto_select.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("オーディオエフェクトを保存");
                    check_af_save.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("オーディオエフェクトの値");
                    af_textBox.Text = keys[0].ToString();


                    keys = appSettings.GetValues("起動時に縮小再生する");
                    check_zoom.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("縮小する倍率");
                    zoom_textBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("ビデオエフェクトを保存");
                    check_vf_save.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("ビデオエフェクトの値");
                    lavfi_textBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("再生開始時に途中から再生する");
                    check_mid_play.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("開始する時間");
                    mid_play_textBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("ボリュームを保存する");
                    check_volume_save.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("ボリューム数");
                    volume_su_Box.Text = keys[0].ToString();


                    keys = appSettings.GetValues("mpvのコマンドのログを取る");
                    check_mpv_log.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("mpvのログを有効");
                    check_mpv_log.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("エラーログを有効");
                    check_error_log.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("キャッシュを有効");
                    checkCache.Checked = bool_to_text.to_bool(keys[0].ToString());

                   
                    keys = appSettings.GetValues("OverClockedReMixをリスト追加");
                    checkOverClocked.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("キャッシュが溜まるまで待つ");
                    checkCacheWait.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("キャッシュサイズ");
                    cache_size_Box.Text = keys[0].ToString();

                    keys = appSettings.GetValues("キャッシュ時間");
                    cache_sc_Box.Text = keys[0].ToString();

                    keys = appSettings.GetValues("終了後の動作");
                    int_conf1 = int.Parse(keys[0].ToString());
                    if (int_conf1 == 1)
                    {

                        endModeRadios[0].Checked = true;
                    }
                    if (int_conf1 == 2)
                    {
                        endModeRadios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        endModeRadios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        endModeRadios[3].Checked = true;
                    }
                    if (int_conf1 == 5)
                    {
                        endModeRadios[4].Checked = true;
                    }
                    keys = appSettings.GetValues("マウスホイールの動作");
                    Debug.WriteLine(keys[0]);
                    int_conf1 = int.Parse(keys[0].ToString());
                    Debug.WriteLine(int_conf1);
                    if (int_conf1 == 1)
                    {
                        MouseWheelRadios[0].Checked = true;
                    }
                    if (int_conf1 == 2)
                    {
                        MouseWheelRadios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        MouseWheelRadios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        MouseWheelRadios[3].Checked = true;
                    }


                    keys = appSettings.GetValues("起動時のウインドウサイズ");
                    int_conf1 = int.Parse(keys[0].ToString());
                    Debug.WriteLine(int_conf1);
                    if (int_conf1 == 1)
                    {
                        StartWindowSizeRadios[0].Checked = true;
                    }
                    if (int_conf1 == 2)
                    {
                        StartWindowSizeRadios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        StartWindowSizeRadios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        StartWindowSizeRadios[3].Checked = true;
                    }
                    if (int_conf1 == 5)
                    {
                        StartWindowSizeRadios[4].Checked = true;
                    }


                    keys = appSettings.GetValues("動画ウインドウのシングルクリックの動作");
                    int_conf1 = int.Parse(keys[0].ToString());
                    Debug.WriteLine(int_conf1);
                    if (int_conf1 == 1)
                    {
                        SingleClickRadios[0].Checked = true;
                    }
                    if (int_conf1 == 2)
                    {
                        SingleClickRadios[1].Checked = true;
                    }
                    if (int_conf1 == 3)
                    {
                        SingleClickRadios[2].Checked = true;
                    }
                    if (int_conf1 == 4)
                    {
                        SingleClickRadios[3].Checked = true;
                    }

                    keys = appSettings.GetValues("mov3を有効");
                    checkmov3.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("primehomeを有効");
                    check_primehome.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("AbemaTV低画質を有効");
                    check_abema_low.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("AbemaTV高画質を有効");
                    check_abema_high.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ラジコを有効");
                    check_radiko.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("utakoを有効");
                    check_utako.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("楽天を有効");
                    check_rakuten.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("履歴を有効");

                    check_arva.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("arvaを有効");


                    check_rireki.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ランキングを有効");
                    check_ranking.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("タスクトレイに常駐");
                    check_task_tray.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("DVDドライブ");
                    dvdBox.Text = keys[0].ToString();


                    keys = appSettings.GetValues("スピードUPボタンを有効");
                    check_seed_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("スクリーンショットボタンを有効");
                    check_ss_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ポーズボタンを有効");
                    check_pause_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("オープンボタンを有効");
                    check_open_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("フルスクリーンボタンを有効");
                    check_full_sc_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ミュートボタンを有効");
                    check_mute_bt.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("スピードスライダーを有効");
                    check_speed_slider_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("停止ボタンを有効");
                    check_stop_bt.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ボリュームスライダーを有効");
                    check_volume_bt.Checked = bool_to_text.to_bool(keys[0].ToString());


                    keys = appSettings.GetValues("コマ送りボタンを有効");
                    check_flame_step.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("プレイリストをメニューに表示");
                    check_playlist.Checked = bool_to_text.to_bool(keys[0].ToString());





                    keys = appSettings.GetValues("ビデオイコライザーを保存");
                    check_video_eq.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("オーディオイコライザーを保存");
                    check_audio_eq.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("tooltipsを有効");
                    check_tips.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("起動時にパンスキャン");
                    check_panscan.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("ボタンに画像を使う");
                    check_img_bt.Checked = bool_to_text.to_bool(keys[0].ToString());





                    keys = appSettings.GetValues("チャプターを上部メニューに表示");
                    check_cap.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("チャプター移動ボタンを有効");
                    check_cap_next.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("ダブルクリックでフルスクリーン有効");
                    checkDoubleClick.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("動画ウインドウをシングルクリックで動作を有効");
                    checkSingleClick.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("シークする時の飛ばすフレーム数");
                    seek_su_textBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("SPEEDアップ数");
                    speed_su_textBox.Text = keys[0].ToString();


                    keys = appSettings.GetValues("速度変更しても音程を維持する");
                    check_audio_pitch.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("起動時SPEED数");
                    speed_start_textBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("起動時SPEED変更");
                    check_start_Speed.Checked = bool_to_text.to_bool(keys[0].ToString());



                    keys = appSettings.GetValues("起動時のwidth");
                    widthBox.Text = keys[0].ToString();
                    keys = appSettings.GetValues("起動時のheight");
                    heightBox.Text = keys[0].ToString();

                    keys = appSettings.GetValues("削除機能を有効");
                    checkDelete.Checked = bool_to_text.to_bool(keys[0].ToString());
                    keys = appSettings.GetValues("削除で確認する");
                    checkDelete_mes.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("スレッド有効");
                    checkThread.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("スレッド数");
                    Thread_su_Box.Text = keys[0].ToString();

                    keys = appSettings.GetValues("マウスホイール");
                    checkWheelMouse.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("レジューム機能");
                    checkResume.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("字幕と音声選択メニューを表示");
                    check_multi_sub_audio.Checked = bool_to_text.to_bool(keys[0].ToString());




                    keys = appSettings.GetValues("再生時にフォルダの動画をリストに入れる");
                    checkFolderAdd.Checked = bool_to_text.to_bool(keys[0].ToString());

                    keys = appSettings.GetValues("履歴数");
                    txtHistory.Text = keys[0].ToString();
                    keys = appSettings.GetValues("ランキング数");
                    txtRank.Text = keys[0].ToString();



                }
                catch (Exception ex)
                {
                    error.write_error_log(ex.Message + ex.StackTrace);
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    //   MessageBox.Show("config読み込みでエラー：" + ex.Message+ex.StackTrace);
                }

            }
            else
            {
                MessageBox.Show(this, "dll.configが無いです。");



            }

        }


        void formClosing(object sender, FormClosingEventArgs e)
        {

            save_config_file();
        }
        private void save_config_file()
        {
            if (System.IO.File.Exists("./DragonVideoPlayer.dll.config"))
            {


                try
                {
                    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    System.Configuration.AppSettingsSection appSettings = config.AppSettings;

                    int int_con1 = 0;

                    if (db_sort_Radios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (db_sort_Radios[1].Checked == true)
                    {


                        int_con1 = 2;

                    }
                    if (db_sort_Radios[2].Checked == true)
                    {


                        int_con1 = 3;

                    }

                    if (db_sort_Radios[3].Checked == true)
                    {


                        int_con1 = 4;

                    }
                    if (db_sort_Radios[4].Checked == true)
                    {


                        int_con1 = 5;

                    }
                    if (db_sort_Radios[5].Checked == true)
                    {


                        int_con1 = 6;

                    }
                    appSettings.Settings["動画DBのソート"].Value = int_con1.ToString();

                    if (folder_sort_Radios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (folder_sort_Radios[1].Checked == true)
                    {


                        int_con1 = 2;

                    }
                    if (folder_sort_Radios[2].Checked == true)
                    {


                        int_con1 = 3;

                    }

                    if (folder_sort_Radios[3].Checked == true)
                    {


                        int_con1 = 4;

                    }
             
                    appSettings.Settings["フォルダ動画のソート"].Value = int_con1.ToString();

                    if (db_sort_desc[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (db_sort_desc[1].Checked == true)
                    {


                        int_con1 = 2;

                    }

                    appSettings.Settings["動画DBのソートの順序"].Value = int_con1.ToString();


                    if (folder_sort_desc[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (folder_sort_desc[1].Checked == true)
                    {


                        int_con1 = 2;

                    }

                    appSettings.Settings["フォルダ動画のソートの順序"].Value = int_con1.ToString();


                    if (Login_Radios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (Login_Radios[1].Checked == true)
                    {


                        int_con1 = 2;

                    }
                    if (Login_Radios[2].Checked == true)
                    {


                        int_con1 = 3;

                    }
                    appSettings.Settings["ログイン方法"].Value = int_con1.ToString();


                    if (MouseWheelRadios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (MouseWheelRadios[1].Checked == true)
                    {


                        int_con1 = 2;

                    }
                    if (MouseWheelRadios[2].Checked == true)
                    {


                        int_con1 = 3;

                    }

                    if (MouseWheelRadios[3].Checked == true)
                    {


                        int_con1 = 4;

                    }
                    if (MouseWheelRadios[4].Checked == true)
                    {


                        int_con1 = 5;

                    }
                    appSettings.Settings["マウスホイールの動作"].Value = int_con1.ToString();

                    int_con1 = 0;



                    if (StartWindowSizeRadios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (StartWindowSizeRadios[1].Checked == true)
                    {


                        int_con1 = 2;

                    }
                    if (StartWindowSizeRadios[2].Checked == true)
                    {

                        int_con1 = 3;

                    }

                    if (StartWindowSizeRadios[3].Checked == true)
                    {

                        int_con1 = 4;

                    }
                    if (StartWindowSizeRadios[4].Checked == true)
                    {

                        int_con1 = 5;

                    }
                    appSettings.Settings["起動時のウインドウサイズ"].Value = int_con1.ToString();

                    int_con1 = 0;

                    if (radioFolder.Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (radioDB.Checked == true)
                    {

                        int_con1 = 2;

                    }
                    if (radioAbema.Checked == true)
                    {

                        int_con1 = 3;

                    }
                    if (radioPrimehome.Checked == true)
                    {

                        int_con1 = 4;

                    }
                    if (radio_utako.Checked == true)
                    {

                        int_con1 = 5;

                    }
                    if (radio_rakuten.Checked == true)
                    {

                        int_con1 = 6;

                    }
                    if (radio_arva.Checked == true)
                    {

                        int_con1 = 7;

                    }
                    appSettings.Settings["起動時のリスト"].Value = int_con1.ToString();



                    if (SingleClickRadios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (SingleClickRadios[1].Checked == true)
                    {
                        int_con1 = 2;

                    }
                    if (SingleClickRadios[2].Checked == true)
                    {

                        int_con1 = 3;

                    }

                    if (SingleClickRadios[3].Checked == true)
                    {
                        int_con1 = 4;

                    }

                    appSettings.Settings["動画ウインドウのシングルクリックの動作"].Value = int_con1.ToString();

                    // hwdec
                    appSettings.Settings["hwdecを有効"].Value = bool_to_text.to_st(chk_hwdec.Checked);
                    appSettings.Settings["hwdecの値"].Value = txt_hwdec.Text;

                    appSettings.Settings["mpvの追加起動コマンドを有効"].Value = bool_to_text.to_st(check_mpv_add_comand.Checked);
                    appSettings.Settings["mpvの追加起動コマンド"].Value = mpv_add_comand_Box.Text;


                    // gpu-api
                    appSettings.Settings["gpu-apiを有効"].Value = bool_to_text.to_st(chk_gpuapi.Checked);
                    appSettings.Settings["gpu-apiの値"].Value = txt_gpuapi.Text;
                    appSettings.Settings["idle=yesを起動引数に入れる"].Value = bool_to_text.to_st((bool)check_idle.Checked);
                    appSettings.Settings["force-window=yesを起動引数に入れる"].Value = bool_to_text.to_st((bool)check_force_window.Checked);

                    appSettings.Settings["OverClockedReMixをリスト追加"].Value = bool_to_text.to_st(checkOverClocked.Checked);

                    appSettings.Settings["起動時に360度VRモード有効"].Value = bool_to_text.to_st(check_vr360.Checked);

                    appSettings.Settings["シークバーのOSDを有効"].Value = bool_to_text.to_st(check_seek_osd.Checked);

                    appSettings.Settings["OSDを有効"].Value = bool_to_text.to_st(check_osd.Checked);

                    appSettings.Settings["cropを起動時に実行"].Value = bool_to_text.to_st(check_crop.Checked);
                    appSettings.Settings["crop"].Value = crop_textBox.Text;


                    // scale
                    appSettings.Settings["scaleを有効"].Value = bool_to_text.to_st(chk_scale.Checked);
                    appSettings.Settings["scaleの値"].Value = txt_scale.Text;

                    // interpolation
                    appSettings.Settings["interpolationを有効"].Value = bool_to_text.to_st(chk_interpolation.Checked);
                    appSettings.Settings["interpolationの値"].Value = txt_interpolation.Text;

                    appSettings.Settings["voを有効"].Value = bool_to_text.to_st(chk_vo.Checked);
                    appSettings.Settings["voの値"].Value = txt_vo.Text;

                    appSettings.Settings["再生時にDB更新を有効"].Value = bool_to_text.to_st(check_db_update.Checked);
                    appSettings.Settings["MPV標準機能でレジューム"].Value = bool_to_text.to_st(check_mpv_Resume.Checked);

                    appSettings.Settings["ビデオエフェクトを保存"].Value = bool_to_text.to_st(check_vf_save.Checked);
                    appSettings.Settings["ビデオエフェクトの値"].Value = lavfi_textBox.Text;

                    appSettings.Settings["オーディオエフェクトを保存"].Value = bool_to_text.to_st(check_af_save.Checked);
                    appSettings.Settings["オーディオエフェクトの値"].Value = af_textBox.Text;

                    appSettings.Settings["再生開始時に途中から再生する"].Value = bool_to_text.to_st(check_mid_play.Checked);
                    appSettings.Settings["開始する時間"].Value = mid_play_textBox.Text;

                    appSettings.Settings["ボリュームを保存する"].Value = bool_to_text.to_st(check_volume_save.Checked);
                    appSettings.Settings["ボリューム数"].Value = volume_su_Box.Text;


                    appSettings.Settings["起動時に縮小再生する"].Value = bool_to_text.to_st(check_zoom.Checked);
                    appSettings.Settings["縮小する倍率"].Value = zoom_textBox.Text;


                    appSettings.Settings["glslのパス"].Value = txt_glslPath.Text;

                    appSettings.Settings["glslを有効"].Value = bool_to_text.to_st(check_glsl.Checked);
                    appSettings.Settings["レジューム機能"].Value = bool_to_text.to_st(checkResume.Checked);

                    appSettings.Settings["キャッシュを有効"].Value = bool_to_text.to_st(checkCache.Checked);
                    appSettings.Settings["キャッシュが溜まるまで待つ"].Value = bool_to_text.to_st(checkCacheWait.Checked);

                    appSettings.Settings["キャッシュサイズ"].Value = cache_size_Box.Text;

                    appSettings.Settings["キャッシュ時間"].Value = cache_sc_Box.Text;

                    appSettings.Settings["動画取得の拡張子の正規表現"].Value = video_regexBox.Text;

                    appSettings.Settings["DVDドライブ"].Value = dvdBox.Text;



                    appSettings.Settings["streamlinkで取得するURLの正規表現"].Value = streamlink_seiki_Box.Text;

                    appSettings.Settings["スレッド数"].Value = Thread_su_Box.Text;

                    appSettings.Settings["削除機能を有効"].Value = bool_to_text.to_st((bool)checkDelete.Checked);

                    appSettings.Settings["削除で確認する"].Value = bool_to_text.to_st((bool)checkDelete_mes.Checked);


                    appSettings.Settings["yt-dlpでログインする"].Value = bool_to_text.to_st((bool)check_ytdlp_login.Checked);


                    appSettings.Settings["スレッド有効"].Value = bool_to_text.to_st((bool)checkThread.Checked);

                    appSettings.Settings["サムネイル作成"].Value = bool_to_text.to_st((bool)checkThumb.Checked);

                    appSettings.Settings["録画ボタンを有効"].Value = bool_to_text.to_st((bool)check_down_bt.Checked);

                    appSettings.Settings["タスクトレイに常駐"].Value = bool_to_text.to_st((bool)check_task_tray.Checked);




                    appSettings.Settings["プレイリストをメニューに表示"].Value = bool_to_text.to_st((bool)check_playlist.Checked);

                    appSettings.Settings["スピードUPボタンを有効"].Value = bool_to_text.to_st((bool)check_seed_bt.Checked);
                    appSettings.Settings["スクリーンショットボタンを有効"].Value = bool_to_text.to_st((bool)check_ss_bt.Checked);
                    appSettings.Settings["ミュートボタンを有効"].Value = bool_to_text.to_st((bool)check_mute_bt.Checked);
                    appSettings.Settings["ポーズボタンを有効"].Value = bool_to_text.to_st((bool)check_pause_bt.Checked);
                    appSettings.Settings["オープンボタンを有効"].Value = bool_to_text.to_st((bool)check_open_bt.Checked);
                    appSettings.Settings["フルスクリーンボタンを有効"].Value = bool_to_text.to_st((bool)check_full_sc_bt.Checked);

                    appSettings.Settings["スピードスライダーを有効"].Value = bool_to_text.to_st((bool)check_speed_slider_bt.Checked);
                    appSettings.Settings["停止ボタンを有効"].Value = bool_to_text.to_st((bool)check_stop_bt.Checked);
                    appSettings.Settings["ボリュームスライダーを有効"].Value = bool_to_text.to_st((bool)check_volume_bt.Checked);
                    appSettings.Settings["フルスクリーンボタンを有効"].Value = bool_to_text.to_st((bool)check_full_sc_bt.Checked);
                    appSettings.Settings["コマ送りボタンを有効"].Value = bool_to_text.to_st((bool)check_flame_step.Checked);


                    appSettings.Settings["チャプターを上部メニューに表示"].Value = bool_to_text.to_st((bool)check_cap.Checked);

                    appSettings.Settings["チャプター移動ボタンを有効"].Value = bool_to_text.to_st((bool)check_cap_next.Checked);
                    appSettings.Settings["ABループボタンを有効"].Value = bool_to_text.to_st((bool)check_ab_bt.Checked);

                    appSettings.Settings["検索窓を有効"].Value = bool_to_text.to_st((bool)check_search.Checked);

                    appSettings.Settings["mpvのコマンドのログを取る"].Value = bool_to_text.to_st((bool)check_command_log.Checked);
                    appSettings.Settings["mpvのログを有効"].Value = bool_to_text.to_st((bool)check_mpv_log.Checked);


                    appSettings.Settings["エラーログを有効"].Value = bool_to_text.to_st((bool)check_error_log.Checked);






                    appSettings.Settings["速度変更しても音程を維持する"].Value = bool_to_text.to_st((bool)check_audio_pitch.Checked);

                    appSettings.Settings["起動時にパンスキャン"].Value = bool_to_text.to_st((bool)check_panscan.Checked);
                    appSettings.Settings["ボタンに画像を使う"].Value = bool_to_text.to_st((bool)check_img_bt.Checked);


                    appSettings.Settings["字幕のフォント名"].Value = textBox_font.Text;
                    appSettings.Settings["字幕のフォントサイズ"].Value = textBox_fontsize.Text;
                    appSettings.Settings["字幕のフォントカラー"].Value = textBox_font_coler.Text;
                    appSettings.Settings["字幕の縦位置"].Value = textBox_sub_pos.Text;
                    appSettings.Settings["字幕の枠の大きさ"].Value = textBox_border_size.Text;
                    appSettings.Settings["字幕の影のオフセット"].Value = textBox_shadow_offset.Text;

                    appSettings.Settings["字幕の枠の色"].Value = textBox_sub_border_color.Text;

                    appSettings.Settings["SRT字幕の設定を有効"].Value = bool_to_text.to_st((bool)check_srt.Checked);


                    appSettings.Settings["mov3を有効"].Value = bool_to_text.to_st((bool)checkmov3.Checked);
                    appSettings.Settings["primehomeを有効"].Value = bool_to_text.to_st((bool)check_primehome.Checked);
                    appSettings.Settings["AbemaTV低画質を有効"].Value = bool_to_text.to_st((bool)check_abema_low.Checked);
                    appSettings.Settings["AbemaTV高画質を有効"].Value = bool_to_text.to_st((bool)check_abema_high.Checked);
                    appSettings.Settings["ラジコを有効"].Value = bool_to_text.to_st((bool)check_radiko.Checked);
                    appSettings.Settings["utakoを有効"].Value = bool_to_text.to_st((bool)check_utako.Checked);
                    appSettings.Settings["楽天を有効"].Value = bool_to_text.to_st((bool)check_rakuten.Checked);

                    appSettings.Settings["arvaを有効"].Value = bool_to_text.to_st((bool)check_arva.Checked);

                    appSettings.Settings["履歴を有効"].Value = bool_to_text.to_st((bool)check_rireki.Checked);
                    appSettings.Settings["ランキングを有効"].Value = bool_to_text.to_st((bool)check_ranking.Checked);

                    appSettings.Settings["tooltipsを有効"].Value = bool_to_text.to_st((bool)check_tips.Checked);

                    appSettings.Settings["DVDの音声と字幕の自動選択を有効"].Value = bool_to_text.to_st((bool)check_DVD_auto_select.Checked);

                    appSettings.Settings["ビデオイコライザーを保存"].Value = bool_to_text.to_st(check_video_eq.Checked);
                    appSettings.Settings["オーディオイコライザーを保存"].Value = bool_to_text.to_st(check_audio_eq.Checked);

                    appSettings.Settings["起動時SPEED変更"].Value = bool_to_text.to_st(check_start_Speed.Checked);
                    appSettings.Settings["起動時SPEED数"].Value = speed_start_textBox.Text;


                    appSettings.Settings["再生時にフォルダの動画をリストに入れる"].Value = bool_to_text.to_st((bool)checkFolderAdd.Checked);

                    appSettings.Settings["動画ウインドウをシングルクリックで動作を有効"].Value = bool_to_text.to_st((bool)checkSingleClick.Checked);

                    appSettings.Settings["SPEEDアップ数"].Value = speed_su_textBox.Text;

                    appSettings.Settings["履歴数"].Value = txtHistory.Text;
                    appSettings.Settings["ランキング数"].Value = txtRank.Text;

                    appSettings.Settings["mpvのパス"].Value = txtMpvPath.Text;
                    appSettings.Settings["streamlinkのパス"].Value = txtStreamlinkPath.Text;
                    appSettings.Settings["yt-dlpのパス"].Value = txtYtDlpPath.Text;


                    appSettings.Settings["起動時のwidth"].Value = widthBox.Text;
                    appSettings.Settings["起動時のheight"].Value = heightBox.Text;

                    appSettings.Settings["mov3を有効"].Value = bool_to_text.to_st(checkmov3.Checked);
                    appSettings.Settings["primehomeを有効"].Value = bool_to_text.to_st(check_primehome.Checked);
                    appSettings.Settings["AbemaTV低画質を有効"].Value = bool_to_text.to_st(check_abema_low.Checked);

                    appSettings.Settings["シークする時の飛ばすフレーム数"].Value = seek_su_textBox.Text;


                    appSettings.Settings["ダブルクリックでフルスクリーン有効"].Value = bool_to_text.to_st((bool)checkDoubleClick.Checked);
                    appSettings.Settings["字幕と音声選択メニューを表示"].Value = bool_to_text.to_st((bool)check_multi_sub_audio.Checked);




                    appSettings.Settings["マウスホイール"].Value = bool_to_text.to_st((bool)checkWheelMouse.Checked);




                    int_con1 = 0;
                    if (endModeRadios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (endModeRadios[1].Checked == true)
                    {

                        int_con1 = 2;

                    }
                    if (endModeRadios[2].Checked == true)
                    {

                        int_con1 = 3;

                    }

                    if (endModeRadios[3].Checked == true)
                    {
                        int_con1 = 4;

                    }
                    appSettings.Settings["終了後の動作"].Value = int_con1.ToString();





                    if (SingleClickRadios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (SingleClickRadios[1].Checked == true)
                    {

                        int_con1 = 2;

                    }
                    if (SingleClickRadios[2].Checked == true)
                    {


                        int_con1 = 3;

                    }

                    if (SingleClickRadios[3].Checked == true)
                    {

                        int_con1 = 4;

                    }
                    appSettings.Settings["動画ウインドウのシングルクリックの動作"].Value = int_con1.ToString();

                    int_con1 = 0;
                    if (DVD_lang_select_Radios[0].Checked == true)
                    {

                        int_con1 = 1;

                    }
                    if (DVD_lang_select_Radios[1].Checked == true)
                    {

                        int_con1 = 2;

                    }

                    appSettings.Settings["DVDの自動選択設定"].Value = int_con1.ToString();



                    config.Save(ConfigurationSaveMode.Modified);


                    ConfigurationManager.RefreshSection("appSettings");
                }
                catch (Exception ex)
                {
                    error.write_error_log(ex.Message + ex.StackTrace);
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    // MessageBox.Show(this, "config書き込みでエラー：" + ex.Message);

                }

            }
            else
            {
                MessageBox.Show(this, "dll.configが無いです。");


            }
        }
        private void TabControl_SelectionChanged(object sender, EventArgs e)
        {
            // 必要なら処理
        }
    }
}