示例#1
0
文件: Archer.cs 项目: ysmood/Archer
		public void Account(object sender, EventArgs e)
		{
			if (accountWnd == null || accountWnd.IsDisposed)
			{
				accountWnd = new AccountManager();
				accountWnd.ShowDialog();
			}
		}
示例#2
0
文件: Archer.cs 项目: ysmood/Archer
		// Launch Arrow
		/// <summary>
		/// Base arrow launch method
		/// </summary>
		/// <param name="a"></param>
		/// <param name="args">Argument to send to this arrow.</param>
		/// <param name="urlEncode">Whether insert urlEncode argument to the Cmd.</param>
		/// <returns>If launch succeed, returns true.</returns>
		public bool LaunchArrow(Arrow a, string arg = "")
		{
			string extention = Common.GetExtension(a.Name);
			string cmd = a.Cmd;

			// Crypt
			if (bool.Parse(a.Encrypted))
			{
				if (string.IsNullOrEmpty(Main.Setting.Password))
				{
					Main.Report(Resource.Exception_DecryptFailed);

					AccountManager accountWindow = new AccountManager();
					accountWindow.Show();
					return false;
				}
				else
				{
					try
					{
						cmd = Crypter.AESString.Decrypt(cmd, Main.Setting.Password);
						arg = Crypter.AESString.Decrypt(arg, Main.Setting.Password);
					}
					catch
					{
						Main.Report(Resource.Exception_DecryptFailed);

						AccountManager accountWindow = new AccountManager();
						accountWindow.Show();
						return false;
					}
				}
			}

			if (extention == string.Empty)
			{
				string type = Common.AutoGetType(cmd);
				if (type != string.Empty)
				{
					a.Name = a.Name.TrimEnd('.') + "." + type;
				}
				extention = type;
			}
			switch (extention.ToLower())
			{
				#region fileName system object
				case "f":
					arg = Common.UnfoldEV(arg);
					string arg_origin = arg;
					string startDir = string.Empty;

					string[] cmds = cmd.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
					int exceptionCount = 0;

					foreach(string item in cmds)
					{
						if (item.StartsWith("*")) startDir = item.TrimStart('*').Trim(new char[] { '\r', '\n', '"' });

						cmd = Common.UnfoldEV(item);
						arg = arg_origin;
						Common.InsertArg(ref cmd, ref arg);
						try
						{
							if (!Directory.Exists(cmd)
								&& Directory.Exists(arg))
								ys.Common.Start(arg);
							else
								ys.Common.Start(cmd, arg, startDir);
							goto CountOnce;
						}
						catch
						{
							exceptionCount++;
						}
					}

					if (exceptionCount == cmds.Length &&
						Report(Resource.Exception_FSONotFound, false, MessageBoxButtons.OKCancel) == DialogResult.OK)
					{
						Ionic.Utils.FolderBrowserDialogEx ofdEx = new Ionic.Utils.FolderBrowserDialogEx();
						ofdEx.Description = string.Format(Resource.ChooseFSO, cmd);
						ofdEx.ShowEditBox = true;
						ofdEx.ShowFullPathInEditBox = true;
						ofdEx.ShowNewFolderButton = true;
						ofdEx.ShowBothFilesAndFolders = true;
						ofdEx.SelectedPath = ys.Common.GetAvailableParentDir(cmd);
						if (ofdEx.ShowDialog() == DialogResult.OK)
						{
							a.Cmd += '\n' + ofdEx.SelectedPath;
							try
							{
								ys.Common.Start(ofdEx.SelectedPath, arg);
							}
							catch (Exception ex)
							{
								Report(ex.Message);
							}
							break;
						}
						else
							return false;
					}
					else
						return false;
				#endregion

				#region Url
				case "u":
					Common.InsertArg(ref cmd, ref arg, ModifierKeys != Keys.Control);
					try
					{
						ys.Common.Start(ys.Common.GetFileFullPath(Setting.DefaultBrowser), cmd + arg);
					}
					catch
					{
						Report(Resource.Exception_BrowserNotFound);
						return false;
					}
					break;
				#endregion

				#region Text selected
				case "t":
					string temp = Clipboard.GetText();	// Keep the pre content of the clipboard.
					try
					{
						SendKeys.SendWait("^c");
						string argument = Clipboard.GetText();
						Common.InsertArg(ref cmd, ref argument, ModifierKeys != Keys.Control);
						ys.Common.Start(ys.Common.GetFileFullPath(Setting.DefaultBrowser), cmd + argument);
					}
					catch (Exception ex)
					{
						Report(ex.Message);
						return false;
					}
					try
					{
						Clipboard.SetText(temp);
					}
					catch { }
					break;
				#endregion

				#region Copy and paste Cmd
				case "c":
					try
					{
						Clipboard.SetText(cmd + arg);
						ShowHideWindow(false);
						SendKeys.SendWait("^v");
					}
					catch (Exception ex)
					{
						Report(ex.Message);
					}
					break;
				#endregion

				#region Stroke of hardware inputs
				case "s":
					try
					{
						if (currentArrow == a)
						{
							ys.StrokeParser.SendStrokes(cmd + arg, a.HotKey);
						}
						else
							ys.StrokeParser.SendStrokes(cmd, a.HotKey);
					}
					catch (Exception ex)
					{
						Report(ex.Message);
					}
					break;
				#endregion

				#region Internal function
				case "i":
					if (!InternalFunction._RunFunction(cmd, arg))
						return false;
					break;
				#endregion

				#region UnknownType
				case "":
					Report(Resource.UnknownType + "\" " + a.Name + ".f \"");
					return false;
				#endregion

				#region _RunFunction C# script
				case "c#":
					string[] args = ys.Common.GetArgs(arg);

					// Get the references: args in list that starts with "!".
					string[] refs = Array.FindAll(args, m=> { return m.StartsWith("!"); });
					for (int i = 0; i < refs.Length; i++)
					{
						refs[i] = refs[i].TrimStart('!');
					}

					try
					{
						CSharpInterpreter.CSharpInterpreter.RunFromSrc(cmd, refs, args);
					}
					catch (Exception ex)
					{
						Report(ex.Message);
					}
					break;
				#endregion

				#region _RunFunction registered script
				default:
					try
					{
						TempFiles.Add(Common.RunTempScript(cmd, extention, arg));
					}
					catch (Exception ex)
					{
						Report(ex.Message);
						return false;
					}
					break;
				#endregion
			}
		CountOnce:
			a.CountOnce();

			return true;
		}
