29 lines
879 B
C#
29 lines
879 B
C#
using Microsoft.Extensions.Configuration;
|
|
using System.Windows;
|
|
|
|
namespace PamhagenSysCtrl.Helpers {
|
|
public class Config {
|
|
|
|
private static readonly string[] TrueValues = ["1", "true", "yes", "on"];
|
|
|
|
private readonly string FileName;
|
|
|
|
public string PlcPort = "COM1";
|
|
|
|
public Config(string filename) {
|
|
FileName = filename;
|
|
Read();
|
|
}
|
|
|
|
public void Read() {
|
|
try {
|
|
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
|
PlcPort = config["plc:port"] ?? "COM1";
|
|
} catch (Exception exc) {
|
|
MessageBox.Show($"Die Konfigurationsdatei konnte nicht gelesen werden:\n\n{exc.Message}", "Konfigurationsdatei lesen", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
App.Current.Shutdown();
|
|
}
|
|
}
|
|
}
|
|
}
|