Created
April 27, 2024 12:26
-
-
Save dustinlacewell/c85c7a5a5598031059bfe40d68a03356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Diagnostics; | |
using System.Collections.Generic; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Attempt to read the configuration file | |
Dictionary<string, string> config = ReadConfiguration("Config.txt"); | |
if (config.TryGetValue("SABAKI_PATH", out string sabakiPath)) | |
{ | |
if (args.Length > 0) | |
{ | |
// Ensure the first argument is correctly handled | |
string firstArg = args[0]; | |
// Wrap the argument in double quotes to handle spaces or special characters | |
string formattedArg = "\"" + firstArg + "\""; | |
Console.WriteLine("Executing Sabaki with argument: " + formattedArg); | |
// Define the process to start | |
ProcessStartInfo startInfo = new ProcessStartInfo | |
{ | |
FileName = sabakiPath, | |
Arguments = formattedArg, | |
UseShellExecute = true | |
}; | |
try | |
{ | |
// Start the process | |
Process.Start(startInfo); | |
} | |
catch (Exception ex) | |
{ | |
// If there is an error, print it | |
Console.Error.WriteLine("Error starting Sabaki: " + ex.Message); | |
} | |
} | |
else | |
{ | |
Console.Error.WriteLine("No arguments were provided."); | |
} | |
} | |
else | |
{ | |
Console.Error.WriteLine("SABAKI_PATH not found in Config.txt."); | |
} | |
} | |
static Dictionary<string, string> ReadConfiguration(string filePath) | |
{ | |
Dictionary<string, string> config = new Dictionary<string, string>(); | |
try | |
{ | |
foreach (var line in File.ReadLines(filePath)) | |
{ | |
if (!string.IsNullOrWhiteSpace(line) && line.Contains("=")) | |
{ | |
// Splitting with a char array, compatible with more versions of .NET | |
var parts = line.Split(new[] { '=' }, 2); | |
if (parts.Length == 2) | |
{ | |
string key = parts[0].Trim(); | |
string value = parts[1].Trim(); | |
config[key] = value; | |
} | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.Error.WriteLine($"Error reading configuration file: {ex.Message}"); | |
} | |
return config; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment