Skip to content

Commit

Permalink
Allow the program to be ran from a different directory
Browse files Browse the repository at this point in the history
- Also fix potential issue with MacOS #8
  • Loading branch information
pixeltris committed May 12, 2020
1 parent 8d1cd7b commit b5b20e9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions GK6X/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ namespace GK6X
{
class Program
{
public static readonly string DataBasePath = "Data";
public static readonly string UserDataPath = "UserData";
public static string BasePath;
public static string DataBasePath = "Data";
public static string UserDataPath = "UserData";

static void Main(string[] args)
{
BasePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
DataBasePath = Path.Combine(BasePath, DataBasePath);
UserDataPath = Path.Combine(BasePath, UserDataPath);

if (!Localization.Load())
{
LogFatalError("Failed to load localization data");
Expand Down Expand Up @@ -68,9 +73,22 @@ static void Main(string[] args)
KeyboardDeviceManager.StartListener();

bool running = true;
bool hasNullInput = false;
while (running)
{
string line = Console.ReadLine();
if (line == null)
{
// Handler for potential issue where ReadLine() returns null - see https://github.com/pixeltris/GK6X/issues/8
if (hasNullInput)
{
Console.WriteLine("Cannot read from command line. Exiting.");
break;
}
hasNullInput = true;
continue;
}
hasNullInput = false;
string[] splitted = line.Split();
switch (splitted[0].ToLower())
{
Expand Down Expand Up @@ -297,7 +315,7 @@ internal static void Log(string str)
{
lock (logLocker)
{
File.AppendAllText("KbLog.txt", "[" + DateTime.Now.TimeOfDay + "] " + str + Environment.NewLine);
File.AppendAllText(Path.Combine(BasePath, "KbLog.txt"), "[" + DateTime.Now.TimeOfDay + "] " + str + Environment.NewLine);
Console.WriteLine(str);
}
}
Expand Down

0 comments on commit b5b20e9

Please sign in to comment.