public static string ShowSimple(string msg, string[] buttons) { var dialog = new Dialog { Message = msg, Buttons = buttons.Select(t => new DialogButton { Text = t }).ToList(), }; var btn = dialog.ShowDialog(); return btn.Text; }
public static SuccessSkip UIDeleteFile(string file) { if (string.IsNullOrEmpty(file) || !File.Exists(file)) return SuccessSkip.Success; new FileInfo(file).Attributes = FileAttributes.Normal; while (true) { try { File.Delete(file); return SuccessSkip.Success; } catch (Exception ex) { var btn = new Dialog { Title = "Delete file failed", Message = string.Format("File: {0}\r\nError: {1}", file, ex.Message), Buttons = new List<DialogButton> { new DialogButton{Text="Retry"}, new DialogButton{Text="Abort"}, new DialogButton{Text="Skip"}, } }.ShowDialog(); if (btn == null || btn.Text == "Abort") { throw new Exception("Installation aborted"); } else if (btn.Text == "Skip") { return SuccessSkip.Skip; } else { //retry } }; } }
public static SuccessSkip UIDeleteDirectory(string dir, bool recursive = true) { if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) return SuccessSkip.Success; new DirectoryInfo(dir).Attributes = FileAttributes.Normal; while (true) { try { Directory.Delete(dir, recursive); return SuccessSkip.Success; } catch (Exception ex) { var btn = new Dialog { Title = "Delete directory failed", Message = string.Format("Directory: {0}\r\nError: {1}", dir, ex.Message), Buttons = new List<DialogButton> { new DialogButton{Text="Retry"}, new DialogButton{Text="Abort"}, new DialogButton{Text="Skip"}, } }.ShowDialog(); if (btn == null || btn.Text == "Abort") { throw new Exception("Installation aborted"); } else if (btn.Text == "Skip") { return SuccessSkip.Skip; //TODO: } else { //retry } }; } }
public static SuccessSkip UICopyOverwrite(string source, string dest) { var checkedEqual = false; while (true) { try { File.Copy(source, dest, true); return SuccessSkip.Success; } catch (Exception e) { if (!checkedEqual && FileHelper.IsFilesContentEqual(source, dest)) return SuccessSkip.Skip; else checkedEqual = true; var btn = new Dialog { Title = "Copy file failed", Message = string.Format("Filename: {0}\r\nError: {1}", dest, e.Message), Buttons = new List<DialogButton> { new DialogButton{Text="Retry"}, new DialogButton{Text="Abort"}, new DialogButton{Text="Skip"}, } }.ShowDialog(); if (btn == null || btn.Text == "Abort") { throw new Exception("Installation aborted"); } else if (btn.Text == "Skip") { return SuccessSkip.Skip; } else { //retry } } } }