fix(*): Make DayCreator cross-platform

This commit is contained in:
Josh Creek
2022-10-13 12:40:30 +01:00
parent c5be2fd048
commit c2752a38cc
+10 -7
View File
@@ -12,19 +12,22 @@ var day = Console.ReadLine().PadLeft(2, '0'); ;
var currentLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
int ix = currentLocation.IndexOf("DayCreator");
var newPathBase = currentLocation.Substring(0, ix - 1);
var newDayCreatorBase = currentLocation.Substring(0, ix + "DayCreator".Length);
string yearPath = Path.GetFullPath(Path.Combine(newPathBase, $@"AOC.Tests\Y{year}\"));
string dataPath = Path.GetFullPath(Path.Combine(yearPath, $@"Data\"));
string tasksPath = Path.GetFullPath(Path.Combine(yearPath, $@"Tasks\"));
string yearPath = Path.GetFullPath(Path.Combine(newPathBase, "AOC.Tests", $"Y{year}"));
string dataPath = Path.GetFullPath(Path.Combine(yearPath, "Data", $"Day{day}.dat"));
string tasksPath = Path.GetFullPath(Path.Combine(yearPath, "Tasks", $"Day{day}.txt"));
// Create data file
using (FileStream fs = File.Create($"{dataPath}Day{day}.dat"));
using (FileStream fs = File.Create(dataPath));
// Create task file
using (FileStream fs = File.Create($"{tasksPath}Day{day}.txt"));
using (FileStream fs = File.Create(tasksPath));
// Create code file
string text = File.ReadAllText("DayX.cs");
var dayXPath = Path.GetFullPath(Path.Combine(newDayCreatorBase, "DayX.cs"));
string text = File.ReadAllText(dayXPath);
text = text.Replace("YX", $"Y{year}");
text = text.Replace("DayX", $"Day{day}");
File.WriteAllText($"{yearPath}Day{day}.cs", text);
var writePath = Path.GetFullPath(Path.Combine(yearPath, $"Day{day}.cs"));
File.WriteAllText(writePath, text);