public static string Create(PencilConfig 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.DeviceNameTextForeground)}={config.DeviceNameTextForeground}"); result.Add($"{nameof(config.StatusTextForeground)}={config.StatusTextForeground}"); result.Add($"{nameof(config.DeviceNameTextForeground)}={config.DeviceNameTextForeground}"); result.Add($"{nameof(config.StaticName)}={config.StaticName}"); result.Add($"{nameof(config.StatusText)}={config.StatusText}"); result.Add($"{nameof(config.IconLocation)}={config.IconLocation}"); return(string.Join("\n", result)); }
public static PencilConfig ParseP(string file) { PencilConfig result = new PencilConfig(); 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 "DeviceNameTextForeground": result.DeviceNameTextForeground = 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 "IconLocation": result.IconLocation = line[1]; break; default: throw new InvalidDataException(); } } } catch (Exception) { Helper.Error("AirPodsUI", "Unable to parse configuration at line " + cLine); Environment.Exit(-1); } return(result); }