Work done so far

This commit is contained in:
minster586
2026-08-11 22:42:01 -04:00
parent da5fb64400
commit 02bd8ffd5e
10 changed files with 1321 additions and 256 deletions
+81 -1
View File
@@ -45,7 +45,7 @@ namespace PainoBar_Helper
throw new ArgumentException($"Profile '{profileName}' does not exist.");
_activeProfileName = profileName;
SaveProfiles();
SaveProfiles(); // Save immediately to persist the active profile
ActiveProfileChanged?.Invoke(this, EventArgs.Empty);
}
@@ -155,6 +155,10 @@ namespace PainoBar_Helper
if (!string.IsNullOrEmpty(configDir))
Directory.CreateDirectory(configDir);
// Generate event command script path
var eventCmdPath = Path.Combine(configDir, "eventcmd.cmd");
GenerateEventCommandScript(eventCmdPath, profile);
var sb = new StringBuilder();
sb.AppendLine("# Pianobar configuration file");
sb.AppendLine($"# Generated by Pianobar Helper for profile: {profile.Name}");
@@ -169,6 +173,16 @@ namespace PainoBar_Helper
sb.AppendLine();
}
// Add event command directive
sb.AppendLine($"event_command = \"{eventCmdPath}\"");
sb.AppendLine();
// Additional settings for better integration
sb.AppendLine("# Output formatting");
sb.AppendLine("format_nowplaying_song = %t|%a|%l|%r");
sb.AppendLine("format_station_list = %i) %n");
sb.AppendLine();
File.WriteAllText(settings.ConfigFilePath, sb.ToString());
}
catch (Exception ex)
@@ -177,6 +191,53 @@ namespace PainoBar_Helper
}
}
private void GenerateEventCommandScript(string scriptPath, Profile profile)
{
try
{
// Create the directory for the event output file
var appDataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"PianobarHelper"
);
Directory.CreateDirectory(appDataPath);
var eventOutputPath = Path.Combine(appDataPath, $"events_{profile.Name}.json");
// Generate Windows batch script for event handling
var sb = new StringBuilder();
sb.AppendLine("@echo off");
sb.AppendLine("REM Pianobar event command script");
sb.AppendLine("REM Generated by Pianobar Helper");
sb.AppendLine();
sb.AppendLine($"set \"EVENT_OUTPUT={eventOutputPath}\"");
sb.AppendLine();
sb.AppendLine("REM Create JSON output for the event");
sb.AppendLine("(");
sb.AppendLine(" echo {");
sb.AppendLine(" echo \"event\": \"%1\",");
sb.AppendLine(" echo \"timestamp\": \"%date% %time%\",");
sb.AppendLine(" echo \"artist\": \"%artist%\",");
sb.AppendLine(" echo \"title\": \"%title%\",");
sb.AppendLine(" echo \"album\": \"%album%\",");
sb.AppendLine(" echo \"coverArt\": \"%coverArt%\",");
sb.AppendLine(" echo \"stationName\": \"%stationName%\",");
sb.AppendLine(" echo \"songDuration\": \"%songDuration%\",");
sb.AppendLine(" echo \"songPlayed\": \"%songPlayed%\",");
sb.AppendLine(" echo \"rating\": \"%rating%\",");
sb.AppendLine(" echo \"detailUrl\": \"%detailUrl%\"");
sb.AppendLine(" echo }");
sb.AppendLine(") > \"%EVENT_OUTPUT%\"");
sb.AppendLine();
sb.AppendLine("exit /b 0");
File.WriteAllText(scriptPath, sb.ToString());
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to generate event command script: {ex.Message}", ex);
}
}
public string? GetActiveConfigPath()
{
var activeProfile = GetActiveProfile();
@@ -184,6 +245,19 @@ namespace PainoBar_Helper
return activeProfile.Settings.ConfigFilePath;
return null;
}
public string? GetEventOutputPath()
{
var activeProfile = GetActiveProfile();
if (activeProfile == null)
return null;
var appDataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"PianobarHelper"
);
return Path.Combine(appDataPath, $"events_{activeProfile.Name}.json");
}
}
public class Profile
@@ -194,6 +268,9 @@ namespace PainoBar_Helper
public class ProfileSettings
{
// Pianobar Path
public string PianobarPath { get; set; } = "pianobar.exe";
// Output Settings
public bool EnableTextFile { get; set; }
public string TextFilePath { get; set; } = string.Empty;
@@ -209,6 +286,9 @@ namespace PainoBar_Helper
public string ConfigFilePath { get; set; } = string.Empty;
public string PianobarUser { get; set; } = string.Empty;
public string PianobarPassword { get; set; } = string.Empty;
// Process Management
public bool KillProcessOnDisconnect { get; set; }
}
internal class ProfileData