-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.IO;
-using System.Text;
-using System.Windows.Forms;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Net;
-using Lugens.Components;
-using Lugens.Passer.Macro;
-using Lugens.Utils;
-
-namespace Lugens.Passer
-{
- public partial class EditEngineForm : Form
- {
- private string id;
- private string name;
- private int shortcut;
- private bool iconChanged;
-
- public EditEngineForm(EngineInfo info)
- {
- InitializeComponent();
- this.Init(info);
- }
-
- public void Init(EngineInfo info)
- {
- this.id = info.Id;
- this.name = info.Name;
- this.shortcut = info.Shortcut;
- this.textBox_name.Text = info.Name;
- this.textBox_url.Text = info.Url;
- this.textBox_searchUrl.Text = info.SearchUrl;
- this.textBox_suggestUrl.Text = info.SuggestUrl;
- this.textBox_display.Text = info.Display;
- this.textBox_shortcut.HotKeycode = info.Shortcut;
- this.button_icon.Image = info.IconImage;
-
- this.textBox_shortcut.AcceptKeys = SettingForm.AcceptKeyList;
- this.textBox_shortcut.GotFocus += SettingForm.hotKeyTextBox_GotFocus;
- this.textBox_shortcut.LostFocus += SettingForm.hotKeyTextBox_LostFocus;
-
- this.iconChanged = false;
- }
-
- private void textBox_shortcut_TextChanged(object sender, EventArgs e)
- {
-/* if (this.textBox_shortcut.HotKeycode != 0)
- {
- foreach (EngineInfo info in Program.DefaultEngineDic.Values)
- {
- if (info.Shortcut == this.textBox_shortcut.HotKeycode && info.Shortcut != this.shortcut)
- {
- this.label_shortcut_duplicate.Visible = true;
- this.button_ok.Enabled = false;
- return;
- }
- }
- foreach (EngineInfo info in Program.SettingForm.EngineDicTmp.Values)
- {
- if (info.Shortcut == this.textBox_shortcut.HotKeycode && info.Shortcut != this.shortcut)
- {
- this.label_shortcut_duplicate.Visible = true;
- this.button_ok.Enabled = false;
- return;
- }
- }
- }
- this.label_shortcut_duplicate.Visible = false;
- this.button_ok.Enabled = true;*/
- }
-
- private void button_ok_Click(object sender, EventArgs e)
- {
- EngineInfo info = new EngineInfo();
- info.Id = this.id;
- info.Name = this.textBox_name.Text;
- info.Url = this.textBox_url.Text;
- info.SearchUrl = this.textBox_searchUrl.Text;
- info.SuggestUrl = this.textBox_suggestUrl.Text;
- info.Shortcut = this.textBox_shortcut.HotKeycode;
- info.Display = this.textBox_display.Text;
- info.IconChanged = this.iconChanged;
-
- if (String.IsNullOrEmpty(info.Url))
- {
- MessageBox.Show("URLを入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (!info.Url.StartsWith("http://") && !info.Url.StartsWith("https://"))
- {
- MessageBox.Show("URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (!String.IsNullOrEmpty(info.SearchUrl) && !info.SearchUrl.StartsWith("http://") && !info.SearchUrl.StartsWith("https://"))
- {
- MessageBox.Show("検索URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (!String.IsNullOrEmpty(info.SuggestUrl) && !info.SuggestUrl.StartsWith("http://") && !info.SuggestUrl.StartsWith("https://"))
- {
- MessageBox.Show("サジェストURLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (this.iconChanged)
- {
- if (!Directory.Exists(Program.EngineIconTmpDir))
- Directory.CreateDirectory(Program.EngineIconTmpDir);
-
- string iconFile = Program.EngineIconTmpDir + "\\" + this.id;
- this.button_icon.Image.Save(iconFile, System.Drawing.Imaging.ImageFormat.Png);
- Bitmap bitmap = new Bitmap(iconFile);
- info.IconImage = new Bitmap(bitmap);
- bitmap.Dispose();
- }
- else
- {
- info.IconImage = this.button_icon.Image;
- }
-
- int index = Program.SettingForm.EngineListTmp.IndexOf(this.name);
- Program.SettingForm.EngineListTmp[index] = this.textBox_name.Text;
- Program.SettingForm.EngineDicTmp.Remove(this.name);
- Program.SettingForm.EngineDicTmp.Add(info.Name, info);
- Program.SettingForm.ReadEngineList(true);
- Program.SettingForm.RequestEngineListViewSelect(info.Name);
- this.Visible = false;
- }
-
- private void button_icon_Click(object sender, EventArgs e)
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string file = openFileDialog.FileName;
- if (File.Exists(file))
- {
- try
- {
- Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
- Win32.SHGetFileInfo(file, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
- Icon icon = Icon.FromHandle(shinfo.hIcon);
- this.button_icon.Image = icon.ToBitmap();
- icon.Dispose();
- this.iconChanged = true;
- }
- catch (Exception ex) { ex.ToString(); }
- }
- }
- }
-
- private void textBox_name_TextChanged(object sender, EventArgs e)
- {
- if (!this.name.Equals(this.textBox_name.Text) && Program.SettingForm.EngineListTmp.Contains(this.textBox_name.Text))
- {
- this.label_engine_duplicate.Visible = true;
- this.button_ok.Enabled = false;
- }
- else
- {
- this.label_engine_duplicate.Visible = false;
- this.button_ok.Enabled = true;
- }
- }
-
- private void button_icon_get_Click(object sender, EventArgs e)
- {
- string str = this.textBox_url.Text;
- if(String.IsNullOrEmpty(str))
- {
- MessageBox.Show("URLを入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (!str.StartsWith("http://") && !str.StartsWith("https://"))
- {
- MessageBox.Show("URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- int n = str.IndexOf("//");
- if(str.LastIndexOf('/') == n + 1)
- str += "/favicon.ico";
- else
- str = str.Substring(0, str.IndexOf('/', n + 2)) + "/favicon.ico";
-
- WebClient wc = new WebClient();
- string file = Program.EngineIconTmpDir + "\\" + this.id;
- try
- {
- Program.CreateEngineIconTmpDir();
- wc.DownloadFile(str, file);
- }
- catch
- {
- MessageBox.Show("ダウンロードエラー");
- return;
- }
-
- try
- {
- Bitmap bitmap = new Bitmap(file);
- this.button_icon.Image = new Bitmap(bitmap);
- bitmap.Dispose();
- this.iconChanged = true;
- return;
- }
- catch
- {
- MessageBox.Show("画像の変換に失敗しました。");
- return;
- }
-
- }
-
- private void button_cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
-
- }
-}
+using System;\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using System.Data;\r
+using System.Drawing;\r
+using System.IO;\r
+using System.Text;\r
+using System.Windows.Forms;\r
+using System.Diagnostics;\r
+using System.Runtime.InteropServices;\r
+using System.Net;\r
+using Lugens.Components;\r
+using Lugens.Passer.Macro;\r
+using Lugens.Utils;\r
+\r
+namespace Lugens.Passer\r
+{\r
+ public partial class EditEngineForm : Form\r
+ {\r
+ private string id;\r
+ private string name;\r
+ private int shortcut;\r
+ private bool iconChanged;\r
+\r
+ public EditEngineForm(EngineInfo info)\r
+ {\r
+ InitializeComponent();\r
+ this.Init(info);\r
+ }\r
+\r
+ public void Init(EngineInfo info)\r
+ {\r
+ this.id = info.Id;\r
+ this.name = info.Name;\r
+ this.shortcut = info.Shortcut;\r
+ this.textBox_name.Text = info.Name;\r
+ this.textBox_url.Text = info.Url;\r
+ this.textBox_searchUrl.Text = info.SearchUrl;\r
+ this.textBox_suggestUrl.Text = info.SuggestUrl;\r
+ this.textBox_display.Text = info.Display;\r
+ this.textBox_shortcut.HotKeycode = info.Shortcut;\r
+ this.button_icon.Image = info.IconImage;\r
+ this.comboBox_encoding.Text = info.Encoding;\r
+\r
+ this.textBox_shortcut.AcceptKeys = SettingForm.AcceptKeyList;\r
+ this.textBox_shortcut.GotFocus += SettingForm.hotKeyTextBox_GotFocus;\r
+ this.textBox_shortcut.LostFocus += SettingForm.hotKeyTextBox_LostFocus;\r
+\r
+ this.iconChanged = false;\r
+ }\r
+\r
+ private void textBox_shortcut_TextChanged(object sender, EventArgs e)\r
+ {\r
+/* if (this.textBox_shortcut.HotKeycode != 0)\r
+ {\r
+ foreach (EngineInfo info in Program.DefaultEngineDic.Values)\r
+ {\r
+ if (info.Shortcut == this.textBox_shortcut.HotKeycode && info.Shortcut != this.shortcut)\r
+ {\r
+ this.label_shortcut_duplicate.Visible = true;\r
+ this.button_ok.Enabled = false;\r
+ return;\r
+ }\r
+ }\r
+ foreach (EngineInfo info in Program.SettingForm.EngineDicTmp.Values)\r
+ {\r
+ if (info.Shortcut == this.textBox_shortcut.HotKeycode && info.Shortcut != this.shortcut)\r
+ {\r
+ this.label_shortcut_duplicate.Visible = true;\r
+ this.button_ok.Enabled = false;\r
+ return;\r
+ }\r
+ }\r
+ }\r
+ this.label_shortcut_duplicate.Visible = false;\r
+ this.button_ok.Enabled = true;*/\r
+ }\r
+\r
+ private void button_ok_Click(object sender, EventArgs e)\r
+ {\r
+ EngineInfo info = new EngineInfo();\r
+ info.Id = this.id;\r
+ info.Name = this.textBox_name.Text;\r
+ info.Url = this.textBox_url.Text;\r
+ info.SearchUrl = this.textBox_searchUrl.Text;\r
+ info.SuggestUrl = this.textBox_suggestUrl.Text;\r
+ info.Shortcut = this.textBox_shortcut.HotKeycode;\r
+ info.Encoding = this.comboBox_encoding.Text;\r
+ info.Display = this.textBox_display.Text;\r
+ info.IconChanged = this.iconChanged;\r
+\r
+ if (String.IsNullOrEmpty(info.Url))\r
+ {\r
+ MessageBox.Show("URLを入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ if (!info.Url.StartsWith("http://") && !info.Url.StartsWith("https://"))\r
+ {\r
+ MessageBox.Show("URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ if (!String.IsNullOrEmpty(info.SearchUrl) && !info.SearchUrl.StartsWith("http://") && !info.SearchUrl.StartsWith("https://"))\r
+ {\r
+ MessageBox.Show("検索URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ if (!String.IsNullOrEmpty(info.SuggestUrl) && !info.SuggestUrl.StartsWith("http://") && !info.SuggestUrl.StartsWith("https://"))\r
+ {\r
+ MessageBox.Show("サジェストURLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ if (this.iconChanged)\r
+ {\r
+ if (!Directory.Exists(Program.EngineIconTmpDir))\r
+ Directory.CreateDirectory(Program.EngineIconTmpDir);\r
+\r
+ string iconFile = Program.EngineIconTmpDir + "\\" + this.id;\r
+ this.button_icon.Image.Save(iconFile, System.Drawing.Imaging.ImageFormat.Png);\r
+ Bitmap bitmap = new Bitmap(iconFile);\r
+ info.IconImage = new Bitmap(bitmap);\r
+ bitmap.Dispose();\r
+ }\r
+ else\r
+ {\r
+ info.IconImage = this.button_icon.Image;\r
+ }\r
+\r
+ int index = Program.SettingForm.EngineListTmp.IndexOf(this.name);\r
+ Program.SettingForm.EngineListTmp[index] = this.textBox_name.Text;\r
+ Program.SettingForm.EngineDicTmp.Remove(this.name);\r
+ Program.SettingForm.EngineDicTmp.Add(info.Name, info);\r
+ Program.SettingForm.ReadEngineList(true);\r
+ Program.SettingForm.RequestEngineListViewSelect(info.Name);\r
+ this.Visible = false;\r
+ }\r
+\r
+ private void button_icon_Click(object sender, EventArgs e)\r
+ {\r
+ if (openFileDialog.ShowDialog() == DialogResult.OK)\r
+ {\r
+ string file = openFileDialog.FileName;\r
+ if (File.Exists(file))\r
+ {\r
+ try\r
+ {\r
+ Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();\r
+ Win32.SHGetFileInfo(file, 0, ref shinfo, Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);\r
+ Icon icon = Icon.FromHandle(shinfo.hIcon);\r
+ this.button_icon.Image = icon.ToBitmap();\r
+ icon.Dispose();\r
+ this.iconChanged = true;\r
+ }\r
+ catch (Exception ex) { ex.ToString(); }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void textBox_name_TextChanged(object sender, EventArgs e)\r
+ {\r
+ if (!this.name.Equals(this.textBox_name.Text) && Program.SettingForm.EngineListTmp.Contains(this.textBox_name.Text))\r
+ {\r
+ this.label_engine_duplicate.Visible = true;\r
+ this.button_ok.Enabled = false;\r
+ }\r
+ else\r
+ {\r
+ this.label_engine_duplicate.Visible = false;\r
+ this.button_ok.Enabled = true;\r
+ }\r
+ }\r
+\r
+ private void button_icon_get_Click(object sender, EventArgs e)\r
+ {\r
+ string str = this.textBox_url.Text;\r
+ if(String.IsNullOrEmpty(str))\r
+ {\r
+ MessageBox.Show("URLを入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ if (!str.StartsWith("http://") && !str.StartsWith("https://"))\r
+ {\r
+ MessageBox.Show("URLを正しく入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+\r
+ int n = str.IndexOf("//");\r
+ if(str.LastIndexOf('/') == n + 1)\r
+ str += "/favicon.ico";\r
+ else\r
+ str = str.Substring(0, str.IndexOf('/', n + 2)) + "/favicon.ico";\r
+\r
+ WebClient wc = new WebClient();\r
+ string file = Program.EngineIconTmpDir + "\\" + this.id;\r
+ try\r
+ {\r
+ Program.CreateEngineIconTmpDir();\r
+ wc.DownloadFile(str, file);\r
+ }\r
+ catch\r
+ {\r
+ MessageBox.Show("ダウンロードエラー");\r
+ return;\r
+ }\r
+\r
+ try\r
+ {\r
+ Bitmap bitmap = new Bitmap(file);\r
+ this.button_icon.Image = new Bitmap(bitmap);\r
+ bitmap.Dispose();\r
+ this.iconChanged = true;\r
+ return;\r
+ }\r
+ catch \r
+ {\r
+ MessageBox.Show("画像の変換に失敗しました。");\r
+ return;\r
+ }\r
+\r
+ }\r
+\r
+ private void button_cancel_Click(object sender, EventArgs e)\r
+ {\r
+ this.Close();\r
+ }\r
+\r
+\r
+ }\r
+}\r