Fix Linux distro being mistakenly logged, log values read from config

pull/32/head
Miepee 4 years ago
parent d50fe6244d
commit 10dc1fbaa8

@ -53,8 +53,8 @@ internal static class MainClass
string osRelease = File.ReadAllText("/etc/os-release"); string osRelease = File.ReadAllText("/etc/os-release");
Regex lineRegex = new Regex(".*=.*"); Regex lineRegex = new Regex(".*=.*");
List<Match> results = lineRegex.Matches(osRelease).ToList(); List<Match> results = lineRegex.Matches(osRelease).ToList();
Match version = results.FirstOrDefault(x => x.Value.Contains("VERSION")); Match version = results.FirstOrDefault(x => x.Value.StartsWith("VERSION"));
string distroName = results.FirstOrDefault(x => x.Value.Contains("NAME"))?.Value[5..].Replace("\"", ""); string distroName = results.FirstOrDefault(x => x.Value.StartsWith("NAME"))?.Value[5..].Replace("\"", "");
string versionName = version == null ? "" : version.Value[8..].Replace("\"", ""); string versionName = version == null ? "" : version.Value[8..].Replace("\"", "");
log.Info($"Current Distro: {distroName} {versionName}"); log.Info($"Current Distro: {distroName} {versionName}");
} }

@ -123,13 +123,14 @@ public partial class MainForm : Form
/// <returns>The value from <paramref name="property"/> as a string</returns> /// <returns>The value from <paramref name="property"/> as a string</returns>
public static string ReadFromConfig(string property) public static string ReadFromConfig(string property)
{ {
log.Info($"Reading {property} from config.");
if (OS.IsWindows) if (OS.IsWindows)
{ {
// We use the configuration manager in order to read `property` from the app.config and then return it // We use the configuration manager in order to read `property` from the app.config and then return it
ConnectionStringSettings appConfig = ConfigurationManager.ConnectionStrings[property]; ConnectionStringSettings appConfig = ConfigurationManager.ConnectionStrings[property];
if (appConfig == null) throw new ArgumentException("The property " + property + " could not be found."); if (appConfig == null) throw new ArgumentException("The property " + property + " could not be found.");
return appConfig.ConnectionString; string value = appConfig.ConnectionString;
log.Info($"Reading {property} from config with value {value}.");
return value;
} }
if (OS.IsUnix) if (OS.IsUnix)
{ {
@ -148,7 +149,9 @@ public partial class MainForm : Form
launcherConfig = Serializer.Deserialize<XML.LauncherConfigXML>(File.ReadAllText(launcherConfigFilePath)); launcherConfig = Serializer.Deserialize<XML.LauncherConfigXML>(File.ReadAllText(launcherConfigFilePath));
// This uses the indexer, which means, we can use the variable in order to get the property. Look at LauncherConfigXML for more info // This uses the indexer, which means, we can use the variable in order to get the property. Look at LauncherConfigXML for more info
return launcherConfig[property]?.ToString(); string value = launcherConfig[property]?.ToString();
log.Info($"Reading {property} from config with value {value}.");
return value;
} }
log.Error(OS.Name + " has no config to read from!"); log.Error(OS.Name + " has no config to read from!");

Loading…
Cancel
Save