Skip to content

Commit

Permalink
Read recording headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaifm committed Nov 11, 2022
1 parent 3502fc1 commit 950f610
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 78 deletions.
87 changes: 52 additions & 35 deletions ElegantRecorder/ElegantRecorder.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 35 additions & 13 deletions ElegantRecorder/ElegantRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Windows.Forms;
using ElegantRecorder.Properties;
Expand All @@ -17,7 +18,8 @@ public partial class ElegantRecorder : Form
public WinAPI WinAPI;
public AutomationEngine AutomationEngine;

public List<UIAction> UISteps = new List<UIAction>();
public Dictionary<string, Recording> RecHeaders = new();
public List<UIAction> UISteps = new();

public string CurrentRecordingName = "";

Expand All @@ -27,17 +29,17 @@ public partial class ElegantRecorder : Form
private Stopwatch stopwatch = new Stopwatch();

public int CurrentHotkeyId = 8;
public Dictionary<int, string> RecHotkeys = new Dictionary<int, string>();
public Dictionary<int, string> RecHotkeys = new();

public ElegantRecorder()
{
InitializeComponent();

ReadOrCreateConfig();
ReadCurrentRecordings();

WinAPI = new WinAPI(this);

ReadOrCreateConfig();
ReadRecordingHeaders();

AutomationEngine = null;

if (ElegantOptions.AutomationEngine == "Win32")
Expand Down Expand Up @@ -100,19 +102,39 @@ private void ReadOrCreateConfig()
}
}

public void ReadCurrentRecordings()
public void ReadRecordingHeaders()
{
dataGridViewRecordings.Rows.Clear();
RecHeaders.Clear();

foreach (var file in Directory.GetFiles(ElegantOptions.DataFolder))
foreach (var file in Directory.GetFiles(ElegantOptions.DataFolder, "*.json"))
{
using StreamReader stream = new StreamReader(file);
char[] buffer = new char[32];
using FileStream stream = new FileStream(file, FileMode.Open);
byte[] buffer = new byte[32];
stream.Read(buffer, 0, 32);

if ((new string(buffer)).Contains(Recording.DefaultTag))
if (Encoding.UTF8.GetString(buffer).Contains(Recording.DefaultTag))
{
dataGridViewRecordings.Rows.Add(Path.GetFileNameWithoutExtension(file), "");
stream.Position = 0;

var tag = "\"UIActions\":";
string header = Recording.ReadUntil(stream, "\"UIActions\":");
header += tag + "[]}";

string recName = Path.GetFileNameWithoutExtension(file);
var rec = new Recording(this, recName);
rec.Deserialize(header);
RecHeaders.Add(recName, rec);

string hotkeyStr = "";
if (rec.Triggers.Hotkey != 0)
{
hotkeyStr = WinAPI.HotkeyToStr(rec.Triggers.Hotkey);
}

dataGridViewRecordings.Rows.Add(recName, hotkeyStr, rec.Encrypted ? Resources.lock_edit : Resources.empty);

rec.ArmTriggers();
}
}

Expand Down Expand Up @@ -604,7 +626,7 @@ private void DeleteRecording()
var currentFile = Path.Combine(ElegantOptions.DataFolder, CurrentRecordingName + ".json");
File.Delete(currentFile);

ReadCurrentRecordings();
ReadRecordingHeaders();
}
}
}
Expand Down Expand Up @@ -646,7 +668,7 @@ private void dataGridViewRecordings_MouseDown(object sender, MouseEventArgs e)

private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
ReadCurrentRecordings();
ReadRecordingHeaders();
}

private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions ElegantRecorder/ElegantRecorder.resx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<metadata name="Recordings.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Hotkey.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Indicator.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down
4 changes: 1 addition & 3 deletions ElegantRecorder/Options.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Windows.Forms;

namespace ElegantRecorder
Expand Down Expand Up @@ -63,7 +61,7 @@ public void SaveOptions()
App.ElegantOptions.Save(App.ConfigFilePath);
Rec.Save(false);

App.ReadCurrentRecordings();
App.ReadRecordingHeaders();
}

private void ChangeAutomationEngine()
Expand Down
20 changes: 20 additions & 0 deletions ElegantRecorder/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ElegantRecorder/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@
<data name="stopwatch" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\stopwatch.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="empty" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\empty.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="lock_edit" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\lock-edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Loading

0 comments on commit 950f610

Please sign in to comment.