mirror of
https://github.com/jcreek/advent-of-code.git
synced 2026-07-13 03:03:46 +00:00
fix(*): Make DayCreator cross-platform
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user