public static string Create(NotificationConfig config) { List <string> result = new List <string>(); result.Add($"{nameof(config.TemplateName)}={config.TemplateName}"); result.Add($"{nameof(config.Background)}={config.Background}"); result.Add($"{nameof(config.CaptionForeground)}={config.CaptionForeground}"); result.Add($"{nameof(config.AppNameColor)}={config.AppNameColor}"); result.Add($"{nameof(config.StatusTextForeground)}={config.StatusTextForeground}"); result.Add($"{nameof(config.StaticName)}={config.StaticName}"); result.Add($"{nameof(config.StatusText)}={config.StatusText}"); result.Add($"{nameof(config.AppName)}={config.AppName}"); result.Add($"{nameof(config.IconLocation)}={config.IconLocation}"); result.Add($"{nameof(config.NotificationSound)}={config.NotificationSound}"); return(string.Join("\n", result)); }
public static NotificationConfig ParseN(string file) { NotificationConfig result = new NotificationConfig(); int cLine = 0; try { List <string> lines = new List <string>(); using (StreamReader sr = new StreamReader(file)) { while (!sr.EndOfStream) { lines.Add(sr.ReadLine()); } } foreach (var(i, index) in lines.WithIndex()) { cLine = index + 1; if (i.StartsWith('#') || string.IsNullOrEmpty(i)) { continue; } string[] line = i.Split('='); if (line.Length != 2) { throw new InvalidDataException(); } line[1] = ReplaceVariables(line[1]); switch (line[0]) { case "TemplateName": result.TemplateName = line[1]; break; case "Background": result.Background = line[1]; break; case "CaptionForeground": result.CaptionForeground = line[1]; break; case "AppNameColor": result.AppNameColor = line[1]; break; case "StatusTextForeground": result.StatusTextForeground = line[1]; break; case "StaticName": result.StaticName = line[1]; break; case "StatusText": result.StatusText = line[1]; break; case "AppName": result.AppName = line[1]; break; case "IconLocation": result.IconLocation = line[1]; break; case "NotificationSound": result.NotificationSound = line[1]; break; default: throw new InvalidDataException(); } } } catch (Exception) { Helper.Error("AirPodsUI", "Unable to parse configuration at line " + cLine); Environment.Exit(-1); } return(result); }