Exemple #1
0
        /// <summary>
        /// エンジンへ送信してクリア
        /// </summary>
        private void button4_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            button4.Enabled = false;
            button3.Enabled = false;
            engineOptionsControl1.Enabled = false;
            var list = engineOptionsControl1.ToList();

            ThreadPool.QueueUserWorkItem(new WaitCallback(arg => {
                try {
                    using (USIDriver usi = new USIDriver(textBoxPath.Text)) {
                        usi.Start();
                        foreach (var p in list)
                        {
                            usi.SendSetOption(p.Name, p.Value);
                        }
                    }
                } catch (Exception ex) {
                    logger.Warn("エンジンへの送信に失敗", ex);
                    FormUtility.SafeInvoke(this, () => {
                        MessageBox.Show(this, "エンジンへの送信に失敗しました。", "エラー");
                    });
                } finally {
                    FormUtility.SafeInvoke(this, () => {
                        button2.Enabled = true;
                        button4.Enabled = true;
                        button3.Enabled = true;
                        engineOptionsControl1.Enabled = true;
                        engineOptionsControl1.Clear();
                    });
                }
            }));
        }
Exemple #2
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            // 重複チェックを行う
            if (engineList.Engines.Any(
                    x => !object.ReferenceEquals(x, engine) &&
                    x.Name == textBoxName.Text &&
                    x.Path == textBoxPath.Text))
            {
                MessageBox.Show(this, "名前・パスが同じエンジンは複数登録できません。", "エラー");
                DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }
            // エンジンの存在チェックを行う
            string path = USIDriver.NormalizeEnginePath(textBoxPath.Text);

            if (!File.Exists(path))
            {
                MessageBox.Show(this, path + " が存在しません。", "エラー");
                DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }
            // コントロールからEngineへ
            engine.Name        = textBoxName.Text;
            engine.Author      = textBoxAuthor.Text;
            engine.Path        = textBoxPath.Text;
            engine.USIPonder   = checkBoxUSIPonder.Checked;
            engine.USIHash     = (int)numericUpDownHash.Value;
            engine.ByoyomiHack = checkBox1.Checked;
            engine.Options     = engineOptionsControl1.ToList();
        }
Exemple #3
0
 /// <summary>
 /// エンジンから取得(設定)
 /// </summary>
 private void button2_Click(object sender, EventArgs e)
 {
     button2.Enabled = false;
     button3.Enabled = false;
     button4.Enabled = false;
     engineOptionsControl1.Enabled = false;
     ThreadPool.QueueUserWorkItem(new WaitCallback(arg => {
         try {
             using (USIDriver usi = new USIDriver(textBoxPath.Text)) {
                 usi.Start();
                 FormUtility.SafeInvoke(this, () => {
                     engineOptionsControl1.Clear();
                     foreach (var opt in usi.Options)
                     {
                         engineOptionsControl1.Add(
                             opt.Type, opt.Name, opt.Default,
                             opt.Min, opt.Max, opt.Var);
                     }
                 });
             }
         } catch (Exception ex) {
             logger.Warn("エンジンからの情報取得に失敗", ex);
             FormUtility.SafeInvoke(this, () => {
                 MessageBox.Show(this, "エンジンからの名前/作者取得に失敗しました。", "エラー");
             });
         } finally {
             FormUtility.SafeInvoke(this, () => {
                 button2.Enabled = true;
                 button3.Enabled = true;
                 button4.Enabled = true;
                 engineOptionsControl1.Enabled = true;
             });
         }
     }));
 }
        /// <summary>
        /// リストビューアイテムにアイコンを設定
        /// </summary>
        private void SetIconToListViewItem(ListViewItem item)
        {
            string path = "";

            try {
                path = USIDriver.NormalizeEnginePath(((Engine)item.Tag).Path);
                if (File.Exists(path))
                {
                    Icon icon = GetIcon(path);
                    FormUtility.SafeInvoke(listView1, () => {
                        item.ImageIndex = imageList1.Images.Add(icon.ToBitmap(), Color.Transparent);
                        if (0 <= item.Index)
                        {
                            listView1.RedrawItems(item.Index, item.Index, false);
                        }
                    });
                }
                else
                {
                    logger.Debug("アイコンの読み込みに失敗: " + path);
                }
            } catch (Exception e) {
                logger.Warn("アイコンの読み込みに失敗: " + path, e);
            }
        }
Exemple #5
0
 /// <summary>
 /// エンジンのパスが変更されたら活性非活性を調整
 /// </summary>
 private void textBoxPath_TextChanged(object sender, EventArgs e)
 {
     try {
         string path = USIDriver.NormalizeEnginePath(textBoxPath.Text);
         buttonGetByEngine.Enabled = File.Exists(path);
         UpdateEnables();
     } catch {
         // 入力は色々あり得るので黙殺
     }
 }
Exemple #6
0
        /// <summary>
        /// ...
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            string path = USIDriver.NormalizeEnginePath(textBoxPath.Text);
            string dir  = Path.GetDirectoryName(path);

            if (Directory.Exists(dir))
            {
                openFileDialog1.InitialDirectory = dir;
                openFileDialog1.FileName         = Path.GetFileName(path);
            }
            else
            {
                openFileDialog1.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; // 適当
            }
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                textBoxPath.Text = openFileDialog1.FileName;
            }
        }
Exemple #7
0
 /// <summary>
 /// エンジンから取得(エンジン名・作者名)
 /// </summary>
 private void buttonGetByEngine_Click(object sender, EventArgs e)
 {
     textBoxName.Enabled       = false;
     textBoxAuthor.Enabled     = false;
     buttonGetByEngine.Enabled = false;
     ThreadPool.QueueUserWorkItem(new WaitCallback(arg => {
         try {
             using (USIDriver usi = new USIDriver(textBoxPath.Text)) {
                 usi.Start();
                 FormUtility.SafeInvoke(this, () => {
                     textBoxName.Text   = usi.IdName;
                     textBoxAuthor.Text = usi.IdAuthor;
                 });
             }
         } catch (Exception ex) {
             logger.Warn("エンジンからの情報取得に失敗", ex);
             FormUtility.SafeInvoke(this, () => {
                 // 空なら仮でファイル名を設定
                 if (textBoxName.TextLength <= 0)
                 {
                     try {
                         textBoxName.Text = Path.GetFileNameWithoutExtension(textBoxPath.Text);
                     } catch (Exception ex2) {
                         logger.Warn("ファイル名の取得に失敗", ex2);
                     }
                 }
                 // エラーメッセージ
                 MessageBox.Show(this, "エンジンからの名前/作者取得に失敗しました。", "エラー");
             });
         } finally {
             FormUtility.SafeInvoke(this, () => {
                 buttonGetByEngine.Enabled = true;
                 textBoxAuthor.Enabled     = true;
                 textBoxName.Enabled       = true;
             });
         }
     }));
 }
Exemple #8
0
        /// <summary>
        /// エンジンが存在するかチェック
        /// </summary>
        public bool EngineExists(string name, string path)
        {
            var engine = Select(name, path);

            return(engine != null && File.Exists(USIDriver.NormalizeEnginePath(engine.Path)));
        }