diff --git a/ElegantOptions.cs b/ElegantOptions.cs new file mode 100644 index 0000000..ae192ef --- /dev/null +++ b/ElegantOptions.cs @@ -0,0 +1,20 @@ +namespace ElegantRecorder +{ + public class ElegantOptions + { + public string PlaybackSpeed { get; set; } + public bool RecordMouseMove { get; set; } + public bool RestrictToExe { get; set; } + public string ExePath { get; set; } + public string RecordingPath { get; set; } + + public ElegantOptions() + { + PlaybackSpeed = "Normal"; + RecordMouseMove = false; + RestrictToExe = false; + ExePath = ""; + RecordingPath = System.Windows.Forms.Application.StartupPath + "ElegantRecording.json"; + } + } +} diff --git a/ElegantRecorder.Designer.cs b/ElegantRecorder.Designer.cs index 505ec50..e3e3603 100644 --- a/ElegantRecorder.Designer.cs +++ b/ElegantRecorder.Designer.cs @@ -1,6 +1,6 @@ using System.Windows.Forms; -namespace UIAuto +namespace ElegantRecorder { partial class ElegantRecorder { @@ -30,144 +30,118 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.labelStatus = new System.Windows.Forms.Label(); - this.textBoxScriptName = new System.Windows.Forms.TextBox(); - this.buttonBrowseScript = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); - this.buttonRecord = new System.Windows.Forms.Button(); + this.buttonPin = new System.Windows.Forms.Button(); this.buttonReplay = new System.Windows.Forms.Button(); - this.textBoxExeName = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.buttonBrowseExe = new System.Windows.Forms.Button(); this.buttonStop = new System.Windows.Forms.Button(); + this.buttonRecord = new System.Windows.Forms.Button(); + this.buttonPause = new System.Windows.Forms.Button(); + this.buttonSettings = new System.Windows.Forms.Button(); + this.toolTipRec = new System.Windows.Forms.ToolTip(this.components); this.SuspendLayout(); // // labelStatus // + this.labelStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelStatus.AutoSize = true; - this.labelStatus.Location = new System.Drawing.Point(12, 145); + this.labelStatus.Location = new System.Drawing.Point(12, 71); this.labelStatus.Name = "labelStatus"; this.labelStatus.Size = new System.Drawing.Size(39, 15); this.labelStatus.TabIndex = 0; this.labelStatus.Text = "Status"; // - // textBoxScriptName - // - this.textBoxScriptName.Location = new System.Drawing.Point(100, 6); - this.textBoxScriptName.Name = "textBoxScriptName"; - this.textBoxScriptName.Size = new System.Drawing.Size(323, 23); - this.textBoxScriptName.TabIndex = 1; - this.textBoxScriptName.TextChanged += new System.EventHandler(this.textBoxScriptName_TextChanged); - // - // buttonBrowseScript + // buttonPin // - this.buttonBrowseScript.Location = new System.Drawing.Point(429, 6); - this.buttonBrowseScript.Name = "buttonBrowseScript"; - this.buttonBrowseScript.Size = new System.Drawing.Size(53, 23); - this.buttonBrowseScript.TabIndex = 2; - this.buttonBrowseScript.Text = "..."; - this.buttonBrowseScript.UseVisualStyleBackColor = true; - this.buttonBrowseScript.Click += new System.EventHandler(this.buttonBrowse_Click); - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 9); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(80, 15); - this.label2.TabIndex = 3; - this.label2.Text = "Recording file"; - // - // buttonRecord - // - this.buttonRecord.Location = new System.Drawing.Point(100, 82); - this.buttonRecord.Name = "buttonRecord"; - this.buttonRecord.Size = new System.Drawing.Size(84, 34); - this.buttonRecord.TabIndex = 4; - this.buttonRecord.Text = "Record"; - this.buttonRecord.UseVisualStyleBackColor = true; - this.buttonRecord.Click += new System.EventHandler(this.buttonRecord_Click); + this.buttonPin.Image = global::ElegantRecorder.Properties.Resources.geo; + this.buttonPin.Location = new System.Drawing.Point(320, 12); + this.buttonPin.Name = "buttonPin"; + this.buttonPin.Size = new System.Drawing.Size(49, 48); + this.buttonPin.TabIndex = 11; + this.toolTipRec.SetToolTip(this.buttonPin, "Pin to top"); + this.buttonPin.UseVisualStyleBackColor = true; + this.buttonPin.Click += new System.EventHandler(this.buttonPin_Click); // // buttonReplay // - this.buttonReplay.Location = new System.Drawing.Point(339, 82); + this.buttonReplay.Image = global::ElegantRecorder.Properties.Resources.play_fill; + this.buttonReplay.Location = new System.Drawing.Point(177, 12); this.buttonReplay.Name = "buttonReplay"; - this.buttonReplay.Size = new System.Drawing.Size(84, 34); - this.buttonReplay.TabIndex = 5; - this.buttonReplay.Text = "Replay"; + this.buttonReplay.Size = new System.Drawing.Size(49, 48); + this.buttonReplay.TabIndex = 12; + this.toolTipRec.SetToolTip(this.buttonReplay, "Replay"); this.buttonReplay.UseVisualStyleBackColor = true; this.buttonReplay.Click += new System.EventHandler(this.buttonReplay_Click); // - // textBoxExeName + // buttonStop // - this.textBoxExeName.Location = new System.Drawing.Point(100, 35); - this.textBoxExeName.Name = "textBoxExeName"; - this.textBoxExeName.Size = new System.Drawing.Size(323, 23); - this.textBoxExeName.TabIndex = 6; - this.textBoxExeName.TextChanged += new System.EventHandler(this.textBoxExeName_TextChanged); + this.buttonStop.Image = global::ElegantRecorder.Properties.Resources.stop_fill; + this.buttonStop.Location = new System.Drawing.Point(122, 12); + this.buttonStop.Name = "buttonStop"; + this.buttonStop.Size = new System.Drawing.Size(49, 48); + this.buttonStop.TabIndex = 13; + this.toolTipRec.SetToolTip(this.buttonStop, "Stop"); + this.buttonStop.UseVisualStyleBackColor = true; + this.buttonStop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.buttonStop_MouseDown); // - // label1 + // buttonRecord // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 38); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(64, 15); - this.label1.TabIndex = 7; - this.label1.Text = "Executable"; + this.buttonRecord.Image = global::ElegantRecorder.Properties.Resources.record_fill; + this.buttonRecord.Location = new System.Drawing.Point(12, 12); + this.buttonRecord.Name = "buttonRecord"; + this.buttonRecord.Size = new System.Drawing.Size(49, 48); + this.buttonRecord.TabIndex = 14; + this.toolTipRec.SetToolTip(this.buttonRecord, "Record"); + this.buttonRecord.UseVisualStyleBackColor = true; + this.buttonRecord.Click += new System.EventHandler(this.buttonRecord_Click); // - // buttonBrowseExe + // buttonPause // - this.buttonBrowseExe.Location = new System.Drawing.Point(429, 35); - this.buttonBrowseExe.Name = "buttonBrowseExe"; - this.buttonBrowseExe.Size = new System.Drawing.Size(53, 23); - this.buttonBrowseExe.TabIndex = 8; - this.buttonBrowseExe.Text = "..."; - this.buttonBrowseExe.UseVisualStyleBackColor = true; - this.buttonBrowseExe.Click += new System.EventHandler(this.buttonBrowseExe_Click); + this.buttonPause.Image = global::ElegantRecorder.Properties.Resources.pause_fill; + this.buttonPause.Location = new System.Drawing.Point(67, 12); + this.buttonPause.Name = "buttonPause"; + this.buttonPause.Size = new System.Drawing.Size(49, 48); + this.buttonPause.TabIndex = 15; + this.toolTipRec.SetToolTip(this.buttonPause, "Pause"); + this.buttonPause.UseVisualStyleBackColor = true; // - // buttonStop + // buttonSettings // - this.buttonStop.Location = new System.Drawing.Point(223, 82); - this.buttonStop.Name = "buttonStop"; - this.buttonStop.Size = new System.Drawing.Size(84, 34); - this.buttonStop.TabIndex = 9; - this.buttonStop.Text = "Stop"; - this.buttonStop.UseVisualStyleBackColor = true; - this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click); + this.buttonSettings.Image = global::ElegantRecorder.Properties.Resources.gear; + this.buttonSettings.Location = new System.Drawing.Point(265, 12); + this.buttonSettings.Name = "buttonSettings"; + this.buttonSettings.Size = new System.Drawing.Size(49, 48); + this.buttonSettings.TabIndex = 16; + this.toolTipRec.SetToolTip(this.buttonSettings, "Settings"); + this.buttonSettings.UseVisualStyleBackColor = true; + this.buttonSettings.Click += new System.EventHandler(this.buttonSettings_Click); // // ElegantRecorder // this.BackColor = System.Drawing.SystemColors.Control; - this.ClientSize = new System.Drawing.Size(515, 169); + this.ClientSize = new System.Drawing.Size(380, 95); + this.Controls.Add(this.buttonSettings); + this.Controls.Add(this.buttonPause); + this.Controls.Add(this.buttonRecord); this.Controls.Add(this.buttonStop); - this.Controls.Add(this.buttonBrowseExe); - this.Controls.Add(this.label1); - this.Controls.Add(this.textBoxExeName); this.Controls.Add(this.buttonReplay); - this.Controls.Add(this.buttonRecord); - this.Controls.Add(this.label2); - this.Controls.Add(this.buttonBrowseScript); - this.Controls.Add(this.textBoxScriptName); + this.Controls.Add(this.buttonPin); this.Controls.Add(this.labelStatus); this.Name = "ElegantRecorder"; this.Text = "Elegant Recorder"; - this.TopMost = true; this.ResumeLayout(false); this.PerformLayout(); } #endregion - - private TextBox textBoxScriptName; - private Button buttonBrowseScript; - private Label label2; - private Button buttonRecord; - private Button buttonReplay; private Label labelStatus; - private TextBox textBoxExeName; - private Label label1; - private Button buttonBrowseExe; + private Button buttonPin; + private Button buttonReplay; private Button buttonStop; + private Button buttonRecord; + private Button buttonPause; + private Button buttonSettings; + private ToolTip toolTipRec; } } \ No newline at end of file diff --git a/ElegantRecorder.cs b/ElegantRecorder.cs index f78b8ef..2b49c7a 100644 --- a/ElegantRecorder.cs +++ b/ElegantRecorder.cs @@ -12,8 +12,10 @@ using System.Windows; using System.Windows.Forms; using System.Text.Json.Serialization; +using ElegantRecorder.Properties; +using System.Threading.Tasks; -namespace UIAuto +namespace ElegantRecorder { public partial class ElegantRecorder : Form { @@ -41,10 +43,14 @@ public partial class ElegantRecorder : Form private const int MOUSEEVENTF_RIGHTUP = 0x10; private const int KEYEVENTF_KEYUP = 0x0002; - private string scriptName; - private string exeName; private string status; private Stopwatch stopwatch = new Stopwatch(); + + public string ConfigFileName; + public string ConfigFilePath; + + public ElegantOptions ElegantOptions; + private class UIAction { [JsonPropertyName("event")] @@ -135,6 +141,40 @@ public ElegantRecorder() InitializeComponent(); labelStatus.Text = ""; + + ReadOrCreateConfig(); + } + + private void ReadOrCreateConfig() + { + ConfigFileName = "ElegantRecorderConfig.json"; + ConfigFilePath = System.Windows.Forms.Application.StartupPath + ConfigFileName; + + if (File.Exists(ConfigFilePath)) + { + try + { + ElegantOptions = JsonSerializer.Deserialize(File.ReadAllText(ConfigFilePath)); + } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show("Failed to read configuratin file. " + ex.ToString()); + } + } + else + { + try + { + File.Create(ConfigFilePath).Close(); + + ElegantOptions = new ElegantOptions(); + File.WriteAllText(ConfigFilePath, JsonSerializer.Serialize(ElegantOptions)); + } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show("Failed to create configuration file. " + ex.ToString()); + } + } } public void InstallHooks() @@ -248,7 +288,7 @@ private AutomationElement FindWindowByName(string name) int pid = (int)window.GetCurrentPropertyValue(AutomationElement.ProcessIdProperty); var process = Process.GetProcessById(pid); - if (Path.GetFileNameWithoutExtension(exeName).ToLower() == process.ProcessName.ToLower()) + if (Path.GetFileNameWithoutExtension(ElegantOptions.ExePath).ToLower() == process.ProcessName.ToLower()) return window; } @@ -479,7 +519,7 @@ private void RecordMouseWorker(int wparam) status = elementName + " : " + automationId + " [" + processName + "]"; - if (Path.GetFileNameWithoutExtension(exeName).ToLower() != processName.ToLower()) + if (Path.GetFileNameWithoutExtension(ElegantOptions.ExePath).ToLower() != processName.ToLower()) return; Rect boundingRect = (Rect)topLevelWindow.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); @@ -519,117 +559,160 @@ private void RecordMouseWorker(int wparam) } } - private void buttonBrowse_Click(object sender, EventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; + private bool recording = false; + private bool replaying = false; - if (dialog.ShowDialog() == DialogResult.OK) - { - textBoxScriptName.Text = dialog.FileName; - scriptName = dialog.FileName; - } - } - - private void buttonBrowseExe_Click(object sender, EventArgs e) + private void ResetButtons() { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Filter = "Exe files (*.exe)|*.exe|All files (*.*)|*.*"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - textBoxExeName.Text = dialog.FileName; - exeName = dialog.FileName; - } + recording = false; + replaying = false; + buttonRecord.Image = Resources.record_fill; + buttonReplay.Image = Resources.play_fill; } private void buttonRecord_Click(object sender, EventArgs e) { - if (scriptName == null || scriptName.Length == 0) + if (recording || replaying) + return; + + buttonRecord.Image = Resources.record_edit; + recording = true; + + if (ElegantOptions.RecordingPath.Length == 0) { labelStatus.Text = "Specify recording file"; + return; } - if (exeName == null || exeName.Length == 0) + if (ElegantOptions.RestrictToExe == true && ElegantOptions.ExePath.Length == 0) { labelStatus.Text = "Specify target executable"; + ResetButtons(); return; } - if (!File.Exists(scriptName)) + if (!File.Exists(ElegantOptions.RecordingPath)) { try { - File.Create(scriptName); + File.Create(ElegantOptions.RecordingPath); } catch { labelStatus.Text = "Failed to create script file"; + ResetButtons(); return; } } uiSteps.Clear(); - File.WriteAllText(scriptName, ""); + File.WriteAllText(ElegantOptions.RecordingPath, ""); stopwatch.Reset(); InstallHooks(); - - buttonRecord.Text = "Recording..."; } - private void buttonStop_Click(object sender, EventArgs e) + CancellationTokenSource tokenSource = new CancellationTokenSource(); + CancellationToken token; + + // Use MouseDown istead of Click event to avoid situations where other UI events happen between mouse down and up, due to the automation + private void buttonStop_MouseDown(object sender, MouseEventArgs e) { UninstallHooks(); - buttonRecord.Text = "Record"; stopwatch.Reset(); - File.WriteAllText(scriptName, "[\n"); - - JsonSerializerOptions jsonOptions = new() + if (tokenSource != null) { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull - }; + tokenSource.Cancel(); + } - for (int i = 0; i < uiSteps.Count; i++) + if (recording) { - string jsonString = JsonSerializer.Serialize(uiSteps[i], jsonOptions); - File.AppendAllText(scriptName, jsonString); + File.WriteAllText(ElegantOptions.RecordingPath, "[\n"); - if (i != uiSteps.Count - 1) + JsonSerializerOptions jsonOptions = new() { - File.AppendAllText(scriptName, ",\n"); - } - else + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }; + + for (int i = 0; i < uiSteps.Count; i++) { - File.AppendAllText(scriptName, "\n"); + string jsonString = JsonSerializer.Serialize(uiSteps[i], jsonOptions); + File.AppendAllText(ElegantOptions.RecordingPath, jsonString); + + if (i != uiSteps.Count - 1) + { + File.AppendAllText(ElegantOptions.RecordingPath, ",\n"); + } + else + { + File.AppendAllText(ElegantOptions.RecordingPath, "\n"); + } } + + File.AppendAllText(ElegantOptions.RecordingPath, "]"); } - File.AppendAllText(scriptName, "]"); + ResetButtons(); } - private void buttonReplay_Click(object sender, EventArgs e) + private async void buttonReplay_Click(object sender, EventArgs e) { + if (replaying) + return; + + replaying = true; + buttonReplay.Image = Resources.play_edit; + + tokenSource.Dispose(); + tokenSource = new CancellationTokenSource(); + token = tokenSource.Token; + labelStatus.Text = ""; + status = ""; + + var task = Task.Run(ReplayWorker, token); + try + { + await task; + } + catch (Exception) { } + + labelStatus.Text = status; + + ResetButtons(); + } + + void ReplayWorker() + { var screenBounds = Screen.PrimaryScreen.Bounds; - UIAction[] steps = JsonSerializer.Deserialize(File.ReadAllText(scriptName)); + UIAction[] steps = JsonSerializer.Deserialize(File.ReadAllText(ElegantOptions.RecordingPath)); foreach (var action in steps) { Thread.Sleep((int)action.elapsed); + try + { + token.ThrowIfCancellationRequested(); + } + catch (OperationCanceledException) + { + status = "Replay stopped"; + return; + } + if (action.EventType == "click") { AutomationElement topLevelWindow = FindWindowByName(action.TopLevelWindow); if (topLevelWindow == null) { - labelStatus.Text = "Failed to find window: " + action.TopLevelWindow; + status = "Failed to find window: " + action.TopLevelWindow; return; } @@ -642,7 +725,7 @@ private void buttonReplay_Click(object sender, EventArgs e) if (targetElement == null) { - labelStatus.Text = "Failed to find element: " + action.ControlName; + status = "Failed to find element: " + action.ControlName; } else { @@ -673,7 +756,7 @@ private void buttonReplay_Click(object sender, EventArgs e) else { Cursor.Position = new System.Drawing.Point((int)x, (int)y); - mouse_event((uint) action.Flags, 0, 0, 0, (uint)action.ExtraInfo); + mouse_event((uint)action.Flags, 0, 0, 0, (uint)action.ExtraInfo); } } else if (action.EventType == "keypress") @@ -682,17 +765,20 @@ private void buttonReplay_Click(object sender, EventArgs e) } } - labelStatus.Text = "Replay finished"; + status = "Replay finished"; } - private void textBoxScriptName_TextChanged(object sender, EventArgs e) + private void buttonSettings_Click(object sender, EventArgs e) { - scriptName = textBoxScriptName.Text; + Options options = new Options(this); + options.Show(); } - private void textBoxExeName_TextChanged(object sender, EventArgs e) + private void buttonPin_Click(object sender, EventArgs e) { - exeName = textBoxExeName.Text; + TopMost = !TopMost; + + buttonPin.Image = TopMost ? Resources.geo_edit : Resources.geo; } } } diff --git a/ElegantRecorder.csproj b/ElegantRecorder.csproj index ca78668..72d4d2c 100644 --- a/ElegantRecorder.csproj +++ b/ElegantRecorder.csproj @@ -15,4 +15,17 @@ wrapper + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + \ No newline at end of file diff --git a/ElegantRecorder.csproj.user b/ElegantRecorder.csproj.user index ddec86d..0b48bbe 100644 --- a/ElegantRecorder.csproj.user +++ b/ElegantRecorder.csproj.user @@ -4,5 +4,13 @@ Form + + Form + + + + + Designer + \ No newline at end of file diff --git a/ElegantRecorder.resx b/ElegantRecorder.resx index f298a7b..f1c9b90 100644 --- a/ElegantRecorder.resx +++ b/ElegantRecorder.resx @@ -57,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Options.Designer.cs b/Options.Designer.cs new file mode 100644 index 0000000..530915c --- /dev/null +++ b/Options.Designer.cs @@ -0,0 +1,207 @@ + +namespace ElegantRecorder +{ + partial class Options + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxRecordingPath = new System.Windows.Forms.TextBox(); + this.buttonBrowseScript = new System.Windows.Forms.Button(); + this.checkBoxRestrictToExe = new System.Windows.Forms.CheckBox(); + this.textBoxExePath = new System.Windows.Forms.TextBox(); + this.buttonBrowseExe = new System.Windows.Forms.Button(); + this.groupBoxOptions = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.checkBoxRecMouseMove = new System.Windows.Forms.CheckBox(); + this.groupBoxOptions.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 155); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Recording file"; + // + // buttonOk + // + this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOk.Location = new System.Drawing.Point(426, 208); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "OK"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(507, 208); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // textBoxRecordingPath + // + this.textBoxRecordingPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxRecordingPath.Location = new System.Drawing.Point(112, 151); + this.textBoxRecordingPath.Name = "textBoxRecordingPath"; + this.textBoxRecordingPath.Size = new System.Drawing.Size(388, 23); + this.textBoxRecordingPath.TabIndex = 4; + // + // buttonBrowseScript + // + this.buttonBrowseScript.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonBrowseScript.Location = new System.Drawing.Point(506, 151); + this.buttonBrowseScript.Name = "buttonBrowseScript"; + this.buttonBrowseScript.Size = new System.Drawing.Size(59, 23); + this.buttonBrowseScript.TabIndex = 5; + this.buttonBrowseScript.Text = "..."; + this.buttonBrowseScript.UseVisualStyleBackColor = true; + this.buttonBrowseScript.Click += new System.EventHandler(this.buttonBrowseScript_Click); + // + // checkBoxRestrictToExe + // + this.checkBoxRestrictToExe.AutoSize = true; + this.checkBoxRestrictToExe.Location = new System.Drawing.Point(6, 109); + this.checkBoxRestrictToExe.Name = "checkBoxRestrictToExe"; + this.checkBoxRestrictToExe.Size = new System.Drawing.Size(100, 19); + this.checkBoxRestrictToExe.TabIndex = 6; + this.checkBoxRestrictToExe.Text = "Restrict to exe"; + this.checkBoxRestrictToExe.UseVisualStyleBackColor = true; + // + // textBoxExePath + // + this.textBoxExePath.Location = new System.Drawing.Point(112, 107); + this.textBoxExePath.Name = "textBoxExePath"; + this.textBoxExePath.Size = new System.Drawing.Size(388, 23); + this.textBoxExePath.TabIndex = 7; + // + // buttonBrowseExe + // + this.buttonBrowseExe.Location = new System.Drawing.Point(505, 106); + this.buttonBrowseExe.Name = "buttonBrowseExe"; + this.buttonBrowseExe.Size = new System.Drawing.Size(59, 23); + this.buttonBrowseExe.TabIndex = 8; + this.buttonBrowseExe.Text = "..."; + this.buttonBrowseExe.UseVisualStyleBackColor = true; + this.buttonBrowseExe.Click += new System.EventHandler(this.buttonBrowseExe_Click); + // + // groupBoxOptions + // + this.groupBoxOptions.Controls.Add(this.label2); + this.groupBoxOptions.Controls.Add(this.comboBox1); + this.groupBoxOptions.Controls.Add(this.checkBoxRecMouseMove); + this.groupBoxOptions.Controls.Add(this.label1); + this.groupBoxOptions.Controls.Add(this.buttonBrowseExe); + this.groupBoxOptions.Controls.Add(this.textBoxRecordingPath); + this.groupBoxOptions.Controls.Add(this.textBoxExePath); + this.groupBoxOptions.Controls.Add(this.buttonBrowseScript); + this.groupBoxOptions.Controls.Add(this.checkBoxRestrictToExe); + this.groupBoxOptions.Location = new System.Drawing.Point(12, 12); + this.groupBoxOptions.Name = "groupBoxOptions"; + this.groupBoxOptions.Size = new System.Drawing.Size(571, 180); + this.groupBoxOptions.TabIndex = 9; + this.groupBoxOptions.TabStop = false; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 30); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(88, 15); + this.label2.TabIndex = 11; + this.label2.Text = "Playback speed"; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Items.AddRange(new object[] { + "Fastest", + "Fast", + "Normal", + "Slow", + "Slowest"}); + this.comboBox1.Location = new System.Drawing.Point(100, 27); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(84, 23); + this.comboBox1.TabIndex = 10; + // + // checkBoxRecMouseMove + // + this.checkBoxRecMouseMove.AutoSize = true; + this.checkBoxRecMouseMove.Location = new System.Drawing.Point(6, 67); + this.checkBoxRecMouseMove.Name = "checkBoxRecMouseMove"; + this.checkBoxRecMouseMove.Size = new System.Drawing.Size(135, 19); + this.checkBoxRecMouseMove.TabIndex = 9; + this.checkBoxRecMouseMove.Text = "Record mouse move"; + this.checkBoxRecMouseMove.UseVisualStyleBackColor = true; + // + // Options + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(594, 243); + this.Controls.Add(this.groupBoxOptions); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Name = "Options"; + this.Text = "Elegant Recorder Options"; + this.groupBoxOptions.ResumeLayout(false); + this.groupBoxOptions.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button buttonOk; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.TextBox textBoxRecordingPath; + private System.Windows.Forms.Button buttonBrowseScript; + private System.Windows.Forms.CheckBox checkBoxRestrictToExe; + private System.Windows.Forms.TextBox textBoxExePath; + private System.Windows.Forms.Button buttonBrowseExe; + private System.Windows.Forms.GroupBox groupBoxOptions; + private System.Windows.Forms.CheckBox checkBoxRecMouseMove; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox comboBox1; + } +} \ No newline at end of file diff --git a/Options.cs b/Options.cs new file mode 100644 index 0000000..6ba7523 --- /dev/null +++ b/Options.cs @@ -0,0 +1,74 @@ +using System; +using System.IO; +using System.Text.Json; +using System.Windows.Forms; + +namespace ElegantRecorder +{ + public partial class Options : Form + { + private ElegantRecorder elegantRecorder; + + public Options(ElegantRecorder elegantRecorder) + { + InitializeComponent(); + + this.elegantRecorder = elegantRecorder; + var elegantOptions = elegantRecorder.ElegantOptions; + + checkBoxRecMouseMove.Checked = elegantOptions.RecordMouseMove; + checkBoxRestrictToExe.Checked = elegantOptions.RestrictToExe; + textBoxExePath.Text = elegantOptions.ExePath; + textBoxRecordingPath.Text = elegantOptions.RecordingPath; + + + textBoxExePath.Enabled = checkBoxRestrictToExe.Checked; + buttonBrowseExe.Enabled = checkBoxRestrictToExe.Checked; + } + + public void SaveOptions() + { + var elegantOptions = elegantRecorder.ElegantOptions; + + elegantOptions.RecordMouseMove = checkBoxRecMouseMove.Checked; + elegantOptions.RestrictToExe = checkBoxRestrictToExe.Checked; + elegantOptions.ExePath = textBoxExePath.Text; + elegantOptions.RecordingPath = textBoxRecordingPath.Text; + + File.WriteAllText(elegantRecorder.ConfigFilePath, JsonSerializer.Serialize(elegantOptions)); + } + + private void buttonBrowseScript_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + textBoxRecordingPath.Text = dialog.FileName; + } + } + + private void buttonBrowseExe_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Exe files (*.exe)|*.exe|All files (*.*)|*.*"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + textBoxExePath.Text = dialog.FileName; + } + } + + private void buttonOk_Click(object sender, EventArgs e) + { + SaveOptions(); + Close(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/Options.resx b/Options.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Options.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs index fd5b7ac..2841e2a 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; -namespace UIAuto +namespace ElegantRecorder { static class Program { diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..2489568 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ElegantRecorder.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ElegantRecorder.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap gear { + get { + object obj = ResourceManager.GetObject("gear", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap geo { + get { + object obj = ResourceManager.GetObject("geo", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap geo_edit { + get { + object obj = ResourceManager.GetObject("geo_edit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap pause_fill { + get { + object obj = ResourceManager.GetObject("pause_fill", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap play_edit { + get { + object obj = ResourceManager.GetObject("play_edit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap play_fill { + get { + object obj = ResourceManager.GetObject("play_fill", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap record_edit { + get { + object obj = ResourceManager.GetObject("record_edit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap record_fill { + get { + object obj = ResourceManager.GetObject("record_fill", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap stop_fill { + get { + object obj = ResourceManager.GetObject("stop_fill", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..8a4c397 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\record-fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\play-fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\pause-fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\gear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\stop-fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\geo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\geo-edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\play-edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\record-edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Resources/gear.png b/Resources/gear.png new file mode 100644 index 0000000..df993ed Binary files /dev/null and b/Resources/gear.png differ diff --git a/Resources/geo-edit.png b/Resources/geo-edit.png new file mode 100644 index 0000000..bf15c70 Binary files /dev/null and b/Resources/geo-edit.png differ diff --git a/Resources/geo.png b/Resources/geo.png new file mode 100644 index 0000000..fae317b Binary files /dev/null and b/Resources/geo.png differ diff --git a/Resources/pause-fill.png b/Resources/pause-fill.png new file mode 100644 index 0000000..d90bc7d Binary files /dev/null and b/Resources/pause-fill.png differ diff --git a/Resources/play-edit.png b/Resources/play-edit.png new file mode 100644 index 0000000..90b196d Binary files /dev/null and b/Resources/play-edit.png differ diff --git a/Resources/play-fill.png b/Resources/play-fill.png new file mode 100644 index 0000000..52a89bf Binary files /dev/null and b/Resources/play-fill.png differ diff --git a/Resources/record-edit.png b/Resources/record-edit.png new file mode 100644 index 0000000..50e349f Binary files /dev/null and b/Resources/record-edit.png differ diff --git a/Resources/record-fill.png b/Resources/record-fill.png new file mode 100644 index 0000000..5f5e799 Binary files /dev/null and b/Resources/record-fill.png differ diff --git a/Resources/stop-fill.png b/Resources/stop-fill.png new file mode 100644 index 0000000..377a4db Binary files /dev/null and b/Resources/stop-fill.png differ