private void TryEnableLogger() { if (!logger.Enable()) { if (logger.LastException != null) { Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { Button1 = Dialog.ButtonType.OK, Button2 = Dialog.ButtonType.Retry, Button3 = Dialog.ButtonType.None, DefaultInput = string.Empty, Message = "Unable to start logger :\n" + logger.LastException, Title = "Error" }; Dialog.ShowDialogResult result = Dialog.ShowDialog(dialogConfig); if (result.DialogResult == Dialog.DialogResult.Retry) { TryEnableLogger(); } } else { MessageBox.Show("Unable to start logger, contact support", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button2_Click(object sender, EventArgs e) { var t = ((Dialog.ButtonType[])Enum.GetValues(typeof(Dialog.ButtonType))); var t2 = ((Dialog.DialogIcon[])Enum.GetValues(typeof(Dialog.DialogIcon))); Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { CustomButton1Text = mB1.Text, CustomButton2Text = mB2.Text, CustomButton3Text = mB3.Text, Message = mMsg.Text, Title = mTitle.Text, DefaultInput = mDInput.Text, Input = true, Button1 = t[mL1.SelectedIndex], Button2 = t[mL2.SelectedIndex], Button3 = t[mL3.SelectedIndex], Icon = t2[mI1.SelectedIndex], }; label1.Text = string.Empty; var t3 = Dialog.ShowDialog(dialogConfig); label1.Text = t3.DialogResult.ToString(); mInput.Text = t3.UserInput; }
private void btnName_Click(object sender, EventArgs e) { if (listHtml2.CheckedItems.Count == 0) { statusStripText.Text = "No name selected"; } else { for (short i = 0; i < htmlFilesOutput.Count; i++) { if (listHtml2.GetItemChecked(i)) { Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { Message = "Enter a new name for : " + htmlFilesOutput.Values.ElementAt(i), Title = "Enter filename", DefaultInput = "", Button1 = Dialog.ButtonType.Skip, Button2 = Dialog.ButtonType.OK, Button3 = Dialog.ButtonType.Cancel, }; var result = Dialog.ShowDialog(dialogConfig); if (result.DialogResult == Dialog.DialogResult.OK) { htmlFilesOutput[htmlFilesOutput.ElementAt(i).Key] = result.UserInput; } else if (result.DialogResult == Dialog.DialogResult.Cancel) { i = (short)htmlFilesOutput.Count; } } } listHtml2.Items.Clear(); listHtml2.Items.AddRange(htmlFilesOutput.Values.ToArray()); } }
private async void CheckUpdate() { try { //MessageBox.Show(System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()); UpdateChecker update = new UpdateChecker(@"http://www.esseivan.ch/files/softwares/resistortool/infos.xml", System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()); update.CheckUpdates(); if (update.Result.ErrorOccurred) { Tools.WriteLog(0, update.Result.Error.ToString(), Logger.Log_level.Error); MessageBox.Show(update.Result.Error.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (update.NeedUpdate()) { // Update available Tools.WriteLog(0, "Update available", Logger.Log_level.Info); var result = update.Result; Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { Message = $"Update is available, do you want to download ?\nCurrent: { result.CurrentVersion}\nLast: { result.LastVersion}", Title = "Update available", Button1 = Dialog.ButtonType.Custom1, CustomButton1Text = "Visit website", Button2 = Dialog.ButtonType.Custom2, CustomButton2Text = "Download and install", Button3 = Dialog.ButtonType.Cancel, }; var dr = Dialog.ShowDialog(dialogConfig); if (dr.DialogResult == Dialog.DialogResult.Custom1) { Tools.WriteLog(0, "Openning website", Logger.Log_level.Debug); // Visit website result.OpenUpdateWebsite(); } else if (dr.DialogResult == Dialog.DialogResult.Custom2) { Tools.WriteLog(0, "Downloading and installing update", Logger.Log_level.Info); // Download and install if (await result.DownloadUpdate()) { Tools.WriteLog(0, "Download complete, closing app to let install continue", Logger.Log_level.Info); Close(); } else { Tools.WriteLog(0, "Download failed", Logger.Log_level.Error); MessageBox.Show("Unable to download update", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { Tools.WriteLog(0, "Up to date ; " + update.Result.LastVersion, Logger.Log_level.Info); MessageBox.Show("No new release found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Tools.WriteLog(0, ex.ToString(), Logger.Log_level.Error); MessageBox.Show($"Unknown error :\n{ex.ToString()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Check for update and ask user what action to do, the result is then returned /// <para>Return result is object array, size of 3 :</para> /// <para>0 : type is CheckUpdateResult (or null if error ocurred at bad place)</para> /// <para>1 : type is CheckUpdateAndAsk_Result</para> /// <para>2 : type is Exception (if ocurred) or null</para> /// </summary> public static object[] CheckUpdateAndAsk(string url, string currentVersion) { object[] output = new object[3]; output[0] = null; output[1] = CheckUpdateAndAsk_Result.None; output[2] = null; try { //showMessage_func(System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()); UpdateChecker update = new UpdateChecker(url, currentVersion); update.CheckUpdates(); if (update.Result.ErrorOccurred) { output[0] = update.Result; output[1] = CheckUpdateAndAsk_Result.Error; output[2] = update.Result.Error; return(output); } if (update.NeedUpdate()) { // Update available var result = update.Result; output[0] = result; Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { Message = $"Update is available, do you want to download ?\nCurrent: { result.CurrentVersion}\nLast: { result.LastVersion}", Title = "Update available", Button1 = Dialog.ButtonType.Custom1, CustomButton1Text = "Visit website", Button2 = Dialog.ButtonType.Custom2, CustomButton2Text = "Download and install", Button3 = Dialog.ButtonType.Cancel, }; var dr = Dialog.ShowDialog(dialogConfig); if (dr.DialogResult == Dialog.DialogResult.Custom1) { // Visit website output[1] = CheckUpdateAndAsk_Result.User_OpenWebsite; } else if (dr.DialogResult == Dialog.DialogResult.Custom2) { // Download and install output[1] = CheckUpdateAndAsk_Result.User_Install; } else { output[1] = CheckUpdateAndAsk_Result.User_DoNothing; } } else { output[1] = CheckUpdateAndAsk_Result.NoUpdate; } } catch (Exception ex) { output[1] = CheckUpdateAndAsk_Result.UnknownError; output[2] = ex; } return(output); }
private static bool CheckUpdate(UpdateChecker update, bool silent) { try { //MessageBox.Show(System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()); update.CheckUpdates(); if (update.Result.ErrorOccurred) { if (!silent) { MessageBox.Show(update.Result.Error.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Console.Error.WriteLine($"ERROR : {update.Result.Error.ToString()}"); } return(false); } if (update.NeedUpdate()) { // Update available var result = update.Result; Dialog.DialogConfig dialogConfig = new Dialog.DialogConfig() { Button1 = Dialog.ButtonType.Custom1, CustomButton1Text = "Visit website", Button2 = Dialog.ButtonType.Custom2, CustomButton2Text = "Download and install", Button3 = Dialog.ButtonType.Cancel, Message = $"Update is available, do you want to download ?\nCurrent : {result.CurrentVersion}\nLast : {result.LastVersion}", Title = "Update available", }; var dialogResult = Dialog.ShowDialog(dialogConfig); if (dialogResult.DialogResult == Dialog.DialogResult.Custom1) { // Visit website result.OpenUpdateWebsite(); } else if (dialogResult.DialogResult == Dialog.DialogResult.Custom2) { return(true); } } else { if (!silent) { MessageBox.Show("No update avaiable", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Console.WriteLine("Already up to date"); } } } catch (Exception ex) { if (!silent) { MessageBox.Show($"Unknown error :\n{ex}\n\n{ex.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Console.Error.WriteLine($"UNKNWON ERROR :\n{ex}\n\n{ex.StackTrace}"); } } return(false); }