2 using System.Collections.Generic;
5 namespace DirectOutput.LedControl.Loader
12 private int _LedWizNumber = 0;
20 public int LedWizNumber
22 get {
return _LedWizNumber; }
23 set { _LedWizNumber = value; }
38 get {
return _TableConfigurations; }
39 set { _TableConfigurations = value; }
52 get {
return _ColorConfigurations; }
53 set { _ColorConfigurations = value; }
72 private void ParseLedControlIni(FileInfo LedControlIniFile,
bool ThrowExceptions =
false)
74 string[] ColorStartStrings = {
"[Colors DOF]",
"[Colors LedWiz]"};
75 string[] OutStartStrings = {
"[Config DOF]",
"[Config outs]"};
81 Data = General.FileReader.ReadFileToString(LedControlIniFile);
85 Log.Exception(
"Could not read file {0}.".Build(LedControlIniFile), E);
89 throw new Exception(
"Could not read file {0}.".Build(LedControlIniFile), E);
92 if (Data.IsNullOrWhiteSpace())
94 Log.Warning(
"File {0} does not contain data.".Build(LedControlIniFile));
97 throw new Exception(
"File {0} does not contain data.".Build(LedControlIniFile));
103 string ColorStartString=
"";
104 foreach (
string S
in ColorStartStrings)
106 ColorStart = Data.IndexOf(S, StringComparison.InvariantCultureIgnoreCase);
108 if (ColorStart >= 0)
break;
111 string OutStartString =
"";
112 foreach (
string S
in OutStartStrings)
114 OutStart = Data.IndexOf(S, StringComparison.InvariantCultureIgnoreCase);
116 if (OutStart >= 0)
break;
121 Log.Exception(
"Could not find color definition section in file {0}.".Build(LedControlIniFile));
124 throw new Exception(
"Could not find color definition section in file {0}.".Build(LedControlIniFile));
131 Log.Exception(
"Could not find table config section in file {0}.".Build(LedControlIniFile));
134 throw new Exception(
"Could not find table config section section in file {1}.".Build(LedControlIniFile));
143 if (ColorStart < OutStart)
145 ColorData = Data.Substring(ColorStart + ColorStartString.Length, OutStart - (ColorStart + ColorStartString.Length)).Split(
new string[] {
"\r\n",
"\n" }, StringSplitOptions.RemoveEmptyEntries);
146 OutData = Data.Substring(OutStart + OutStartString.Length).Split(
new string[] {
"\r\n",
"\n" }, StringSplitOptions.RemoveEmptyEntries);
150 OutData = Data.Substring(OutStart + OutStartString.Length, ColorStart - (OutStart + OutStartString.Length)).Split(
new string[] {
"\r\n",
"\n" }, StringSplitOptions.RemoveEmptyEntries);
151 ColorData = Data.Substring(ColorStart + ColorStartString.Length).Split(
new string[] {
"\r\n",
"\n" }, StringSplitOptions.RemoveEmptyEntries);
155 if (OutData.Length == 0)
157 Log.Exception(
"File {1} does not contain data in the {0} section.".Build(OutStartString, LedControlIniFile));
160 throw new Exception(
"File {1} does not contain data in the {0} section.".Build(OutStartString, LedControlIniFile));
165 if (ColorData.Length == 0)
167 Log.Exception(
"File {1} does not contain data in the {0} section.".Build(ColorStartString, LedControlIniFile));
170 throw new Exception(
"File {1} does not contain data in the {0} section.".Build(ColorStartString, LedControlIniFile));
177 ColorConfigurations.ParseLedControlData(ColorData, ThrowExceptions);
179 TableConfigurations.ParseLedcontrolData(OutData, ThrowExceptions);
181 ResolveOutputNumbers();
185 private void ResolveRGBColors()
188 foreach (TableConfig TC
in TableConfigurations)
190 foreach (TableConfigColumn C
in TC.Columns)
192 foreach (TableConfigSetting S
in C)
194 if (ColorConfigurations.Contains(S.ColorName))
196 ColorConfig CC = ColorConfigurations[S.ColorName];
208 private void ResolveOutputNumbers()
211 Dictionary<int, int> RequiredOutputs =
new Dictionary<int, int>();
212 foreach (TableConfig TC
in TableConfigurations)
215 foreach (TableConfigColumn C
in TC.Columns)
217 foreach (TableConfigSetting S
in C)
220 if (RequiredOutputs.ContainsKey(C.Number))
223 if (RequiredOutputs[C.Number] < Cnt)
225 RequiredOutputs[C.Number] = Cnt;
230 RequiredOutputs.Add(C.Number, Cnt);
284 public LedControlConfig(
string LedControlIniFilename,
int LedWizNumber,
bool ThrowExceptions =
false)
287 ParseLedControlIni(
new FileInfo(LedControlIniFilename), ThrowExceptions);
288 this.LedWizNumber = LedWizNumber;
305 public LedControlConfig(FileInfo LedControlIniFile,
int LedWizNumber,
bool ThrowExceptions =
false)
308 ParseLedControlIni(LedControlIniFile, ThrowExceptions);
309 this.LedWizNumber = LedWizNumber;