2 using System.Collections.Generic;
3 using System.ComponentModel;
6 using System.Runtime.InteropServices;
8 using System.Windows.Forms;
11 namespace Lugens.Passer
13 public partial class AddCommandForm : Form
15 public AddCommandForm()
17 InitializeComponent();
21 public AddCommandForm(string targetFile) : this()
23 SetSelectedFile(targetFile);
28 this.textBox_command.Text = "
\90V
\82µ
\82¢
\83R
\83}
\83\93\83h";
29 this.textBox_target.Text = "";
30 this.textBox_path.Text = "";
31 this.textBox_arguments.Text = "";
32 this.textBox_comment.Text = "";
35 private string ExtractCommandName(string filename)
37 int fileIndex = filename.LastIndexOf('\\');
42 string command = filename.Substring(fileIndex + 1);
43 if (command.LastIndexOf('.') != -1)
45 command = command.Substring(0, command.LastIndexOf('.'));
50 private string ExtraCommandPath(string filename)
52 int fileIndex = filename.LastIndexOf('\\');
57 return filename.Substring(0, fileIndex);
60 public void SetSelectedFile(string filename)
63 Win32.SHFILEINFO info = new Win32.SHFILEINFO();
65 ret = Win32.SHGetFileInfo(filename, 0, ref info, Marshal.SizeOf(info), Win32.SHGFI_ATTRIBUTES);
66 if (ret == IntPtr.Zero) return;
69 if ((info.dwAttributes & Win32.SFGAO_LINK) != 0)
71 //
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82Ì
\8fê
\8d\87
72 ShellLink shellLink = new ShellLink(filename);
73 string targetfile = shellLink.TargetPath;
74 this.textBox_command.Text = ExtractCommandName(filename);
75 this.textBox_target.Text = targetfile;
76 this.textBox_path.Text = shellLink.WorkingDirectory;
77 this.textBox_arguments.Text = shellLink.Arguments;
78 this.textBox_comment.Text = shellLink.Description;
79 if (this.textBox_path.Text.Length == 0)
81 this.textBox_path.Text = ExtraCommandPath(targetfile);
88 //
\83t
\83@
\83C
\83\8b\81A
\83t
\83H
\83\8b\83_
\82Ì
\8fê
\8d\87
89 this.textBox_command.Text = ExtractCommandName(filename);
90 this.textBox_target.Text = filename;
91 this.textBox_path.Text = ExtraCommandPath(filename);
93 this.textBox_command.Text = this.textBox_command.Text.Replace(' ', '_');
95 if(Program.SettingForm.CommandDicTmp.ContainsKey(this.textBox_command.Text))
98 for (int i = 2; i < 256; i++)
100 text = this.textBox_command.Text + i;
101 if (!Program.SettingForm.CommandDicTmp.ContainsKey(text))
103 this.textBox_command.Text = text;
112 private void button_view_Click(object sender, EventArgs e)
115 if (DialogResult.OK == openFileDialog1.ShowDialog(this))
117 SetSelectedFile(openFileDialog1.FileName);
121 private void textBox_command_TextChanged(object sender, EventArgs e)
123 if (Program.SettingForm == null)
125 if (this.textBox_command.Text.Length == 0)
127 this.label_duplicate.Visible = false;
128 this.button_ok.Enabled = false;
131 if (Program.DefaultCommand.Equals(this.textBox_command.Text))
133 this.label_duplicate.Visible = false;
134 this.button_ok.Enabled = true;
137 if (this.textBox_command.Text[0] == '\\' || this.textBox_command.Text[0] == '!' || this.textBox_command.Text[0] == '$' || this.textBox_command.Text[0] == ':' || this.textBox_command.Text[0] == '@')
139 this.label_duplicate.Text = "
\81¦
\93ü
\97Í
\82³
\82ê
\82½
\8bL
\8d\86\82Í
\8eg
\97p
\82Å
\82«
\82Ü
\82¹
\82ñ";
140 this.label_duplicate.Visible = true;
141 this.button_ok.Enabled = false;
144 if (this.textBox_command.Text.IndexOf(' ') != -1)
146 this.label_duplicate.Text = "
\81¦
\83X
\83y
\81[
\83X
\82Í
\8eg
\97p
\82Å
\82«
\82Ü
\82¹
\82ñ";
147 this.label_duplicate.Visible = true;
148 this.button_ok.Enabled = false;
151 if (Program.SettingForm.CommandDicTmp.ContainsKey(this.textBox_command.Text))
153 this.label_duplicate.Text = "
\81¦
\8fd
\95¡
\82µ
\82Ä
\82¢
\82Ü
\82·";
154 this.label_duplicate.Visible = true;
155 this.button_ok.Enabled = false;
159 this.label_duplicate.Visible = false;
160 this.button_ok.Enabled = true;
164 private void AddCommandForm_Load(object sender, EventArgs e)
166 //this.textBox_command.Text = "
\90V
\82µ
\82¢
\83R
\83}
\83\93\83h";
169 private void button_ok_Click(object sender, EventArgs e)
171 if (Program.SettingForm.CommandDicTmp.ContainsKey(this.textBox_command.Text))
173 MessageBox.Show(this, "
\83R
\83}
\83\93\83h
\96¼
\82ª
\8fd
\95¡
\82µ
\82Ä
\82¢
\82Ü
\82·", "
\93o
\98^
\83G
\83\89\81[", MessageBoxButtons.OK, MessageBoxIcon.Warning);
177 if (String.IsNullOrEmpty(this.textBox_target.Text))
179 MessageBox.Show(this, "
\83t
\83@
\83C
\83\8b\82ª
\8ew
\92è
\82³
\82ê
\82Ä
\82¢
\82Ü
\82¹
\82ñ", "
\93o
\98^
\83G
\83\89\81[", MessageBoxButtons.OK, MessageBoxIcon.Warning);
183 CommandInfo info = new CommandInfo();
184 info.Name = this.textBox_command.Text;
185 info.Target = this.textBox_target.Text;
186 info.Path = this.textBox_path.Text;
187 info.Arguments = this.textBox_arguments.Text;
188 info.Comment = this.textBox_comment.Text.Length == 0 ? null : this.textBox_comment.Text;
189 Program.AddCommand(Program.SettingForm.CommandDicTmp, Program.SettingForm.CommandListTmp, info);
190 Program.SettingForm.ReadCommandList(true);
191 Program.SettingForm.RequestCommandListViewSelect(info.Name);
193 this.Visible = false;
196 private void button_cancel_Click(object sender, EventArgs e)
201 private void AddCommandForm_DragEnter(object sender, DragEventArgs e)
203 if (e.Data.GetDataPresent(DataFormats.FileDrop))
205 e.Effect = DragDropEffects.Copy;
209 private void AddCommandForm_DragDrop(object sender, DragEventArgs e)
211 string[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
212 if (files == null || files.Length == 0)
216 string file = files[0];
218 this.SetSelectedFile(file);
221 private void AddCommandForm_VisibleChanged(object sender, EventArgs e)
224 Program.ForceForegroundWindow(this.Handle);