Skip to content

Commit

Permalink
Added possibility to provide a config file name as a program argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Blondazz committed Jun 6, 2023
1 parent 20af77f commit f1042be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions KeyOverlay/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class AppWindow
private Clock _clock = new();


public AppWindow()
public AppWindow(string configFileName)
{
var config = ReadConfig();
var config = ReadConfig(configFileName);
var windowWidth = config["windowWidth"];
var windowHeight = config["windowHeight"];
_window = new RenderWindow(new VideoMode(uint.Parse(windowWidth!), uint.Parse(windowHeight!)),
Expand Down Expand Up @@ -101,10 +101,12 @@ public AppWindow()
_counter = true;
}

private Dictionary<string, string> ReadConfig()
private Dictionary<string, string> ReadConfig(string configFileName)
{
var objectDict = new Dictionary<string, string>();
var file = File.ReadLines("config.txt").ToArray();
var file = configFileName == null ?
File.ReadLines("config.txt").ToArray() :
File.ReadLines(configFileName).ToArray();
foreach (var s in file) objectDict.Add(s.Split("=")[0], s.Split("=")[1]);
return objectDict;
}
Expand Down
3 changes: 2 additions & 1 deletion KeyOverlay/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;

namespace KeyOverlay
{
Expand All @@ -10,7 +11,7 @@ private static void Main(string[] args)
AppWindow window;
try
{
window = new AppWindow();
window = new AppWindow(args.FirstOrDefault());
}
catch (Exception e)
{
Expand Down

0 comments on commit f1042be

Please sign in to comment.