public static void TryDeleteDirectoryIfExists(string path, IMessagePrinter printer) { try { DeleteDirectoryIfExists(path); } catch (Exception exc) { printer.PrintError($"An error occurred when deleting folder {path}: {exc.Message}"); } }
public static void TryDeleteDirectoryIfExists(string path, IMessagePrinter printer) { try { DeleteDirectoryIfExists(path); } catch (Exception exc) { printer.PrintError($"删除文件夹时发生错误 {path}: {exc.Message}"); } }
public void RemoveComponentIfAllowed(string component, IMessagePrinter printer) { if (!HasBeenExtracted()) { ExtractAndLock(); } printer.PrintHeading($"Running install-wim-tweak to remove {component}..."); int exitCode = SystemUtils.RunProcessBlockingWithOutput(extractedFilePath, $"/o /c {component} /r", printer); if (exitCode == SystemUtils.EXIT_CODE_SUCCESS) { printer.PrintMessage("Install-wim-tweak executed successfully!"); } else { printer.PrintError($"An error occurred during the removal of {component}: " + "install-wim-tweak exited with a non-zero status."); } }
public static int RunProcessBlockingWithOutput(string name, string args, IMessagePrinter printer) { using var process = CreateProcessInstance(name, args); process.OutputDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintMessage(evt.Data); } }; process.ErrorDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintError(evt.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); return(process.ExitCode); }
public void PrintError(string message, bool newLine = true) { msgPrinter.PrintError(message, newLine); }
/// <summary> /// Output error message and re-read input /// </summary> /// <param name="message"></param> private string PrintErrorAndRead(string message) { msgPrinter.PrintError(message); return(Console.ReadLine()); }