示例#3
0
        private void encrypt(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Main.Setting.Password))
            {
                AccountManager accountWindow = new AccountManager();

                // Must be a model window. We need to block this thread.
                accountWindow.Show();
                if (accountWindow.OK)
                {
                    encrypt(null, null);
                }
            }
            else
            {
                DataGridViewCell cell_cmd = dgv[dgvCmd.Name, dgv.CurrentRow.Index] as DataGridViewCell;
                DataGridViewCell cell_arg = dgv[dgvArg.Name, dgv.CurrentRow.Index] as DataGridViewCell;

                if (encryptMenuItem.Checked)
                {
                    try
                    {
                        cell_cmd.Value = Crypter.AESString.Decrypt(
                                                                cell_cmd.Value.ToString(),
                                                                Main.Setting.Password
                                                            );
                        cell_cmd.Style.BackColor = cell_cmd.RowIndex % 2 == 0 ? Color.White : Color.FromArgb(255, 240, 240, 240);

                        cell_arg.Value = Crypter.AESString.Decrypt(
                                                                cell_arg.Value.ToString(),
                                                                Main.Setting.Password
                                                            );
                        cell_arg.Style.BackColor = cell_arg.RowIndex % 2 == 0 ? Color.White : Color.FromArgb(255, 240, 240, 240);

                        encryptMenuItem.Checked = false;
                    }
                    catch
                    {
                        Main.Report(Resource.Exception_DecryptFailed);

                        AccountManager accountWindow = new AccountManager();
                        accountWindow.Show();
                        if (accountWindow.OK)
                        {
                            encrypt(null, null);
                        }
                    }
                }
                else
                {
                    cell_cmd.Value = Crypter.AESString.Encrypt(
                                                    cell_cmd.Value.ToString(),
                                                    Main.Setting.Password
                                                );
                    cell_cmd.Style.BackColor = encryptedColor;
                    cell_arg.Value = Crypter.AESString.Encrypt(
                                                    cell_arg.Value.ToString(),
                                                    Main.Setting.Password
                                                );
                    cell_arg.Style.BackColor = encryptedColor;
                    encryptMenuItem.Checked = true;
                }
            }
        }
示例#4
0
文件: Archer.cs 项目: ysmood/Archer
		private void ChangeAccount(object sender, EventArgs e)
		{
			AccountManager accountWindow = new AccountManager();
			accountWindow.Show(this);
		}
示例#5
0
文件: Editor.cs 项目: ysmood/Archer
        private void encrypt(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Main.Setting.Password))
            {
                AccountManager accountWindow = new AccountManager();

                // Must be a model window. We need to block this thread.
                accountWindow.ShowDialog(this);
                if (accountWindow.OK)
                {
                    encrypt(null, null);
                }
            }
            else
            {

                if (btnEncrypted.Checked)
                {
                    try
                    {
                        txtCmd.Text = Crypter.AESString.Decrypt(
                                                                txtCmd.Text,
                                                                Main.Setting.Password
                                                            );
                        txtArg.Text = Crypter.AESString.Decrypt(
                                                                txtArg.Text,
                                                                Main.Setting.Password
                                                            );
                        btnEncrypted.Checked = false;
                    }
                    catch
                    {
                        Main.Report(Resource.Exception_DecryptFailed);

                        AccountManager accountWindow = new AccountManager();
                        accountWindow.ShowDialog(this);
                        if (accountWindow.OK)
                        {
                            encrypt(null, null);
                        }
                    }
                }
                else
                {
                    txtCmd.Text = Crypter.AESString.Encrypt(
                                                    txtCmd.Text,
                                                    Main.Setting.Password
                                                );
                    txtArg.Text = Crypter.AESString.Encrypt(
                                                    txtArg.Text,
                                                    Main.Setting.Password
                                                );
                    btnEncrypted.Checked = true;
                }
                txtCmd.Refresh();
            }
        }