Example #1
0
        /// <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);
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }