Ejemplo n.º 1
0
        public bool add_arrow(string name, string cmd, string arg, string tag,
			string hotkey, string enabled,string encrypted, string timestamp, string guid)
        {
            // First check safety, the script in an arrow may attack user'path computer.
            string report = Resource.ArrowSafetyWarning + "\n>> Name : " + name + "\n>> Tag : " + tag;
            if (Main.Report(report, false, MessageBoxButtons.YesNo)
                == DialogResult.Yes)
            {
                Arrow a = new Arrow()
                {
                    Name = name,
                    Cmd = cmd,
                    Arg = arg,
                    Tag = tag,
                    HotKey = hotkey,
                    HotkeyEnabled = bool.Parse(enabled),
                    Encrypted = encrypted,
                    Timestamp = timestamp,
                    GUID = guid,
                };
                Main.Self.Arrows.Add(a);
                return true;
            }
            else
                return false;
        }
Ejemplo n.º 2
0
        /******** Archer Common Part ********/
        public void Show(bool newArrow = false)
        {
            base.Show();
            this.WindowState = FormWindowState.Normal;

            this.newArrow = newArrow;

            if (newArrow)
                currentArrow = new Arrow();
            else
                currentArrow = Main.Self.CurrentArrow;

            if (currentArrow == null) return;

            txtArg.Text = currentArrow.Arg;
            txtCmd.Text = currentArrow.Cmd;
            txtKey.Text = currentArrow.HotKey;
            txtName.Text = currentArrow.Name;
            txtTag.Text = currentArrow.Tag;

            btnHotkeyEnabled.Checked = currentArrow.HotkeyEnabled;
            btnEncrypted.Checked = bool.Parse(currentArrow.Encrypted);

            IsShown = true;

            foreach (var item in txtCmd.Document.FoldingManager.FoldMarker)
                item.IsFolded = true;

            if (ys.Common.GetExtension(currentArrow.Name).ToLower() == "c#"
                || ys.Common.GetExtension(currentArrow.Name).ToLower() == "cs")
                CSharpHighlight = true;
        }
Ejemplo n.º 3
0
		// 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;
		}
Ejemplo n.º 4
0
		// Settings: user data handling
		public bool LoadUserData()
		{
			if (!File.Exists(Resource.UserData)) return false;

			arrows.Clear();

			XmlReader xr = XmlReader.Create(Resource.UserData);
			try
			{
				PropertyInfo[] pis;

				while (xr.Read())
				{
					/// Now Archer is English only. This part is reserved for future.
					#region Language
					//if (xr.Name == "Language")
					//{
					//    int i = 0;
					//    while (xr.MoveToNextAttribute())
					//    {
					//        string n = xr.Name;
					//        string v = xr.GetAttribute(i++);

					//        System.Reflection.FieldInfo[] fieldInfoes = resource.GetExtension().GetFields();
					//        foreach (System.Reflection.FieldInfo fieldInfo in fieldInfoes)
					//        {
					//            if (fieldInfo.Name == n && fieldInfo.FieldType == typeof(string) && fieldInfo.IsStatic)
					//                fieldInfo.SetValue(resource, v);
					//        }
					//    }
					//    xr.Skip();
					//}
					#endregion

					#region Arrows
					if (xr.Name == typeof(Arrow).Name)
					{
						int i = 0;
						Arrow a = new Arrow();
						while (xr.MoveToNextAttribute())
						{
							string n = xr.Name;
							string v = xr.GetAttribute(i++);

							pis = a.GetType().GetProperties();
							foreach (var p in pis)
							{
								if (p.PropertyType == typeof(string) && n == p.Name)
									p.SetValue(a, v, null);
							}
						}
						arrows.Add(a);
						xr.Skip();
					}
					#endregion

					#region Setting

					pis = typeof(Setting).GetProperties();
					foreach (var p in pis)
					{
						if (xr.Name == p.Name)
						{
							int i = 0;
							while (xr.MoveToNextAttribute())
							{
								string n = xr.Name;
								string v = xr.GetAttribute(i++);

								if (n == "Value")
									p.SetValue(Setting, v, null);
							}
							xr.Skip();
						}
					}

					#endregion
				}
			}
			catch (Exception ex)
			{
				Report(Resource.Exception_IllegalInitValue + "\n\n" + ex.Message, false);
				xr.Close();
				return false;
			}
			xr.Close();

			return true;
		}
Ejemplo n.º 5
0
		private void cbName_TextChanged(object sender, EventArgs e)
		{
			currentArrow = arrows.Find(m => { return m.Name == cbName.Text; });

			if (currentArrow == preArrow) return;

			pbIcon.Visible = false;

			if (currentArrow != null)
			{
				lbName.Text = currentArrow.Name;

				// This will save the CPU on rendering text.
				if (currentArrow.Cmd.Length > 300)
				{
					lbCmd.Text = Resource.Multiline;
					lbCmd.ForeColor = Color.DeepSkyBlue;
				}
				else
				{
					lbCmd.Text = currentArrow.Cmd.StartsWith("*") ? currentArrow.Cmd.Substring(currentArrow.Cmd.IndexOf('\n') + 1) : currentArrow.Cmd;
					lbCmd.ForeColor = this.ForeColor;
				}

				#region Set Icon
				Bitmap icon = null;

				string extension = ys.Common.GetExtension(currentArrow.Name);
				switch (extension)
				{
					case "f":
						string[] cmds = currentArrow.Cmd.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
						foreach (var item in cmds)
						{
							if (Directory.Exists(ys.Common.UnfoldEV(item)))
							{
								icon = Properties.Resources.Folder;
								break;
							}
							else
							{ 
								try
								{
									icon = Icon.ExtractAssociatedIcon(ys.Common.GetFileFullPath(item)).ToBitmap();
									break;
								}
								catch { }
							}
						}
						break;

					case "u":
						try
						{
							string faviconPath = ys.Common.GetPathForCachedFile("http://" + new Uri(currentArrow.Cmd).Host + "/favicon.ico");
							if (faviconPath != null)
								icon = new Icon(faviconPath).ToBitmap();
							else
								icon = Icon.ExtractAssociatedIcon(ys.Common.GetFileFullPath(Main.Setting.DefaultBrowser)).ToBitmap();
						}
						catch { }
						break;

					case "t":
						try
						{
							icon = Icon.ExtractAssociatedIcon(ys.Common.GetFileFullPath(Main.Setting.DefaultBrowser)).ToBitmap();
						}
						catch { }
						break;

					case "c":
						icon = Properties.Resources.T;
						break;

					case "s":
						icon = Properties.Resources.S;
						break;

					case "i":
						icon = Properties.Resources.ArcherIcon.ToBitmap();
						break;

					case "c#":
						icon = Properties.Resources.CSharp;
						break;

					default:
						try
						{
							icon = ys.IconManager.IconFromExtensionShell(extension,ys.IconManager.SystemIconSize.Large).ToBitmap();
						}
						catch { }
						break;
				}

				if (icon != null)
				{
					pbIcon.BackgroundImage = icon;
					pbIcon.Visible = true;
				}
				#endregion


				// Encrypted
				if (bool.Parse(currentArrow.Encrypted))
				{
					lbCmd.ForeColor = Color.MediumVioletRed;
				}

				// HotkeyEnabled
				if (currentArrow.HotkeyEnabled)
				{
					lbHotKey.ForeColor = Color.ForestGreen;
				}
				else
				{
					lbHotKey.ForeColor = this.ForeColor;
				}

				if (ys.Common.GetForegroundWindow() == this.Handle
					&& sender != null)
				{
					cbArg.Text = currentArrow.Arg;
				}

				lbArg.Text = cbArg.Text;
				lbTag.Text = currentArrow.Tag;
				lbHotKey.Text = currentArrow.HotKey;
				lbCount.Text = currentArrow.Count;
			}
			else
			{
				lbName.Text = "";
				lbCmd.Text = "";
				lbArg.Text = "";
				lbTag.Text = "";
				lbHotKey.Text = "";
				lbCount.Text = "";
			}

			preArrow = currentArrow;
		}
Ejemplo n.º 6
0
        private void ShareArrow(object sender, EventArgs e)
        {
            if (dgv.CurrentCell != null)
            {
                int row = dgv.CurrentCell.RowIndex;
                Arrow arrow = new Arrow()
                {
                    Name = dgv[dgvName.Name, row].Value + "." + dgv[dgvType.Name, row].Value,
                    Cmd = dgv[dgvCmd.Name, row].Value + "",
                    Arg = dgv[dgvArg.Name, row].Value + "",
                    Tag = dgv[dgvTag.Name, row].Value + "",
                    HotKey = dgv[dgvHotkey.Name, row].Value + "",
                    Count = "0",
                    Timestamp = dgv[dgvTimestamp.Name, row].Value + "",
                    GUID = dgv[dgvGUID.Name, row].Value + "",
                };

                ServerContactor share = new ServerContactor();
                share.Show();
                share.ShareArrow(arrow);
            }
        }
Ejemplo n.º 7
0
        public void SaveSettings(object sender, EventArgs e)
        {
            Main.Setting.DefaultEditor = txtEditorPath.Text;
            Main.Setting.DefaultBrowser = txtDefaultBrowser.Text;
            Main.Setting.StrokeProperty =  txtStrokeProp.Text;

            if (Main.Self.GestureManager != null)
                Main.Self.GestureManager.StrokeProperty = txtStrokeProp.Text;

            dgv.EndEdit();

            foreach (var a in Main.Self.Arrows)
            {
                a.HotkeyEnabled = false;
            }

            Main.Self.Arrows.Clear();
            for (int i = 0; i < dgv.RowCount; i++)
            {
                if (!string.IsNullOrEmpty((string)dgv["dgvCmd", i].Value))
                {
                    Arrow arrow = new Arrow()
                    {
                        Name = dgv[dgvName.Name, i].Value + "." + dgv[dgvType.Name, i].Value,
                        Cmd = dgv[dgvCmd.Name, i].Value + "",
                        Encrypted = (dgv[dgvCmd.Name, i].Style.BackColor == encryptedColor ? true : false) + "",
                        Arg = dgv[dgvArg.Name, i].Value + "",
                        Tag = dgv[dgvTag.Name, i].Value + "",
                        HotKey = dgv[dgvHotkey.Name, i].Value + "",
                        Count = dgv[dgvCount.Name, i].Value + "",
                        GUID = dgv[dgvGUID.Name, i].Value + "",
                    };

                    if (lstChangedArrowID.Contains(arrow.GUID))
                        arrow.Timestamp = DateTime.Now.ToString("u");
                    else
                        arrow.Timestamp = dgv[dgvTimestamp.Name, i].Value + "";

                    if (dgv[dgvHotkeyEnabled.Name, i].Value != null)
                        arrow.HotkeyEnabled = (bool)dgv[dgvHotkeyEnabled.Name, i].Value;

                    Main.Self.Arrows.Add(arrow);

                }
            }
            Main.Self.UpdateTextInfo();
            Main.Self.SaveUserData();

            if(sender is Button)
                this.Close();
        }
Ejemplo n.º 8
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            Arrow a = new Arrow()
            {
                Arg = txtArg.Text,
                Cmd = txtCmd.Text,
                Name = txtName.Text,
            };

            Main.Self.LaunchArrow(a, a.Arg);
        }