Work done so far
This commit is contained in:
+33
-7
@@ -6,6 +6,7 @@ namespace PainoBar_Helper
|
||||
private List<string> _stations;
|
||||
private List<string> _filteredStations;
|
||||
private bool _stationsLoaded = false;
|
||||
private bool _stationEntriesStarted = false;
|
||||
|
||||
public StationForm(PianobarManager pianobarManager)
|
||||
{
|
||||
@@ -16,7 +17,6 @@ namespace PainoBar_Helper
|
||||
_filteredStations = new List<string>();
|
||||
|
||||
InitializeControls();
|
||||
LoadStations();
|
||||
}
|
||||
|
||||
#region Initialization
|
||||
@@ -32,8 +32,21 @@ namespace PainoBar_Helper
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
base.OnShown(e);
|
||||
|
||||
if (!_stationsLoaded)
|
||||
LoadStations();
|
||||
}
|
||||
|
||||
private void LoadStations()
|
||||
{
|
||||
_stations.Clear();
|
||||
_filteredStations.Clear();
|
||||
_stationsLoaded = false;
|
||||
_stationEntriesStarted = false;
|
||||
|
||||
// Subscribe to output to capture station list
|
||||
_pianobarManager.OutputReceived += PianobarManager_OutputReceived;
|
||||
|
||||
@@ -62,28 +75,41 @@ namespace PainoBar_Helper
|
||||
|
||||
private void PianobarManager_OutputReceived(object? sender, string e)
|
||||
{
|
||||
var line = StripAnsiCodes(e).Trim();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
return;
|
||||
|
||||
// Parse station list from Pianobar output
|
||||
// Format is typically: "0) Station Name"
|
||||
var match = System.Text.RegularExpressions.Regex.Match(e, @"^\s*(\d+)\)\s*(.+)$");
|
||||
// Handles formats like: "0) Station", "*0) Station", " 12) Station"
|
||||
var match = System.Text.RegularExpressions.Regex.Match(line, @"^\s*\*?\s*(\d+)\)\s*(.+)$");
|
||||
if (match.Success)
|
||||
{
|
||||
_stationEntriesStarted = true;
|
||||
string stationName = match.Groups[2].Value.Trim();
|
||||
if (!_stations.Contains(stationName))
|
||||
{
|
||||
_stations.Add(stationName);
|
||||
Invoke(() => UpdateStationList());
|
||||
if (!IsDisposed && IsHandleCreated)
|
||||
BeginInvoke(() => UpdateStationList());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect end of station list
|
||||
if (e.Contains("Select station:") || e.Contains("[?]"))
|
||||
// Detect end of station list only after we started receiving entries
|
||||
if (_stationEntriesStarted && line.Contains("Select station:", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_stationsLoaded = true;
|
||||
_pianobarManager.OutputReceived -= PianobarManager_OutputReceived;
|
||||
Invoke(() => FinalizeStationList());
|
||||
if (!IsDisposed && IsHandleCreated)
|
||||
BeginInvoke(() => FinalizeStationList());
|
||||
}
|
||||
}
|
||||
|
||||
private static string StripAnsiCodes(string value)
|
||||
{
|
||||
return System.Text.RegularExpressions.Regex.Replace(value, @"\x1B\[[0-9;]*[A-Za-z]", string.Empty);
|
||||
}
|
||||
|
||||
private void UpdateStationList()
|
||||
{
|
||||
if (lstStations == null)
|
||||
|
||||
Reference in New Issue
Block a user