Adapted main page for futur data integration
This commit is contained in:
+34
-15
@@ -15,8 +15,9 @@ namespace Test_Merge
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
Reader Reader = null;
|
||||
F1TVEmulator Emulator = null;
|
||||
//private Reader Reader = null;
|
||||
private F1TVEmulator Emulator = null;
|
||||
private DataWrapper Wrapper = null;
|
||||
private bool cancelRequested = false;
|
||||
private SemaphoreSlim semaphore = new SemaphoreSlim(1);
|
||||
|
||||
@@ -29,7 +30,11 @@ namespace Test_Merge
|
||||
}
|
||||
public async void RefreshUI()
|
||||
{
|
||||
|
||||
if (Directory.Exists(ConfigurationTool.CONFIGS_FOLDER_NAME))
|
||||
{
|
||||
lsbPresets.DataSource = null;
|
||||
lsbPresets.DataSource = Directory.GetFiles(ConfigurationTool.CONFIGS_FOLDER_NAME);
|
||||
}
|
||||
}
|
||||
private async void btnSettings_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -61,12 +66,16 @@ namespace Test_Merge
|
||||
//Those are the default values but they will need to be changed later when the configuration has been done
|
||||
ConfigFile = "./Presets/Clean_4K_2023.json";
|
||||
GpUrl = "https://f1tv.formula1.com/detail/1000006688/2023-azerbaijan-grand-prix?action=play";
|
||||
|
||||
textBox1.Text = GpUrl;
|
||||
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private async void btnUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
cancelRequested = false;
|
||||
if (Emulator != null && Reader != null)
|
||||
if (Emulator != null && Wrapper != null)
|
||||
{
|
||||
// Disable UI controls to prevent re-entrancy
|
||||
btnStartDecoding.Enabled = false;
|
||||
@@ -86,14 +95,15 @@ namespace Test_Merge
|
||||
|
||||
Bitmap screen = Emulator.Screenshot();
|
||||
screen.Save("HopefullyDataScreenshot.png");
|
||||
Reader.ChangeImage(screen);
|
||||
|
||||
string result = await Reader.Decode(Reader.MainZones, Reader.Drivers);
|
||||
Wrapper.ChangeImage(screen);
|
||||
int errorCode = await Wrapper.Refresh();
|
||||
|
||||
sw.Stop();
|
||||
// Task completed
|
||||
Invoke((MethodInvoker)delegate
|
||||
{
|
||||
DisplayResults(result, sw, screen);
|
||||
DisplayResults(errorCode,sw, screen);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -115,19 +125,16 @@ namespace Test_Merge
|
||||
Emulator.Stop();
|
||||
}
|
||||
}
|
||||
private void DisplayResults(string result, Stopwatch sw, Bitmap screen)
|
||||
private void DisplayResults(int errorCode,Stopwatch sw, Bitmap screen)
|
||||
{
|
||||
if (result == "")
|
||||
if (errorCode != 0)
|
||||
{
|
||||
cancelRequested = true;
|
||||
MessageBox.Show("An error has occured while trying to recover data from live feed. This can happen sometimes. I would advise you to restart a few times. If the problem persists check your configuration.");
|
||||
}
|
||||
else
|
||||
{
|
||||
tbxResult.Text = "";
|
||||
tbxResult.Text = "Decoding done in :" + sw.ElapsedMilliseconds + "ms" + Environment.NewLine;
|
||||
tbxResult.Text += result;
|
||||
pbxResult.Image = screen;
|
||||
Wrapper.DisplayLiveRanking(pnlLiveRanking);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +157,7 @@ namespace Test_Merge
|
||||
Emulator.ResetDriver();
|
||||
|
||||
Emulator = null;
|
||||
Reader = null;
|
||||
Wrapper = null;
|
||||
|
||||
Emulator = new F1TVEmulator(GpUrl);
|
||||
errorCode = await Emulator.Start();
|
||||
@@ -164,11 +171,23 @@ namespace Test_Merge
|
||||
}
|
||||
else
|
||||
{
|
||||
Reader = new Reader(ConfigFile, Emulator.Screenshot(), true);
|
||||
Wrapper = new DataWrapper(ConfigFile, Emulator.Screenshot());
|
||||
btnResetEmulator.Enabled = true;
|
||||
btnSettings.Enabled = true;
|
||||
btnStartDecoding.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (lsbPresets.SelectedIndex >= 0)
|
||||
ConfigFile = lsbPresets.Items[lsbPresets.SelectedIndex].ToString();
|
||||
}
|
||||
|
||||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (tbxResult.Text != "")
|
||||
GpUrl = textBox1.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user