string[] DiffTheAnswer(FileInfo fileinfo, string txtOutPath, string diffOutPath, string answerPath, bool force = false) { var txtpath = new FileInfo($"{txtOutPath}{fileinfo.Name}.txt").FullName; var diffpath = $"{diffOutPath}{fileinfo.Name}.diff"; var diffOut = ""; var diffResult = new ExecProgramResult() { ExitCode = 0, StdOut = "", StdErr = "" }; if (force || !File.Exists(diffpath)) { diffResult = ExecProgram( @"C:\Windows\System32\cmd.exe", $"/c diff -w -y \"{answerPath}\" \"{txtpath}\""); if (string.IsNullOrWhiteSpace(diffResult.StdOut)) { diffOut = "No diff"; } else { diffOut = diffResult.StdOut; } File.WriteAllText(diffpath, diffOut); return(new string[] { diffpath, diffOut }); } return(new string[] { diffpath, File.ReadAllText(diffpath) }); }
string[] CompileAndExecCpp(FileInfo fileinfo, string exeOutPath, string txtOutPath, string[] input, bool force = false) { var exepath = $"{new DirectoryInfo(exeOutPath).FullName}{fileinfo.Name}.exe"; var txtpath = $"{txtOutPath}{fileinfo.Name}.txt"; var compileResult = new ExecProgramResult() { ExitCode = 0, StdOut = "", StdErr = "" }; var execResult = new ExecProgramResult() { ExitCode = 0, StdOut = "", StdErr = "" }; if (force || !File.Exists(exepath)) { string header = $"{fileinfo.DirectoryName}\\{Path.GetFileNameWithoutExtension(fileinfo.Name)}class.h"; string headerCpp = $"{fileinfo.DirectoryName}\\{Path.GetFileNameWithoutExtension(fileinfo.FullName)}class.cpp"; compileResult = ExecProgram( @"C:\Windows\System32\cmd.exe", $"/c g++ \"{fileinfo.FullName}\" -o \"{exepath}\""); if (compileResult.ExitCode != 0) { File.WriteAllText(txtpath, compileResult.StdErr); return(new string[] { txtpath, compileResult.StdErr }); } } if (force || !File.Exists(txtpath)) { execResult = ExecProgram(@"C:\Windows\System32\cmd.exe", $"/c \"{exepath}\"", input); File.WriteAllText(txtpath, execResult.StdOut); return(new string[] { txtpath, execResult.StdOut }); } return(new string[] { txtpath, File.ReadAllText(txtpath) }); }