diff --git a/ElegantRecorder/ElegantRecorder.cs b/ElegantRecorder/ElegantRecorder.cs index 8a354ef..c8c0c65 100644 --- a/ElegantRecorder/ElegantRecorder.cs +++ b/ElegantRecorder/ElegantRecorder.cs @@ -126,7 +126,7 @@ public void ReadRecordingHeaders() stream.Position = 0; var tag = "\"UIActions\":"; - string header = global::ElegantRecorder.Recording.ReadUntil(stream, "\"UIActions\":"); + string header = Util.ReadUntil(stream, "\"UIActions\":"); header += tag + "[]}"; string recName = Path.GetFileNameWithoutExtension(file); @@ -269,6 +269,16 @@ private void LockUI(bool disabled) textBoxNewRec.Enabled = !disabled; } + public void RefreshCurrentRow(Recording rec) + { + if (rec.Triggers.Hotkey != 0) + dataGridViewRecordings.SelectedRows[0].Cells[1].Value = Util.HotkeyToString(rec.Triggers.Hotkey); + else + dataGridViewRecordings.SelectedRows[0].Cells[1].Value = ""; + + dataGridViewRecordings.SelectedRows[0].Cells[2].Value = rec.Encrypted ? Resources.lock_edit : Resources.empty; + } + private void buttonRecord_Click(object sender, EventArgs e) { Record(); @@ -391,7 +401,7 @@ private void buttonReplay_Click(object sender, EventArgs e) public void Replay(string recording) { - if (Replaying) + if (Recording || Replaying) return; ResetButtons(); diff --git a/ElegantRecorder/ElegantTriggers.cs b/ElegantRecorder/ElegantTriggers.cs index f288841..321be02 100644 --- a/ElegantRecorder/ElegantTriggers.cs +++ b/ElegantRecorder/ElegantTriggers.cs @@ -22,7 +22,7 @@ public ElegantTriggers(ElegantRecorder elegantRecorder) Rec.Load(); checkBoxHotkey.Checked = Rec.Triggers.HotkeyEnabled; - textBoxHotkey.Text = string.Join("+", ((Keys)Rec.Triggers.Hotkey).ToString().Split(", ").Reverse()); + textBoxHotkey.Text = Util.HotkeyToString(Rec.Triggers.Hotkey); hotkeyData = Rec.Triggers.Hotkey; checkBoxTime.Checked = Rec.Triggers.TimeEnabled; dateTimePickerDate.Value = Rec.Triggers.Date; @@ -76,6 +76,7 @@ private void buttonCancel_Click(object sender, EventArgs e) private void buttonOk_Click(object sender, EventArgs e) { SaveTriggers(); + App.RefreshCurrentRow(Rec); Close(); } @@ -125,7 +126,7 @@ private void TriggerEditor_KeyDown(object sender, KeyEventArgs e) if (e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.Menu) return; - textBoxHotkey.Text = string.Join("+", e.KeyData.ToString().Split(", ").Reverse()); + textBoxHotkey.Text = Util.HotkeyToString((int) e.KeyData); hotkeyData = (int)e.KeyData; e.SuppressKeyPress = true; diff --git a/ElegantRecorder/Recording.cs b/ElegantRecorder/Recording.cs index 46585aa..3c5b8d3 100644 --- a/ElegantRecorder/Recording.cs +++ b/ElegantRecorder/Recording.cs @@ -326,52 +326,5 @@ public void DisarmTriggers() App.TriggerData.RecRec.Remove(Name); } } - - public static string ReadUntil(FileStream Stream, string UntilText) - { - System.Text.StringBuilder builder = new System.Text.StringBuilder(); - System.Text.StringBuilder returnTextBuilder = new System.Text.StringBuilder(); - string returnText = string.Empty; - int size = Convert.ToInt32(UntilText.Length / (double)2) - 1; - byte[] buffer = new byte[size + 1]; - int currentRead = -1; - - while (currentRead != 0) - { - string collected = null; - string chars = null; - int foundIndex = -1; - - currentRead = Stream.Read(buffer, 0, buffer.Length); - chars = System.Text.Encoding.Default.GetString(buffer, 0, currentRead); - - builder.Append(chars); - returnTextBuilder.Append(chars); - - collected = builder.ToString(); - foundIndex = collected.IndexOf(UntilText); - - if (foundIndex >= 0) - { - returnText = returnTextBuilder.ToString(); - - int indexOfSep = returnText.IndexOf(UntilText); - int cutLength = returnText.Length - indexOfSep; - - returnText = returnText.Remove(indexOfSep, cutLength); - - builder.Remove(0, foundIndex + UntilText.Length); - - if (cutLength > UntilText.Length) - Stream.Position -= cutLength - UntilText.Length; - - return returnText; - } - else if (!collected.Contains(UntilText.First())) - builder.Length = 0; - } - - return string.Empty; - } } } diff --git a/ElegantRecorder/Util.cs b/ElegantRecorder/Util.cs new file mode 100644 index 0000000..bbad947 --- /dev/null +++ b/ElegantRecorder/Util.cs @@ -0,0 +1,62 @@ +using System.Windows.Forms; +using System.Linq; +using System.IO; +using System; + +namespace ElegantRecorder +{ + public static class Util + { + public static string HotkeyToString(int hotkey) + { + return string.Join("+", ((Keys)hotkey).ToString().Split(", ").Reverse()); + } + + public static string ReadUntil(FileStream Stream, string UntilText) + { + System.Text.StringBuilder builder = new System.Text.StringBuilder(); + System.Text.StringBuilder returnTextBuilder = new System.Text.StringBuilder(); + string returnText = string.Empty; + int size = Convert.ToInt32(UntilText.Length / (double)2) - 1; + byte[] buffer = new byte[size + 1]; + int currentRead = -1; + + while (currentRead != 0) + { + string collected = null; + string chars = null; + int foundIndex = -1; + + currentRead = Stream.Read(buffer, 0, buffer.Length); + chars = System.Text.Encoding.Default.GetString(buffer, 0, currentRead); + + builder.Append(chars); + returnTextBuilder.Append(chars); + + collected = builder.ToString(); + foundIndex = collected.IndexOf(UntilText); + + if (foundIndex >= 0) + { + returnText = returnTextBuilder.ToString(); + + int indexOfSep = returnText.IndexOf(UntilText); + int cutLength = returnText.Length - indexOfSep; + + returnText = returnText.Remove(indexOfSep, cutLength); + + builder.Remove(0, foundIndex + UntilText.Length); + + if (cutLength > UntilText.Length) + Stream.Position -= cutLength - UntilText.Length; + + return returnText; + } + else if (!collected.Contains(UntilText.First())) + builder.Length = 0; + } + + return string.Empty; + } + } +}