88 lines
2.0 KiB
C#
88 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Test_EnvSetzen
|
|
{
|
|
class UgiiEnvParser
|
|
{
|
|
public UgiiEnvParser(string filename)
|
|
{
|
|
ParseUgiiEnv(filename);
|
|
}
|
|
|
|
private void ParseUgiiEnv(string filename)
|
|
{
|
|
//ugii_env-Parser
|
|
string line;
|
|
System.IO.StreamReader file = new System.IO.StreamReader(filename);
|
|
|
|
string ifValue = "";
|
|
string env = "";
|
|
string value = "";
|
|
|
|
while ((line = file.ReadLine()) != null)
|
|
{
|
|
if (line.ToLower().StartsWith("#if"))
|
|
{
|
|
if (line.ToLower().Contains("file"))
|
|
{
|
|
ifValue = ReplaceVariableThroughValue(line.Remove(0, line.ToLower().IndexOf("file") + 5));
|
|
|
|
if (File.Exists(ifValue))
|
|
{
|
|
line = file.ReadLine();
|
|
|
|
if (line.Contains("="))
|
|
{
|
|
env = line.Remove(line.IndexOf("="));
|
|
value = ReplaceVariableThroughValue(line.Remove(0, line.IndexOf("=") + 1));
|
|
Environment.SetEnvironmentVariable(env, value);
|
|
}
|
|
|
|
while ((line = file.ReadLine().ToLower()) != "#endif")
|
|
{
|
|
//Bis zum Ende der If-Anweisung einlesen
|
|
}
|
|
}
|
|
else
|
|
{
|
|
line = file.ReadLine(); //Wertezeile nach der If-Anweisung
|
|
line = file.ReadLine(); //Zeile nach der Wertezeile
|
|
|
|
if (line.ToLower() == "else")
|
|
{
|
|
line = file.ReadLine();
|
|
|
|
env = line.Remove(line.IndexOf("="));
|
|
value = ReplaceVariableThroughValue(line.Remove(0, line.IndexOf("=") + 1));
|
|
Environment.SetEnvironmentVariable(env, value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (line.Contains("=") & !line.StartsWith("#"))
|
|
{
|
|
env = line.Remove(line.IndexOf("="));
|
|
value = ReplaceVariableThroughValue(line.Remove(0, line.IndexOf("=") + 1));
|
|
Environment.SetEnvironmentVariable(env, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
file.Close();
|
|
}
|
|
|
|
private string ReplaceVariableThroughValue(string value)
|
|
{
|
|
var rv = new ReplaceVariable();
|
|
return rv.ExtractVariable(value);
|
|
}
|
|
}
|
|
}
|